chooseCustomModal.vue 14 KB

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