chooseCustomModal.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <a-modal
  3. v-model="opened"
  4. :title="title"
  5. centered
  6. :maskClosable="false"
  7. :confirmLoading="confirmLoading"
  8. :width="800"
  9. :footer="null"
  10. @cancel="cancel"
  11. >
  12. <a-spin :spinning="spinning" tip="Loading...">
  13. <a-form-model
  14. id="chooseCustom-form"
  15. ref="ruleForm"
  16. :model="form"
  17. :rules="rules"
  18. :label-col="formItemLayout.labelCol"
  19. :wrapper-col="formItemLayout.wrapperCol">
  20. <a-form-model-item label="客户名称" prop="buyerSn">
  21. <dealerSubareaScopeList ref="dealerSubareaScopeList" id="chooseCustom-buyerSn" defValKey="buyerSn" @change="custChange" v-model="form.buyerSn" />
  22. </a-form-model-item>
  23. <a-form-model-item label="支付方式" prop="settleStyleSn">
  24. <v-select
  25. code="SETTLE_STYLE"
  26. id="chooseCustom-settleStyleSn"
  27. v-model="form.settleStyleSn"
  28. allowClear
  29. placeholder="请选择支付方式"></v-select>
  30. </a-form-model-item>
  31. <a-form-model-item prop="consigneeTel">
  32. <span slot="label">收货地址</span>
  33. {{ chooseAddr }}
  34. <a-button type="link" :disabled="!form.buyerSn" id="chooseCustom-chooseAddr" @click="handleChoose">{{ addressVal }} >></a-button>
  35. </a-form-model-item>
  36. <a-form-model-item :wrapper-col="{ span: 12, offset: 6 }" style="text-align: center;">
  37. <a-button type="primary" :loading="confirmLoading" @click="handleSubmit" id="chooseCustom-btn-submit">保存</a-button>
  38. <a-button @click="cancel" style="margin-left: 15px" id="chooseCustom-btn-back">取消</a-button>
  39. </a-form-model-item>
  40. </a-form-model>
  41. </a-spin>
  42. <!-- 选择地址 -->
  43. <choose-address-modal :openModal="openAddrModal" :paramsData="form.buyerSn" @ok="handleOk" @verify="verifyFun" @close="openAddrModal=false" />
  44. </a-modal>
  45. </template>
  46. <script>
  47. import { VSelect } from '@/components'
  48. import dealerSubareaScopeList from '@/views/common/dealerSubareaScopeList.vue'
  49. import chooseAddressModal from './receivingAddress/chooseAddressModal.vue'
  50. import { dealerRecevieAddrQuery } from '@/api/dealerRecevieAddr'
  51. import { salesSave } from '@/api/sales'
  52. export default {
  53. name: 'ChooseCustomModal',
  54. components: { VSelect, dealerSubareaScopeList, chooseAddressModal },
  55. props: {
  56. show: [Boolean]
  57. },
  58. data () {
  59. return {
  60. opened: this.show,
  61. spinning: false,
  62. title: '选择客户',
  63. confirmLoading: false,
  64. formItemLayout: {
  65. labelCol: { span: 4 },
  66. wrapperCol: { span: 18 }
  67. },
  68. form: {
  69. buyerSn: undefined, // 客户sn
  70. buyerName: '',
  71. settleStyleSn: undefined,
  72. shippingAddrProvinceSn: '',
  73. shippingAddrProvinceName: '', // 省
  74. shippingAddrCitySn: '',
  75. shippingAddrCityName: '', // 市
  76. shippingAddrCountySn: '',
  77. shippingAddrCountyName: '', // 区
  78. shippingAddr: '', // 详细地址
  79. consigneeTel: '', // 联系电话
  80. consigneeName: '' // 联系人名称
  81. },
  82. rules: {
  83. buyerSn: [ { required: true, message: '请选择客户', trigger: ['change', 'blur'] } ],
  84. settleStyleSn: [ { required: true, message: '请选择支付方式', trigger: ['change', 'blur'] } ],
  85. consigneeTel: [ { required: true, message: '请选择收货地址', trigger: ['change', 'blur'] } ]
  86. },
  87. addressVal: '选择地址', // 选择地址/更换地址
  88. chooseAddr: '', // 当前已选地址信息
  89. openAddrModal: false // 选择地址弹框是否显示
  90. }
  91. },
  92. methods: {
  93. // 客户 change
  94. custChange (val) {
  95. if (val && val.key) {
  96. this.form.buyerSn = val.key || undefined
  97. this.form.buyerName = val.name || ''
  98. this.getDefaultAddress()
  99. } else {
  100. this.verifyFun(this.addressId)
  101. }
  102. },
  103. // 选择地址
  104. handleChoose () {
  105. this.openAddrModal = true
  106. },
  107. // 保存
  108. handleSubmit (e) {
  109. e.preventDefault()
  110. const _this = this
  111. this.$refs.ruleForm.validate(valid => {
  112. if (valid) {
  113. _this.salesSaveFun()
  114. } else {
  115. console.log('error submit!!')
  116. return false
  117. }
  118. })
  119. },
  120. // 新建或编辑销售单
  121. salesSaveFun () {
  122. const _this = this
  123. const form = this.form
  124. _this.spinning = true
  125. salesSave(form).then(res => {
  126. if (res.status == 200) {
  127. _this.$message.success(res.message)
  128. _this.$emit('ok', res.data)
  129. if (_this.form.id) {
  130. _this.$emit('updateData')
  131. }
  132. _this.cancel()
  133. _this.spinning = false
  134. } else {
  135. _this.spinning = false
  136. }
  137. })
  138. },
  139. cancel () {
  140. this.opened = false
  141. this.$emit('cancel')
  142. this.$refs.ruleForm.resetFields()
  143. },
  144. // 地址保存
  145. handleOk (data) {
  146. this.chooseAddr = (data.consigneeName || '') + '(' + (data.consigneeTel || '-') + ')' + ' ' + (data.address || '')
  147. this.addressVal = '更换地址'
  148. this.form.shippingAddrProvinceSn = data.provinceSn || ''
  149. this.form.shippingAddrProvinceName = data.provinceName || '' // 省
  150. this.form.shippingAddrCitySn = data.citySn || ''
  151. this.form.shippingAddrCityName = data.cityName || '' // 市
  152. this.form.shippingAddrCountySn = data.countySn || ''
  153. this.form.shippingAddrCountyName = data.countyName || '' // 区
  154. this.form.shippingAddr = data.addr || ''// 详细地址
  155. this.form.consigneeTel = data.consigneeTel || '' // 联系电话
  156. this.form.consigneeName = data.consigneeName || ''
  157. this.addressId = data.id || undefined
  158. this.openAddrModal = false
  159. // 移除表单项的校验结果
  160. this.$refs.ruleForm.clearValidate('consigneeTel')
  161. },
  162. verifyFun (id) {
  163. if (id == this.addressId) {
  164. this.chooseAddr = ''
  165. this.addressVal = '选择地址'
  166. this.form.shippingAddrProvinceSn = ''
  167. this.form.shippingAddrProvinceName = ''// 省
  168. this.form.shippingAddrCitySn = ''
  169. this.form.shippingAddrCityName = '' // 市
  170. this.form.shippingAddrCountySn = ''
  171. this.form.shippingAddrCountyName = '' // 区
  172. this.form.shippingAddr = ''// 详细地址
  173. this.form.consigneeTel = '' // 联系电话
  174. this.form.consigneeName = ''
  175. }
  176. },
  177. // 获取默认地址
  178. getDefaultAddress () {
  179. dealerRecevieAddrQuery({ defaultFlag: 1, dealerSn: this.form.buyerSn }).then(res => {
  180. if (res.status == 200) {
  181. if (res.data.length == 1) {
  182. res.data[0].address = res.data[0].provinceName + '-' + res.data[0].cityName + '-' + res.data[0].countyName + '-' + res.data[0].addr
  183. this.addressId = res.data[0].id || undefined
  184. this.handleOk(res.data[0])
  185. } else {
  186. this.verifyFun(this.addressId)
  187. }
  188. }
  189. })
  190. }
  191. },
  192. watch: {
  193. show (newValue, oldValue) {
  194. this.opened = newValue
  195. if (!newValue) {
  196. this.$refs.dealerSubareaScopeList.resetForm()
  197. this.$refs.ruleForm.resetFields()
  198. this.verifyFun(this.addressId)
  199. }
  200. }
  201. }
  202. }
  203. </script>