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.

single.vue 7.0 KiB

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