chooseCustomModal.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <template>
  2. <div v-if="opened">
  3. <a-modal
  4. v-model="opened"
  5. :title="title"
  6. centered
  7. :maskClosable="false"
  8. :confirmLoading="confirmLoading"
  9. :width="960"
  10. :footer="null"
  11. @cancel="cancel"
  12. >
  13. <a-spin :spinning="spinning" tip="Loading...">
  14. <a-form-model
  15. id="chooseCustom-form"
  16. ref="ruleForm"
  17. :model="form"
  18. :rules="rules"
  19. :label-col="formItemLayout.labelCol"
  20. :wrapper-col="formItemLayout.wrapperCol"
  21. >
  22. <a-row :gutter="15">
  23. <a-col :span="16">
  24. <a-form-model-item label="客户名称" prop="buyerSn" :labelCol="{ span: 3 }" :wrapperCol="{ span: 20 }">
  25. <selectCust ref="custList" :isValidateEnabled="true" id="chooseCustom-buyerSn" @change="custChange" v-model="form.buyerSn"></selectCust>
  26. </a-form-model-item>
  27. </a-col>
  28. <a-col :span="8" v-if="$hasPermissions('B_customer_customerInfo_add')">
  29. <a-form-model-item :labelCol="{ span: 0 }" :wrapperCol="{ span: 24 }">
  30. <a-button type="primary" class="button-primary" @click="openNewCust" icon="plus">新增</a-button>
  31. (点击新增按钮新增客户)
  32. </a-form-model-item>
  33. </a-col>
  34. </a-row>
  35. <a-row :gutter="15">
  36. <a-col :span="24">
  37. <a-form-model-item label="客户地址" required style="margin: 0;" :labelCol="{ span: 2 }" :wrapperCol="{ span: 22 }">
  38. <a-row :gutter="15">
  39. <!-- 客户地址 -->
  40. <a-col span="8">
  41. <a-form-model-item prop="shippingAddressProvinceSn">
  42. <a-select id="chooseCustom-provinceSn" allowClear @change="getCityList" v-model="form.shippingAddressProvinceSn" placeholder="请选择省">
  43. <a-select-option v-for="item in addrProvinceList" :value="item.areaSn" :key="item.areaSn + 'a'">{{ item.name }}</a-select-option>
  44. </a-select>
  45. </a-form-model-item>
  46. </a-col>
  47. <a-col span="8">
  48. <a-form-model-item prop="shippingAddressCitySn">
  49. <a-select id="chooseCustom-citySn" allowClear @change="getAreaList" v-model="form.shippingAddressCitySn" placeholder="请选择市">
  50. <a-select-option v-for="item in addrCityList" :value="item.areaSn" :key="item.areaSn + 'b'">{{ item.name }}</a-select-option>
  51. </a-select>
  52. </a-form-model-item>
  53. </a-col>
  54. <a-col span="8">
  55. <a-form-model-item prop="shippingAddressCountySn">
  56. <a-select id="chooseCustom-countySn" allowClear @change="areaCharged" v-model="form.shippingAddressCountySn" placeholder="请选择区/县">
  57. <a-select-option v-for="item in addrDistrictList" :value="item.areaSn" :key="item.areaSn + 'c'">{{ item.name }}</a-select-option>
  58. </a-select>
  59. </a-form-model-item>
  60. </a-col>
  61. </a-row>
  62. </a-form-model-item>
  63. </a-col>
  64. <a-col :span="24">
  65. <a-form-model-item label="详细地址" prop="shippingAddress" :labelCol="{ span: 2 }" :wrapperCol="{ span: 22 }">
  66. <a-input
  67. id="chooseCustom-shippingAddress"
  68. :maxLength="60"
  69. v-model.trim="form.shippingAddress"
  70. placeholder="请输入详细地址(最多60个字符)"
  71. allowClear />
  72. </a-form-model-item>
  73. </a-col>
  74. </a-row>
  75. <a-row :gutter="15">
  76. <a-col :span="8">
  77. <a-form-model-item label="联系人" prop="consigneeName">
  78. <a-input
  79. id="chooseCustom-consigneeName"
  80. :maxLength="30"
  81. v-model.trim="form.consigneeName"
  82. placeholder="请输入联系人(最多30个字符)"
  83. allowClear />
  84. </a-form-model-item>
  85. </a-col>
  86. <a-col :span="8">
  87. <a-form-model-item label="联系电话" prop="consigneeTel">
  88. <a-input
  89. id="chooseCustom-consigneeTel"
  90. :maxLength="15"
  91. v-model.trim="form.consigneeTel"
  92. placeholder="请输入联系电话(最多15个字符)"
  93. allowClear />
  94. </a-form-model-item>
  95. </a-col>
  96. <a-col :span="8">
  97. <a-form-model-item label="联系手机" prop="consigneeMobile">
  98. <a-input
  99. id="chooseCustom-consigneeMobile"
  100. :maxLength="11"
  101. v-model.trim="form.consigneeMobile"
  102. placeholder="请输入联系电话(最多11个字符)"
  103. allowClear />
  104. </a-form-model-item>
  105. </a-col>
  106. </a-row>
  107. <a-row :gutter="15">
  108. <a-col :span="8">
  109. <a-form-model-item label="价格类型" prop="priceType">
  110. <a-row :gutter="15">
  111. <a-col :span="20">
  112. <v-select
  113. code="PRICE_TYPE"
  114. :disabled="priceTypeDisabled"
  115. id="chooseCustom-priceType"
  116. v-model="form.priceType"
  117. @change="changePriceType"
  118. allowClear
  119. placeholder="请选择价格类型" ></v-select>
  120. </a-col>
  121. <a-col :span="4">
  122. <a-popover>
  123. <template slot="content">(选择后在当前工单不可修改)</template>
  124. <a-icon type="question-circle" />
  125. </a-popover>
  126. </a-col>
  127. </a-row>
  128. </a-form-model-item>
  129. </a-col>
  130. <a-col :span="8">
  131. <a-form-model-item label="收款方式" prop="settleStyleSn">
  132. <settleStyle
  133. v-model="form.settleStyleSn"
  134. placeholder="请选择收款方式">
  135. </settleStyle>
  136. </a-form-model-item>
  137. </a-col>
  138. <a-col :span="8">
  139. <a-form-model-item label="配送方式" prop="dispatchType">
  140. <v-select code="DISPATCH_TYPE" id="chooseCustom-dispatchType" v-model="form.dispatchType" allowClear placeholder="请选择配送方式"></v-select>
  141. </a-form-model-item>
  142. </a-col>
  143. </a-row>
  144. <a-row :gutter="15">
  145. <a-col :span="8">
  146. <a-form-model-item label="业务员" prop="salesManSn">
  147. <a-select id="chooseCustom-salesManSn" allowClear @change="salesManChange" v-model="form.salesManSn" placeholder="请选择业务员">
  148. <a-select-option v-for="item in userList" :value="item.employeeSn" :key="item.id + 'c'">{{ item.name }}</a-select-option>
  149. </a-select>
  150. </a-form-model-item>
  151. </a-col>
  152. <a-col :span="8">
  153. <a-form-model-item label="铺货出库" prop="distributionFlag">
  154. <v-select code="FLAG" id="chooseCustom-distributionFlag" v-model="form.distributionFlag" allowClear placeholder="请选择是否铺货出库"></v-select>
  155. </a-form-model-item>
  156. </a-col>
  157. </a-row>
  158. <a-row :gutter="15">
  159. <a-col :span="8">
  160. <a-form-model-item label="备注" prop="remarks">
  161. <a-input
  162. id="chooseCustom-remarks"
  163. type="textarea"
  164. :maxLength="100"
  165. v-model.trim="form.remarks"
  166. placeholder="请输入备注(最多100个字符)"
  167. allowClear />
  168. </a-form-model-item>
  169. </a-col>
  170. <a-col :span="8">
  171. <a-form-model-item label="开单人">{{ $store.state.user.info.userNameCN }}</a-form-model-item>
  172. </a-col>
  173. </a-row>
  174. <a-form-model-item :wrapper-col="{ span: 12, offset: 6 }" style="text-align: center;">
  175. <a-button type="primary" size="large" :loading="confirmLoading" @click="handleSubmit" id="chooseCustom-btn-submit">保存</a-button>
  176. <a-button @click="cancel" size="large" style="margin-left: 15px" id="chooseCustom-btn-back">取消</a-button>
  177. </a-form-model-item>
  178. </a-form-model>
  179. <!-- 新增客户 -->
  180. <a-modal
  181. v-model="isNewCust"
  182. title="新增客户"
  183. centered
  184. :width="960"
  185. :maskClosable="false"
  186. @cancel="cancelNewCust"
  187. :footer="null"
  188. >
  189. <CustomerManagementEdit ref="newCust" model="modal" @ok="newCustFun"></CustomerManagementEdit>
  190. </a-modal>
  191. </a-spin>
  192. </a-modal>
  193. </div>
  194. </template>
  195. <script>
  196. import { getArea } from '@/api/data'
  197. import { custFindById, updateByCustomerSn } from '@/api/customer'
  198. import { salesSave } from '@/api/sales'
  199. import { employeeAllList } from '@/api/salesman'
  200. import settleStyle from '@/views/common/settleStyle'
  201. import { VSelect } from '@/components'
  202. import selectCust from '@/views/common/selectCust.vue'
  203. import CustomerManagementEdit from '@/views/customerManagement/customerInfo/edit.vue'
  204. export default {
  205. name: 'ChooseCustomModal',
  206. components: { VSelect, CustomerManagementEdit, selectCust, settleStyle },
  207. props: {
  208. show: [Boolean],
  209. distributionFlag: {
  210. type: [String, Number],
  211. default: '0'
  212. }
  213. },
  214. data () {
  215. return {
  216. spinning: false,
  217. opened: this.show,
  218. title: '选择客户',
  219. confirmLoading: false,
  220. formItemLayout: {
  221. labelCol: { span: 6 },
  222. wrapperCol: { span: 18 }
  223. },
  224. buyerSnBak: '', // 更改前客户sn备份
  225. priceTypeBak: '', // 更改前客户价格类型备份
  226. form: {
  227. buyerName: '', // 客户名称
  228. buyerSn: undefined, // 客户sn
  229. consigneeTel: '', // 联系电话
  230. consigneeMobile: '',
  231. consigneeName: '', // 联系人
  232. shippingAddressProvinceSn: undefined, // 省
  233. shippingAddressProvinceName: '',
  234. shippingAddressCitySn: undefined, // 市
  235. shippingAddressCityName: '',
  236. shippingAddressCountySn: undefined, // 区
  237. shippingAddressCountyName: '',
  238. shippingAddress: '', // 详细地址
  239. fax: '', // 客户传真
  240. dispatchType: undefined, // 配送方式
  241. satelliteFlag: 0, // 是否卫星仓客户
  242. priceType: undefined, // 价格类型
  243. settleStyleSn: undefined, // 收款方式
  244. salesManSn: undefined, // 业务员
  245. salesManName: '',
  246. distributionFlag: undefined, // 铺货出库
  247. salesTragetType: 'CUSTOMER',
  248. remarks: '' // 备注
  249. },
  250. rules: {
  251. buyerSn: [
  252. { required: true, message: '请选择客户', trigger: ['change', 'blur'] }
  253. ],
  254. consigneeMobile: [{ required: false, pattern: /^\d{11}$/, message: '请输入正确的手机号', trigger: 'blur' }],
  255. shippingAddressProvinceSn: [
  256. { required: true, message: '请选择省', trigger: 'change' }
  257. ],
  258. shippingAddressCitySn: [
  259. { required: true, message: '请选择市', trigger: 'change' }
  260. ],
  261. shippingAddressCountySn: [
  262. { required: true, message: '请选择区/县', trigger: 'change' }
  263. ],
  264. priceType: [
  265. { required: true, message: '请选择价格类型', trigger: ['change', 'blur'] }
  266. ],
  267. settleStyleSn: [
  268. { required: true, message: '请选择收款方式', trigger: ['change', 'blur'] }
  269. ],
  270. distributionFlag: [
  271. { required: true, message: '请选择是否铺货出库', trigger: 'change' }
  272. ]
  273. // salesManSn: [
  274. // { required: true, message: '请选择业务员', trigger: 'change' }
  275. // ]
  276. },
  277. addrProvinceList: [], // 省下拉
  278. addrCityList: [], // 市下拉
  279. addrDistrictList: [], // 区下拉
  280. userList: [], // 业务员 下拉
  281. custId: undefined, // 客户id
  282. isEdit: false, // 是否编辑状态
  283. priceTypeDisabled: false, // 价格类型可编辑
  284. isChangeCust: false, // 是否更换客户
  285. interId: null,
  286. isNewCust: false // 是否新增客户
  287. }
  288. },
  289. methods: {
  290. changePriceType (v) {
  291. this.form.priceType = v
  292. this.$refs.ruleForm.clearValidate('priceType')
  293. },
  294. openNewCust () {
  295. this.isNewCust = true
  296. setTimeout(() => {
  297. this.$refs.newCust.getBaseData()
  298. }, 500)
  299. },
  300. // 新建客户
  301. newCustFun (data) {
  302. console.log(data, this.isEdit)
  303. this.isNewCust = false
  304. // 更新客户信息
  305. this.$refs.custList.setData({ key: data.customerSn, label: data.customerName, row: data })
  306. this.custChange({ key: data.customerSn, label: data.customerName, row: data })
  307. },
  308. // 业务员
  309. salesManChange (employeeSn) {
  310. if (employeeSn) {
  311. this.form.salesManName = this.userList.find(item => item.employeeSn == employeeSn).name
  312. } else {
  313. this.form.salesManName = ''
  314. }
  315. },
  316. // 客户 change
  317. custChange (obj) {
  318. const _this = this
  319. if (obj && obj.key) {
  320. const cust = obj.row
  321. this.form.buyerSn = cust.customerSn
  322. // 编辑
  323. if (this.isEdit) {
  324. this.$confirm({
  325. title: '提示',
  326. content: '更换客户后信息需要重新完善,确认要更换吗?',
  327. centered: true,
  328. onOk () {
  329. _this.custId = cust.id
  330. _this.form.buyerName = cust.customerName
  331. _this.priceTypeDisabled = false
  332. _this.getDetail()
  333. },
  334. onCancel () {
  335. _this.form.buyerSn = _this.buyerSnBak
  336. }
  337. })
  338. } else {
  339. _this.custId = cust.id
  340. _this.form.buyerName = cust.customerName
  341. _this.getDetail()
  342. }
  343. } else {
  344. this.$refs.ruleForm.resetFields()
  345. this.$refs.custList.resetForm()
  346. }
  347. },
  348. // 编辑客户信息
  349. editCust (data) {
  350. console.log(data)
  351. this.title = '编辑客户信息'
  352. this.isEdit = true
  353. this.priceTypeDisabled = true
  354. if (data.shippingAddressProvinceSn) { this.getArea('city', data.shippingAddressProvinceSn) }
  355. if (data.shippingAddressCitySn) { this.getArea('district', data.shippingAddressCitySn) }
  356. this.form = Object.assign(this.form, data)
  357. this.form.buyerName = data.buyerNameCurrent || data.buyerName
  358. this.buyerSnBak = this.form.buyerSn
  359. this.priceTypeBak = this.form.priceType
  360. this.$nextTick(() => {
  361. this.$refs.custList.setData({ key: data.buyerSn, label: data.buyerNameCurrent || data.buyerName, row: data })
  362. })
  363. },
  364. // 获取详情
  365. getDetail () {
  366. this.spinning = true
  367. custFindById({ id: this.custId }).then(res => {
  368. const data = res.data
  369. console.log(res)
  370. if (res.status == 200 && data) {
  371. if (data.provinceSn) { this.getArea('city', data.provinceSn) }
  372. if (data.citySn) { this.getArea('district', data.citySn) }
  373. this.form = Object.assign(this.form, {
  374. buyerName: data.customerName, // 客户名称
  375. buyerSn: data.customerSn, // 客户sn
  376. consigneeTel: data.contactTel, // 联系电话
  377. consigneeMobile: data.contactMobile,
  378. consigneeName: data.contactName, // 联系人
  379. shippingAddressProvinceSn: data.provinceSn, // 省
  380. shippingAddressProvinceName: data.provinceName,
  381. shippingAddressCitySn: data.citySn, // 市
  382. shippingAddressCityName: data.cityName,
  383. shippingAddressCountySn: data.countySn, // 区
  384. shippingAddressCountyName: data.countyName,
  385. shippingAddress: data.customerAddr, // 详细地址
  386. fax: data.fax, // 客户传真
  387. dispatchType: data.dispatchType, // 配送方式
  388. satelliteFlag: data.satelliteFlag, // 是否卫星仓客户
  389. priceType: data.priceType, // 价格类型
  390. settleStyleSn: data.settleStyleSn // 收款方式
  391. })
  392. // this.buyerSnBak = this.form.buyerSn
  393. // this.priceTypeBak = this.form.priceType
  394. } else {
  395. this.$message.error('获取客户信息失败')
  396. this.$refs.ruleForm.resetFields()
  397. }
  398. this.$refs.ruleForm.clearValidate()
  399. this.spinning = false
  400. })
  401. },
  402. // 保存客户信息
  403. handleSaveCust () {
  404. const params = {
  405. customerName: this.form.buyerName,
  406. customerSn: this.form.buyerSn,
  407. contactTel: this.form.consigneeTel, // 联系电话
  408. contactMobile: this.form.consigneeMobile,
  409. contactName: this.form.consigneeName, // 联系人
  410. provinceSn: this.form.shippingAddressProvinceSn, // 省
  411. provinceName: this.form.shippingAddressProvinceName,
  412. citySn: this.form.shippingAddressCitySn, // 市
  413. cityName: this.form.shippingAddressCityName,
  414. countySn: this.form.shippingAddressCountySn, // 区
  415. countyName: this.form.shippingAddressCountyName,
  416. customerAddr: this.form.shippingAddress, // 详细地址
  417. dispatchType: this.form.dispatchType, // 配送方式
  418. priceType: this.form.priceType, // 价格类型
  419. settleStyleSn: this.form.settleStyleSn // 收款方式
  420. }
  421. this.spinning = true
  422. updateByCustomerSn(params).then(res => {
  423. this.spinning = false
  424. if (res.status == 200) {
  425. // 保存销售单
  426. this.salesSaveFun()
  427. this.spinning = false
  428. } else {
  429. this.spinning = false
  430. }
  431. })
  432. },
  433. // 保存
  434. handleSubmit (e) {
  435. e.preventDefault()
  436. const _this = this
  437. console.log(_this.form, '------save')
  438. this.$refs.ruleForm.validate(valid => {
  439. if (valid) {
  440. // 如果价格类型改变,提示
  441. if (_this.priceTypeBak != _this.form.priceType && this.isEdit) {
  442. this.$confirm({
  443. title: '提示',
  444. content: '价格类型变更,确认提交吗?',
  445. centered: true,
  446. onOk () {
  447. // 保存客户信息
  448. _this.handleSaveCust()
  449. }
  450. })
  451. } else {
  452. // 保存客户信息
  453. _this.handleSaveCust()
  454. }
  455. } else {
  456. console.log('error submit!!')
  457. return false
  458. }
  459. })
  460. },
  461. // 新建或编辑销售单
  462. salesSaveFun () {
  463. const _this = this
  464. const form = this.form
  465. _this.spinning = true
  466. salesSave(form).then(res => {
  467. if (res.status == 200) {
  468. _this.$message.success(res.message)
  469. _this.$emit('ok', res.data)
  470. if (_this.form.id) {
  471. _this.$emit('updateData', form.priceType)
  472. }
  473. _this.cancel()
  474. _this.spinning = false
  475. } else {
  476. _this.spinning = false
  477. }
  478. })
  479. },
  480. cancel () {
  481. this.opened = false
  482. this.$emit('cancel')
  483. this.$refs.ruleForm.resetFields()
  484. this.$refs.custList.resetForm()
  485. },
  486. cancelNewCust () {
  487. this.isNewCust = false
  488. this.$refs.newCust.getBaseData()
  489. },
  490. // 获取业务员列表数据
  491. getUserAllList () {
  492. employeeAllList({}).then(res => {
  493. if (res.status == 200) {
  494. this.userList = res.data || []
  495. } else {
  496. this.userList = []
  497. }
  498. })
  499. },
  500. // 获取城市列表
  501. getCityList (val) {
  502. this.addrCityList = []
  503. this.addrDistrictList = []
  504. this.form.shippingAddressCitySn = undefined
  505. this.form.shippingAddressCityName = ''
  506. this.form.shippingAddressCountySn = undefined
  507. this.form.shippingAddressCountyName = ''
  508. if (val) {
  509. this.getArea('city', val)
  510. this.form.shippingAddressProvinceName = this.addrProvinceList.find(item => item.areaSn == val).name
  511. } else {
  512. this.form.shippingAddressProvinceName = ''
  513. }
  514. },
  515. // 获取区县列表
  516. getAreaList (val) {
  517. this.addrDistrictList = []
  518. this.form.shippingAddressCountySn = undefined
  519. this.form.shippingAddressCountyName = ''
  520. if (val) {
  521. this.getArea('district', val)
  522. this.form.shippingAddressCityName = this.addrCityList.find(item => item.areaSn == val).name
  523. } else {
  524. this.form.shippingAddressCityName = ''
  525. }
  526. },
  527. // 区县变更
  528. areaCharged (val) {
  529. if (val) {
  530. this.form.shippingAddressCountyName = this.addrDistrictList.find(item => item.areaSn == val).name
  531. } else {
  532. this.form.shippingAddressCountyName = ''
  533. }
  534. },
  535. // 省/市/区
  536. getArea (leve, sn) {
  537. let params
  538. if (leve == 'province') {
  539. params = { type: '2' }
  540. } else {
  541. params = { parentId: sn, type: leve == 'city' ? '3' : '4' }
  542. }
  543. getArea(params).then(res => {
  544. if (res.status == 200) {
  545. if (leve == 'province') {
  546. this.addrProvinceList = res.data || []
  547. } else if (leve == 'city') {
  548. this.addrCityList = res.data || []
  549. } else if (leve == 'district') {
  550. this.addrDistrictList = res.data || []
  551. }
  552. } else {
  553. if (leve == 'province') {
  554. this.addrProvinceList = []
  555. } else if (leve == 'city') {
  556. this.addrCityList = []
  557. } else if (leve == 'district') {
  558. this.addrDistrictList = []
  559. }
  560. }
  561. })
  562. }
  563. },
  564. watch: {
  565. show (newValue, oldValue) {
  566. this.opened = newValue
  567. if (newValue) {
  568. this.getArea('province')
  569. this.getUserAllList()
  570. }
  571. },
  572. distributionFlag (newValue, oldValue) {
  573. console.log(newValue, oldValue)
  574. this.form.distributionFlag = newValue.toString()
  575. }
  576. }
  577. }
  578. </script>