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.
 
 
 
 
 
 

292 lines
8.9 KiB

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