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 11 KiB

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