wk-field-revelance.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <view class="wk-field wk-field-select" @click.stop="handleChoose">
  3. <view v-if="_label" class="wk-field__label">
  4. <view v-if="field.isNull === 1" class="line" />
  5. {{ _label }}
  6. </view>
  7. <view class="wk-field__body">
  8. <view class="wk-field__body-core">
  9. {{ valueStr }}
  10. </view>
  11. <text class="wk wk-arrow-right icon-right" />
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. import mixins from './mixins'
  17. export default {
  18. name: 'WkFieldRevelance',
  19. mixins: [mixins],
  20. props: {
  21. req: {
  22. type: Function,
  23. default: null
  24. },
  25. isDetailTable: {
  26. type: Boolean,
  27. default: false
  28. }
  29. },
  30. data() {
  31. return {
  32. guid: null,
  33. formValue: [],
  34. keyMap: {
  35. customer: {labelField: 'customerName', valueField: 'customerId'},
  36. contacts: {labelField: 'contactsName', valueField: 'contactsId'},
  37. business: {labelField: 'businessName', valueField: 'businessId'},
  38. contract: {labelField: 'num', valueField: 'contractId'},
  39. }
  40. }
  41. },
  42. computed: {
  43. type() {
  44. return this.field.formType
  45. },
  46. valueStr() {
  47. let obj = null
  48. if (
  49. this.config &&
  50. this.config.optionsConfig &&
  51. (
  52. this.config.optionsConfig.labelField ||
  53. this.config.optionsConfig.valueField
  54. )
  55. ) {
  56. obj = this.config.optionsConfig
  57. } else {
  58. obj = this.keyMap[this.type] || {}
  59. }
  60. if (this.$isEmpty(obj)) return ''
  61. // console.log('obj--', obj, this.formValue)
  62. const key = obj.labelField
  63. const arr = this.formValue || []
  64. return arr.map(o => o[key]).join(',')
  65. },
  66. list() {
  67. return this.field.setting.map(o => {
  68. return {
  69. label: o,
  70. value: o
  71. }
  72. })
  73. }
  74. },
  75. created() {
  76. this.guid = this.$guid()
  77. },
  78. methods: {
  79. handleChoose() {
  80. if (this.field.disabled) {
  81. if (this.config && this.config.disabledMsg) {
  82. this.$toast(this.config.disabledMsg)
  83. }
  84. return
  85. }
  86. const bridge = getApp().globalData.selectedValBridge
  87. // 主要是处理微信小程序端 uni限制 props 不能传递函数的问题
  88. let formBridge = {}
  89. if (this.isDetailTable) {
  90. formBridge = getApp().globalData.detailTableFields
  91. } else {
  92. formBridge = getApp().globalData.formBridge
  93. }
  94. // const formBridge = getApp().globalData.formBridge
  95. let request = null
  96. if (
  97. formBridge &&
  98. formBridge.fields &&
  99. formBridge.fields[this.index] &&
  100. formBridge.fields[this.index].sys_config
  101. ) {
  102. request = formBridge.fields[this.index].sys_config.request || null
  103. }
  104. bridge[this.type] = {
  105. guid: this.guid,
  106. title: '选择' + this.field.name,
  107. maxlength: 1,
  108. defaultVal: this.formValue || [],
  109. params: this.config ? (this.config.otherParams || {}) : {},
  110. request: request,
  111. config: this.config ? (this.config.optionsConfig || null) : null
  112. }
  113. // console.log('bridge: ', formBridge, bridge)
  114. uni.$on('selected-relevance', this.selectedRelevance)
  115. this.$Router.navigateTo({
  116. url: '/pages_common/selectList/relevance',
  117. query: {
  118. type: this.field.formType
  119. }
  120. })
  121. },
  122. selectedRelevance(data) {
  123. if (this.guid === data.guid) {
  124. this.formValue = data.data
  125. this.$emit('input', this.formValue)
  126. this.$emit('change', {
  127. index: this.index,
  128. field: this.field,
  129. value: this.formValue
  130. })
  131. }
  132. uni.$off('selected-options')
  133. }
  134. }
  135. }
  136. </script>
  137. <style scoped lang="scss">
  138. @import './wkField.scss';
  139. </style>