chooseCustomModal.vue 7.6 KB

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