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.
 
 
 
 
 
 

220 lines
7.5 KiB

  1. <template>
  2.   <view class="page">
  3.     <view v-if="ready">
  4.       <l-date-picker
  5.         @input="setValue('ActivitySchedule.Date', $event)"
  6.         :value="getValue('ActivitySchedule.Date')"
  7.         :disabled="!edit"
  8.         title="时间"
  9.       />
  10.       <l-input
  11.         @input="setValue('ActivitySchedule.Address', $event)"
  12.         :value="getValue('ActivitySchedule.Address')"
  13.         :disabled="!edit"
  14.         title="地点"
  15.       />
  16.       <l-input
  17.         @input="setValue('ActivitySchedule.Title', $event)"
  18.         :value="getValue('ActivitySchedule.Title')"
  19.         :disabled="!edit"
  20.         title="主题"
  21.       />
  22.       <l-textarea
  23.         @input="setValue('ActivitySchedule.Content', $event)"
  24.         :value="getValue('ActivitySchedule.Content')"
  25.         :readonly="!edit"
  26.         title="内容"
  27.       />
  28.       <l-textarea
  29.         @input="setValue('ActivitySchedule.Remark', $event)"
  30.         :value="getValue('ActivitySchedule.Remark')"
  31.         :readonly="!edit"
  32.         title="备注"
  33.       />
  34.     </view>
  35.   
  36.     <view v-if="ready" class="bg-white margin-tb padding" style="padding-top: 0; overflow: hidden;">
  37.       <l-button v-if="edit" @click="action('save')" size="lg" color="green" class="block margin-top" block>
  38.         提交保存
  39.       </l-button>
  40.       <l-button v-if="!edit && mode !== 'create'" @click="action('edit')" size="lg" line="orange" class="block margin-top" block>
  41.         编辑本页
  42.       </l-button>
  43.       <l-button v-if="edit && mode !== 'create'" @click="action('reset')" size="lg" line="red" class="block margin-top" block>
  44.         取消编辑
  45.       </l-button>
  46.       <l-button v-if="!edit && mode !== 'create'" @click="action('delete')" size="lg" line="red" class="block margin-top" block>
  47.         删除
  48.       </l-button>
  49.     </view>
  50.   </view>
  51. </template>
  52.   
  53.   
  54. <script>
  55. /*
  56.  * 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架(http://www.learun.cn)
  57.  * Copyright (c) 2013-2020 上海力软信息技术有限公司
  58.  * 创建人:超级管理员
  59.  * 日  期:2020-10-20 09:25
  60.  * 描  述:活动安排
  61.  */
  62.   
  63. /**
  64.  * 本段代码由移动端代码生成器输出,移动端须 2.2.0 版本及以上可以使用
  65.  * 请在移动端 /pages.json 中的 pages 字段中添加一条记录:
  66.  * { "path": "pages/PersonnelManagement/ActivitySchedule/single", "style": { "navigationBarTitleText": "表单详情页" } }
  67.  * 
  68.  * (navigationBarTitleText 字段为本页面的标题文本,可以修改)
  69.  * (必须自行操作该步骤,力软代码生成器不会自动帮您修改 /pages.json 文件)
  70.  */
  71.   
  72. import get from 'lodash/get'
  73. import set from 'lodash/set'
  74. import moment from 'moment'
  75. import customPageMixins from '@/common/custompage.js'
  76.   
  77. export default {
  78.   mixins: [customPageMixins],
  79.   
  80.   data() {
  81.     return {
  82.       // 页面相关参数
  83.       id: null,
  84.       mode: null,
  85.       edit: null,
  86.       ready: false,
  87.   
  88.       // 表单数据
  89.       current: {},
  90.       origin: {},
  91.   
  92.       // 表单项数据结构
  93.       scheme: {
  94.         ActivitySchedule: {
  95.           Date: { type: 'datetime', title: '时间', dateformat: '0' },
  96.           Address: { type: 'text', title: '地点' },
  97.           Title: { type: 'text', title: '主题' },
  98.           Content: { type: 'textarea', title: '内容' },
  99.           Remark: { type: 'textarea', title: '备注' },
  100.         },
  101.   
  102.       },
  103.   
  104.       // 数据源
  105.       dataSource: {
  106.         ActivitySchedule: {
  107.         },
  108.   
  109.       }
  110.     }
  111.   },
  112.   
  113.   async onLoad({ type, id }) {
  114.     await this.init(type, id)
  115.   },
  116.   
  117.   methods: {
  118.     // 页面初始化
  119.     async init(type, id) {
  120.       this.LOADING('加载数据中...')
  121.   
  122.       this.id = id
  123.       this.mode = type
  124.       this.edit = ['create', 'edit'].includes(this.mode)
  125.   
  126.       // 拉取表单数据,同时拉取所有来自数据源的选单数据
  127.       await Promise.all([
  128.   
  129.   
  130.         () => {}
  131.       ])
  132.       await this.fetchForm()
  133.   
  134.       this.ready = true
  135.       this.HIDE_LOADING()
  136.     },
  137.   
  138.     // 加载表单数据
  139.     async fetchForm() {
  140.       if (this.mode === 'create') {
  141.         this.origin = await this.getDefaultForm()
  142.       } else {
  143.         const result = await this.HTTP_GET('/PersonnelManagement/ActivitySchedule/form', this.id)
  144.         this.origin = await this.formatFormData(result)
  145.       }
  146.       this.current = this.COPY(this.origin)
  147.     },
  148.   
  149.     // 点击 「编辑」、「重置」、「保存」、「删除」 按钮
  150.     async action(type) {
  151.       switch (type) {
  152.         case 'edit':
  153.           this.edit = true
  154.           break
  155.   
  156.         case 'reset':
  157.           this.current = this.COPY(this.origin)
  158.           this.edit = false
  159.           break
  160.   
  161.         case 'save':
  162.           const verifyResult = this.verifyForm()
  163.           if (verifyResult.length > 0) {
  164.             this.CONFIRM('表单验证失败', verifyResult.join('\n'))
  165.             return
  166.           }
  167.   
  168.           if (!(await this.CONFIRM('提交确认', '确定要提交本页表单内容吗?', true))) {
  169.             return
  170.           }
  171.   
  172.           this.LOADING('正在提交...')
  173.           const postData = await this.getPostData(this.id)
  174.   
  175.           this.HTTP_POST('/PersonnelManagement/ActivitySchedule/save', postData, '表单提交保存失败').then(success => {
  176.             this.HIDE_LOADING()
  177.             if (!success) {
  178.               return
  179.             }
  180.   
  181.             this.EMIT('PersonnelManagementActivitySchedule-list-change')
  182.             this.NAV_BACK()
  183.             this.TOAST('提交保存成功')
  184.           })
  185.           break
  186.   
  187.         case 'delete':
  188.           if (!(await this.CONFIRM('删除项目', '确定要删除本项吗?', true))) {
  189.             return
  190.           }
  191.   
  192.           this.LOADING('提交删除中...')
  193.           this.HTTP_POST('/PersonnelManagement/ActivitySchedule/delete', this.id, '删除失败').then(success => {
  194.             this.HIDE_LOADING()
  195.             if (!success) {
  196.               return
  197.             }
  198.   
  199.             this.EMIT('PersonnelManagementActivitySchedule-list-change')
  200.             this.NAV_BACK()
  201.             this.this.TOAST('删除成功', 'success')
  202.           })
  203.           break
  204.   
  205.         default: break
  206.       }
  207.     },
  208.   
  209.     // 获取表单值
  210.     getValue(path) {
  211.       return get(this.current, path)
  212.     },
  213.   
  214.     // 设置表单值
  215.     setValue(path, val) {
  216.       set(this.current, path, val)
  217.     }
  218.   }
  219. }
  220. </script>