dsModal.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <a-modal
  3. centered
  4. class="dealerAccountEdit-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. :title="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="dealerAccountEdit-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="客户名称">
  23. <span>{{ detailData ? detailData.buyerName : '--' }}</span>
  24. </a-form-model-item>
  25. <a-form-model-item label="收货客户名称" extra="如果收货客户和下单客户相同,则不需要选择收货客户名称">
  26. <dealerSubareaScopeList ref="dealerSubareaScopeList" defValKey="buyerSn" @change="custChange" v-model="form.receiverSn" />
  27. </a-form-model-item>
  28. <a-form-model-item label="收货地址" prop="dealerRecevieAddressSn" v-if="form.receiverSn">
  29. <div style="display:flex;">
  30. <div style="width:80%;flex-grow:1;line-height: 24px;">{{ chooseAddr }}</div>
  31. <a-button type="link" @click="openAddrModal = true">{{ addressVal }} >></a-button>
  32. </div>
  33. </a-form-model-item>
  34. <a-form-model-item label="发货编号" prop="sendNo">
  35. <a-input
  36. id="dealerAccountEdit-phone"
  37. :maxLength="10"
  38. v-model.trim="form.sendNo"
  39. placeholder="请输入发货编号"
  40. allowClear />
  41. <div style="height: 24px;line-height: normal;">
  42. 常用:<a-button size="small" v-for="i in 5" @click="setSendNo(i)" type="link">{{ i }}</a-button>
  43. </div>
  44. </a-form-model-item>
  45. <a-form-model-item label="备货打印" prop="printStatus">
  46. <a-radio-group v-model="form.printStatus">
  47. <a-radio value="NO_PRINT">
  48. 允许打印
  49. </a-radio>
  50. <a-radio value="UNABLE_PRINT">
  51. 暂不打印
  52. </a-radio>
  53. </a-radio-group>
  54. </a-form-model-item>
  55. </a-form-model>
  56. <div class="btn-cont">
  57. <a-button id="dealerAccountEdit-back" @click="isShow = false">取消下推</a-button>
  58. <a-button type="primary" id="dealerAccountEdit-save" @click="handleSave" style="margin-left: 15px;">确定下推</a-button>
  59. </div>
  60. </a-spin>
  61. <!-- 选择地址 -->
  62. <choose-address-modal :openModal="openAddrModal" :paramsData="form.receiverSn" @ok="handleOk" @verify="verifyFun" @close="openAddrModal=false" />
  63. </div>
  64. </a-modal>
  65. </template>
  66. <script>
  67. import { commonMixin } from '@/utils/mixin'
  68. import chooseAddressModal from '../salesQuery/receivingAddress/chooseAddressModal.vue'
  69. import dealerSubareaScopeList from '@/views/common/dealerSubareaScopeList.vue'
  70. import { dealerRecevieAddrQuery } from '@/api/dealerRecevieAddr'
  71. export default {
  72. name: 'DsModal',
  73. mixins: [commonMixin],
  74. components: { dealerSubareaScopeList, chooseAddressModal },
  75. props: {
  76. openModal: { // 弹框显示状态
  77. type: Boolean,
  78. default: false
  79. },
  80. title: {
  81. type: String,
  82. default: '下推销售单'
  83. }
  84. },
  85. data () {
  86. return {
  87. isShow: this.openModal, // 是否打开弹框
  88. spinning: false,
  89. formItemLayout: {
  90. labelCol: { span: 4 },
  91. wrapperCol: { span: 18 }
  92. },
  93. form: {
  94. sendNo: '',
  95. printStatus: undefined,
  96. buyerName: '',
  97. receiverSn: '',
  98. receiverName: '',
  99. dealerRecevieAddressSn: undefined // 地址sn
  100. },
  101. rules: {
  102. sendNo: [{ required: true, message: '请输入发货编号', trigger: 'change' }],
  103. printStatus: [{ required: true, message: '请选择备货打印', trigger: 'change' }],
  104. dealerRecevieAddressSn: [ { required: true, message: '请选择收货地址', trigger: ['change', 'blur'] } ]
  105. },
  106. detailData: null, // 详情数据
  107. addressVal: '选择地址', // 选择地址/更换地址
  108. chooseAddr: '', // 当前已选地址信息
  109. openAddrModal: false // 选择地址弹框是否显示
  110. }
  111. },
  112. methods: {
  113. setSendNo (i) {
  114. this.form.sendNo = i
  115. this.$refs.ruleForm.validateField('sendNo')
  116. },
  117. // 客户 change
  118. custChange (val) {
  119. if (val && val.key) {
  120. this.form.receiverSn = val.key || undefined
  121. this.form.receiverName = val.name || ''
  122. this.$refs.ruleForm.clearValidate()
  123. this.getDefaultAddress()
  124. } else {
  125. this.verifyFun(this.addressId)
  126. }
  127. },
  128. // 获取默认地址
  129. getDefaultAddress () {
  130. dealerRecevieAddrQuery({ defaultFlag: 1, dealerSn: this.form.receiverSn }).then(res => {
  131. if (res.status == 200) {
  132. if (res.data.length == 1) {
  133. const ret = res.data[0]
  134. ret.address = (ret.provinceName ? (ret.provinceName + '-') : '') + (ret.cityName ? (ret.cityName + '-') : '') + (ret.countyName ? (ret.countyName + '-') : '') + ret.addr
  135. this.addressId = ret.id || undefined
  136. this.handleOk(ret)
  137. } else {
  138. this.verifyFun(this.addressId)
  139. }
  140. }
  141. })
  142. },
  143. verifyFun (id) {
  144. if (id == this.addressId) {
  145. this.chooseAddr = ''
  146. this.addressVal = '选择地址'
  147. this.form.dealerRecevieAddressSn = undefined
  148. }
  149. },
  150. // 保存
  151. handleSave () {
  152. const _this = this
  153. _this.$refs.ruleForm.validate(valid => {
  154. if (valid) {
  155. const formData = JSON.parse(JSON.stringify(_this.form))
  156. _this.$emit('ok', formData)
  157. _this.isShow = false
  158. } else {
  159. return false
  160. }
  161. })
  162. },
  163. // 地址保存
  164. handleOk (data) {
  165. console.log(data, 'chooseAddr')
  166. this.chooseAddr = (data.consigneeName || '') + '(' + (data.consigneeTel || '-') + ')' + ' ' + (data.address || '')
  167. this.addressVal = '更换地址'
  168. this.form.dealerRecevieAddressSn = data.dealerRecevieAddressSn || undefined
  169. this.addressId = data.id || undefined
  170. this.openAddrModal = false
  171. // 移除表单项的校验结果
  172. this.$refs.ruleForm.clearValidate('dealerRecevieAddressSn')
  173. },
  174. // 获取详情
  175. setDetail (data) {
  176. this.detailData = data
  177. },
  178. // 重置表单
  179. resetForm () {
  180. this.detailData = null
  181. this.$refs.ruleForm.resetFields()
  182. this.form = {
  183. sendNo: '',
  184. printStatus: undefined,
  185. buyerName: '',
  186. receiverSn: '',
  187. receiverName: ''
  188. }
  189. this.$refs.dealerSubareaScopeList.resetForm()
  190. this.verifyFun(this.addressId)
  191. }
  192. },
  193. watch: {
  194. // 父页面传过来的弹框状态
  195. openModal (newValue, oldValue) {
  196. this.isShow = newValue
  197. },
  198. // 重定义的弹框状态
  199. isShow (newValue, oldValue) {
  200. if (!newValue) {
  201. this.$emit('close')
  202. this.resetForm()
  203. }
  204. }
  205. }
  206. }
  207. </script>
  208. <style lang="less">
  209. .dealerAccountEdit-modal{
  210. .ant-modal-body {
  211. padding: 40px 40px 24px;
  212. }
  213. .btn-cont {
  214. text-align: center;
  215. margin: 35px 0 10px;
  216. }
  217. }
  218. </style>