associateModal.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <a-modal
  3. centered
  4. class="relationshipBinding-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="编辑"
  8. v-model="isShow"
  9. @cancel="isShow=false"
  10. :width="800">
  11. <!-- 表单 -->
  12. <div>
  13. <a-spin :spinning="spinning" tip="Loading...">
  14. <a-form-model
  15. id="relationshipBinding-form"
  16. ref="ruleForm"
  17. :model="form"
  18. :rules="rules"
  19. :label-col="formItemLayout.labelCol"
  20. :wrapper-col="formItemLayout.wrapperCol"
  21. >
  22. <a-form-model-item label="经销商名称" v-if="nowData">
  23. {{ nowData.subDealer.dealerName }}
  24. </a-form-model-item>
  25. <a-form-model-item label="上级经销商">
  26. <queryChild ref="higherLevel" :isShowSn="rebateDealerSn" placeholderInfo="请输入上级经销商名称搜索" :dealerLevelList="dealerLevelList" @change="handleHigherLevel"></queryChild>
  27. </a-form-model-item>
  28. <a-form-model-item label="指定差价归属">
  29. <queryChild ref="queryChid" :isShowSn="higherDealerSn" placeholderInfo="请输入指定差价归属经销商名称搜索" :dealerLevelList="dealerLevelList" @change="handleDisassociate"></queryChild>
  30. </a-form-model-item>
  31. </a-form-model>
  32. <div class="btn-cont">
  33. <a-button id="product-category-edit-modal-back" @click="isShow = false" >取消</a-button>
  34. <a-button type="primary" style="margin-left: 15px;" id="product-category-edit-modal-save" @click="handleSave">确定</a-button>
  35. </div>
  36. </a-spin>
  37. </div>
  38. </a-modal>
  39. </template>
  40. <script>
  41. import { commonMixin } from '@/utils/mixin'
  42. import { updateRebate } from '@/api/dealerRelation'
  43. import queryChild from './queryChild.vue'
  44. export default {
  45. name: 'AssociateModal',
  46. mixins: [commonMixin],
  47. components: { queryChild },
  48. props: {
  49. openModal: { // 弹框显示状态
  50. type: Boolean,
  51. default: false
  52. },
  53. nowData: {
  54. type: Object,
  55. default: null
  56. }
  57. },
  58. data () {
  59. return {
  60. isShow: this.openModal, // 是否打开弹框
  61. spinning: false,
  62. form: {},
  63. rules: {},
  64. formItemLayout: {
  65. labelCol: { span: 6 },
  66. wrapperCol: { span: 16 }
  67. },
  68. dealerLevelList: [],
  69. rebateDealerSn: '',
  70. higherDealerSn: ''
  71. }
  72. },
  73. methods: {
  74. handleDisassociate (val) {
  75. console.log('选中', val)
  76. this.rebateDealerSn = val ? val.key : ''
  77. },
  78. handleHigherLevel (e) {
  79. this.higherDealerSn = e ? e.key : ''
  80. },
  81. // 保存
  82. handleSave () {
  83. const _this = this
  84. _this.$refs.ruleForm.validate(valid => {
  85. if (valid) {
  86. const formData = {
  87. parentDealerSn: _this.higherDealerSn,
  88. rebateDealerSn: _this.rebateDealerSn,
  89. dealerSn: _this.nowData && _this.nowData.subDealer.dealerSn ? _this.nowData.subDealer.dealerSn : undefined
  90. }
  91. _this.spinning = true
  92. updateRebate(formData).then(res => {
  93. if (res.status == 200) {
  94. _this.$message.success(res.message)
  95. _this.$emit('ok', formData.dealerSn)
  96. _this.isShow = false
  97. _this.spinning = false
  98. } else {
  99. _this.spinning = false
  100. }
  101. })
  102. } else {
  103. return false
  104. }
  105. })
  106. },
  107. filterOption (input, option) {
  108. return (
  109. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  110. )
  111. }
  112. },
  113. watch: {
  114. // 父页面传过来的弹框状态
  115. openModal (newValue, oldValue) {
  116. this.isShow = newValue
  117. },
  118. // 重定义的弹框状态
  119. isShow (newValue, oldValue) {
  120. if (!newValue) {
  121. this.$emit('close')
  122. this.$refs.ruleForm.resetFields()
  123. this.$refs.higherLevel.resetForm()
  124. this.$refs.queryChid.resetForm()
  125. this.rebateDealerSn = ''
  126. this.higherDealerSn = ''
  127. this.dealerLevelList = []
  128. } else {
  129. // 上级经销商
  130. if (this.nowData && this.nowData.supDealer) {
  131. this.higherDealerSn = this.nowData.supDealer.dealerSn ? this.nowData.supDealer.dealerSn : ''
  132. const higherDealerName = this.nowData.supDealer.dealerName ? this.nowData.supDealer.dealerName : ''
  133. if (higherDealerName) {
  134. this.$refs.higherLevel.setVal(this.higherDealerSn, higherDealerName)
  135. }
  136. }
  137. // 指定差价归属
  138. if (this.nowData && this.nowData.rebateDealer) {
  139. this.rebateDealerSn = this.nowData.rebateDealer.dealerSn ? this.nowData.rebateDealer.dealerSn : ''
  140. const dealerName = this.nowData.rebateDealer.dealerName ? this.nowData.rebateDealer.dealerName : ''
  141. this.$refs.queryChid.setVal(this.rebateDealerSn, dealerName)
  142. }
  143. // 特约 ['CITY', 'PROVINCE'] 市级经销商 ['PROVINCE']
  144. if (this.nowData && this.nowData.subDealer) {
  145. this.dealerLevelList = this.nowData.subDealer.dealerLevel == 'CITY' ? ['PROVINCE'] : ['CITY', 'PROVINCE']
  146. }
  147. }
  148. }
  149. }
  150. }
  151. </script>
  152. <style lang="less">
  153. .relationshipBinding-modal{
  154. .ant-modal-body {
  155. padding: 40px 40px 24px;
  156. }
  157. .search-opt{
  158. padding: 0;
  159. margin: 0;
  160. list-style: none;
  161. li{
  162. padding: 5px 15px;
  163. }
  164. }
  165. .btn-cont {
  166. text-align: center;
  167. margin: 35px 0 10px;
  168. }
  169. }
  170. </style>