dsModal.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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;padding-top:6px;">
  30. <div style="width:80%;flex-grow:1;line-height: 24px;">{{ chooseAddr }}</div>
  31. <a-button size="small" 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: '' // 地址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' } ]
  105. },
  106. detailData: null, // 详情数据
  107. addressVal: '选择地址', // 选择地址/更换地址
  108. chooseAddr: '', // 当前已选地址信息
  109. openAddrModal: false, // 选择地址弹框是否显示
  110. addressId: undefined
  111. }
  112. },
  113. methods: {
  114. setSendNo (i) {
  115. this.form.sendNo = i
  116. this.$refs.ruleForm.validateField('sendNo')
  117. },
  118. // 客户 change
  119. custChange (val) {
  120. if (val && val.key) {
  121. this.form.receiverSn = val.key || undefined
  122. this.form.receiverName = val.name || ''
  123. this.$refs.ruleForm.clearValidate()
  124. this.getDefaultAddress()
  125. } else {
  126. this.form.receiverSn = undefined
  127. this.form.receiverName = ''
  128. this.verifyFun(this.addressId)
  129. }
  130. },
  131. // 获取默认地址
  132. getDefaultAddress () {
  133. dealerRecevieAddrQuery({ defaultFlag: 1, dealerSn: this.form.receiverSn }).then(res => {
  134. if (res.status == 200) {
  135. if (res.data.length == 1) {
  136. const ret = res.data[0]
  137. ret.address = (ret.provinceName ? (ret.provinceName + '-') : '') + (ret.cityName ? (ret.cityName + '-') : '') + (ret.countyName ? (ret.countyName + '-') : '') + ret.addr
  138. this.handleOk(ret)
  139. } else {
  140. this.verifyFun(this.addressId)
  141. }
  142. }
  143. })
  144. },
  145. verifyFun (id) {
  146. if (id == this.addressId) {
  147. this.chooseAddr = ''
  148. this.addressVal = '选择地址'
  149. this.form.dealerRecevieAddressSn = ''
  150. }
  151. },
  152. // 保存
  153. handleSave () {
  154. const _this = this
  155. _this.$refs.ruleForm.validate(valid => {
  156. if (valid) {
  157. const formData = JSON.parse(JSON.stringify(_this.form))
  158. _this.$emit('ok', formData)
  159. _this.isShow = false
  160. } else {
  161. return false
  162. }
  163. })
  164. },
  165. // 地址保存
  166. handleOk (data) {
  167. console.log(data, 'chooseAddr')
  168. this.chooseAddr = (data.consigneeName || '') + '(' + (data.consigneeTel || '-') + ')' + ' ' + (data.address || '')
  169. this.addressVal = '更换地址'
  170. this.form.dealerRecevieAddressSn = data.dealerRecevieAddressSn || ''
  171. this.addressId = data.id || undefined
  172. this.openAddrModal = false
  173. // 移除表单项的校验结果
  174. console.log(this.form.dealerRecevieAddressSn)
  175. this.$refs.ruleForm.validateField('dealerRecevieAddressSn')
  176. },
  177. // 获取详情
  178. setDetail (data) {
  179. this.detailData = data
  180. },
  181. // 重置表单
  182. resetForm () {
  183. this.detailData = null
  184. this.$refs.ruleForm.resetFields()
  185. this.form = {
  186. sendNo: '',
  187. printStatus: undefined,
  188. buyerName: '',
  189. receiverSn: '',
  190. receiverName: '',
  191. dealerRecevieAddressSn: ''
  192. }
  193. this.$refs.dealerSubareaScopeList.resetForm()
  194. this.verifyFun(this.addressId)
  195. }
  196. },
  197. watch: {
  198. // 父页面传过来的弹框状态
  199. openModal (newValue, oldValue) {
  200. this.isShow = newValue
  201. },
  202. // 重定义的弹框状态
  203. isShow (newValue, oldValue) {
  204. if (!newValue) {
  205. this.$emit('close')
  206. this.resetForm()
  207. }
  208. }
  209. }
  210. }
  211. </script>
  212. <style lang="less">
  213. .dealerAccountEdit-modal{
  214. .ant-modal-body {
  215. padding: 40px 40px 24px;
  216. }
  217. .btn-cont {
  218. text-align: center;
  219. margin: 35px 0 10px;
  220. }
  221. }
  222. </style>