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.
 
 
 
 
 
 

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