scanForm.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <view class="dynamicModel-v">
  3. <template v-if="showPage">
  4. <view class="jnpf-wrap jnpf-wrap-form" v-if="config.mt == 2">
  5. <JnpfParser :formConf="formConf" ref="dynamicForm" @submit="sumbitForm" :key="key" />
  6. </view>
  7. <template v-else>
  8. <FlowForm ref="flowForm" />
  9. </template>
  10. </template>
  11. </view>
  12. </template>
  13. <script>
  14. import FlowForm from '@/pages/workFlow/flowBefore/flowForm'
  15. import {
  16. getConfigData,
  17. getModelInfo
  18. } from '@/api/apply/visualDev'
  19. export default {
  20. name: 'scanForm',
  21. components: {
  22. FlowForm
  23. },
  24. data() {
  25. return {
  26. webType: '',
  27. showPage: false,
  28. origin: '',
  29. id: '',
  30. config: {},
  31. formConf: {},
  32. key: +new Date(),
  33. isAdd: false,
  34. userInfo: {}
  35. }
  36. },
  37. onLoad(option) {
  38. this.userInfo = uni.getStorageSync('userInfo') || {}
  39. this.config = JSON.parse(option.config)
  40. this.initData()
  41. },
  42. methods: {
  43. initData() {
  44. this.showPage = false
  45. if (this.config.mt == 2) {
  46. this.getConfigData()
  47. } else {
  48. this.isAdd = true
  49. let data = {
  50. flowId: this.config.fid,
  51. id: this.config.pid,
  52. formType: 2,
  53. opType: this.config.opt,
  54. taskId: this.config.ftid
  55. }
  56. this.showPage = true
  57. this.$nextTick(() => {
  58. this.$refs.flowForm.init(data)
  59. })
  60. }
  61. },
  62. getConfigData() {
  63. getConfigData(this.config.mid).then(res => {
  64. if (res.code !== 200 || !res.data) {
  65. uni.showToast({
  66. title: '暂无此页面',
  67. icon: 'none',
  68. complete: () => {
  69. setTimeout(() => {
  70. uni.navigateBack()
  71. }, 1500)
  72. }
  73. })
  74. return
  75. }
  76. this.formConf = JSON.parse(res.data.formData)
  77. uni.setNavigationBarTitle({
  78. title: res.data.fullName
  79. })
  80. let extra = {
  81. modelId: this.config.mid,
  82. id: this.config.id,
  83. type: this.config.mt
  84. }
  85. uni.setStorageSync('dynamicModelExtra', extra)
  86. getModelInfo(this.config.mid, this.config.id).then(res => {
  87. if (!res.data.data) return
  88. let formData = JSON.parse(res.data.data)
  89. this.fillFormData(this.formConf, formData)
  90. this.$nextTick(() => {
  91. this.showPage = true
  92. this.key = +new Date()
  93. })
  94. })
  95. })
  96. },
  97. fillFormData(form, data) {
  98. const loop = list => {
  99. for (let i = 0; i < list.length; i++) {
  100. let item = list[i]
  101. let vModel = item.__vModel__
  102. let config = item.__config__
  103. if (vModel) {
  104. let val = data.hasOwnProperty(vModel) ? data[vModel] : config.defaultValue
  105. if (!config.isSubTable) config.defaultValue = val
  106. if (this.isAdd || config.isSubTable) { //新增时候,默认当前
  107. if (config.defaultCurrent) {
  108. if (config.jnpfKey === 'datePicker') {
  109. if (!data.hasOwnProperty(vModel)) {
  110. let format = this.jnpf.handelFormat(item.format)
  111. let dateStr = this.jnpf.toDate(new Date().getTime(), format)
  112. let time = format === 'yyyy' ? '-01-01 00:00:00' : format === 'yyyy-MM' ?
  113. '-01 00:00:00' : format === 'yyyy-MM-dd' ?
  114. ' 00:00:00' : ''
  115. val = new Date(dateStr + time).getTime()
  116. config.defaultValue = val
  117. }
  118. }
  119. if (config.jnpfKey === 'timePicker') {
  120. if (!data.hasOwnProperty(vModel)) {
  121. config.defaultValue = this.jnpf.toDate(new Date(), item.format)
  122. }
  123. }
  124. if (config.jnpfKey === 'organizeSelect' && this.userInfo.organizeIds?.length) {
  125. config.defaultValue = item.multiple ? this.userInfo.organizeIds :
  126. this.userInfo.organizeId
  127. }
  128. if (config.jnpfKey === 'posSelect' && this.userInfo.positionIds?.length) {
  129. config.defaultValue = item.multiple ? this.userInfo.positionIds :
  130. this.userInfo.positionId
  131. }
  132. const userId = this.userInfo.userId
  133. if (config.jnpfKey === 'userSelect' && userId) {
  134. config.defaultValue = item.multiple ? [userId] : userId;
  135. }
  136. if (config.jnpfKey === 'usersSelect' && userId) {
  137. config.defaultValue = [userId + '--user'];
  138. }
  139. if (config.jnpfKey === 'sign' && this.userInfo.signImg) {
  140. config.defaultValue = this.userInfo.signImg
  141. }
  142. }
  143. }
  144. this.$set(item, 'disabled', true)
  145. let noShow = !item.__config__.noShow ? false : item.__config__.noShow
  146. let isVisibility = false
  147. if (!item.__config__.visibility || (Array.isArray(item.__config__.visibility) && item
  148. .__config__.visibility.includes('app'))) isVisibility = true
  149. this.$set(item.__config__, 'isVisibility', isVisibility)
  150. this.$set(item.__config__, 'noShow', noShow)
  151. } else {
  152. let noShow = false,
  153. isVisibility = false
  154. if (!item.__config__.visibility || (Array.isArray(item.__config__.visibility) && item
  155. .__config__.visibility.includes('app'))) isVisibility = true
  156. this.$set(item.__config__, 'isVisibility', isVisibility)
  157. this.$set(item.__config__, 'noShow', noShow)
  158. }
  159. if (item.__config__ && item.__config__.jnpfKey !== 'table' && item.__config__.children && Array
  160. .isArray(item.__config__.children)) {
  161. loop(item.__config__.children)
  162. }
  163. }
  164. }
  165. loop(form.fields)
  166. },
  167. }
  168. }
  169. </script>
  170. <style lang="scss">
  171. page {
  172. background-color: #f0f2f6;
  173. }
  174. .dynamicModel-v {
  175. height: 100%;
  176. }
  177. </style>