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.
 
 
 
 
 
 

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