ProductInfoCard.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <div class="product-info-card" v-loading="loading">
  3. <el-form label-width="126px">
  4. <el-row :gutter="2">
  5. <el-col :span="24">
  6. <ProductTypeSelector
  7. :productTypeOptions="productTypeOptions2"
  8. :showErrorTip="showErrorTip"
  9. :value="productTypeResult"
  10. :loading="loading"
  11. :showLoading="true"
  12. @input="onProductionInput"
  13. @change="onProductionChange"
  14. />
  15. </el-col>
  16. </el-row>
  17. <el-collapse-transition>
  18. <el-row :gutter="2" v-if="productTypeResult && productTypeResult.productCode">
  19. <el-col :span="24">
  20. <ProductSchemaForm
  21. :productType="productTypeResult.productCode"
  22. :productInfo="productTypeInfo"
  23. :value="productForm"
  24. :index="index"
  25. :readonly="readonly"
  26. @input="onSchemaFormChange"
  27. @loading="changeLoading"
  28. />
  29. </el-col>
  30. </el-row>
  31. </el-collapse-transition>
  32. </el-form>
  33. </div>
  34. </template>
  35. <script>
  36. import ProductTypeSelector from './product-info-submodule/ProductTypeSelector.vue'
  37. import ProductSchemaForm from './schema-form/schema-form.vue'
  38. import { mapState } from 'vuex'
  39. import { cloneDeep } from 'lodash'
  40. export default {
  41. name: 'ProductInfoCard',
  42. components: {
  43. ProductTypeSelector,
  44. ProductSchemaForm,
  45. },
  46. props: {
  47. type: {
  48. type: String,
  49. default: ''
  50. },
  51. index: {
  52. type: [String, Number],
  53. default: '0'
  54. },
  55. readonly: {
  56. type: Boolean,
  57. default: false,
  58. },
  59. },
  60. data() {
  61. return {
  62. loading: false,
  63. // productTypeResult: {
  64. // productCode: '',
  65. // activityCode: '',
  66. // },
  67. // productTypeInfo: {},
  68. // form: {}
  69. }
  70. },
  71. computed: {
  72. ...mapState({
  73. productTypeOptions: state => state.order.productList,
  74. productInfoList: state => state.order.orderInfo.productInfoList,
  75. pageForm: state => state.order.pageForm,
  76. }),
  77. productTypeOptions2() {
  78. if (this.index <= 0) {
  79. // 过滤:产品1(索引是0的产品)隐藏那些只能赠送的选项
  80. const productList = cloneDeep(this.productTypeOptions)
  81. productList.forEach(p1 => {
  82. if (Array.isArray(p1.children) && p1.children.length > 0) {
  83. // 排除仅赠送的
  84. p1.children = p1.children.filter(p2 => p2.tactics !== 2)
  85. }
  86. })
  87. return productList.filter(t => t.children.length > 0)
  88. } else {
  89. return this.productTypeOptions
  90. }
  91. },
  92. productInfoListItem() {
  93. return this.productInfoList[this.index]?.productCardInfo || {}
  94. },
  95. productTypeInfo(){
  96. return this.productInfoListItem.info || {}
  97. },
  98. productForm() {
  99. return this.productInfoListItem.form || {}
  100. },
  101. productTypeResult() {
  102. return this.productInfoListItem.result || {
  103. productCode: '',
  104. activityCode: '',
  105. }
  106. },
  107. showErrorTip() {
  108. return this.pageForm.buySubject === 1
  109. },
  110. },
  111. methods: {
  112. onProductionChange(e) {
  113. // this.productTypeInfo = e.info
  114. const p = {
  115. key: 'info',
  116. data: e.info,
  117. index: this.index,
  118. }
  119. this.$store.commit('order/refreshOrderProductItemCardForm', p)
  120. this.onChange()
  121. },
  122. onProductionInput(e) {
  123. const p = {
  124. key: 'result',
  125. data: e,
  126. index: this.index,
  127. }
  128. this.$store.commit('order/refreshOrderProductItemCardForm', p)
  129. },
  130. onSchemaFormChange(e) {
  131. const p = {
  132. key: 'form',
  133. data: e,
  134. index: this.index,
  135. }
  136. this.$store.commit('order/refreshOrderProductItemCardForm', p)
  137. this.onChange()
  138. },
  139. getState() {
  140. const p = {
  141. result: this.productTypeResult,
  142. info: this.productTypeInfo,
  143. form: this.form,
  144. }
  145. return JSON.parse(JSON.stringify(p))
  146. },
  147. onChange() {
  148. const payload = this.getState()
  149. this.$emit('change', payload)
  150. },
  151. changeLoading(e) {
  152. this.loading = e
  153. }
  154. }
  155. }
  156. </script>
  157. <style lang="scss" scoped>
  158. ::v-deep {
  159. .product-type-cascader {
  160. width: 90%;
  161. }
  162. }
  163. </style>