index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <view class="jnpf-popup-select">
  3. <selectBox v-model="innerValue" :placeholder="placeholder" @openSelect="openSelect"></selectBox>
  4. <DisplayList :extraObj="extraObj" :extraOptions="extraOptions"
  5. v-if="Object.keys(extraObj).length && innerValue">
  6. </DisplayList>
  7. </view>
  8. </template>
  9. <script>
  10. import DisplayList from '@/components/displayList'
  11. import selectBox from '@/components/selectBox'
  12. import {
  13. getDataInterfaceDataInfoByIds
  14. } from '@/api/common.js'
  15. import {
  16. useBaseStore
  17. } from '@/store/modules/base'
  18. const baseStore = useBaseStore()
  19. export default {
  20. name: 'jnpf-popup-select',
  21. components: {
  22. DisplayList,
  23. selectBox
  24. },
  25. props: {
  26. modelValue: {
  27. default: ''
  28. },
  29. formType: {
  30. type: String,
  31. default: 'select'
  32. },
  33. placeholder: {
  34. type: String,
  35. default: '请选择'
  36. },
  37. disabled: {
  38. type: Boolean,
  39. default: false
  40. },
  41. columnOptions: {
  42. type: Array,
  43. default: () => []
  44. },
  45. extraOptions: {
  46. type: Array,
  47. default: () => []
  48. },
  49. relationField: {
  50. type: String,
  51. default: ''
  52. },
  53. propsValue: {
  54. type: String,
  55. default: ''
  56. },
  57. popupTitle: {
  58. type: String,
  59. default: ''
  60. },
  61. interfaceId: {
  62. type: String,
  63. default: ''
  64. },
  65. hasPage: {
  66. type: Boolean,
  67. default: false
  68. },
  69. pageSize: {
  70. type: Number,
  71. default: 100000
  72. },
  73. vModel: {
  74. type: String,
  75. default: ''
  76. },
  77. rowIndex: {
  78. default: null
  79. },
  80. formData: {
  81. type: Object
  82. },
  83. templateJson: {
  84. type: Array,
  85. default: () => []
  86. }
  87. },
  88. data() {
  89. return {
  90. selectShow: false,
  91. innerValue: '',
  92. defaultValue: '',
  93. current: null,
  94. defaultOptions: [],
  95. firstVal: '',
  96. firstId: 0,
  97. selectData: [],
  98. extraObj: {}
  99. }
  100. },
  101. watch: {
  102. modelValue(val) {
  103. this.setDefault()
  104. },
  105. },
  106. created() {
  107. uni.$on('popConfirm', (subVal, innerValue, list, selectData) => {
  108. this.confirm(subVal, innerValue, list, selectData)
  109. })
  110. this.setDefault()
  111. },
  112. methods: {
  113. setDefault() {
  114. if (this.modelValue) {
  115. if (!this.interfaceId) return
  116. let query = {
  117. ids: [this.modelValue],
  118. interfaceId: this.interfaceId,
  119. propsValue: this.propsValue,
  120. relationField: this.relationField,
  121. paramList: this.getParamList()
  122. }
  123. getDataInterfaceDataInfoByIds(this.interfaceId, query).then(res => {
  124. const data = res.data && res.data.length ? res.data[0] : {};
  125. this.extraObj = data
  126. this.innerValue = data[this.relationField]
  127. if (!this.vModel) return
  128. let relationData = baseStore.relationData
  129. relationData[this.vModel] = data
  130. baseStore.updateRelationData(relationData)
  131. })
  132. } else {
  133. this.innerValue = ''
  134. if (!this.vModel) return
  135. let relationData = baseStore.relationData
  136. relationData[this.vModel] = {}
  137. baseStore.updateRelationData(relationData)
  138. }
  139. },
  140. getParamList() {
  141. let templateJson = this.templateJson
  142. if (!this.formData) return templateJson
  143. for (let i = 0; i < templateJson.length; i++) {
  144. if (templateJson[i].relationField && templateJson[i].sourceType == 1) {
  145. if (templateJson[i].relationField.includes('-')) {
  146. let tableVModel = templateJson[i].relationField.split('-')[0]
  147. let childVModel = templateJson[i].relationField.split('-')[1]
  148. templateJson[i].defaultValue = this.formData[tableVModel] && this.formData[tableVModel][this
  149. .rowIndex
  150. ] && this.formData[tableVModel][this.rowIndex][childVModel] || ''
  151. } else {
  152. templateJson[i].defaultValue = this.formData[templateJson[i].relationField] || ''
  153. }
  154. }
  155. }
  156. return templateJson
  157. },
  158. openSelect() {
  159. if (this.disabled) return
  160. const pageSize = this.hasPage ? this.pageSize : 100000
  161. let data = {
  162. columnOptions: this.columnOptions,
  163. relationField: this.relationField,
  164. type: 'popup',
  165. propsValue: this.propsValue,
  166. modelId: this.interfaceId,
  167. hasPage: this.hasPage,
  168. pageSize,
  169. id: [this.modelValue],
  170. vModel: this.vModel,
  171. popupTitle: this.popupTitle || '选择数据',
  172. innerValue: this.innerValue,
  173. paramList: this.getParamList(),
  174. selectData: this.selectData
  175. }
  176. uni.navigateTo({
  177. url: '/pages/apply/popSelect/index?data=' + encodeURIComponent(JSON.stringify(data))
  178. })
  179. },
  180. confirm(subVal, innerValue, vModel, selectData) {
  181. if (vModel === this.vModel) {
  182. this.firstVal = innerValue;
  183. this.firstId = subVal;
  184. this.innerValue = innerValue;
  185. this.extraObj = selectData
  186. this.$emit('update:modelValue', subVal)
  187. this.$emit('change', subVal, selectData)
  188. }
  189. },
  190. }
  191. }
  192. </script>
  193. <style lang="scss">
  194. .jnpf-popup-select {
  195. width: 100%;
  196. height: 100%;
  197. }
  198. </style>