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.
 
 
 
 
 
 

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