childTable.vue 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. <template>
  2. <view class="jnpf-table">
  3. <view class="jnpf-table-title u-line-1" @click="clickIcon(config)">
  4. {{config.__config__.label}}
  5. <u-icon v-if="config.__config__.tipLabel" :name="'question-circle-fill'" class="u-m-l-10" color="#a0acb7" />
  6. </view>
  7. <view class="jnpf-table-item" v-for="(item,i) in tableFormData" :key="i">
  8. <view class="jnpf-table-item-title">
  9. <u-checkbox @change="checkboxChange($event,item,index)" v-model="item.checked" @tap.stop
  10. shape="circle"></u-checkbox>
  11. <view class="jnpf-table-item-title-num">({{i+1}})</view>
  12. <template v-if="!disabled">
  13. <template v-for="(it, index) in config.columnBtnsList">
  14. <view v-if="it.show&&!disabled"
  15. :class="it.value=='remove'?'jnpf-table-delete-btn':'jnpf-table-copy-btn'"
  16. @click="columnBtnsHandel(it, i)" :key="index">
  17. {{ it.labelI18nCode ? $t(it.labelI18nCode) : it.label }}
  18. </view>
  19. </template>
  20. </template>
  21. </view>
  22. <view class="form-item-box" v-for="(child,cIndex) in item" :key="cIndex">
  23. <u-form-item :label="child.__config__.showLabel?child.__config__.label:''"
  24. :required="child.__config__.required"
  25. :left-icon='child.__config__.showLabel &&child.__config__.tipLabel && child.__config__.label? "question-circle-fill":""'
  26. @clickIcon="clickIcon(child)" :left-icon-style="{'color':'#a8aaaf'}"
  27. :label-width="child.__config__.labelWidth ? child.__config__.labelWidth * 1.5 : undefined"
  28. v-if="!child.__config__.noShow && child.__config__.isVisibility">
  29. <JnpfInput v-if="child.__config__.jnpfKey=='input'" v-model="tableFormData[i][cIndex].value"
  30. :showPassword="child.showPassword" :placeholder="child.placeholder" :maxlength="child.maxlength"
  31. :showCount="child.showCount" :disabled="disabled||child.disabled" :clearable='child.clearable'
  32. :useScan="child.useScan" :addonBefore="child.addonBefore" :addonAfter="child.addonAfter"
  33. @change="onChange($event,child,i)" @blur="onBlur($event,child,i)" />
  34. <JnpfTextarea v-if="child.__config__.jnpfKey=='textarea'" v-model="tableFormData[i][cIndex].value"
  35. :placeholder="child.placeholder" :maxlength="child.maxlength" :showCount="child.showCount"
  36. :disabled="disabled||child.disabled" :clearable='child.clearable'
  37. @change="onChange($event,child,i)" @blur="onBlur($event,child,i)" />
  38. <JnpfInputNumber v-if="child.__config__.jnpfKey=='inputNumber'"
  39. v-model="tableFormData[i][cIndex].value" :step='child.step' :max='child.max' :min='child.min'
  40. :disabled="disabled||child.disabled" :placeholder="child.placeholder"
  41. :isAmountChinese="child.isAmountChinese" :thousands="child.thousands"
  42. :addonAfter="child.addonAfter" :addonBefore="child.addonBefore" :controls="child.controls"
  43. :precision="child.precision" @change="onChange($event,child,i)"
  44. @blur="onBlur($event,child,i)" />
  45. <JnpfSwitch v-if="child.__config__.jnpfKey=='switch'" v-model="tableFormData[i][cIndex].value"
  46. :disabled="disabled||child.disabled" @change="onChange($event,child,i)" />
  47. <JnpfSelect v-if="child.__config__.jnpfKey=='select'" v-model="tableFormData[i][cIndex].value"
  48. :placeholder="child.placeholder" :options="child.options" :props="child.props"
  49. :multiple="child.multiple" :disabled="disabled||child.disabled"
  50. @change="(val,value)=>{onChange(value,child,i)}" :filterable="child.filterable" />
  51. <JnpfCascader v-if="child.__config__.jnpfKey=='cascader'" v-model="tableFormData[i][cIndex].value"
  52. :placeholder="child.placeholder" :options="child.options" :props="child.props"
  53. :disabled="disabled||child.disabled" :multiple="child.multiple" :filterable='child.filterable'
  54. :clearable='child.clearable' :showAllLevels="child.showAllLevels"
  55. @change="(val,value)=>{onChange(value,child,i)}" />
  56. <JnpfDatePicker v-if="child.__config__.jnpfKey=='datePicker'"
  57. v-model="tableFormData[i][cIndex].value" :placeholder="child.placeholder"
  58. :disabled="disabled||child.disabled" :format="child.format" :startTime="child.startTime"
  59. :endTime='child.endTime' @change="onChange($event,child,i)" />
  60. <JnpfTimePicker v-if="child.__config__.jnpfKey=='timePicker'"
  61. v-model="tableFormData[i][cIndex].value" :placeholder="child.placeholder"
  62. :disabled="disabled||child.disabled" :format="child.format" :startTime="child.startTime"
  63. :endTime='child.endTime' @change="onChange($event,child,i)" />
  64. <!-- #ifndef APP-HARMONY -->
  65. <JnpfUploadFile v-if="child.__config__.jnpfKey=='uploadFile'"
  66. v-model="tableFormData[i][cIndex].value" :disabled="disabled||child.disabled"
  67. :limit="child.limit" :sizeUnit="child.sizeUnit" :fileSize="child.fileSize"
  68. :pathType="child.pathType" :isAccount="child.isAccount" :folder="child.folder"
  69. :accept="child.accept" :tipText="child.tipText" @change="onChange($event,child,i)"
  70. :sortRule="child.sortRule" :timeFormat="child.timeFormat" />
  71. <!-- #endif -->
  72. <JnpfUploadImg v-if="child.__config__.jnpfKey=='uploadImg'" v-model="tableFormData[i][cIndex].value"
  73. :disabled="disabled||child.disabled" :limit="child.limit" :sizeUnit="child.sizeUnit"
  74. :fileSize="child.fileSize" :pathType="child.pathType" :isAccount="child.isAccount"
  75. :folder="child.folder" :tipText="child.tipText" @change="onChange($event,child,i)"
  76. :sortRule="child.sortRule" :timeFormat="child.timeFormat" />
  77. <JnpfRate v-if="child.__config__.jnpfKey=='rate'" v-model="tableFormData[i][cIndex].value"
  78. :max="child.count" :allowHalf="child.allowHalf" :disabled="disabled||child.disabled"
  79. @change="onChange($event,child,i)" />
  80. <JnpfSlider v-if="child.__config__.jnpfKey=='slider'" v-model="tableFormData[i][cIndex].value"
  81. :step="child.step" :min="child.min" :max="child.max" :disabled="disabled||child.disabled"
  82. @change="onChange($event,child,i)" />
  83. <JnpfOrganizeSelect v-if="child.__config__.jnpfKey=='organizeSelect'"
  84. v-model="tableFormData[i][cIndex].value" :multiple="child.multiple"
  85. :placeholder="child.placeholder" :disabled="disabled||child.disabled"
  86. :selectType="child.selectType" :ableIds="child.ableIds"
  87. @change="(val,value)=>{onChange(value,child,i)}" />
  88. <JnpfDepSelect v-if="child.__config__.jnpfKey=='depSelect'" v-model="tableFormData[i][cIndex].value"
  89. :multiple="child.multiple" :placeholder="child.placeholder" :disabled="disabled||child.disabled"
  90. :ableIds="child.ableIds" :selectType="child.selectType"
  91. @change="(val,value)=>{onChange(value,child,i)}" />
  92. <JnpfPosSelect v-if="child.__config__.jnpfKey=='posSelect'" v-model="tableFormData[i][cIndex].value"
  93. :multiple="child.multiple" :placeholder="child.placeholder" :disabled="disabled||child.disabled"
  94. :ableIds="child.ableIds" :selectType="child.selectType"
  95. @change="(val,value)=>{onChange(value,child,i)}" />
  96. <JnpfUserSelect v-if="child.__config__.jnpfKey=='userSelect'"
  97. v-model="tableFormData[i][cIndex].value" :multiple="child.multiple"
  98. :placeholder="child.placeholder" :disabled="disabled||child.disabled"
  99. :selectType="child.selectType" :ableIds="child.ableIds" :clearable="child.clearable"
  100. :ableRelationIds="child.ableRelationIds" @change="(val,value)=>{onChange(value,child,i)}" />
  101. <JnpfUsersSelect v-if="child.__config__.jnpfKey=='usersSelect'"
  102. v-model="tableFormData[i][cIndex].value" :multiple="child.multiple"
  103. :placeholder="child.placeholder" :disabled="disabled||child.disabled"
  104. :selectType="child.selectType" :ableIds="child.ableIds" :clearable="child.clearable"
  105. @change="(val,value)=>{onChange(value,child,i)}" />
  106. <JnpfRoleSelect v-if="child.__config__.jnpfKey=='roleSelect'"
  107. v-model="tableFormData[i][cIndex].value" :vModel='child.__vModel__' :multiple="child.multiple"
  108. :disabled="disabled||child.disabled" :placeholder="child.placeholder"
  109. :selectType="child.selectType" :ableIds="child.ableIds"
  110. @change="(val,value)=>{onChange(value,child,i)}" />
  111. <JnpfGroupSelect v-if="child.__config__.jnpfKey=='groupSelect'"
  112. v-model="tableFormData[i][cIndex].value" :vModel='child.__vModel__' :multiple="child.multiple"
  113. :disabled="disabled||child.disabled" :placeholder="child.placeholder"
  114. :selectType="child.selectType" :ableIds="child.ableIds"
  115. @change="(val,value)=>{onChange(value,child,i)}" />
  116. <JnpfTreeSelect v-if="child.__config__.jnpfKey=='treeSelect'"
  117. v-model="tableFormData[i][cIndex].value" :options="child.options" :props="child.props"
  118. :multiple="child.multiple" :placeholder="child.placeholder" :disabled="disabled||child.disabled"
  119. :filterable="child.filterable" @change="(val,value)=>{onChange(value,child,i)}" />
  120. <JnpfAutoComplete v-if="child.__config__.jnpfKey=='autoComplete'"
  121. v-model="tableFormData[i][cIndex].value" :disabled="disabled||child.disabled"
  122. :interfaceName="child.interfaceName" :placeholder="child.placeholder"
  123. :interfaceId="child.interfaceId" :total="child.total" :templateJson="child.templateJson"
  124. :formData='formData' :relationField="child.relationField" :propsValue="child.propsValue"
  125. :clearable='child.clearable' @change="onChange($event,child,i)" />
  126. <JnpfAreaSelect v-if="child.__config__.jnpfKey=='areaSelect'"
  127. v-model="tableFormData[i][cIndex].value" :placeholder="child.placeholder" :level="child.level"
  128. :disabled="disabled||child.disabled" :multiple="child.multiple"
  129. @change="(val,value)=>{onChange(value,child,i)}" />
  130. <JnpfRelationForm v-if="child.__config__.jnpfKey=='relationForm'"
  131. v-model="tableFormData[i][cIndex].value" :placeholder="child.placeholder"
  132. :disabled="disabled||child.disabled" :modelId="child.modelId"
  133. :columnOptions="child.columnOptions" :relationField="child.relationField"
  134. :hasPage="child.hasPage" :pageSize="child.pageSize" :queryType="child.queryType"
  135. :vModel="child.__config__.tableName ? child.__vModel__ + '_jnpfTable_' + child.__config__.tableName + (child.__config__.isSubTable ? '0' : '1')+'_jnpfRelation_'+i : child.__vModel__+'_jnpfRelation_'+i"
  136. :popupTitle="child.popupTitle" @change="(val,value)=>{onChange(value,child,i)}"
  137. :propsValue="child.propsValue" />
  138. <JnpfRelationFormAttr v-if="child.__config__.jnpfKey=='relationFormAttr'"
  139. v-model="tableFormData[i][cIndex].value" :showField="child.showField"
  140. :relationField="child.relationField+'_jnpfRelation_'+i" :isStorage='child.isStorage' />
  141. <JnpfPopupSelect
  142. v-if="child.__config__.jnpfKey=='popupSelect'||child.__config__.jnpfKey=='popupTableSelect'"
  143. v-model="tableFormData[i][cIndex].value" :placeholder="child.placeholder" :rowIndex="i"
  144. :disabled="disabled||child.disabled" :interfaceId="child.interfaceId" :formData="formData"
  145. :templateJson="child.templateJson" :columnOptions="child.columnOptions"
  146. :relationField="child.relationField" :propsValue="child.propsValue" :hasPage="child.hasPage"
  147. :pageSize="child.pageSize"
  148. :vModel="child.__config__.tableName ? child.__vModel__ + '_jnpfTable_' + child.__config__.tableName + (child.__config__.isSubTable ? '0' : '1')+'_jnpfRelation_'+i : child.__vModel__+'_jnpfRelation_'+i"
  149. :popupTitle="child.popupTitle" @change="(val,value)=>{onChange(value,child,i)}" />
  150. <JnpfPopupAttr v-if="child.__config__.jnpfKey=='popupAttr'" v-model="tableFormData[i][cIndex].value"
  151. :showField="child.showField" :relationField="child.relationField+'_jnpfRelation_'+i"
  152. :isStorage='child.isStorage' />
  153. <JnpfCalculate v-if="child.__config__.jnpfKey=='calculate'" v-model="tableFormData[i][cIndex].value"
  154. :expression='child.expression' :config='child.__config__' :formData='formData'
  155. :precision="child.precision" :isAmountChinese="child.isAmountChinese"
  156. :thousands="child.thousands" :rowIndex="i" :roundType="child.roundType" />
  157. <JnpfSign v-if="child.__config__.jnpfKey=='sign'" v-model="tableFormData[i][cIndex].value"
  158. :fieldKey="child.__vModel__" :disabled="disabled||child.disabled"
  159. @change="onChange($event,child,i)" :isInvoke="child.isInvoke" />
  160. <JnpfSignature v-if="child.__config__.jnpfKey=='signature'" v-model="tableFormData[i][cIndex].value"
  161. :disabled="disabled||child.disabled" @change="onChange($event,child,i)"
  162. :ableIds="child.ableIds" />
  163. <JnpfLocation v-if="child.__config__.jnpfKey=='location'" v-model="tableFormData[i][cIndex].value"
  164. :autoLocation="child.autoLocation" :adjustmentScope="child.adjustmentScope"
  165. :enableLocationScope="child.enableLocationScope"
  166. :enableDesktopLocation="child.enableDesktopLocation" :locationScope="child.locationScope"
  167. :disabled="disabled||child.disabled" :clearable='child.clearable'
  168. @change="onChange($event,child,i)" />
  169. <JnpfOpenData v-if="systemList.includes(child.__config__.jnpfKey)"
  170. v-model="tableFormData[i][cIndex].value" />
  171. </u-form-item>
  172. </view>
  173. </view>
  174. <view class="jnpf-table-footer-btn" v-if="!disabled && getFooterBtnsList.length">
  175. <template v-for="item in getFooterBtnsList">
  176. <view class="jnpf-table-btn" :class="'jnpf-table-'+item.btnType+'-btn'" @click="footerBtnsHandle(item)">
  177. <text class="jnpf-table-btn-icon" :class="item.btnIcon" />
  178. <text class="jnpf-table-btn-text">
  179. {{ item.labelI18nCode ? $t(item.labelI18nCode, item.label) : item.label }}
  180. </text>
  181. </view>
  182. </template>
  183. </view>
  184. <view class="jnpf-table-item" v-if="config.showSummary && summaryField.length">
  185. <view class="jnpf-table-item-title">
  186. <text class="jnpf-table-item-title-num">
  187. {{config.__config__.label}}{{$t('component.table.summary')}}
  188. </text>
  189. </view>
  190. <view class="form-item-box">
  191. <u-form-item v-for="(item,index) in summaryField" :label="item.__config__.label" :key="item.__vModel__"
  192. :label-width="item.__config__.labelWidth ? item.__config__.labelWidth * 1.5 : undefined">
  193. <JnpfInput v-model="item.value" disabled placeholder="" />
  194. </u-form-item>
  195. </view>
  196. </view>
  197. <u-modal v-model="showTipsModal" width='70%' border-radius="16" :content-style="contentStyle"
  198. :titleStyle="titleStyle" :confirm-style="confirmStyle" :title="tipsTitle" :content="tipsContent"
  199. :confirm-text="$t('common.okText')" />
  200. </view>
  201. </template>
  202. <script>
  203. import {
  204. getModelInfo
  205. } from '@/api/apply/visualDev'
  206. import {
  207. getDictionaryDataSelector,
  208. getDataInterfaceRes
  209. } from '@/api/common'
  210. import {
  211. useBaseStore
  212. } from '@/store/modules/base'
  213. const baseStore = useBaseStore()
  214. const dyOptionsList = ['select', 'cascader', 'treeSelect']
  215. const systemList = ['createUser', 'createTime', 'modifyUser', 'modifyTime', 'currOrganize', 'currDept', 'currPosition',
  216. 'billRule'
  217. ]
  218. import childTableMixin from './mixin'
  219. export default {
  220. name: 'jnpf-child-table',
  221. inject: ["parameter", "relations", "isShortLink"],
  222. mixins: [childTableMixin],
  223. props: {
  224. config: {
  225. type: Object,
  226. default: () => {}
  227. },
  228. formData: {
  229. type: Object,
  230. required: true
  231. },
  232. modelValue: {
  233. type: [Array, String],
  234. default: () => ([])
  235. }
  236. },
  237. data() {
  238. return {
  239. systemList,
  240. dataInterfaceInfo: [],
  241. activeRowIndex: 0,
  242. tableData: [],
  243. tableFormData: [],
  244. summaryField: [],
  245. isIgnore: false,
  246. tableVmodel: '',
  247. childRelations: {},
  248. userInfo: {},
  249. showTipsModal: false,
  250. tipsContent: '',
  251. tipsTitle: this.$t('common.tipTitle'),
  252. contentStyle: {
  253. fontSize: '28rpx',
  254. padding: '20rpx',
  255. lineHeight: '44rpx',
  256. textAlign: 'left'
  257. },
  258. titleStyle: {
  259. padding: '20rpx'
  260. },
  261. confirmStyle: {
  262. height: '80rpx',
  263. lineHeight: '80rpx',
  264. },
  265. }
  266. },
  267. watch: {
  268. tableFormData: {
  269. handler(val, oldVal) {
  270. //获取子表数据并更新
  271. const data = this.submit(true)
  272. this.config.__config__.defaultValue = data
  273. this.$emit('input', this.config)
  274. // 获取合计数据
  275. this.getTableSummaries()
  276. },
  277. deep: true
  278. },
  279. },
  280. computed: {
  281. disabled() {
  282. return this.config.disabled
  283. },
  284. getFooterBtnsList() {
  285. if (!this.config?.footerBtnsList?.length) return [];
  286. let list = this.config.footerBtnsList.filter(o => o.show);
  287. if (this.isShortLink) list = list.filter(o => ['add'].includes(o.value));
  288. //移除批量删除
  289. list = list.filter(item => item.value != 'batchRemove')
  290. return list;
  291. },
  292. },
  293. created() {
  294. this.init()
  295. },
  296. methods: {
  297. init() {
  298. this.userInfo = uni.getStorageSync('userInfo') || {}
  299. this.tableData = this.config.__config__.children || []
  300. this.handleSummary()
  301. this.buildOptions()
  302. this.handleListen()
  303. this.buildRelation()
  304. },
  305. handleSummary() {
  306. this.summaryField = []
  307. let summaryField = this.config.summaryField || []
  308. for (let i = 0; i < summaryField.length; i++) {
  309. for (let o = 0; o < this.tableData.length; o++) {
  310. const item = this.tableData[o]
  311. if (item.__vModel__ === summaryField[i] && !item.__config__.noShow) {
  312. this.summaryField.push({
  313. value: '0.00',
  314. ...item
  315. })
  316. }
  317. }
  318. }
  319. },
  320. handleListen() {
  321. uni.$on('linkPageConfirm', (subVal, Vmodel) => {
  322. if (this.config.__vModel__ === Vmodel) {
  323. subVal.forEach(t => {
  324. this.tableFormData.push(this.getEmptyItem(t))
  325. this.buildRowAttr(this.tableFormData.length - 1, t)
  326. })
  327. setTimeout(() => {
  328. uni.$emit('initCollapse')
  329. }, 50)
  330. }
  331. })
  332. uni.$on('handleRelation', this.handleRelationForParent)
  333. },
  334. buildOptions() {
  335. for (let i = 0; i < this.tableData.length; i++) {
  336. const config = this.tableData[i].__config__
  337. if (dyOptionsList.indexOf(config.jnpfKey) > -1) {
  338. if (config.dataType === 'dictionary' && config.dictionaryType) {
  339. baseStore.getDicDataSelector(config.dictionaryType).then(res => {
  340. this.tableData[i].options = res || []
  341. uni.$emit('initCollapse')
  342. })
  343. }
  344. if (config.dataType === 'dynamic' && config.propsUrl) {
  345. let query = {
  346. paramList: this.getDefaultParamList(config.templateJson, this.formData)
  347. }
  348. const matchInfo = JSON.stringify({
  349. id: config.propsUrl,
  350. query
  351. });
  352. const item = {
  353. matchInfo,
  354. rowIndex: -1,
  355. colIndex: i
  356. };
  357. this.dataInterfaceInfo.push(item);
  358. getDataInterfaceRes(config.propsUrl, query).then(res => {
  359. this.tableData[i].options = Array.isArray(res.data) ? res.data : []
  360. })
  361. }
  362. }
  363. }
  364. this.initData()
  365. },
  366. initData() {
  367. if (Array.isArray(this.modelValue) && this.modelValue.length) {
  368. this.modelValue.forEach((t, index) => {
  369. this.tableFormData.push(this.getEmptyItem(t))
  370. this.buildAttr(index, t)
  371. })
  372. this.initRelationData()
  373. this.$nextTick(() => {
  374. uni.$emit('initCollapse')
  375. })
  376. }
  377. },
  378. buildAttr(rowIndex, val) {
  379. let row = this.tableFormData[rowIndex];
  380. for (let i = 0; i < row.length; i++) {
  381. let item = row[i];
  382. const config = item.__config__
  383. if (dyOptionsList.indexOf(config.jnpfKey) > -1) {
  384. if (config.dataType === 'dictionary' && config.dictionaryType) {
  385. baseStore.getDicDataSelector(config.dictionaryType).then(res => {
  386. item.options = res || []
  387. uni.$emit('initCollapse')
  388. })
  389. }
  390. if (config.dataType === 'dynamic' && config.propsUrl) {
  391. this.handleRelation(item, rowIndex)
  392. if (item.options && item.options.length && (!config.templateJson || !config.templateJson
  393. .length || !this.hasTemplateJsonRelation(config.templateJson))) continue
  394. let query = {
  395. paramList: this.getParamList(config.templateJson, this.formData, rowIndex)
  396. }
  397. const matchInfo = JSON.stringify({
  398. id: config.propsUrl,
  399. query
  400. });
  401. const itemInfo = {
  402. matchInfo,
  403. rowIndex,
  404. colIndex: i
  405. };
  406. const infoIndex = this.dataInterfaceInfo.findIndex(o => o.matchInfo === matchInfo);
  407. let useCacheOptions = false;
  408. if (infoIndex === -1) {
  409. this.dataInterfaceInfo.push(itemInfo);
  410. } else {
  411. const cacheOptions = this.getCacheOptions(infoIndex);
  412. if (cacheOptions.length) {
  413. item.options = cacheOptions;
  414. useCacheOptions = true;
  415. uni.$emit('initCollapse')
  416. }
  417. }
  418. if (!useCacheOptions) {
  419. getDataInterfaceRes(config.propsUrl, query).then(res => {
  420. item.options = Array.isArray(res.data) ? res.data : []
  421. uni.$emit('initCollapse')
  422. })
  423. }
  424. }
  425. }
  426. }
  427. },
  428. buildRelation() {
  429. for (let key in this.relations) {
  430. if (key.includes('-')) {
  431. let tableVModel = key.split('-')[0]
  432. if (tableVModel === this.config.__vModel__) {
  433. let newKey = key.split('-')[1]
  434. this.childRelations[newKey] = this.relations[key]
  435. }
  436. }
  437. }
  438. },
  439. /* 合计 */
  440. getTableSummaries() {
  441. if (!this.config.showSummary) return
  442. if (!this.tableFormData.length) return this.handleSummary()
  443. const list = this.tableFormData.map((row, i) => {
  444. return row.reduce((p, c) => {
  445. p[c.__vModel__] = c.value
  446. return p
  447. }, {})
  448. })
  449. for (let i = 0; i < this.summaryField.length; i++) {
  450. let val = 0
  451. for (let j = 0; j < list.length; j++) {
  452. const value = list[j][this.summaryField[i].__vModel__]
  453. if (value) {
  454. let data = isNaN(value) ? 0 : Number(value)
  455. val += data
  456. }
  457. }
  458. let realVal = val && !Number.isInteger(val) ? Number(val).toFixed(2) : val;
  459. if (this.summaryField[i].thousands) realVal = Number(realVal).toLocaleString('zh')
  460. this.summaryField[i].value = realVal
  461. }
  462. },
  463. handleRelationForParent(e, defaultValue, st) {
  464. if (!this.tableFormData.length) return
  465. for (let i = 0; i < this.tableFormData.length; i++) {
  466. let row = this.tableFormData[i];
  467. for (let j = 0; j < row.length; j++) {
  468. let item = row[j];
  469. const vModel = item.jnpfKey === 'popupSelect' ? item.__vModel__.substring(0, item.__vModel__
  470. .indexOf('_jnpfRelation_')) : item.__vModel__
  471. if (e.__vModel__ === vModel) {
  472. if (e.opType === 'setOptions') {
  473. item.options = []
  474. let query = {
  475. paramList: this.getParamList(e.__config__.templateJson, this.formData, i)
  476. }
  477. getDataInterfaceRes(e.__config__.propsUrl, query).then(res => {
  478. item.options = Array.isArray(res.data) ? res.data : []
  479. uni.$emit('initCollapse')
  480. })
  481. }
  482. if (e.opType === 'setUserOptions') {
  483. if (e.relationField.includes('-')) {
  484. const [attr1, attr2] = e.relationField.split('-')
  485. this.$nextTick(() => {
  486. let value = this.formData[attr1][i][attr2] || []
  487. this.$set(this.tableFormData[i][j], 'ableRelationIds', Array.isArray(
  488. value) ? value : [value])
  489. })
  490. } else {
  491. let value = this.formData[e.relationField] || []
  492. this.$set(this.tableFormData[i][j], 'ableRelationIds', Array.isArray(value) ? value : [
  493. value
  494. ])
  495. }
  496. }
  497. this.$nextTick(() => {
  498. if (e.opType === 'setDate') {
  499. let startTime = 0
  500. let endTime = 0
  501. if (e.__config__.startRelationField && e.__config__.startTimeType == 2) {
  502. if (e.__config__.startRelationField.includes('-')) {
  503. const [attr0, attr5] = e.__config__.startRelationField.split('-')
  504. startTime = this.formData[attr0][i][attr5] || 0
  505. } else {
  506. startTime = this.formData[e.__config__.startRelationField] || 0
  507. }
  508. } else {
  509. startTime = e.startTime
  510. }
  511. if (e.__config__.endRelationField && e.__config__.endTimeType == 2) {
  512. if (e.__config__.endRelationField.includes('-')) {
  513. const [attr3, attr4] = e.__config__.endRelationField.split('-')
  514. endTime = this.formData[attr3][i][attr4] || 0
  515. } else {
  516. endTime = this.formData[e.__config__.endRelationField] || 0
  517. }
  518. } else {
  519. endTime = e.endTime
  520. }
  521. item.startTime = startTime
  522. item.endTime = endTime
  523. }
  524. if (e.opType === 'setTime') {
  525. let format = e.format
  526. let startTime = ''
  527. let endTime = ''
  528. if (e.__config__.startRelationField && e.__config__.startTimeType == 2) {
  529. if (e.__config__.startRelationField.includes('-')) {
  530. const [attr0, attr5] = e.__config__.startRelationField.split('-')
  531. startTime = this.formData[attr0][i][attr5] || '00:00:00'
  532. } else {
  533. startTime = this.formData[e.__config__.startRelationField] ||
  534. '00:00:00'
  535. }
  536. startTime = startTime && startTime.split(':').length == 3 ? startTime :
  537. startTime + ':00'
  538. } else {
  539. startTime = e.startTime
  540. }
  541. if (e.__config__.endRelationField && e.__config__.endTimeType == 2) {
  542. if (e.__config__.endRelationField.includes('-')) {
  543. const [attr3, attr4] = e.__config__.endRelationField.split('-')
  544. endTime = this.formData[attr3][i][attr4] || '23:59:59'
  545. } else {
  546. endTime = this.formData[e.__config__.endRelationField] || '23:59:59'
  547. }
  548. endTime = endTime && endTime.split(':').length == 3 ? endTime : endTime +
  549. ':00'
  550. } else {
  551. endTime = e.endTime
  552. }
  553. item.startTime = startTime
  554. item.endTime = endTime
  555. }
  556. })
  557. if (item.value != defaultValue) {
  558. if (st || !item.value) item.value = defaultValue
  559. }
  560. }
  561. }
  562. }
  563. },
  564. handleRelation(data, rowIndex) {
  565. const currRelations = this.childRelations
  566. for (let key in currRelations) {
  567. if (key === data.__vModel__) {
  568. for (let i = 0; i < currRelations[key].length; i++) {
  569. const e = currRelations[key][i];
  570. const config = e.__config__
  571. const jnpfKey = config.jnpfKey
  572. let defaultValue = ''
  573. if (['checkbox', 'cascader'].includes(jnpfKey) || (['select', 'treeSelect',
  574. 'popupSelect',
  575. 'popupTableSelect', 'userSelect'
  576. ].includes(jnpfKey) && e.multiple)) {
  577. defaultValue = []
  578. }
  579. let row = this.tableFormData[rowIndex];
  580. for (let j = 0; j < row.length; j++) {
  581. let item = row[j];
  582. const vModel = item.jnpfKey === 'popupSelect' ? item.__vModel__.substring(0, item
  583. .__vModel__.indexOf('_jnpfRelation_')) : item.__vModel__
  584. if (e.__vModel__ === vModel) {
  585. if (e.opType === 'setOptions') {
  586. item.options = []
  587. let query = {
  588. paramList: this.getParamList(config.templateJson, this.formData, rowIndex)
  589. }
  590. getDataInterfaceRes(config.propsUrl, query).then(res => {
  591. item.options = Array.isArray(res.data) ? res.data : []
  592. uni.$emit('initCollapse')
  593. })
  594. }
  595. if (e.opType === 'setUserOptions') {
  596. let value = this.getFieldVal(e.relationField, rowIndex) || []
  597. item.ableRelationIds = Array.isArray(value) ? value : [value]
  598. }
  599. if (e.opType === 'setDate') {
  600. let startTime = 0
  601. let endTime = 0
  602. if (config.startRelationField && config.startTimeType == 2) {
  603. startTime = this.getFieldVal(config.startRelationField, rowIndex) || 0
  604. } else {
  605. startTime = e.startTime
  606. }
  607. if (config.endRelationField && config.endTimeType == 2) {
  608. endTime = this.getFieldVal(config.endRelationField, rowIndex) || 0
  609. } else {
  610. endTime = e.endTime
  611. }
  612. item.startTime = startTime
  613. item.endTime = endTime
  614. }
  615. if (e.opType === 'setTime') {
  616. let startTime = 0
  617. let endTime = 0
  618. if (config.startRelationField && config.startTimeType == 2) {
  619. startTime = this.getFieldVal(config.startRelationField, rowIndex) || '00:00:00'
  620. startTime = startTime.split(':').length == 3 ? startTime : startTime + ':00'
  621. } else {
  622. startTime = e.startTime
  623. }
  624. if (config.endRelationField && config.endTimeType == 2) {
  625. endTime = this.getFieldVal(config.endRelationField, rowIndex) || '23:59:59'
  626. endTime = endTime.split(':').length == 3 ? endTime : endTime + ':00'
  627. } else {
  628. endTime = e.endTime
  629. }
  630. item.startTime = startTime
  631. item.endTime = endTime
  632. }
  633. if (item.value != defaultValue) {
  634. item.value = defaultValue
  635. this.$nextTick(() => this.handleRelation(item, rowIndex));
  636. }
  637. }
  638. }
  639. }
  640. }
  641. }
  642. },
  643. handleDefaultRelation(data, rowIndex = 0) {
  644. const currRelations = this.childRelations
  645. for (let key in currRelations) {
  646. if (key === data) {
  647. for (let i = 0; i < currRelations[key].length; i++) {
  648. const e = currRelations[key][i];
  649. const config = e.__config__
  650. let defaultValue = ''
  651. let row = this.tableFormData[rowIndex];
  652. for (let j = 0; j < row.length; j++) {
  653. let item = row[j];
  654. const vModel = item.jnpfKey === 'popupSelect' ? item.__vModel__.substring(0, item
  655. .__vModel__.indexOf('_jnpfRelation_')) : item.__vModel__
  656. if (e.__vModel__ === vModel) {
  657. if (e.opType === 'setUserOptions') {
  658. let value = this.getFieldVal(e.relationField, rowIndex) || []
  659. item.ableRelationIds = Array.isArray(value) ? value : [value]
  660. }
  661. if (e.opType === 'setDate') {
  662. let startTime = 0
  663. let endTime = 0
  664. if (config.startRelationField && config.startTimeType == 2) {
  665. startTime = this.getFieldVal(config.startRelationField, rowIndex) || 0
  666. } else {
  667. startTime = e.startTime
  668. }
  669. if (config.endRelationField && config.endTimeType == 2) {
  670. endTime = this.getFieldVal(config.endRelationField, rowIndex) || 0
  671. } else {
  672. endTime = e.endTime
  673. }
  674. item.startTime = startTime
  675. item.endTime = endTime
  676. }
  677. if (e.opType === 'setTime') {
  678. let startTime = 0
  679. let endTime = 0
  680. if (config.startRelationField && config.startTimeType == 2) {
  681. startTime = this.getFieldVal(config.startRelationField, rowIndex) || '00:00:00'
  682. if (startTime.split(':').length == 3) {
  683. startTime = startTime
  684. } else {
  685. startTime = startTime + ':00'
  686. }
  687. } else {
  688. startTime = e.startTime
  689. }
  690. if (config.endRelationField && config.endTimeType == 2) {
  691. endTime = this.getFieldVal(config.endRelationField, rowIndex) ||
  692. '23:59:59'
  693. if (endTime.split(':').length == 3) {
  694. endTime = endTime
  695. } else {
  696. endTime = endTime + ':00'
  697. }
  698. } else {
  699. endTime = e.endTime
  700. }
  701. item.startTime = startTime
  702. item.endTime = endTime
  703. }
  704. }
  705. }
  706. }
  707. }
  708. }
  709. },
  710. getFieldVal(field, rowIndex) {
  711. let val = ''
  712. if (field.includes('-')) {
  713. let childVModel = field.split('-')[1]
  714. let list = this.tableFormData[rowIndex].filter(o => o.__vModel__ === childVModel)
  715. val = list.length ? list[0].value : ''
  716. } else {
  717. val = this.formData[field] || ''
  718. }
  719. return val
  720. },
  721. buildRowAttr(rowIndex, val) {
  722. let row = this.tableFormData[rowIndex];
  723. for (let i = 0; i < row.length; i++) {
  724. let item = row[i];
  725. const config = item.__config__
  726. for (let key in this.modelValue[rowIndex]) {
  727. if (key === item.__vModel__) item.value = this.modelValue[rowIndex][key]
  728. }
  729. if (dyOptionsList.indexOf(config.jnpfKey) > -1) {
  730. if (config.dataType === 'dictionary' && config.dictionaryType) {
  731. baseStore.getDicDataSelector(config.dictionaryType).then(res => {
  732. item.options = res || []
  733. uni.$emit('initCollapse')
  734. })
  735. }
  736. if (config.dataType === 'dynamic' && config.propsUrl) {
  737. this.handleRelation(item, rowIndex)
  738. if (item.options && item.options.length && (!config.templateJson || !config.templateJson
  739. .length || !this.hasTemplateJsonRelation(config.templateJson))) continue
  740. let query = {
  741. paramList: this.getParamList(config.templateJson, this.formData, rowIndex)
  742. }
  743. const matchInfo = JSON.stringify({
  744. id: config.propsUrl,
  745. query
  746. });
  747. const itemInfo = {
  748. matchInfo,
  749. rowIndex,
  750. colIndex: i
  751. };
  752. const infoIndex = this.dataInterfaceInfo.findIndex(o => o.matchInfo === matchInfo);
  753. let useCacheOptions = false;
  754. if (infoIndex === -1) {
  755. this.dataInterfaceInfo.push(itemInfo);
  756. } else {
  757. const cacheOptions = this.getCacheOptions(infoIndex);
  758. if (cacheOptions.length) {
  759. item.options = cacheOptions;
  760. uni.$emit('initCollapse')
  761. useCacheOptions = true;
  762. }
  763. }
  764. if (!useCacheOptions) {
  765. getDataInterfaceRes(config.propsUrl, query).then(res => {
  766. item.options = Array.isArray(res.data) ? res.data : []
  767. uni.$emit('initCollapse')
  768. })
  769. }
  770. }
  771. }
  772. if (config.jnpfKey === 'userSelect' && item.relationField && item.selectType !== 'all' && item
  773. .selectType !== 'custom') {
  774. let value = this.getFieldVal(item.relationField, rowIndex) || []
  775. item.ableRelationIds = Array.isArray(value) ? value : [value]
  776. }
  777. if (config.jnpfKey === 'datePicker') {
  778. let startTime = 0
  779. let endTime = 0
  780. if (config.startRelationField && config.startTimeType == 2) {
  781. startTime = this.getFieldVal(config.startRelationField, rowIndex) || 0
  782. } else {
  783. startTime = item.startTime
  784. }
  785. if (config.endRelationField && config.endTimeType == 2) {
  786. endTime = this.getFieldVal(config.endRelationField, rowIndex) || 0
  787. } else {
  788. endTime = item.endTime
  789. }
  790. item.startTime = startTime
  791. item.endTime = endTime
  792. }
  793. if (config.jnpfKey === 'timePicker') {
  794. let startTime = 0
  795. let endTime = 0
  796. if (config.startRelationField && config.startTimeType == 2) {
  797. startTime = this.getFieldVal(config.startRelationField, rowIndex) || '00:00:00'
  798. startTime = startTime && (startTime.split(':').length == 3) ? startTime : startTime + ':00'
  799. } else {
  800. startTime = item.startTime
  801. }
  802. if (config.endRelationField && config.endTimeType == 2) {
  803. endTime = this.getFieldVal(config.endRelationField, rowIndex) || '23:59:59'
  804. endTime = endTime.split(':').length == 3 ? endTime : endTime + ':00'
  805. } else {
  806. endTime = item.endTime
  807. }
  808. item.startTime = startTime
  809. item.endTime = endTime
  810. }
  811. }
  812. },
  813. // 获取缓存options数据
  814. getCacheOptions(index) {
  815. const item = this.dataInterfaceInfo[index];
  816. if (item.rowIndex === -1) return this.tableData[item.colIndex].options || [];
  817. return this.tableFormData[item.rowIndex][item.colIndex].options || [];
  818. },
  819. // 判断templateJson里是否有关联字段
  820. hasTemplateJsonRelation(templateJson) {
  821. return templateJson.some(o => o.relationField);
  822. },
  823. getParamList(templateJson, formData, index) {
  824. if (!templateJson) return []
  825. for (let i = 0; i < templateJson.length; i++) {
  826. if (templateJson[i].relationField && templateJson[i].sourceType == 1) {
  827. if (templateJson[i].relationField.includes('-')) {
  828. let childVModel = templateJson[i].relationField.split('-')[1]
  829. let list = this.tableFormData[index].filter(o => o.__vModel__ === childVModel)
  830. templateJson[i].defaultValue = list.length ? list[0].value : ''
  831. } else {
  832. templateJson[i].defaultValue = formData[templateJson[i].relationField] || ''
  833. }
  834. }
  835. }
  836. return templateJson
  837. },
  838. getDefaultParamList(templateJson, formData) {
  839. if (!templateJson) return []
  840. for (let i = 0; i < templateJson.length; i++) {
  841. if (templateJson[i].relationField && templateJson[i].sourceType == 1) {
  842. if (templateJson[i].relationField.includes('-')) {
  843. let childVModel = templateJson[i].relationField.split('-')[1]
  844. let list = this.tableData.filter(o => o.__vModel__ === childVModel)
  845. templateJson[i].defaultValue = ''
  846. if (list.length) templateJson[i].defaultValue = list[0].__config__.defaultValue || ''
  847. } else {
  848. templateJson[i].defaultValue = formData[templateJson[i].relationField] || ''
  849. }
  850. }
  851. }
  852. return templateJson
  853. },
  854. initRelationData() {
  855. const handleRelationFun = (list) => {
  856. list.forEach(cur => {
  857. this.handleDefaultRelation(cur.__vModel__)
  858. if (cur.__config__.children) handleRelationFun(cur.__config__.children)
  859. })
  860. }
  861. handleRelationFun(this.config.__config__.children)
  862. },
  863. getEmptyItem(val) {
  864. return this.tableData.map(o => {
  865. const config = o.__config__
  866. if (config.jnpfKey === 'datePicker' && config.defaultCurrent) {
  867. let format = this.jnpf.handelFormat(o.format)
  868. let dateStr = this.jnpf.toDate(new Date().getTime(), format)
  869. let time = format === 'yyyy' ? '-01-01 00:00:00' : format === 'yyyy-MM' ? '-01 00:00:00' :
  870. format === 'yyyy-MM-dd' ? ' 00:00:00' : ''
  871. config.defaultValue = new Date(dateStr + time).getTime()
  872. }
  873. if (config.jnpfKey === 'timePicker' && config.defaultCurrent) {
  874. config.defaultValue = this.jnpf.toDate(new Date(), o.format)
  875. }
  876. const res = {
  877. ...o,
  878. value: val ? val[o.__vModel__] : config.defaultValue,
  879. options: config.dataType == "dynamic" ? [] : o.options,
  880. rowData: val || {}
  881. }
  882. return res
  883. })
  884. },
  885. formatData() {
  886. const organizeIdList = this.userInfo.organizeIdList
  887. for (let i = 0; i < this.tableFormData.length; i++) {
  888. const item = this.tableFormData[i]
  889. for (let j = 0; j < item.length; j++) {
  890. const it = item[j]
  891. const config = item[j].__config__
  892. if (config.jnpfKey === 'datePicker' && config.defaultCurrent &&
  893. i === this.tableFormData.length - 1) {
  894. let format = this.jnpf.handelFormat(it.format)
  895. let dateStr = this.jnpf.toDate(new Date().getTime(), format)
  896. let time = format === 'yyyy' ? '-01-01 00:00:00' : format === 'yyyy-MM' ?
  897. '-01 00:00:00' : format === 'yyyy-MM-dd' ?
  898. ' 00:00:00' : ''
  899. it.value = new Date(dateStr + time).getTime()
  900. }
  901. if (config.jnpfKey === 'organizeSelect' && config.defaultCurrent && Array.isArray(
  902. organizeIdList) && organizeIdList.length && i === this.tableFormData.length - 1) {
  903. it.value = it.multiple ? [organizeIdList] : organizeIdList
  904. }
  905. }
  906. }
  907. },
  908. checkData(item) {
  909. if ([null, undefined, ''].includes(item.value)) return false
  910. if (Array.isArray(item.value)) return item.value.length > 0
  911. return true
  912. },
  913. submit(noShowToast) {
  914. let res = true
  915. outer: for (let i = 0; i < this.tableFormData.length; i++) {
  916. const row = this.tableFormData[i]
  917. for (let j = 0; j < row.length; j++) {
  918. const cur = row[j]
  919. const config = cur.__config__
  920. if (config.required && !this.checkData(cur) && config.isVisibility && !config.noShow) {
  921. res = false
  922. if (!noShowToast) this.$u.toast(
  923. `${this.config.__config__.label}(${i+1})${config.label}${this.$t('sys.validate.textRequiredSuffix')}`
  924. )
  925. break outer
  926. }
  927. if (config.regList && config.regList.length && config.isVisibility) {
  928. let regList = config.regList
  929. for (let ii = 0; ii < regList.length; ii++) {
  930. const item = regList[ii];
  931. if (item.pattern) {
  932. item.pattern = item.pattern.toString()
  933. let start = item.pattern.indexOf('/')
  934. let stop = item.pattern.lastIndexOf('/')
  935. let str = item.pattern.substring(start + 1, stop)
  936. let reg = new RegExp(str)
  937. item.pattern = reg
  938. }
  939. if (cur.value && item.pattern && !item.pattern.test(cur.value)) {
  940. if (item.messageI18nCode) {
  941. item.message = this.$t(item.messageI18nCode, item.message);
  942. }
  943. if (!noShowToast) this.$u.toast(
  944. `${this.config.__config__.label}(${i+1})${config.label}${item.message}`
  945. )
  946. res = false
  947. break outer
  948. }
  949. }
  950. }
  951. }
  952. }
  953. const data = this.getTableValue() || []
  954. return noShowToast ? data : res ? data : false
  955. },
  956. getTableValue() {
  957. return this.tableFormData.map(row => row.reduce((p, c) => {
  958. let str = c.__vModel__
  959. if (c.__vModel__ && c.__vModel__.indexOf('_jnpfRelation_') >= 0) {
  960. str = c.__vModel__.substring(0, c.__vModel__.indexOf('_jnpfRelation_'))
  961. }
  962. p[str] = c.value
  963. if (c.rowData) p = {
  964. ...c.rowData,
  965. ...p
  966. }
  967. return p
  968. }, {}))
  969. },
  970. setTableFormData(prop, value) {
  971. let activeRow = this.tableFormData[this.activeRowIndex] || []
  972. for (let i = 0; i < activeRow.length; i++) {
  973. if (activeRow[i].__vModel__ === prop) {
  974. activeRow[i].value = value
  975. break
  976. }
  977. }
  978. },
  979. getTableFieldOptions(prop) {
  980. let res = []
  981. for (let i = 0; i < this.tableData.length; i++) {
  982. if (this.tableData[i].__vModel__ === prop) {
  983. res = this.tableData[i].options || []
  984. break
  985. }
  986. }
  987. return res
  988. },
  989. onChange(val, data, rowIndex) {
  990. this.activeRowIndex = rowIndex;
  991. this.setScriptFunc(val, data, 'change', rowIndex)
  992. if (['popupSelect', 'relationForm'].includes(data.__config__.jnpfKey)) {
  993. this.setTransferFormData(val, data.__config__, data.__config__.jnpfKey)
  994. }
  995. this.$nextTick(() => this.handleRelation(data, rowIndex))
  996. },
  997. setScriptFunc(val, data, type = 'change', rowIndex) {
  998. if (data && data.on && data.on[type]) {
  999. const func = this.jnpf.getScriptFunc(data.on[type]);
  1000. if (!func) return
  1001. func.call(this, {
  1002. data: val,
  1003. rowIndex,
  1004. ...this.parameter
  1005. })
  1006. }
  1007. },
  1008. setTransferFormData(data, config, jnpfKey) {
  1009. if (!config.transferList.length) return;
  1010. let row = this.tableFormData[this.activeRowIndex];
  1011. for (let index = 0; index < config.transferList.length; index++) {
  1012. const element = config.transferList[index];
  1013. if (element.sourceValue.includes('-')) element.sourceValue = element.sourceValue.split('-')[1];
  1014. for (let index = 0; index < row.length; index++) {
  1015. const e = row[index];
  1016. if (e.__vModel__ == element.sourceValue) e.value = data[element.targetField];
  1017. }
  1018. }
  1019. },
  1020. clickIcon(e) {
  1021. if (!e.__config__.tipLabel) return
  1022. this.tipsContent = e.__config__.tipLabel
  1023. this.tipsTitle = e.__config__.label
  1024. this.showTipsModal = true
  1025. },
  1026. onBlur(val, data, rowIndex) {
  1027. this.activeRowIndex = rowIndex
  1028. this.setScriptFunc(val, data, 'blur', rowIndex)
  1029. },
  1030. columnBtnsHandel(item, index) {
  1031. if (item.value == 'remove') return this.removeRow(index, item.showConfirm);
  1032. if (item.value == 'copy') return this.copyRow(index);
  1033. },
  1034. /* 子表删除 */
  1035. removeRow(index, showConfirm = 0) {
  1036. const handleRemove = () => {
  1037. this.tableFormData.splice(index, 1);
  1038. this.modelValue.splice(index, 1)
  1039. this.$nextTick(() => uni.$emit('initCollapse'))
  1040. };
  1041. if (!showConfirm) return handleRemove();
  1042. uni.showModal({
  1043. title: this.$t('common.tipTitle'),
  1044. content: this.$t('common.delTip'),
  1045. success: (res) => {
  1046. if (res.confirm) handleRemove()
  1047. }
  1048. })
  1049. },
  1050. /* 子表复制 */
  1051. copyRow(index) {
  1052. let item = JSON.parse(JSON.stringify(this.tableFormData[index]));
  1053. item.forEach(item => {
  1054. if (systemList.includes(item.__config__.jnpfKey)) {
  1055. item.value = ''
  1056. item.placeholder = '系统自动生成'
  1057. }
  1058. })
  1059. item.length && item.map(o => delete o.rowData);
  1060. this.tableFormData.push(item);
  1061. },
  1062. footerBtnsHandle(item) {
  1063. item.value == 'add' ? this.addRow() : this.openSelectDialog(item)
  1064. },
  1065. /* 子表删除 */
  1066. addRow(val) {
  1067. this.tableFormData.push(this.getEmptyItem(val))
  1068. if (this.tableFormData.length) this.formatData()
  1069. const rowIndex = this.tableFormData.length - 1
  1070. this.buildRowAttr(rowIndex, val)
  1071. this.$nextTick(() => uni.$emit('initCollapse'))
  1072. }
  1073. }
  1074. }
  1075. </script>