chooseCustomModal.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <template>
  2. <a-modal
  3. v-model="opened"
  4. :title="title"
  5. centered
  6. :maskClosable="false"
  7. :confirmLoading="confirmLoading"
  8. :width="960"
  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. >
  21. <a-row :gutter="15">
  22. <a-col :span="16">
  23. <a-form-model-item label="客户名称" prop="buyerSn" :labelCol="{ span: 3 }" :wrapperCol="{ span: 20 }">
  24. <custList ref="custList" :isValidateEnabled="true" @change="custChange" v-model="form.buyerSn"></custList>
  25. </a-form-model-item>
  26. </a-col>
  27. <!-- <a-col :span="16">
  28. <a-form-model-item>
  29. <a-button type="primary" class="button-primary" @click="openNewCust" icon="plus">新增</a-button>
  30. (点击新增按钮新增客户)
  31. </a-form-model-item>
  32. </a-col> -->
  33. </a-row>
  34. <a-row :gutter="15">
  35. <a-col :span="24">
  36. <a-form-model-item label="客户地址" required style="margin: 0;" :labelCol="{ span: 2 }" :wrapperCol="{ span: 22 }">
  37. <a-row :gutter="15">
  38. <!-- 客户地址 -->
  39. <a-col span="8">
  40. <a-form-model-item prop="provinceSn">
  41. <a-select id="chooseCustom-provinceSn" allowClear @change="getCityList" v-model="form.provinceSn" placeholder="请选择省">
  42. <a-select-option v-for="item in addrProvinceList" :value="item.areaSn" :key="item.areaSn + 'a'">{{ item.name }}</a-select-option>
  43. </a-select>
  44. </a-form-model-item>
  45. </a-col>
  46. <a-col span="8">
  47. <a-form-model-item prop="citySn">
  48. <a-select id="chooseCustom-citySn" allowClear @change="getAreaList" v-model="form.citySn" placeholder="请选择市">
  49. <a-select-option v-for="item in addrCityList" :value="item.areaSn" :key="item.areaSn + 'b'">{{ item.name }}</a-select-option>
  50. </a-select>
  51. </a-form-model-item>
  52. </a-col>
  53. <a-col span="8">
  54. <a-form-model-item prop="countySn">
  55. <a-select id="chooseCustom-countySn" allowClear @change="areaCharged" v-model="form.countySn" placeholder="请选择区/县">
  56. <a-select-option v-for="item in addrDistrictList" :value="item.areaSn" :key="item.areaSn + 'c'">{{ item.name }}</a-select-option>
  57. </a-select>
  58. </a-form-model-item>
  59. </a-col>
  60. </a-row>
  61. </a-form-model-item>
  62. </a-col>
  63. <a-col :span="24">
  64. <a-form-model-item label="详细地址" prop="customerAddr" :labelCol="{ span: 2 }" :wrapperCol="{ span: 22 }">
  65. <a-input
  66. id="chooseCustom-customerAddr"
  67. :maxLength="60"
  68. v-model="form.customerAddr"
  69. placeholder="请输入详细地址(最多60个字符)"
  70. allowClear />
  71. </a-form-model-item>
  72. </a-col>
  73. </a-row>
  74. <a-row :gutter="15">
  75. <a-col :span="8">
  76. <a-form-model-item label="联系人" prop="consigneeName">
  77. <a-input
  78. id="chooseCustom-consigneeName"
  79. :maxLength="30"
  80. v-model="form.consigneeName"
  81. placeholder="请输入联系人(最多30个字符)"
  82. allowClear />
  83. </a-form-model-item>
  84. </a-col>
  85. <a-col :span="8">
  86. <a-form-model-item label="联系电话" prop="contactTel">
  87. <a-input
  88. id="chooseCustom-contactTel"
  89. :maxLength="15"
  90. v-model="form.contactTel"
  91. placeholder="请输入联系电话(最多15个字符)"
  92. allowClear />
  93. </a-form-model-item>
  94. </a-col>
  95. <a-col :span="8">
  96. <a-form-model-item label="联系手机" prop="contactMobile">
  97. <a-input
  98. id="chooseCustom-contactMobile"
  99. :maxLength="11"
  100. v-model="form.contactMobile"
  101. placeholder="请输入联系手机(最多11个字符)"
  102. allowClear />
  103. </a-form-model-item>
  104. </a-col>
  105. </a-row>
  106. <a-row :gutter="15">
  107. <a-col :span="8">
  108. <a-form-model-item label="是否抓单" prop="grabFlag">
  109. <v-select code="FLAG" id="chooseCustom-grabFlag" v-model="form.grabFlag" allowClear placeholder="请选择"></v-select>
  110. </a-form-model-item>
  111. </a-col>
  112. <a-col :span="8">
  113. <a-form-model-item label="开单人">{{ $store.state.user.info.userNameCN }}</a-form-model-item>
  114. </a-col>
  115. </a-row>
  116. <a-form-model-item :wrapper-col="{ span: 12, offset: 6 }" style="text-align: center;">
  117. <a-button type="primary" :loading="confirmLoading" @click="handleSubmit" id="chooseCustom-btn-submit">保存</a-button>
  118. <a-button @click="cancel" style="margin-left: 15px" id="chooseCustom-btn-back">取消</a-button>
  119. </a-form-model-item>
  120. </a-form-model>
  121. <!-- 新增客户 -->
  122. <a-modal
  123. v-model="isNewCust"
  124. title="新增客户"
  125. centered
  126. width="60%"
  127. :maskClosable="false"
  128. @cancel="cancelNewCust"
  129. :footer="null"
  130. >
  131. <CustomerManagementEdit ref="newCust" model="modal" @ok="newCustFun"></CustomerManagementEdit>
  132. </a-modal>
  133. </a-spin>
  134. </a-modal>
  135. </template>
  136. <script>
  137. import { getArea } from '@/api/data'
  138. import { custFindById, updateByCustomerSn } from '@/api/customer'
  139. import { salesReturnSave } from '@/api/salesReturn'
  140. import { VSelect } from '@/components'
  141. import custList from '@/views/common/custList.vue'
  142. import CustomerManagementEdit from '@/views/customerManagement/customerInfo/edit.vue'
  143. export default {
  144. name: 'ChooseCustomModal',
  145. components: { VSelect, CustomerManagementEdit, custList },
  146. props: {
  147. show: [Boolean]
  148. },
  149. data () {
  150. return {
  151. spinning: false,
  152. opened: this.show,
  153. title: '选择客户',
  154. confirmLoading: false,
  155. formItemLayout: {
  156. labelCol: { span: 6 },
  157. wrapperCol: { span: 18 }
  158. },
  159. buyerSnBak: '', // 更改前客户sn备份
  160. form: {
  161. buyerName: '', // 客户名称
  162. buyerSn: undefined, // 客户sn
  163. contactTel: '', // 联系电话
  164. contactMobile: '',
  165. consigneeName: '', // 联系人
  166. priceType: '', // 价格类型
  167. provinceSn: undefined, // 省
  168. provinceName: '',
  169. citySn: undefined, // 市
  170. cityName: '',
  171. countySn: undefined, // 区
  172. countyName: '',
  173. customerAddr: '', // 详细地址
  174. grabFlag: '1' // 是否抓单
  175. },
  176. rules: {
  177. buyerSn: [
  178. { required: true, message: '请选择客户', trigger: ['change', 'blur'] }
  179. ],
  180. contactMobile: [{ required: false, pattern: /^\d{11}$/, message: '请输入正确的手机号', trigger: 'blur' }],
  181. provinceSn: [
  182. { required: true, message: '请选择省', trigger: 'change' }
  183. ],
  184. citySn: [
  185. { required: true, message: '请选择市', trigger: 'change' }
  186. ],
  187. countySn: [
  188. { required: true, message: '请选择区/县', trigger: 'change' }
  189. ],
  190. grabFlag: [
  191. { required: true, message: '请选择是否铺货出库', trigger: 'change' }
  192. ]
  193. },
  194. addrProvinceList: [], // 省下拉
  195. addrCityList: [], // 市下拉
  196. addrDistrictList: [], // 区下拉
  197. custId: undefined, // 客户id
  198. isEdit: false, // 是否编辑状态
  199. isChangeCust: false, // 是否更换客户
  200. interId: null,
  201. isNewCust: false // 是否新增客户
  202. }
  203. },
  204. methods: {
  205. openNewCust () {
  206. this.isNewCust = true
  207. setTimeout(() => {
  208. this.$refs.newCust.getBaseData()
  209. }, 500)
  210. },
  211. // 新建客户
  212. newCustFun (data) {
  213. console.log(data, this.isEdit)
  214. this.isNewCust = false
  215. // 更新客户信息
  216. this.$refs.custList.setData({ key: data.customerSn, label: data.customerName, row: data })
  217. this.custChange({ key: data.customerSn, label: data.customerName, row: data })
  218. },
  219. cancelNewCust () {
  220. this.isNewCust = false
  221. this.$refs.newCust.getBaseData()
  222. },
  223. // 客户 change
  224. custChange (obj) {
  225. const _this = this
  226. if (obj && obj.key) {
  227. const cust = obj.row
  228. this.form.buyerSn = cust.customerSn
  229. // 编辑
  230. if (this.isEdit) {
  231. this.$confirm({
  232. title: '提示',
  233. content: '更换客户后信息需要重新完善,确认要更换吗?',
  234. centered: true,
  235. onOk () {
  236. _this.custId = cust.id
  237. _this.form.buyerName = cust.customerName
  238. _this.getDetail()
  239. },
  240. onCancel () {
  241. _this.form.buyerSn = _this.buyerSnBak
  242. }
  243. })
  244. } else {
  245. _this.custId = cust.id
  246. _this.form.buyerName = cust.customerName
  247. _this.getDetail()
  248. }
  249. } else {
  250. this.$refs.ruleForm.resetFields()
  251. this.$refs.custList.resetForm()
  252. }
  253. },
  254. // 编辑客户信息
  255. editCust (data) {
  256. console.log(data)
  257. this.title = '编辑客户信息'
  258. this.isEdit = true
  259. if (data.provinceSn) { this.getArea('city', data.provinceSn) }
  260. if (data.citySn) { this.getArea('district', data.citySn) }
  261. this.form = Object.assign(this.form, data)
  262. this.buyerSnBak = this.form.buyerSn
  263. },
  264. // 获取详情
  265. getDetail () {
  266. custFindById({ id: this.custId }).then(res => {
  267. const data = res.data
  268. if (res.status == 200 && data) {
  269. if (data.provinceSn) { this.getArea('city', data.provinceSn) }
  270. if (data.citySn) { this.getArea('district', data.citySn) }
  271. this.form = Object.assign(this.form, {
  272. buyerName: data.customerName, // 客户名称
  273. buyerSn: data.customerSn, // 客户sn
  274. contactTel: data.contactTel, // 联系电话
  275. contactMobile: data.contactMobile,
  276. consigneeName: data.contactName, // 联系人
  277. provinceSn: data.provinceSn, // 省
  278. provinceName: data.provinceName,
  279. priceType: data.priceType,
  280. citySn: data.citySn, // 市
  281. cityName: data.cityName,
  282. countySn: data.countySn, // 区
  283. countyName: data.countyName,
  284. customerAddr: data.customerAddr, // 详细地址
  285. fax: data.fax // 客户传真
  286. })
  287. } else {
  288. this.$message.error('获取客户信息失败')
  289. this.$refs.ruleForm.resetFields()
  290. }
  291. this.$refs.ruleForm.clearValidate()
  292. })
  293. },
  294. // 保存客户信息
  295. handleSaveCust () {
  296. const params = {
  297. customerName: this.form.buyerName,
  298. customerSn: this.form.buyerSn,
  299. contactTel: this.form.contactTel, // 联系电话
  300. contactMobile: this.form.contactMobile,
  301. contactName: this.form.consigneeName, // 联系人
  302. provinceSn: this.form.provinceSn, // 省
  303. provinceName: this.form.provinceName,
  304. priceType: this.form.priceType,
  305. citySn: this.form.citySn, // 市
  306. cityName: this.form.cityName,
  307. countySn: this.form.countySn, // 区
  308. countyName: this.form.countyName,
  309. customerAddr: this.form.customerAddr // 详细地址
  310. }
  311. this.spinning = true
  312. updateByCustomerSn(params).then(res => {
  313. this.spinning = false
  314. if (res.status == 200) {
  315. // 保存销售单
  316. this.salesSaveFun()
  317. this.spinning = false
  318. } else {
  319. this.spinning = false
  320. }
  321. })
  322. },
  323. // 保存
  324. handleSubmit (e) {
  325. e.preventDefault()
  326. const _this = this
  327. this.$refs.ruleForm.validate(valid => {
  328. if (valid) {
  329. // 保存客户信息
  330. _this.handleSaveCust()
  331. } else {
  332. console.log('error submit!!')
  333. return false
  334. }
  335. })
  336. },
  337. // 新建或编辑销售单
  338. salesSaveFun () {
  339. const _this = this
  340. const form = this.form
  341. _this.spinning = true
  342. salesReturnSave(form).then(res => {
  343. if (res.status == 200) {
  344. _this.$message.success(res.message)
  345. _this.$emit('ok', res.data)
  346. _this.cancel()
  347. _this.spinning = false
  348. } else {
  349. _this.spinning = false
  350. }
  351. })
  352. },
  353. cancel () {
  354. this.opened = false
  355. this.$refs.ruleForm.resetFields()
  356. this.$refs.custList.resetForm()
  357. this.$emit('cancel')
  358. },
  359. // 获取城市列表
  360. getCityList (val) {
  361. this.addrCityList = []
  362. this.addrDistrictList = []
  363. this.form.citySn = undefined
  364. this.form.cityName = ''
  365. this.form.countySn = undefined
  366. this.form.countyName = ''
  367. this.form.customerAddr = ''
  368. if (val) {
  369. this.getArea('city', val)
  370. this.form.provinceName = this.addrProvinceList.find(item => item.areaSn == val).name
  371. } else {
  372. this.form.provinceName = ''
  373. }
  374. },
  375. // 获取区县列表
  376. getAreaList (val) {
  377. this.addrDistrictList = []
  378. this.form.countySn = undefined
  379. this.form.countyName = ''
  380. this.form.customerAddr = ''
  381. if (val) {
  382. this.getArea('district', val)
  383. this.form.cityName = this.addrCityList.find(item => item.areaSn == val).name
  384. } else {
  385. this.form.cityName = ''
  386. }
  387. },
  388. // 区县变更
  389. areaCharged (val) {
  390. this.form.customerAddr = ''
  391. if (val) {
  392. this.form.countyName = this.addrDistrictList.find(item => item.areaSn == val).name
  393. } else {
  394. this.form.countyName = ''
  395. }
  396. },
  397. // 省/市/区
  398. getArea (leve, sn) {
  399. let params
  400. if (leve == 'province') {
  401. params = { type: '2' }
  402. } else {
  403. params = { parentId: sn, type: leve == 'city' ? '3' : '4' }
  404. }
  405. getArea(params).then(res => {
  406. if (res.status == 200) {
  407. if (leve == 'province') {
  408. this.addrProvinceList = res.data || []
  409. } else if (leve == 'city') {
  410. this.addrCityList = res.data || []
  411. } else if (leve == 'district') {
  412. this.addrDistrictList = res.data || []
  413. }
  414. } else {
  415. if (leve == 'province') {
  416. this.addrProvinceList = []
  417. } else if (leve == 'city') {
  418. this.addrCityList = []
  419. } else if (leve == 'district') {
  420. this.addrDistrictList = []
  421. }
  422. }
  423. })
  424. }
  425. },
  426. watch: {
  427. show (newValue, oldValue) {
  428. this.opened = newValue
  429. if (newValue) {
  430. this.getArea('province')
  431. }
  432. }
  433. }
  434. }
  435. </script>