detail.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <view class="dynamicModel-form-v jnpf-wrap jnpf-wrap-form" v-if="showPage">
  3. <uni-nav-bar class='nav' :fixed="true" :statusBar="true" :border="false" height="44">
  4. <view class="nav-left">
  5. <view class="nav-left-text">详情</view>
  6. </view>
  7. </uni-nav-bar>
  8. <Parser :formConf="formConf" :formValue="formData" ref="dynamicForm" v-if="!loading" :key="key"
  9. @toDetail="toDetail" />
  10. <view class="buttom-actions">
  11. <u-button class="buttom-btn" @click.stop="jnpf.goBack">取消</u-button>
  12. <u-button class="buttom-btn" type="primary" @click.stop="handleEdit"
  13. v-if="btnType === 'btn_edit'&&!this.setting.noShowBtn">编辑
  14. </u-button>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import {
  20. getConfig,
  21. createModel,
  22. getDataChange
  23. } from '@/api/apply/webDesign'
  24. import Parser from '@/pages/apply/dynamicModel/components/detail/Parser'
  25. const getFormDataFields = item => {
  26. const config = item.__config__
  27. if (!config || !config.jnpfKey) return true
  28. const jnpfKey = config.jnpfKey
  29. const list = ["input", "textarea", "inputNumber", "switch", "datePicker", "timePicker", "colorPicker", "rate",
  30. "slider", "editor", "link", "text", "alert", 'table', "collapse", 'collapseItem', 'tabItem',
  31. "tab", "row", "card", "groupTitle", "divider", 'location', 'stepItem', 'steps'
  32. ]
  33. const fieldsSelectList = ["radio", "checkbox", "select", "cascader", "treeSelect"]
  34. if (list.includes(jnpfKey) || (fieldsSelectList.includes(jnpfKey) && config.dataType === 'static')) return true
  35. return false
  36. }
  37. export default {
  38. components: {
  39. Parser
  40. },
  41. data() {
  42. return {
  43. showPage: false,
  44. loading: true,
  45. isPreview: '0',
  46. modelId: '',
  47. formConf: {},
  48. formData: {},
  49. dataForm: {
  50. id: '',
  51. data: ''
  52. },
  53. btnType: '',
  54. formPermissionList: {},
  55. formList: [],
  56. encryption: ''
  57. }
  58. },
  59. onLoad(option) {
  60. let config = JSON.parse(this.jnpf.base64.decode(option.config))
  61. this.formPermissionList = !config.currentMenu ? [] : JSON.parse(decodeURIComponent(config.currentMenu))
  62. this.formList = this.formPermissionList.formList
  63. this.btnType = config.jurisdictionType || ''
  64. this.modelId = config.modelId;
  65. this.encryption = config.encryption;
  66. this.isPreview = config.isPreview || '0';
  67. this.dataForm.id = config.id || ''
  68. this.setting = config
  69. this.getConfigData()
  70. uni.$on('refresh', () => {
  71. this.getConfigData()
  72. })
  73. },
  74. beforeDestroy() {
  75. uni.$off('refresh')
  76. },
  77. methods: {
  78. // 递归过滤
  79. recursivefilter(arr, value) {
  80. let newColumn = arr.filter(item => getFormDataFields(item))
  81. newColumn.forEach(x =>
  82. x.__config__ && x.__config__.children && Array.isArray(x.__config__.children) && (x
  83. .__config__.children = this.recursivefilter(x.__config__.children))
  84. )
  85. return newColumn
  86. },
  87. getConfigData() {
  88. this.loading = true
  89. getConfig(this.modelId, this.encryption).then(res => {
  90. if (res.code !== 200 || !res.data) {
  91. uni.showToast({
  92. title: '暂无此页面',
  93. icon: 'none',
  94. complete: () => {
  95. setTimeout(() => {
  96. uni.navigateBack()
  97. }, 1500)
  98. }
  99. })
  100. return
  101. }
  102. this.formConf = res.data.formData ? JSON.parse(res.data.formData) : {};
  103. this.beforeInit(this.formConf.fields || []);
  104. this.showPage = true
  105. this.key = +new Date()
  106. this.initData()
  107. })
  108. },
  109. beforeInit(fields) {
  110. const loop = (list) => {
  111. for (var index = 0; index < list.length; index++) {
  112. const config = list[index].__config__;
  113. if (config.children && config.children.length) loop(config.children);
  114. if (config.jnpfKey == "tableGrid") {
  115. let newList = [];
  116. for (var i = 0; i < config.children.length; i++) {
  117. let element = config.children[i];
  118. for (var j = 0; j < element.__config__.children.length; j++) {
  119. let item = element.__config__.children[j];
  120. newList.push(...item.__config__.children);
  121. }
  122. }
  123. list.splice(index, 1, ...newList);
  124. }
  125. }
  126. };
  127. loop(fields);
  128. },
  129. initData() {
  130. this.$nextTick(() => {
  131. if (this.dataForm.id) {
  132. let extra = {
  133. modelId: this.modelId,
  134. id: this.dataForm.id,
  135. type: 2
  136. }
  137. getDataChange(this.modelId, this.dataForm.id, this.encryption).then(res => {
  138. this.dataForm = res.data
  139. if (!this.dataForm.data) return
  140. this.formData = {
  141. ...JSON.parse(this.dataForm.data),
  142. id: this.dataForm.id
  143. }
  144. let fields = this.recursivefilter(this.formConf.fields)
  145. this.formConf.fields = fields
  146. this.fillFormData(fields, this.formData)
  147. this.initRelationForm(fields)
  148. })
  149. } else {
  150. this.loading = false
  151. }
  152. this.key = +new Date()
  153. })
  154. },
  155. fillFormData(form, data) {
  156. const loop = (list, parent) => {
  157. for (let i = 0; i < list.length; i++) {
  158. let item = list[i]
  159. if (item.__vModel__) {
  160. if (item.__config__.jnpfKey === 'relationForm' || item.__config__.jnpfKey ===
  161. 'popupSelect') {
  162. item.__config__.defaultValue = data[item.__vModel__ + '_id']
  163. this.$set(item, 'name', data[item.__vModel__] || '')
  164. } else {
  165. let val = data.hasOwnProperty(item.__vModel__) ? data[item.__vModel__] : item
  166. .__config__.defaultValue
  167. if (!item.__config__.custom && item.__config__.defaultCurrent && item.__config__
  168. .jnpfKey === 'time') val = this.jnpf.toDate(new Date(), item.format)
  169. item.__config__.defaultValue = val
  170. }
  171. if (this.formPermissionList.useFormPermission) {
  172. let id = item.__config__.isSubTable ? parent.__vModel__ + '-' + item.__vModel__ : item
  173. .__vModel__
  174. let noShow = true
  175. if (this.formList && this.formList.length) {
  176. noShow = !this.formList.some(o => o.enCode === id)
  177. }
  178. noShow = item.__config__.noShow ? item.__config__.noShow : noShow
  179. this.$set(item.__config__, 'noShow', noShow)
  180. }
  181. } else {
  182. if (['relationFormAttr', 'popupAttr'].includes(item.__config__.jnpfKey)) {
  183. item.__config__.defaultValue =
  184. data[item.relationField.split('_jnpfTable_')[0] + '_' + item.showField];
  185. }
  186. }
  187. if (item.__config__ && item.__config__.children && Array.isArray(item.__config__.children)) {
  188. loop(item.__config__.children, item)
  189. }
  190. }
  191. }
  192. loop(form)
  193. this.loading = false
  194. },
  195. initRelationForm(componentList) {
  196. componentList.forEach(cur => {
  197. const config = cur.__config__
  198. if (config.jnpfKey == 'relationFormAttr' || config.jnpfKey == 'popupAttr') {
  199. const relationKey = cur.relationField.split("_jnpfTable_")[0]
  200. componentList.forEach(item => {
  201. const noVisibility = Array.isArray(item.__config__.visibility) && !item
  202. .__config__.visibility.includes('app')
  203. if ((relationKey == item.__vModel__) && (noVisibility || !!item.__config__
  204. .noShow)) {
  205. cur.__config__.noShow = true
  206. }
  207. })
  208. }
  209. if (cur.__config__.children && cur.__config__.children.length) this.initRelationForm(cur
  210. .__config__.children)
  211. })
  212. },
  213. toDetail(item) {
  214. const id = item.__config__.defaultValue
  215. if (!id) return
  216. let config = {
  217. modelId: item.modelId,
  218. id: id,
  219. formTitle: '详情',
  220. noShowBtn: 1,
  221. noDataLog: 1
  222. }
  223. this.$nextTick(() => {
  224. const url =
  225. '/pages/apply/dynamicModel/detail?config=' + this.base64.encode(JSON.stringify(config),
  226. "UTF-8")
  227. uni.navigateTo({
  228. url: url
  229. })
  230. })
  231. },
  232. handleEdit() {
  233. const currentMenu = encodeURIComponent(JSON.stringify(this.formPermissionList))
  234. let config = {
  235. modelId: this.modelId,
  236. isPreview: this.isPreview,
  237. id: this.setting.id,
  238. jurisdictionType: 'btn_edit',
  239. currentMenu,
  240. list: this.setting.list,
  241. index: this.setting.index
  242. }
  243. const url = '/pages/apply/dynamicModel/form?config=' + this.base64.encode(JSON.stringify(config), "UTF-8")
  244. uni.navigateTo({
  245. url: url
  246. })
  247. }
  248. }
  249. }
  250. </script>
  251. <style lang="scss">
  252. page {
  253. background-color: #f0f2f6;
  254. }
  255. .nav {
  256. z-index: 99999;
  257. :deep(.uni-navbar__content) {
  258. z-index: 99999;
  259. }
  260. :deep(.uni-navbar__header-container) {
  261. justify-content: center;
  262. }
  263. }
  264. .nav-left {
  265. max-width: 100%;
  266. display: flex;
  267. align-items: center;
  268. .nav-left-text {
  269. font-weight: 700;
  270. font-size: 32rpx;
  271. flex: 1;
  272. min-width: 0;
  273. white-space: nowrap;
  274. overflow: hidden;
  275. text-overflow: ellipsis;
  276. }
  277. .right-icons {
  278. font-weight: 700;
  279. margin-top: 2px;
  280. margin-left: 4px;
  281. transition-duration: 0.3s;
  282. }
  283. .select-right-icons {
  284. transform: rotate(-180deg);
  285. }
  286. }
  287. </style>