chooseCustomModal.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  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.buyerSnBak = this.form.buyerSn
  358. this.priceTypeBak = this.form.priceType
  359. this.$nextTick(() => {
  360. this.$refs.custList.setData({ key: data.buyerSn, label: data.buyerName, row: data })
  361. })
  362. },
  363. // 获取详情
  364. getDetail () {
  365. this.spinning = true
  366. custFindById({ id: this.custId }).then(res => {
  367. const data = res.data
  368. console.log(res)
  369. if (res.status == 200 && data) {
  370. if (data.provinceSn) { this.getArea('city', data.provinceSn) }
  371. if (data.citySn) { this.getArea('district', data.citySn) }
  372. this.form = Object.assign(this.form, {
  373. buyerName: data.customerName, // 客户名称
  374. buyerSn: data.customerSn, // 客户sn
  375. consigneeTel: data.contactTel, // 联系电话
  376. consigneeMobile: data.contactMobile,
  377. consigneeName: data.contactName, // 联系人
  378. shippingAddressProvinceSn: data.provinceSn, // 省
  379. shippingAddressProvinceName: data.provinceName,
  380. shippingAddressCitySn: data.citySn, // 市
  381. shippingAddressCityName: data.cityName,
  382. shippingAddressCountySn: data.countySn, // 区
  383. shippingAddressCountyName: data.countyName,
  384. shippingAddress: data.customerAddr, // 详细地址
  385. fax: data.fax, // 客户传真
  386. dispatchType: data.dispatchType, // 配送方式
  387. satelliteFlag: data.satelliteFlag, // 是否卫星仓客户
  388. priceType: data.priceType, // 价格类型
  389. settleStyleSn: data.settleStyleSn // 收款方式
  390. })
  391. // this.buyerSnBak = this.form.buyerSn
  392. // this.priceTypeBak = this.form.priceType
  393. } else {
  394. this.$message.error('获取客户信息失败')
  395. this.$refs.ruleForm.resetFields()
  396. }
  397. this.$refs.ruleForm.clearValidate()
  398. this.spinning = false
  399. })
  400. },
  401. // 保存客户信息
  402. handleSaveCust () {
  403. const params = {
  404. customerName: this.form.buyerName,
  405. customerSn: this.form.buyerSn,
  406. contactTel: this.form.consigneeTel, // 联系电话
  407. contactMobile: this.form.consigneeMobile,
  408. contactName: this.form.consigneeName, // 联系人
  409. provinceSn: this.form.shippingAddressProvinceSn, // 省
  410. provinceName: this.form.shippingAddressProvinceName,
  411. citySn: this.form.shippingAddressCitySn, // 市
  412. cityName: this.form.shippingAddressCityName,
  413. countySn: this.form.shippingAddressCountySn, // 区
  414. countyName: this.form.shippingAddressCountyName,
  415. customerAddr: this.form.shippingAddress, // 详细地址
  416. dispatchType: this.form.dispatchType, // 配送方式
  417. priceType: this.form.priceType, // 价格类型
  418. settleStyleSn: this.form.settleStyleSn // 收款方式
  419. }
  420. this.spinning = true
  421. updateByCustomerSn(params).then(res => {
  422. this.spinning = false
  423. if (res.status == 200) {
  424. // 保存销售单
  425. this.salesSaveFun()
  426. this.spinning = false
  427. } else {
  428. this.spinning = false
  429. }
  430. })
  431. },
  432. // 保存
  433. handleSubmit (e) {
  434. e.preventDefault()
  435. const _this = this
  436. console.log(_this.form, '------save')
  437. this.$refs.ruleForm.validate(valid => {
  438. if (valid) {
  439. // 如果价格类型改变,提示
  440. if (_this.priceTypeBak != _this.form.priceType && this.isEdit) {
  441. this.$confirm({
  442. title: '提示',
  443. content: '价格类型变更,确认提交吗?',
  444. centered: true,
  445. onOk () {
  446. // 保存客户信息
  447. _this.handleSaveCust()
  448. }
  449. })
  450. } else {
  451. // 保存客户信息
  452. _this.handleSaveCust()
  453. }
  454. } else {
  455. console.log('error submit!!')
  456. return false
  457. }
  458. })
  459. },
  460. // 新建或编辑销售单
  461. salesSaveFun () {
  462. const _this = this
  463. const form = this.form
  464. _this.spinning = true
  465. salesSave(form).then(res => {
  466. if (res.status == 200) {
  467. _this.$message.success(res.message)
  468. _this.$emit('ok', res.data)
  469. if (_this.form.id) {
  470. _this.$emit('updateData', form.priceType)
  471. }
  472. _this.cancel()
  473. _this.spinning = false
  474. } else {
  475. _this.spinning = false
  476. }
  477. })
  478. },
  479. cancel () {
  480. this.opened = false
  481. this.$emit('cancel')
  482. this.$refs.ruleForm.resetFields()
  483. this.$refs.custList.resetForm()
  484. },
  485. cancelNewCust () {
  486. this.isNewCust = false
  487. this.$refs.newCust.getBaseData()
  488. },
  489. // 获取业务员列表数据
  490. getUserAllList () {
  491. employeeAllList({}).then(res => {
  492. if (res.status == 200) {
  493. this.userList = res.data || []
  494. } else {
  495. this.userList = []
  496. }
  497. })
  498. },
  499. // 获取城市列表
  500. getCityList (val) {
  501. this.addrCityList = []
  502. this.addrDistrictList = []
  503. this.form.shippingAddressCitySn = undefined
  504. this.form.shippingAddressCityName = ''
  505. this.form.shippingAddressCountySn = undefined
  506. this.form.shippingAddressCountyName = ''
  507. if (val) {
  508. this.getArea('city', val)
  509. this.form.shippingAddressProvinceName = this.addrProvinceList.find(item => item.areaSn == val).name
  510. } else {
  511. this.form.shippingAddressProvinceName = ''
  512. }
  513. },
  514. // 获取区县列表
  515. getAreaList (val) {
  516. this.addrDistrictList = []
  517. this.form.shippingAddressCountySn = undefined
  518. this.form.shippingAddressCountyName = ''
  519. if (val) {
  520. this.getArea('district', val)
  521. this.form.shippingAddressCityName = this.addrCityList.find(item => item.areaSn == val).name
  522. } else {
  523. this.form.shippingAddressCityName = ''
  524. }
  525. },
  526. // 区县变更
  527. areaCharged (val) {
  528. if (val) {
  529. this.form.shippingAddressCountyName = this.addrDistrictList.find(item => item.areaSn == val).name
  530. } else {
  531. this.form.shippingAddressCountyName = ''
  532. }
  533. },
  534. // 省/市/区
  535. getArea (leve, sn) {
  536. let params
  537. if (leve == 'province') {
  538. params = { type: '2' }
  539. } else {
  540. params = { parentId: sn, type: leve == 'city' ? '3' : '4' }
  541. }
  542. getArea(params).then(res => {
  543. if (res.status == 200) {
  544. if (leve == 'province') {
  545. this.addrProvinceList = res.data || []
  546. } else if (leve == 'city') {
  547. this.addrCityList = res.data || []
  548. } else if (leve == 'district') {
  549. this.addrDistrictList = res.data || []
  550. }
  551. } else {
  552. if (leve == 'province') {
  553. this.addrProvinceList = []
  554. } else if (leve == 'city') {
  555. this.addrCityList = []
  556. } else if (leve == 'district') {
  557. this.addrDistrictList = []
  558. }
  559. }
  560. })
  561. }
  562. },
  563. watch: {
  564. show (newValue, oldValue) {
  565. this.opened = newValue
  566. if (newValue) {
  567. this.getArea('province')
  568. this.getUserAllList()
  569. }
  570. },
  571. distributionFlag (newValue, oldValue) {
  572. console.log(newValue, oldValue)
  573. this.form.distributionFlag = newValue.toString()
  574. }
  575. }
  576. }
  577. </script>