Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pirms 4 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="page">
  3. <!-- 渲染表单 -->
  4. <l-customform v-if="ready" :initFormValue="current" :editMode="editMode" :scheme="scheme" ref="form" />
  5. <!-- 操作区按钮 -->
  6. <view v-if="ready" class="padding bg-white margin-tb">
  7. <l-button v-if="editMode" @click="action('save')" size="lg" color="green" class="block" block>提交保存</l-button>
  8. <l-button v-else @click="action('edit')" size="lg" color="orange" class="block" block>编辑本页</l-button>
  9. <l-button
  10. v-if="mode !== 'create' && editMode"
  11. @click="action('reset')"
  12. class="block margin-top"
  13. size="lg"
  14. line="red"
  15. block
  16. >
  17. 取消编辑
  18. </l-button>
  19. <l-button
  20. v-if="mode !== 'create' && !editMode"
  21. @click="action('delete')"
  22. class="block margin-top"
  23. size="lg"
  24. color="red"
  25. block
  26. >
  27. 删除
  28. </l-button>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import customAppFormMixins from './customapp.js'
  34. export default {
  35. mixins: [customAppFormMixins],
  36. data() {
  37. return {
  38. id: '',
  39. schemeId: '',
  40. mode: '',
  41. editMode: false,
  42. ready: false,
  43. scheme: [],
  44. current: {},
  45. origin: {}
  46. }
  47. },
  48. async onLoad({ type, id }) {
  49. await this.init(type, id)
  50. },
  51. methods: {
  52. // 页面初始化
  53. async init(type, id) {
  54. this.LOADING('加载数据中…')
  55. const schemeData = this.GET_PARAM()
  56. this.schemeId = schemeData.F_SchemeInfoId
  57. this.id = id
  58. this.mode = type
  59. this.editMode = ['create', 'edit'].includes(this.mode)
  60. const formData = this.mode !== 'create' ? await this.fetchFormData(this.schemeId, this.id) : null
  61. const keyValue = this.mode !== 'create' ? this.id : null
  62. const { formValue, scheme } = await this.getCustomAppForm({ schemeData, formData, keyValue })
  63. this.scheme = scheme
  64. this.origin = formValue
  65. this.current = this.COPY(this.origin)
  66. this.ready = true
  67. this.HIDE_LOADING()
  68. },
  69. // 拉取表单的 formData
  70. async fetchFormData(schemeInfoId, keyValue) {
  71. const result = await this.HTTP_GET('/form/data', [{ schemeInfoId, keyValue }], '加载表单失败')
  72. return result || {}
  73. },
  74. // 点击编辑、重置、提交保存、删除按钮
  75. async action(type) {
  76. switch (type) {
  77. case 'edit':
  78. this.editMode = true
  79. return
  80. case 'reset':
  81. this.editMode = false
  82. this.current = this.COPY(this.origin)
  83. this.$refs.form.setFormValue(this.current)
  84. return
  85. case 'save':
  86. const verifyResult = this.$refs.form.verifyValue()
  87. if (verifyResult.length > 0) {
  88. this.CONFIRM('表单验证失败', verifyResult.join('\n'))
  89. return
  90. }
  91. if (!(await this.CONFIRM('提交确认', '确定要提交本页表单内容吗?', true))) {
  92. return
  93. }
  94. this.LOADING('正在提交…')
  95. const formValue = this.$refs.form.getFormValue()
  96. const postData = await this.getPostData(formValue, this.scheme)
  97. this.HTTP_POST('/form/save', postData, '表单提交保存失败').then(success => {
  98. this.HIDE_LOADING()
  99. if (!success) {
  100. return
  101. }
  102. this.EMIT('custom-list-change')
  103. this.origin = this.COPY(this.current)
  104. this.mode = 'view'
  105. this.editMode = false
  106. this.TOAST('提交保存成功', 'success')
  107. })
  108. return
  109. case 'delete':
  110. if (!(await this.CONFIRM('删除项目', '确定要删除本项吗?'))) {
  111. return
  112. }
  113. this.HTTP_POST('/form/delete', { schemeInfoId: this.schemeId, keyValue: this.id }).then(success => {
  114. if (!success) {
  115. this.TOAST('删除失败')
  116. return
  117. }
  118. this.EMIT('custom-list-change')
  119. this.NAV_BACK()
  120. this.TOAST('删除成功', 'success')
  121. })
  122. return
  123. default:
  124. return
  125. }
  126. }
  127. }
  128. }
  129. </script>