childTable.vue 44 KB

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