chooseCustomModal.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 { commonMixin } from '@/utils/mixin'
  48. import { VSelect } from '@/components'
  49. import dealerSubareaScopeList from '@/views/common/dealerSubareaScopeList.vue'
  50. import chooseAddressModal from './receivingAddress/chooseAddressModal.vue'
  51. import { dealerRecevieAddrQuery } from '@/api/dealerRecevieAddr'
  52. import { salesSave } from '@/api/sales'
  53. export default {
  54. name: 'SalesChooseCustomModal',
  55. mixins: [commonMixin],
  56. components: { VSelect, dealerSubareaScopeList, chooseAddressModal },
  57. props: {
  58. show: [Boolean]
  59. },
  60. data () {
  61. return {
  62. opened: this.show,
  63. spinning: false,
  64. title: '选择客户',
  65. confirmLoading: false,
  66. formItemLayout: {
  67. labelCol: { span: 4 },
  68. wrapperCol: { span: 18 }
  69. },
  70. form: {
  71. buyerSn: undefined, // 客户sn
  72. buyerName: '',
  73. settleStyleSn: undefined,
  74. shippingAddrProvinceSn: '',
  75. shippingAddrProvinceName: '', // 省
  76. shippingAddrCitySn: '',
  77. shippingAddrCityName: '', // 市
  78. shippingAddrCountySn: '',
  79. shippingAddrCountyName: '', // 区
  80. shippingAddr: '', // 详细地址
  81. consigneeTel: '', // 联系电话
  82. consigneeName: '' // 联系人名称
  83. },
  84. rules: {
  85. buyerSn: [ { required: true, message: '请选择客户', trigger: ['change', 'blur'] } ],
  86. settleStyleSn: [ { required: true, message: '请选择支付方式', trigger: ['change', 'blur'] } ],
  87. consigneeTel: [ { required: true, message: '请选择收货地址', trigger: ['change', 'blur'] } ]
  88. },
  89. addressVal: '选择地址', // 选择地址/更换地址
  90. chooseAddr: '', // 当前已选地址信息
  91. openAddrModal: false // 选择地址弹框是否显示
  92. }
  93. },
  94. methods: {
  95. // 客户 change
  96. custChange (val) {
  97. if (val && val.key) {
  98. this.form.buyerSn = val.key || undefined
  99. this.form.buyerName = val.name || ''
  100. this.$refs.ruleForm.clearValidate()
  101. this.getDefaultAddress()
  102. } else {
  103. this.verifyFun(this.addressId)
  104. }
  105. },
  106. // 选择地址
  107. handleChoose () {
  108. this.openAddrModal = true
  109. },
  110. // 保存
  111. handleSubmit (e) {
  112. e.preventDefault()
  113. const _this = this
  114. this.$refs.ruleForm.validate(valid => {
  115. if (valid) {
  116. _this.salesSaveFun()
  117. } else {
  118. console.log('error submit!!')
  119. return false
  120. }
  121. })
  122. },
  123. // 新建或编辑销售单
  124. salesSaveFun () {
  125. const _this = this
  126. const form = this.form
  127. _this.spinning = true
  128. salesSave(form).then(res => {
  129. if (res.status == 200) {
  130. _this.$message.success(res.message)
  131. _this.$emit('ok', res.data)
  132. if (_this.form.id) {
  133. _this.$emit('updateData')
  134. }
  135. _this.cancel()
  136. _this.spinning = false
  137. } else {
  138. _this.spinning = false
  139. }
  140. })
  141. },
  142. cancel () {
  143. this.opened = false
  144. this.$emit('cancel')
  145. this.$refs.ruleForm.resetFields()
  146. },
  147. // 地址保存
  148. handleOk (data) {
  149. this.chooseAddr = (data.consigneeName || '') + '(' + (data.consigneeTel || '-') + ')' + ' ' + (data.address || '')
  150. this.addressVal = '更换地址'
  151. this.form.shippingAddrProvinceSn = data.provinceSn || ''
  152. this.form.shippingAddrProvinceName = data.provinceName || '' // 省
  153. this.form.shippingAddrCitySn = data.citySn || ''
  154. this.form.shippingAddrCityName = data.cityName || '' // 市
  155. this.form.shippingAddrCountySn = data.countySn || ''
  156. this.form.shippingAddrCountyName = data.countyName || '' // 区
  157. this.form.shippingAddr = data.addr || ''// 详细地址
  158. this.form.consigneeTel = data.consigneeTel || '' // 联系电话
  159. this.form.consigneeName = data.consigneeName || ''
  160. this.addressId = data.id || undefined
  161. this.openAddrModal = false
  162. // 移除表单项的校验结果
  163. this.$refs.ruleForm.clearValidate('consigneeTel')
  164. },
  165. verifyFun (id) {
  166. if (id == this.addressId) {
  167. this.chooseAddr = ''
  168. this.addressVal = '选择地址'
  169. this.form.shippingAddrProvinceSn = ''
  170. this.form.shippingAddrProvinceName = ''// 省
  171. this.form.shippingAddrCitySn = ''
  172. this.form.shippingAddrCityName = '' // 市
  173. this.form.shippingAddrCountySn = ''
  174. this.form.shippingAddrCountyName = '' // 区
  175. this.form.shippingAddr = ''// 详细地址
  176. this.form.consigneeTel = '' // 联系电话
  177. this.form.consigneeName = ''
  178. }
  179. },
  180. // 获取默认地址
  181. getDefaultAddress () {
  182. dealerRecevieAddrQuery({ defaultFlag: 1, dealerSn: this.form.buyerSn }).then(res => {
  183. if (res.status == 200) {
  184. if (res.data.length == 1) {
  185. const ret = res.data[0]
  186. ret.address = (ret.provinceName ? (ret.provinceName + '-') : '') + (ret.cityName ? (ret.cityName + '-') : '') + (ret.countyName ? (ret.countyName + '-') : '') + ret.addr
  187. this.addressId = ret.id || undefined
  188. this.handleOk(ret)
  189. } else {
  190. this.verifyFun(this.addressId)
  191. }
  192. }
  193. })
  194. }
  195. },
  196. watch: {
  197. show (newValue, oldValue) {
  198. this.opened = newValue
  199. if (!newValue) {
  200. this.$refs.dealerSubareaScopeList.resetForm()
  201. this.$refs.ruleForm.resetFields()
  202. this.verifyFun(this.addressId)
  203. }
  204. }
  205. }
  206. }
  207. </script>