scanForm.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. const organizeIdList = this.userInfo.organizeIdList
  125. if (config.jnpfKey === 'organizeSelect' && Array.isArray(organizeIdList) &&
  126. organizeIdList.length) {
  127. config.defaultValue = item.multiple ? [organizeIdList] : organizeIdList
  128. }
  129. const departmentId = this.userInfo.departmentId
  130. if (config.jnpfKey === 'depSelect' && departmentId) {
  131. config.defaultValue = item.multiple ? [departmentId] : departmentId;
  132. }
  133. const positionIds = this.userInfo.positionIds
  134. if (config.jnpfKey === 'posSelect' && Array.isArray(positionIds) && positionIds
  135. .length) {
  136. config.defaultValue = item.multiple ? positionIds.map(o => o.id) : positionIds[
  137. 0].id
  138. }
  139. const roleIds = this.userInfo.roleIds
  140. if (config.jnpfKey === 'roleSelect' && Array.isArray(roleIds) && roleIds.length) {
  141. config.defaultValue = item.multiple ? roleIds : roleIds[0];
  142. }
  143. const groupIds = this.userInfo.groupIds
  144. if (config.jnpfKey === 'groupSelect' && Array.isArray(groupIds) && groupIds
  145. .length) {
  146. config.defaultValue = item.multiple ? groupIds : groupIds[0];
  147. }
  148. const userId = this.userInfo.userId
  149. if (config.jnpfKey === 'userSelect' && userId) {
  150. config.defaultValue = item.multiple ? [userId] : userId;
  151. }
  152. if (config.jnpfKey === 'usersSelect' && userId) {
  153. config.defaultValue = item.multiple ? [userId + '--user'] : userId + '--user';
  154. }
  155. if (config.jnpfKey === 'sign' && this.userInfo.signImg) {
  156. config.defaultValue = this.userInfo.signImg
  157. }
  158. }
  159. }
  160. this.$set(item, 'disabled', true)
  161. let noShow = !item.__config__.noShow ? false : item.__config__.noShow
  162. let isVisibility = false
  163. if (!item.__config__.visibility || (Array.isArray(item.__config__.visibility) && item
  164. .__config__.visibility.includes('app'))) isVisibility = true
  165. this.$set(item.__config__, 'isVisibility', isVisibility)
  166. this.$set(item.__config__, 'noShow', noShow)
  167. } else {
  168. let noShow = false,
  169. isVisibility = false
  170. if (!item.__config__.visibility || (Array.isArray(item.__config__.visibility) && item
  171. .__config__.visibility.includes('app'))) isVisibility = true
  172. this.$set(item.__config__, 'isVisibility', isVisibility)
  173. this.$set(item.__config__, 'noShow', noShow)
  174. }
  175. if (item.__config__ && item.__config__.jnpfKey !== 'table' && item.__config__.children && Array
  176. .isArray(item.__config__.children)) {
  177. loop(item.__config__.children)
  178. }
  179. }
  180. }
  181. loop(form.fields)
  182. },
  183. }
  184. }
  185. </script>
  186. <style lang="scss">
  187. page {
  188. background-color: #f0f2f6;
  189. }
  190. .dynamicModel-v {
  191. height: 100%;
  192. }
  193. </style>