123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- <template>
- <a-modal
- v-model="opened"
- :title="title"
- centered
- :maskClosable="false"
- :confirmLoading="confirmLoading"
- width="80%"
- :footer="null"
- @cancel="cancel"
- >
- <a-form-model
- id="chooseCustom-form"
- ref="ruleForm"
- :model="form"
- :rules="rules"
- :label-col="formItemLayout.labelCol"
- :wrapper-col="formItemLayout.wrapperCol"
- >
- <a-row :gutter="15">
- <a-col :span="8">
- <a-form-model-item label="客户名称" prop="buyerSn">
- <a-select
- id="chooseCustom-buyerSn"
- show-search
- placeholder="请选择客户"
- v-model="form.buyerSn"
- :filter-option="filterOption"
- @change="custChange">
- <a-select-option v-for="item in custAllList" :key="item.id" :value="item.customerSn">{{ item.customerName }}</a-select-option>
- </a-select>
- </a-form-model-item>
- </a-col>
- <a-col :span="16">
- <a-form-model-item>
- <a-button type="primary" class="button-primary" @click="openNewCust" icon="plus">新增</a-button>
- (点击新增按钮新增客户)
- </a-form-model-item>
- </a-col>
- </a-row>
- <a-row :gutter="15">
- <a-col :span="16">
- <a-form-model-item label="客户地址" required style="margin: 0;" :labelCol="{ span: 4 }" :wrapperCol="{ span: 20 }">
- <a-row :gutter="15">
- <!-- 客户地址 -->
- <a-col span="8">
- <a-form-model-item prop="provinceSn">
- <a-select id="chooseCustom-provinceSn" @change="getCityList" v-model="form.provinceSn" placeholder="请选择省">
- <a-select-option v-for="item in addrProvinceList" :value="item.id" :key="item.id + 'a'">{{ item.name }}</a-select-option>
- </a-select>
- </a-form-model-item>
- </a-col>
- <a-col span="8">
- <a-form-model-item prop="citySn">
- <a-select id="chooseCustom-citySn" @change="getAreaList" v-model="form.citySn" placeholder="请选择市">
- <a-select-option v-for="item in addrCityList" :value="item.id" :key="item.id + 'b'">{{ item.name }}</a-select-option>
- </a-select>
- </a-form-model-item>
- </a-col>
- <a-col span="8">
- <a-form-model-item prop="countySn">
- <a-select id="chooseCustom-countySn" @change="areaCharged" v-model="form.countySn" placeholder="请选择区/县">
- <a-select-option v-for="item in addrDistrictList" :value="item.id" :key="item.id + 'c'">{{ item.name }}</a-select-option>
- </a-select>
- </a-form-model-item>
- </a-col>
- </a-row>
- </a-form-model-item>
- </a-col>
- <a-col :span="8">
- <a-form-model-item label="" prop="customerAddr">
- <a-input
- id="chooseCustom-customerAddr"
- :maxLength="60"
- v-model="form.customerAddr"
- placeholder="请输入详细地址(最多60个字符)"
- allowClear />
- </a-form-model-item>
- </a-col>
- </a-row>
- <a-row :gutter="15">
- <a-col :span="8">
- <a-form-model-item label="联系人" prop="consigneeName">
- <a-input
- id="chooseCustom-consigneeName"
- :maxLength="30"
- v-model="form.consigneeName"
- placeholder="请输入联系人(最多30个字符)"
- allowClear />
- </a-form-model-item>
- </a-col>
- <a-col :span="8">
- <a-form-model-item label="联系电话" prop="consigneeTel">
- <a-input
- id="chooseCustom-consigneeTel"
- :maxLength="30"
- v-model="form.consigneeTel"
- placeholder="请输入联系电话(最多30个字符)"
- allowClear />
- </a-form-model-item>
- </a-col>
- </a-row>
- <a-row :gutter="15">
- <a-col :span="8">
- <a-form-model-item label="是否抓单" prop="grabFlag">
- <v-select code="FLAG" id="chooseCustom-grabFlag" v-model="form.grabFlag" allowClear placeholder="请选择"></v-select>
- </a-form-model-item>
- </a-col>
- <a-col :span="8">
- <a-form-model-item label="开单人">{{ $store.state.user.info.userNameCN }}</a-form-model-item>
- </a-col>
- </a-row>
- <a-form-model-item :wrapper-col="{ span: 12, offset: 6 }" style="text-align: center;">
- <a-button type="primary" :loading="confirmLoading" @click="handleSubmit" id="chooseCustom-btn-submit">保存</a-button>
- <a-button @click="cancel" style="margin-left: 15px" id="chooseCustom-btn-back">取消</a-button>
- </a-form-model-item>
- </a-form-model>
- <!-- 新增客户 -->
- <a-modal
- v-model="isNewCust"
- title="新增客户"
- centered
- width="60%"
- :maskClosable="false"
- :footer="null"
- >
- <CustomerManagementEdit ref="newCust" model="modal" @ok="newCustFun"></CustomerManagementEdit>
- </a-modal>
- </a-modal>
- </template>
- <script>
- import { getArea } from '@/api/data'
- import { custAllList, custFindById, updateByCustomerSn } from '@/api/customer'
- import { salesReturnSave } from '@/api/salesReturn'
- import { VSelect } from '@/components'
- import CustomerManagementEdit from '@/views/customerManagement/customerInfo/edit.vue'
- export default {
- name: 'ChooseCustomModal',
- components: { VSelect, CustomerManagementEdit },
- props: {
- show: [Boolean]
- },
- data () {
- return {
- opened: this.show,
- title: '选择客户',
- confirmLoading: false,
- formItemLayout: {
- labelCol: { span: 8 },
- wrapperCol: { span: 16 }
- },
- buyerSnBak: '', // 更改前客户sn备份
- form: {
- buyerName: '', // 客户名称
- buyerSn: undefined, // 客户sn
- consigneeTel: '', // 联系电话
- consigneeName: '', // 联系人
- provinceSn: undefined, // 省
- provinceName: '',
- citySn: undefined, // 市
- cityName: '',
- countySn: undefined, // 区
- countyName: '',
- customerAddr: '', // 详细地址
- grabFlag: '1' // 是否抓单
- },
- rules: {
- buyerSn: [
- { required: true, message: '请选择客户', trigger: ['change', 'blur'] }
- ],
- consigneeTel: [
- { required: true, message: '请输入联系电话', trigger: 'blur' }
- ],
- provinceSn: [
- { required: true, message: '请选择省', trigger: 'change' }
- ],
- citySn: [
- { required: true, message: '请选择市', trigger: 'change' }
- ],
- countySn: [
- { required: true, message: '请选择区/县', trigger: 'change' }
- ],
- customerAddr: [
- { required: true, message: '请输入详细地址', trigger: 'blur' }
- ],
- grabFlag: [
- { required: true, message: '请选择是否铺货出库', trigger: 'change' }
- ]
- },
- custAllList: [], // 客户 下拉数据
- addrProvinceList: [], // 省下拉
- addrCityList: [], // 市下拉
- addrDistrictList: [], // 区下拉
- custId: undefined, // 客户id
- isEdit: false, // 是否编辑状态
- isChangeCust: false, // 是否更换客户
- interId: null,
- isNewCust: false // 是否新增客户
- }
- },
- methods: {
- openNewCust () {
- this.isNewCust = true
- setTimeout(() => {
- this.$refs.newCust.getBaseData()
- }, 500)
- },
- // 新建客户
- newCustFun (data) {
- console.log(data, this.isEdit)
- this.isNewCust = false
- // 更新客户信息
- this.custAllList.unshift(data)
- setTimeout(() => {
- this.custChange(data.customerSn)
- }, 300)
- },
- // 客户 change
- custChange (val) {
- console.log(val, 'custChange')
- const _this = this
- const cust = this.custAllList.find(item => item.customerSn == val)
- // 编辑
- if (this.isEdit) {
- this.$confirm({
- title: '提示',
- content: '更换客户后信息需要重新完善,确认要更换吗?',
- centered: true,
- onOk () {
- _this.custId = cust.id
- _this.form.buyerName = cust.customerName
- _this.getDetail()
- },
- onCancel () {
- _this.form.buyerSn = _this.buyerSnBak
- }
- })
- } else {
- _this.custId = cust.id
- _this.form.buyerName = cust.customerName
- _this.getDetail()
- }
- },
- // 编辑客户信息
- editCust (data) {
- console.log(data)
- this.title = '编辑客户信息'
- this.isEdit = true
- if (data.provinceSn) { this.getArea('city', data.provinceSn) }
- if (data.citySn) { this.getArea('district', data.citySn) }
- this.form = Object.assign(this.form, data)
- this.buyerSnBak = this.form.buyerSn
- },
- // 获取详情
- getDetail () {
- custFindById({ id: this.custId }).then(res => {
- const data = res.data
- if (res.status == 200 && data) {
- if (data.provinceSn) { this.getArea('city', data.provinceSn) }
- if (data.citySn) { this.getArea('district', data.citySn) }
- this.form = Object.assign(this.form, {
- buyerName: data.customerName, // 客户名称
- buyerSn: data.customerSn, // 客户sn
- consigneeTel: data.contactTel, // 联系电话
- consigneeName: data.contactName, // 联系人
- provinceSn: data.provinceSn, // 省
- provinceName: data.provinceName,
- citySn: data.citySn, // 市
- cityName: data.cityName,
- countySn: data.countySn, // 区
- countyName: data.countyName,
- customerAddr: data.customerAddr, // 详细地址
- fax: data.fax // 客户传真
- })
- } else {
- this.$message.error('获取客户信息失败')
- this.$refs.ruleForm.resetFields()
- }
- this.$refs.ruleForm.clearValidate()
- })
- },
- // 保存客户信息
- handleSaveCust () {
- const params = {
- customerName: this.form.buyerName,
- customerSn: this.form.buyerSn,
- contactTel: this.form.consigneeTel, // 联系电话
- contactName: this.form.consigneeName, // 联系人
- provinceSn: this.form.provinceSn, // 省
- provinceName: this.form.provinceName,
- citySn: this.form.citySn, // 市
- cityName: this.form.cityName,
- countySn: this.form.countySn, // 区
- countyName: this.form.countyName,
- customerAddr: this.form.customerAddr // 详细地址
- }
- updateByCustomerSn(params).then(res => {
- if (res.status != 200) {
- this.$message.error(res.message)
- }
- })
- },
- // 保存
- handleSubmit (e) {
- e.preventDefault()
- const _this = this
- this.$refs.ruleForm.validate(valid => {
- if (valid) {
- // 保存客户信息
- _this.handleSaveCust()
- // 保存销售单
- if (_this.form.buyerSn) {
- _this.salesSaveFun()
- }
- } else {
- console.log('error submit!!')
- return false
- }
- })
- },
- // 新建或编辑销售单
- salesSaveFun () {
- const _this = this
- const form = this.form
- console.log(form, 'save data')
- salesReturnSave(form).then(res => {
- if (res.status == 200) {
- _this.$message.success(res.message)
- _this.$emit('ok', res.data)
- if (_this.form.id) {
- _this.$emit('updateData')
- }
- _this.cancel()
- }
- })
- },
- cancel () {
- this.opened = false
- this.$refs.ruleForm.resetFields()
- this.$emit('cancel')
- },
- // 客户无分页列表数据
- getCustAllList () {
- const _this = this
- custAllList().then(res => {
- if (res.status == 200) {
- _this.custAllList = res.data || []
- } else {
- _this.custAllList = []
- }
- })
- },
- // 获取城市列表
- getCityList (val) {
- console.log(val, '-------------')
- this.addrCityList = []
- this.addrDistrictList = []
- this.form.citySn = undefined
- this.form.cityName = ''
- this.form.countySn = undefined
- this.form.countyName = ''
- this.form.customerAddr = ''
- this.form.countyName = this.addrProvinceList.find(item => item.id == val).name
- this.getArea('city', val)
- },
- // 获取区县列表
- getAreaList (val) {
- this.addrDistrictList = []
- this.form.countySn = undefined
- this.form.countyName = ''
- this.form.customerAddr = ''
- this.form.cityName = this.addrCityList.find(item => item.id == val).name
- this.getArea('district', val)
- },
- // 区县变更
- areaCharged (val) {
- this.form.customerAddr = ''
- this.form.countyName = this.addrDistrictList.find(item => item.id == val).name
- },
- // 省/市/区
- getArea (type, sn) {
- let params
- if (type == 'province') {
- params = { level: '1' }
- } else {
- params = { psn: sn }
- }
- getArea(params).then(res => {
- if (res.status == 200) {
- if (type == 'province') {
- this.addrProvinceList = res.data || []
- } else if (type == 'city') {
- this.addrCityList = res.data || []
- } else if (type == 'district') {
- this.addrDistrictList = res.data || []
- }
- } else {
- if (type == 'province') {
- this.addrProvinceList = []
- } else if (type == 'city') {
- this.addrCityList = []
- } else if (type == 'district') {
- this.addrDistrictList = []
- }
- }
- })
- },
- filterOption (input, option) {
- return (
- option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
- )
- }
- },
- watch: {
- show (newValue, oldValue) {
- this.opened = newValue
- if (newValue) {
- this.getArea('province')
- this.getCustAllList()
- }
- }
- }
- }
- </script>
- <style>
- </style>
|