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.
 
 
 
 
 
 

218 lines
6.3 KiB

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