chooseCustomModal.vue 21 KB

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