Item.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <template>
  2. <view :class="{'item-card':config.jnpfKey==='card'}"
  3. v-if="!config.noShow && (!config.visibility || (Array.isArray(config.visibility) && config.visibility.includes('app')))">
  4. <template v-if="config.layout==='colFormItem'">
  5. <JnpfText v-if="config.jnpfKey=='text'" :content="item.content" :textStyle="item.textStyle" />
  6. <JnpfDivider v-else-if="config.jnpfKey==='divider'" :content="item.content" />
  7. <JnpfGroupTitle v-else-if="config.jnpfKey=='groupTitle'" :content="item.content"
  8. :content-position="item.contentPosition" :helpMessage="item.helpMessage" @groupIcon="clickIcon(item)" />
  9. <u-form-item v-else-if="config.jnpfKey==='popupSelect' || config.jnpfKey==='relationForm'"
  10. :label="realLabel" :prop="item.__vModel__" class="popup-select" :label-width="labelWidth"
  11. :left-icon="leftIcon" :left-icon-style="{'color':'#a8aaaf'}" @clickIcon="clickIcon(item)">
  12. <view class="detail-text-box" v-if="config.jnpfKey==='popupSelect'">
  13. <view class="jnpf-detail-text">
  14. {{formData[item.__vModel__]}}
  15. </view>
  16. <DisplayList v-if="Object.keys(extraObj).length" :extraObj="extraObj"
  17. :extraOptions="item.extraOptions">
  18. </DisplayList>
  19. </view>
  20. <view class="detail-text-box" @click.native="toDetail(item)" v-if="config.jnpfKey==='relationForm'">
  21. <view class="jnpf-detail-text" style="color:rgb(41, 121, 255)">
  22. {{formData[item.__vModel__]}}
  23. </view>
  24. <DisplayList v-if="Object.keys(extraObj).length" :extraObj="extraObj"
  25. :extraOptions="item.extraOptions">
  26. </DisplayList>
  27. </view>
  28. </u-form-item>
  29. <u-form-item v-else :label="realLabel" :prop="item.__vModel__" :label-width="labelWidth"
  30. :left-icon="leftIcon" :left-icon-style="{'color':'#a8aaaf'}" @clickIcon="clickIcon(item)">
  31. <!-- #ifndef APP-HARMONY -->
  32. <JnpfUploadFile v-if="config.jnpfKey=='uploadFile'" v-model="config.defaultValue" detailed />
  33. <!-- #endif -->
  34. <view class="preview-image-box" v-if="config.jnpfKey==='uploadImg'">
  35. <image v-for="(cItem,ci) in item.__config__.defaultValue" :key="ci" class="u-preview-image"
  36. :src="define.baseURL+cItem.url" mode="aspectFill"
  37. @tap.stop="doPreviewImage(define.baseURL+cItem.url, item.__config__.defaultValue)"></image>
  38. </view>
  39. <JnpfColorPicker v-else-if="config.jnpfKey==='colorPicker'" v-model="config.defaultValue"
  40. :colorFormat="item.colorFormat" disabled />
  41. <JnpfRate v-else-if="config.jnpfKey==='rate'" v-model="config.defaultValue" :max="item.count"
  42. :allowHalf="item.allowHalf" disabled />
  43. <JnpfEditor v-else-if="config.jnpfKey==='editor'" v-model="config.defaultValue" detailed />
  44. <JnpfBarcode v-else-if="config.jnpfKey=='barcode'" :staticText="item.staticText" :width="item.width"
  45. :height="item.height" :format="item.format" :dataType="item.dataType" :lineColor="item.lineColor"
  46. :background="item.background" :relationField="item.relationField+'_id'" :formData="formData" />
  47. <JnpfQrcode v-else-if="config.jnpfKey=='qrcode'" :staticText="item.staticText" :width="item.width"
  48. :dataType="item.dataType" :colorDark="item.colorDark" :colorLight="item.colorLight"
  49. :relationField="item.relationField+'_id'" :formData="formData" />
  50. <JnpfInputNumber v-else-if="config.jnpfKey=='inputNumber'" v-model="config.defaultValue"
  51. :step='item.step' :max='item.max||999999999999999' :min='item.min||-999999999999999'
  52. :disabled="item.disabled" :placeholder="item.placeholder" :isAmountChinese="item.isAmountChinese"
  53. :thousands="item.thousands" :addonAfter="item.addonAfter" :addonBefore="item.addonBefore"
  54. :controls="item.controls" :precision="item.precision" detailed />
  55. <JnpfCalculate v-else-if="config.jnpfKey==='calculate'&&item.isStorage==0" :expression='item.expression'
  56. :vModel='item.__vModel__' :config='config' :formData='formData' v-model="config.defaultValue"
  57. :precision="item.precision" :isAmountChinese="item.isAmountChinese" :thousands="item.thousands"
  58. :roundType="item.roundType" />
  59. <!--start labelwidth=0-->
  60. <JnpfLink v-else-if="config.jnpfKey=='link'" :content="item.content" :href="item.href"
  61. :target='item.target' :textStyle="item.textStyle" />
  62. <JnpfAlert v-else-if="config.jnpfKey=='alert'" :type="item.type" :title="item.title"
  63. :tagIcon='item.tagIcon' :showIcon="item.showIcon" :closable="item.closable"
  64. :description="item.description" :closeText="item.closeText" />
  65. <JnpfButton v-else-if="config.jnpfKey=='button'" :buttonText="item.buttonText" :align="item.align"
  66. :type="item.type" :disabled="item.disabled" />
  67. <JnpfSlider v-else-if="config.jnpfKey=='slider'" v-model="config.defaultValue" :step="item.step"
  68. :min="item.min||0" :max="item.max||100" disabled />
  69. <JnpfSign v-else-if="config.jnpfKey=='sign'" v-model="config.defaultValue" detailed />
  70. <JnpfSignature v-else-if="config.jnpfKey=='signature'" v-model="config.defaultValue" detailed />
  71. <JnpfLocation v-else-if="config.jnpfKey=='location'" v-model="config.defaultValue"
  72. :enableLocationScope="item.enableLocationScope" detailed />
  73. <!--end labelwidth=0-->
  74. <template v-else>
  75. <view class="jnpf-detail-text" v-if="config.jnpfKey==='calculate'">
  76. <view>{{ toThousands(config.defaultValue, item) }}</view>
  77. <view v-if="item.isAmountChinese" style="color: #999;">
  78. {{jnpf.getAmountChinese(getValue(item))}}
  79. </view>
  80. </view>
  81. <JnpfInput v-else-if="config.jnpfKey=='input'" v-model="config.defaultValue" detailed
  82. :useMask="item.useMask" :maskConfig="item.maskConfig" :addonBefore="item.addonBefore"
  83. :addonAfter="item.addonAfter" />
  84. <view class="jnpf-detail-text" v-else>{{ getValue(item) }}</view>
  85. </template>
  86. </u-form-item>
  87. </template>
  88. <template v-else>
  89. <view class="jnpf-card" v-if="config.jnpfKey==='card'||config.jnpfKey==='row'">
  90. <view class="jnpf-card-cap u-line-1 u-flex" v-if="item.header" @click="clickIcon(item)">
  91. {{item.header}}
  92. <u-icon :name="config.tipLabel? 'question-circle-fill':''" class="u-m-l-10" color="#a0acb7" />
  93. </view>
  94. <Item v-for="(child, index) in config.children" :key="config.renderKey+index" :itemData="child"
  95. :formConf="formConf" :formData="formData" @toDetail="toDetail" @clickIcon='clickIcon' />
  96. </view>
  97. <template v-if="config.jnpfKey==='table'">
  98. <view class="jnpf-table">
  99. <view class="jnpf-table-title u-line-1" @click="clickIcon(item)">
  100. {{config.label}}
  101. <u-icon v-if="config.tipLabel" :name="'question-circle-fill'" class="u-m-l-10"
  102. color="#a0acb7" />
  103. </view>
  104. <view v-for="(column,columnIndex) in config.defaultValue" :key="columnIndex">
  105. <view class="jnpf-table-item-title">
  106. <view class="jnpf-table-item-title-num">({{columnIndex+1}})</view>
  107. </view>
  108. <view class="form-item-box" v-for="(childItem,cIndex) in config.children" :key="cIndex">
  109. <u-form-item :label="childItem.__config__.showLabel?childItem.__config__.label:''"
  110. :label-width="childItem.__config__.labelWidth ? childItem.__config__.labelWidth * 1.5 : undefined"
  111. @clickIcon="clickIcon(childItem)"
  112. :left-icon='childItem.__config__.tipLabel &&childItem.__config__.showLabel&& childItem.__config__.label? "question-circle-fill":""'
  113. :left-icon-style="{'color':'#a0acb7'}"
  114. v-if="!childItem.__config__.noShow&&(!childItem.__config__.visibility|| (Array.isArray(childItem.__config__.visibility) && childItem.__config__.visibility.includes('app')))">
  115. <template
  116. v-if="['relationFormAttr','popupAttr'].includes(childItem.__config__.jnpfKey)">
  117. <view class="jnpf-detail-text" v-if="!childItem.__vModel__">
  118. {{ column[childItem.relationField.split('_jnpfTable_')[0]+'_'+childItem.showField] }}
  119. </view>
  120. <view class="jnpf-detail-text" v-else>
  121. {{column[childItem.__vModel__]}}
  122. </view>
  123. </template>
  124. <view v-else-if="childItem.__config__.jnpfKey==='relationForm'" class="jnpf-detail-text"
  125. style="color:rgb(41, 121, 255)"
  126. @click.native="toTableDetail(childItem,column[childItem.__vModel__+'_id'])">
  127. {{column[childItem.__vModel__]}}
  128. </view>
  129. <JnpfSign v-else-if="childItem.__config__.jnpfKey=='sign'"
  130. v-model="column[childItem.__vModel__]" detailed />
  131. <JnpfSignature v-else-if="childItem.__config__.jnpfKey=='signature'"
  132. v-model="column[childItem.__vModel__]" detailed />
  133. <JnpfLocation v-else-if="childItem.__config__.jnpfKey=='location'"
  134. v-model="column[childItem.__vModel__]"
  135. :enableLocationScope="item.enableLocationScope" detailed />
  136. <!-- #ifndef APP-HARMONY -->
  137. <JnpfUploadFile v-else-if="childItem.__config__.jnpfKey==='uploadFile'"
  138. v-model="column[childItem.__vModel__]" detailed />
  139. <!-- #endif -->
  140. <JnpfUploadImg v-else-if="childItem.__config__.jnpfKey==='uploadImg'"
  141. v-model="column[childItem.__vModel__]" detailed />
  142. <JnpfInputNumber v-else-if="childItem.__config__.jnpfKey=='inputNumber'"
  143. v-model="column[childItem.__vModel__]" :step='childItem.step' :max='childItem.max'
  144. :min='childItem.min' :disabled="childItem.disabled"
  145. :placeholder="childItem.placeholder" :isAmountChinese="childItem.isAmountChinese"
  146. :thousands="childItem.thousands" :addonAfter="childItem.addonAfter"
  147. :addonBefore="childItem.addonBefore" :controls="childItem.controls"
  148. :precision="childItem.precision" detailed />
  149. <JnpfCalculate
  150. v-else-if="childItem.__config__.jnpfKey==='calculate'&&childItem.isStorage==0"
  151. :expression='childItem.expression' :vModel='childItem.__vModel__'
  152. :config='childItem.__config__' :formData='formData' :roundType="childItem.roundType"
  153. v-model="column[childItem.__vModel__]" :precision="childItem.precision"
  154. :isAmountChinese="childItem.isAmountChinese" :thousands="childItem.thousands" />
  155. <JnpfRate v-else-if="childItem.__config__.jnpfKey==='rate'" :max="childItem.count"
  156. v-model="column[childItem.__vModel__]" :allowHalf="childItem.allowHalf" disabled />
  157. <JnpfSlider v-else-if="childItem.__config__.jnpfKey=='slider'"
  158. v-model="column[childItem.__vModel__]" :step="childItem.step"
  159. :min="childItem.min||0" :max="childItem.max||100" disabled />
  160. <template v-else>
  161. <view class="jnpf-detail-text" v-if="childItem.__config__.jnpfKey==='calculate'">
  162. <view>{{toThousands(column[childItem.__vModel__],childItem)}}</view>
  163. <view v-if="childItem.isAmountChinese" style="color: #999;">
  164. {{jnpf.getAmountChinese(column[childItem.__vModel__])}}
  165. </view>
  166. </view>
  167. <JnpfInput v-else-if="childItem.__config__.jnpfKey=='input'"
  168. v-model="column[childItem.__vModel__]" detailed :useMask="childItem.useMask"
  169. :maskConfig="childItem.maskConfig" :addonBefore="childItem.addonBefore"
  170. :addonAfter="childItem.addonAfter" />
  171. <view class="jnpf-detail-text" v-else>{{column[childItem.__vModel__]}}</view>
  172. </template>
  173. </u-form-item>
  174. </view>
  175. </view>
  176. <view class="jnpf-table-item" v-if="item.showSummary && summaryField.length">
  177. <view class="jnpf-table-item-title u-flex u-row-between">
  178. <text class="jnpf-table-item-title-num">{{item.__config__.label}}合计</text>
  179. </view>
  180. <view class=" u-p-l-20 u-p-r-20 form-item-box">
  181. <u-form-item v-for="(item,index) in summaryField" :label="item.__config__.label"
  182. :key="item.__vModel__">
  183. <u-input input-align='right' v-model="item.value" disabled />
  184. </u-form-item>
  185. </view>
  186. </view>
  187. </view>
  188. </template>
  189. <view v-else-if="config.jnpfKey==='steps'" style="background-color: #fff;padding:15px 0">
  190. <view class="step-container">
  191. <u-steps :list="config.children" name="title" :mode="item.simple ? 'dot' :'number'"
  192. @change="onStepChange($event,item)" :current="stepCurrent">
  193. </u-steps>
  194. </view>
  195. <view v-for="(itemSub,i) in config.children" :key='i'>
  196. <view v-if="i === stepCurrent">
  197. <Item v-for="(childItem, childIndex) in itemSub.__config__.children" :key="childIndex"
  198. :itemData="childItem" :formConf="formConf" :formData="formData" @toDetail="toDetail"
  199. @clickIcon='clickIcon' />
  200. </view>
  201. </view>
  202. </view>
  203. <view class="jnpf-tab" v-if="config.jnpfKey==='tab'">
  204. <u-tabs is-scroll :list="config.children" name="title" v-model="tabCurrent" @change="onTabChange" />
  205. <view v-for="(pane,i) in config.children" :key='i'>
  206. <view v-show="i == tabCurrent">
  207. <Item v-for="(childItem, childIndex) in pane.__config__.children" :key="childIndex"
  208. :itemData="childItem" :formConf="formConf" :formData="formData" @toDetail="toDetail"
  209. @clickIcon='clickIcon' />
  210. </view>
  211. </view>
  212. </view>
  213. <template v-if="config.jnpfKey==='collapse'">
  214. <u-collapse :head-style="{'padding-left':'20rpx'}" :accordion="item.accordion" ref="collapseRef">
  215. <u-collapse-item :title="pane.title" v-for="(pane, i) in config.children" :key="i"
  216. :open="config.active.indexOf(pane.name)>-1">
  217. <Item v-for="(child, j) in pane.__config__.children" :key="child.__config__.renderKey"
  218. :itemData="child" :formConf="formConf" :formData="formData" @toDetail="toDetail"
  219. @clickIcon='clickIcon' />
  220. </u-collapse-item>
  221. </u-collapse>
  222. </template>
  223. </template>
  224. </view>
  225. </template>
  226. <script>
  227. import {
  228. getRelationFormDetail,
  229. getDataInterfaceDataInfoByIds
  230. } from '@/api/common.js'
  231. // #ifdef MP
  232. import Item from './Item.vue' //兼容小程序
  233. // #endif
  234. import DisplayList from '@/components/displayList'
  235. const specialList = ['link', 'editor', 'button', 'alert']
  236. export default {
  237. name: 'Item',
  238. components: {
  239. // #ifdef MP
  240. Item,
  241. // #endif
  242. DisplayList
  243. },
  244. props: {
  245. itemData: {
  246. type: Object,
  247. required: true
  248. },
  249. formConf: {
  250. type: Object,
  251. required: true
  252. },
  253. formData: {
  254. type: Object,
  255. },
  256. },
  257. computed: {
  258. item() {
  259. const item = uni.$u.deepClone(this.itemData)
  260. this.initI18n(item)
  261. return item
  262. },
  263. config() {
  264. return this.item.__config__
  265. },
  266. labelWidth() {
  267. if (specialList.indexOf(this.config.jnpfKey) > -1) return 0
  268. return this.config.labelWidth ? this.config.labelWidth * 1.5 : undefined
  269. },
  270. label() {
  271. return this.config.showLabel && specialList.indexOf(this.config.jnpfKey) < 0 ? this.config.label : ''
  272. },
  273. realLabel() {
  274. return this.label ? (this.label + (this.formConf.labelSuffix || '')) : ''
  275. },
  276. leftIcon() {
  277. return this.config.tipLabel && this.label && this.config.showLabel ? "question-circle-fill" : ""
  278. }
  279. },
  280. data() {
  281. return {
  282. tabCurrent: 0,
  283. tableData: [],
  284. summaryField: [],
  285. stepCurrent: 0,
  286. extraObj: {}
  287. }
  288. },
  289. created() {
  290. this.handleSummary()
  291. this.handleTab()
  292. },
  293. mounted() {
  294. if (this.config.jnpfKey === 'collapse') {
  295. this.$refs.collapseRef && this.$refs.collapseRef.init()
  296. }
  297. uni.$on('initCollapse', () => {
  298. this.$refs.collapseRef && this.$refs.collapseRef.init()
  299. })
  300. this.getDataChange()
  301. this.getDataInterfaceDataInfoByIds()
  302. },
  303. methods: {
  304. onStepChange(index, item) {
  305. if (this.stepCurrent === index) return
  306. item.__config__.active = index
  307. this.stepCurrent = index
  308. this.$nextTick(() => {
  309. uni.$emit('updateCode')
  310. uni.$emit('initCollapse')
  311. })
  312. },
  313. initI18n(item) {
  314. const config = item.__config__
  315. if (item.placeholderI18nCode) {
  316. //#ifdef MP-WEIXIN
  317. item.placeholder = this.$t(item.placeholderI18nCode);
  318. //#endif
  319. //#ifndef MP-WEIXIN
  320. item.placeholder = this.$t(item.placeholderI18nCode, item.placeholder);
  321. //#endif
  322. }
  323. if (item.__config__.label && item.__config__.labelI18nCode) {
  324. //#ifdef MP-WEIXIN
  325. item.__config__.label = this.$t(item.__config__.labelI18nCode);
  326. //#endif
  327. //#ifndef MP-WEIXIN
  328. item.__config__.label = this.$t(item.__config__.labelI18nCode, item.__config__.label);
  329. //#endif
  330. }
  331. if (item.__config__.tipLabel && item.__config__.tipLabelI18nCode) {
  332. //#ifdef MP-WEIXIN
  333. item.__config__.tipLabel = this.$t(item.__config__.tipLabelI18nCode);
  334. //#endif
  335. //#ifndef MP-WEIXIN
  336. item.__config__.tipLabel = this.$t(item.__config__.tipLabelI18nCode, item.__config__.tipLabel);
  337. //#endif
  338. }
  339. if (['groupTitle', 'divider', 'link', 'text'].includes(config.jnpfKey)) {
  340. if (item.contentI18nCode) {
  341. //#ifdef MP-WEIXIN
  342. item.content = this.$t(item.contentI18nCode);
  343. //#endif
  344. //#ifndef MP-WEIXIN
  345. item.content = this.$t(item.contentI18nCode, item.content);
  346. //#endif
  347. }
  348. if (item.helpMessageI18nCode) {
  349. //#ifdef MP-WEIXIN
  350. item.helpMessage = this.$t(item.helpMessageI18nCode);
  351. //#endif
  352. //#ifndef MP-WEIXIN
  353. item.helpMessage = this.$t(item.helpMessageI18nCode, item.helpMessage);
  354. //#endif
  355. }
  356. }
  357. if (config.jnpfKey === 'button') {
  358. if (item.buttonTextI18nCode) {
  359. //#ifdef MP-WEIXIN
  360. item.buttonText = this.$t(item.buttonTextI18nCode);
  361. //#endif
  362. //#ifndef MP-WEIXIN
  363. item.buttonText = this.$t(item.buttonTextI18nCode.item.buttonText);
  364. //#endif
  365. }
  366. }
  367. if (config.jnpfKey === 'alert') {
  368. if (item.titleI18nCode) {
  369. //#ifdef MP-WEIXIN
  370. item.title = this.$t(item.titleI18nCode);
  371. //#endif
  372. //#ifndef MP-WEIXIN
  373. item.title = this.$t(item.titleI18nCode, item.title);
  374. //#endif
  375. }
  376. if (item.descriptionI18nCode) {
  377. //#ifdef MP-WEIXIN
  378. item.description = this.$t(item.descriptionI18nCode);
  379. //#endif
  380. //#ifndef MP-WEIXIN
  381. item.description = this.$t(item.descriptionI18nCode, item.description);
  382. //#endif
  383. }
  384. if (item.closeTextI18nCode) {
  385. //#ifdef MP-WEIXIN
  386. item.closeText = this.$t(item.closeTextI18nCode);
  387. //#endif
  388. //#ifndef MP-WEIXIN
  389. item.closeText = this.$t(item.closeTextI18nCode, item.closeText);
  390. //#endif
  391. }
  392. }
  393. if (config.jnpfKey === 'card') {
  394. if (item.headerI18nCode) {
  395. //#ifdef MP-WEIXIN
  396. item.header = this.$t(item.headerI18nCode);
  397. //#endif
  398. //#ifndef MP-WEIXIN
  399. item.header = this.$t(item.headerI18nCode, item.header);
  400. //#endif
  401. }
  402. }
  403. if (['tab', 'collapse', 'steps'].includes(config.jnpfKey)) {
  404. if (config.children && config.children.length) {
  405. for (let i = 0; i < config.children.length; i++) {
  406. if (config.children[i].titleI18nCode) {
  407. //#ifdef MP-WEIXIN
  408. config.children[i].title =
  409. this.$t(config.children[i].titleI18nCode);
  410. //#endif
  411. //#ifndef MP-WEIXIN
  412. config.children[i].title =
  413. this.$t(config.children[i].titleI18nCode, config.children[i].title);
  414. //#endif
  415. }
  416. }
  417. }
  418. if (item.headerI18nCode) {
  419. //#ifdef MP-WEIXIN
  420. item.header = this.$t(item.headerI18nCode);
  421. //#endif
  422. //#ifndef MP-WEIXIN
  423. item.header = this.$t(item.headerI18nCode, item.header);
  424. //#endif
  425. }
  426. }
  427. if (config.jnpfKey === 'table') {
  428. if (config.children && config.children.length) {
  429. for (let i = 0; i < config.children.length; i++) {
  430. this.initI18n(config.children[i])
  431. }
  432. }
  433. }
  434. },
  435. handleTab() {
  436. if (this.config.jnpfKey === 'steps') return this.stepCurrent = this.config.active
  437. if (this.config.jnpfKey !== 'tab') return
  438. for (var i = 0; i < this.config.children.length; i++) {
  439. if (this.config.active == this.config.children[i].name) {
  440. this.tabCurrent = i
  441. break
  442. }
  443. }
  444. },
  445. getDataChange() {
  446. if (this.config.jnpfKey === 'relationForm' && this.config.defaultValue) {
  447. let query = {
  448. id: this.formData[this.item.__vModel__ + '_id'],
  449. };
  450. if (this.item.propsValue) query = {
  451. ...query,
  452. propsValue: this.item.propsValue
  453. };
  454. getRelationFormDetail(this.item.modelId, query).then(res => {
  455. if ((!res.data || !res.data.data) || res.data.data === "undefined") return
  456. let data = JSON.parse(res.data?.data)
  457. this.extraObj = data
  458. })
  459. }
  460. },
  461. getDataInterfaceDataInfoByIds() {
  462. if (this.config.jnpfKey === 'popupSelect' && this.config.defaultValue) {
  463. let query = {
  464. ids: [this.config.defaultValue],
  465. interfaceId: this.item.interfaceId,
  466. propsValue: this.item.propsValue,
  467. relationField: this.item.relationField,
  468. paramList: this.getParamList()
  469. }
  470. getDataInterfaceDataInfoByIds(this.item.interfaceId, query).then(res => {
  471. const data = res.data && res.data.length ? res.data[0] : {};
  472. this.extraObj = data
  473. })
  474. }
  475. },
  476. getParamList() {
  477. let templateJson = this.item.templateJson
  478. if (!this.formData) return templateJson
  479. for (let i = 0; i < templateJson.length; i++) {
  480. if (templateJson[i].relationField && templateJson[i].sourceType == 1) {
  481. if (templateJson[i].relationField.includes('-')) {
  482. let tableVModel = templateJson[i].relationField.split('-')[0]
  483. let childVModel = templateJson[i].relationField.split('-')[1]
  484. templateJson[i].defaultValue = this.formData[tableVModel] && this.formData[tableVModel][this
  485. .rowIndex
  486. ] && this.formData[tableVModel][this.rowIndex][childVModel] || ''
  487. } else {
  488. templateJson[i].defaultValue = this.formData[templateJson[i].relationField] || ''
  489. }
  490. }
  491. }
  492. return templateJson
  493. },
  494. handleSummary() {
  495. if (this.item.__config__.jnpfKey !== 'table') return
  496. const val = this.item.__config__.defaultValue
  497. let summaryField = this.item.summaryField || []
  498. this.summaryField = []
  499. this.tableData = this.item.__config__.children || []
  500. for (let i = 0; i < summaryField.length; i++) {
  501. for (let o = 0; o < this.tableData.length; o++) {
  502. const item = this.tableData[o]
  503. if (this.tableData[o].__vModel__ === summaryField[i] && !item.__config__.noShow) {
  504. this.summaryField.push({
  505. value: '',
  506. ...item
  507. })
  508. }
  509. }
  510. }
  511. this.$nextTick(() => this.getTableSummaries(val, this.item))
  512. },
  513. toThousands(val, column) {
  514. if (val) {
  515. let valList = val.toString().split('.')
  516. let num = Number(valList[0])
  517. let newVal = column.thousands ? num.toLocaleString() : num
  518. return valList[1] ? newVal + '.' + valList[1] : newVal
  519. } else {
  520. return val
  521. }
  522. },
  523. getTableSummaries(newVal, config) {
  524. for (let i = 0; i < this.summaryField.length; i++) {
  525. let val = 0
  526. for (let j = 0; j < newVal.length; j++) {
  527. if (newVal[j][this.summaryField[i].__vModel__]) {
  528. let data = isNaN(newVal[j][this.summaryField[i].__vModel__]) ? 0 :
  529. Number(newVal[j][this.summaryField[i].__vModel__])
  530. val += data
  531. }
  532. }
  533. let realVal = val && !Number.isInteger(val) ? Number(val).toFixed(2) : val;
  534. if (this.summaryField[i].thousands) realVal = Number(realVal).toLocaleString('zh')
  535. this.summaryField[i].value = realVal
  536. }
  537. },
  538. clickIcon(e) {
  539. this.$emit('clickIcon', e)
  540. },
  541. onTabChange(index) {
  542. if (this.tabCurrent === index) return
  543. this.tabCurrent = index;
  544. this.$emit('tab-change', this.item, index)
  545. this.$nextTick(() => {
  546. uni.$emit('initCollapse')
  547. uni.$emit('updateCode')
  548. })
  549. },
  550. doPreviewImage(current, imageList) {
  551. const images = imageList.map(item => this.define.baseURL + item.url);
  552. uni.previewImage({
  553. urls: images,
  554. current: current,
  555. success: () => {},
  556. fail: () => {
  557. uni.showToast({
  558. title: '预览图片失败',
  559. icon: 'none'
  560. });
  561. }
  562. });
  563. },
  564. toDetail(item) {
  565. const data = {
  566. ...item,
  567. ...(item.__config__.jnpfKey === 'relationForm' ? {
  568. sourceRelationForm: true,
  569. propsValue: item.propsValue
  570. } : {})
  571. };
  572. this.$emit('toDetail', data)
  573. },
  574. toTableDetail(item, value) {
  575. item.__config__.defaultValue = value
  576. this.$emit('toDetail', item)
  577. },
  578. getValue(item) {
  579. if (Array.isArray(item.__config__.defaultValue)) {
  580. if (['timeRange', 'dateRange'].includes(item.__config__.jnpfKey)) {
  581. return item.__config__.defaultValue.join('')
  582. }
  583. return item.__config__.defaultValue.join()
  584. }
  585. return item.__config__.defaultValue
  586. },
  587. }
  588. }
  589. </script>
  590. <style lang="scss">
  591. .detail-text-box {
  592. width: 100%;
  593. }
  594. </style>