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.
 
 
 
 
 
 

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