dsModal.vue 7.4 KB

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