dsModal.vue 9.2 KB

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