You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

list.vue 8.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <view class="page">
  3. <!-- 主列表页 -->
  4. <view :class="sideOpen ? 'show' : ''" class="mainpage" style="padding-top: 80rpx;">
  5. <!-- 顶部条目/分页信息栏 -->
  6. <l-customlist-banner @buttonClick="sideOpen = true">{{ tips }}</l-customlist-banner>
  7. <!-- 滚动列表,跨端支持上拉/下拉 -->
  8. <l-scroll-list v-if="ready" @pullDown="pullDown" @toBottom="fetchList()" ref="list">
  9. <l-customlist :tips="loadState" showTips>
  10. <!-- 单条记录 -->
  11. <view class="customlist-item" v-for="item of list" :key="item.ID">
  12. <view class="customlist-item-field">
  13. <text class="customlist-item-field-title">时间:</text>
  14. {{ displayListItem(item, 'Date') }}
  15. </view>
  16. <view class="customlist-item-field">
  17. <text class="customlist-item-field-title">值班人:</text>
  18. {{ displayListItem(item, 'Person') }}
  19. </view>
  20. <view class="customlist-item-field">
  21. <text class="customlist-item-field-title">备注:</text>
  22. {{ displayListItem(item, 'Remark') }}
  23. </view>
  24. <l-customlist-action showEdit @edit="action('edit', item.ID)" showDelete @delete="action('delete', item.ID)" @view="action('view', item.ID)" />
  25. </view>
  26. </l-customlist>
  27. </l-scroll-list>
  28. </view>
  29. <!-- 关闭侧边抽屉按钮 -->
  30. <view @click="sideOpen = false" :class="sideOpen ? 'show' : ''" class="sideclose">
  31. <l-icon type="pullright" color="blue" />
  32. </view>
  33. <!-- 侧边栏,用于设置查询条件 -->
  34. <scroll-view :class="sideOpen ? 'show' : ''" class="sidepage" scroll-y>
  35. <view v-if="ready" class="padding">
  36. <!-- 重置查询条件按钮 -->
  37. <view class="padding-tb">
  38. <l-button @click="reset" line="orange" class="block" block>重置查询条件</l-button>
  39. </view>
  40. </view>
  41. </scroll-view>
  42. <l-customlist-add v-if="!sideOpen" @click="action('add')" />
  43. </view>
  44. </template>
  45. <script>
  46. /*
  47. * 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架(http://www.learun.cn)
  48. * Copyright (c) 2013-2020 上海力软信息技术有限公司
  49. * 创建人:超级管理员
  50. * 日 期:2020-10-20 09:55
  51. * 描 述:值班安排
  52. */
  53. /**
  54. * 本段代码由移动端代码生成器输出,移动端须 2.2.0 版本及以上可以使用
  55. * 请在移动端 /pages.json 中的 pages 字段中添加一条记录:
  56. * { "path": "pages/PersonnelManagement/DutySchedule/list", "style": { "navigationBarTitleText": "表单列表页" } }
  57. *
  58. * (navigationBarTitleText 字段为本页面的标题文本,可以修改)
  59. * (必须自行操作该步骤,力软代码生成器不会自动帮您修改 /pages.json 文件)
  60. */
  61. import moment from 'moment'
  62. import get from 'lodash/get'
  63. import set from 'lodash/set'
  64. import pickBy from 'lodash/pickBy'
  65. import mapValues from 'lodash/mapValues'
  66. export default {
  67. data() {
  68. return {
  69. // 数据项的数据类型、结构
  70. scheme: {
  71. Date: { type: 'datetime', dateformat: '0' },
  72. Person: { type: 'text' },
  73. Remark: { type: 'textarea' },
  74. },
  75. // 查询条件
  76. searchData: {},
  77. defaultQueryData: {},
  78. queryData: {
  79. },
  80. // 数据源
  81. dataSource: {
  82. },
  83. // 页面相关参数
  84. ready: false,
  85. tips: '加载中...',
  86. loadState: '向下翻以加载更多',
  87. sideOpen: false,
  88. // 列表与分页信息
  89. page: 1,
  90. total: 2,
  91. list: []
  92. }
  93. },
  94. async onLoad() {
  95. await this.init()
  96. },
  97. onUnload() {
  98. this.OFF('PersonnelManagementDutySchedule-list-change')
  99. },
  100. methods: {
  101. // 页面初始化
  102. async init() {
  103. this.ON('PersonnelManagementDutySchedule-list-change', this.refreshList)
  104. // 拉取加载列表和数据源
  105. await Promise.all([
  106. () => {}
  107. ])
  108. await this.fetchList()
  109. // 初始化查询条件
  110. this.defaultQueryData = this.COPY(this.queryData)
  111. this.ready = true
  112. },
  113. // 拉取列表
  114. async fetchList() {
  115. if (this.page > this.total) { return }
  116. const result = await this.HTTP_GET(
  117. 'learun/adms/PersonnelManagement/DutySchedule/pagelist',
  118. {
  119. // 这里 sidx 表示排序字段,sord 表示排序方式(DESC=降序,ASC=升序)
  120. // 代码生成器生成时默认按照主键排序,您可以修改成按创建时间的字段降序
  121. pagination: { rows: 10, page: this.page, sidx: 'ID', sord: 'DESC' },
  122. queryJson: JSON.stringify(this.searchData)
  123. },
  124. '加载数据时出错'
  125. )
  126. if (!result) { return }
  127. this.total = result.total
  128. this.page = result.page + 1
  129. this.list = this.list.concat(result.rows)
  130. this.tips = `已加载 ${Math.min(result.page, result.total)} / ${result.total} 页,共 ${result.records} 项`
  131. this.loadState = result.page >= result.total ? '已加载所有项目' : '向下翻以加载更多'
  132. },
  133. // 刷新清空列表
  134. async refreshList() {
  135. this.page = 1
  136. this.total = 2
  137. this.list = []
  138. await this.fetchList()
  139. },
  140. // 列表下拉
  141. pullDown() {
  142. this.refreshList().then(() => {
  143. this.$refs.list.stopPullDown()
  144. })
  145. },
  146. // 设置搜索条件
  147. async searchChange() {
  148. const result = {}
  149. // 将其他查询项添加到查询 JSON 中
  150. const queryObj = pickBy(this.queryData, t => (Array.isArray(t) ? t.length > 0 : t))
  151. Object.assign(result, mapValues(queryObj, t => (Array.isArray(t) ? t.join(',') : t)))
  152. this.searchData = result
  153. await this.refreshList()
  154. },
  155. // 点击「清空查询条件」按钮
  156. reset() {
  157. this.queryData = this.COPY(this.defaultQueryData)
  158. this.searchChange()
  159. },
  160. // 点击「编辑」、「查看」、「添加」、「删除」按钮
  161. async action(type, id = '') {
  162. switch (type) {
  163. case 'view':
  164. this.NAV_TO(`./single?type=view&id=${id}`)
  165. return
  166. case 'add':
  167. this.NAV_TO('./single?type=create')
  168. return
  169. case 'edit':
  170. this.NAV_TO(`./single?type=edit&id=${id}`)
  171. return
  172. case 'delete':
  173. if (!(await this.CONFIRM('删除项目', '确定要删除该项吗?', true))) {
  174. return
  175. }
  176. this.HTTP_POST('learun/adms/PersonnelManagement/DutySchedule/delete', id, '删除失败').then(success => {
  177. if(!success) { return }
  178. this.TOAST('删除成功', 'success')
  179. this.refreshList()
  180. })
  181. return
  182. default:
  183. return
  184. }
  185. },
  186. // 显示列表中的标题项
  187. displayListItem(item, field) {
  188. const fieldItem = this.scheme[field]
  189. const value = item[field]
  190. switch (fieldItem.type) {
  191. case 'currentInfo':
  192. case 'organize':
  193. return fieldItem.dataType === 'time' ? value : get(this.GET_GLOBAL(fieldItem.dataType), `${value}.name`, '')
  194. case 'radio':
  195. case 'select':
  196. const selectItem = this.dataSource[field].find(t => t.value === String(value))
  197. return get(selectItem, 'text', '')
  198. case 'checkbox':
  199. if (!value || value.split(',').length <= 0) { return '' }
  200. const checkboxItems = value.split(',')
  201. return this.dataSource[field].filter(t => checkboxItems.includes(t.value)).map(t => t.text).join(',')
  202. case 'datetime':
  203. if (!value) { return '' }
  204. return moment(value).format(Number(fieldItem.dateformat) === 0 ? 'YYYY年 M月 D日' : 'YYYY-MM-DD HH:mm')
  205. default: return value === null || value === undefined ? '' : value
  206. }
  207. }
  208. }
  209. }
  210. </script>
  211. <style lang="less" scoped>
  212. @import '~@/common/css/sidepage.less';
  213. @import '~@/common/css/customlist.less';
  214. </style>