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.
 
 
 
 
 
 

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