chooseCustomModal.vue 7.8 KB

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