123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- <template>
- <div class="customerManagementEdit-wrap">
- <a-page-header :ghost="false" :backIcon="false" v-if="model=='page'" class="customerManagementEdit-back">
- <!-- 自定义的二级文字标题 -->
- <template slot="subTitle">
- <a id="customerManagementEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
- </template>
- </a-page-header>
- <a-card size="small" :bordered="false" class="customerManagementEdit-table-page-wrapper">
- <a-form-model
- id="customerManagementEdit-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="customerName">
- <a-input
- id="customerManagementEdit-customerName"
- :maxLength="30"
- v-model.trim="form.customerName"
- @change="filterEmpty"
- placeholder="请输入客户名称(最多30个字符)"
- allowClear />
- </a-form-model-item>
- </a-col>
- <a-col :span="8">
- <a-form-model-item label="联系电话" prop="contactTel">
- <a-input id="customerManagementEdit-contactTel" :maxLength="11" v-model.trim="form.contactTel" placeholder="请输入联系电话(最多11个字符)" allowClear />
- </a-form-model-item>
- </a-col>
- <a-col :span="8">
- <a-form-model-item label="联系人" prop="contactName">
- <a-input id="customerManagementEdit-contactName" :maxLength="30" v-model.trim="form.contactName" placeholder="请输入联系人(最多30个字符)" allowClear />
- </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="customerManagementEdit-provinceSn" @change="getCityList" v-model="form.provinceSn" placeholder="请选择省">
- <a-select-option v-for="item in addrProvinceList" :value="item.sn" :key="item.sn + '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="customerManagementEdit-citySn" @change="getAreaList" v-model="form.citySn" placeholder="请选择市">
- <a-select-option v-for="item in addrCityList" :value="item.sn" :key="item.sn + '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="customerManagementEdit-countySn" @change="areaCharged" v-model="form.countySn" placeholder="请选择区/县">
- <a-select-option v-for="item in addrDistrictList" :value="item.sn" :key="item.sn + '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="customerManagementEdit-customerAddr" :maxLength="60" v-model.trim="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="fax">
- <a-input id="customerManagementEdit-fax" :maxLength="30" v-model.trim="form.fax" placeholder="请输入客户传真(最多30个字符)" allowClear />
- </a-form-model-item>
- </a-col>
- <a-col :span="8">
- <a-form-model-item label="配送方式" prop="dispatchType">
- <v-select
- code="DISPATCH_TYPE"
- id="customerManagementEdit-dispatchType"
- v-model="form.dispatchType"
- allowClear
- placeholder="请选择配送方式"
- ></v-select>
- </a-form-model-item>
- </a-col>
- <a-col :span="8">
- <a-form-model-item label="是否卫星仓客户" prop="satelliteFlag">
- <span style="padding-left: 11px;">{{ form.satelliteFlag == 1 ? '是' : '否' }}</span>
- </a-form-model-item>
- </a-col>
- </a-row>
- <a-row :gutter="15">
- <a-col :span="8">
- <a-form-model-item label="价格类型" ref="priceType" prop="priceType">
- <v-select code="PRICE_TYPE" id="customerManagementEdit-priceType" v-model="form.priceType" allowClear placeholder="请选择价格类型" ></v-select>
- </a-form-model-item>
- </a-col>
- <a-col :span="8">
- <a-form-model-item label="收款方式" prop="settleStyleSn">
- <a-select id="customerManagementEdit-settleStyleSn" v-model="form.settleStyleSn" allowClear placeholder="请选择收款方式">
- <a-select-option v-for="item in settleStyleList" :value="item.settleStyleSn" :key="item.settleStyleSn">{{ item.name }}</a-select-option>
- </a-select>
- </a-form-model-item>
- </a-col>
- <a-col :span="8">
- <a-form-model-item label="客户类型" prop="customerTypeSn">
- <a-select id="customerManagementEdit-customerTypeSn" v-model="form.customerTypeSn" allowClear placeholder="请选择客户类型">
- <a-select-option v-for="item in custTypeList" :value="item.customerTypeSn" :key="item.customerTypeSn">{{ item.name }}</a-select-option>
- </a-select>
- </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" @click="handleSubmit" size="large" id="customerManagementEdit-btn-submit" style="padding: 0 60px;">保存</a-button>
- </a-form-model-item>
- </a-form-model>
- </a-card>
- </div>
- </template>
- <script>
- import { STable, VSelect } from '@/components'
- import { getArea } from '@/api/data'
- import { custSave, custFindById, settleStyleFindAllList } from '@/api/customer'
- import { custTypeFindAllList } from '@/api/custType'
- export default {
- name: 'CustomerManagementEdit',
- components: { STable, VSelect },
- props: {
- model: {
- type: String,
- default: 'page'
- }
- },
- data () {
- return {
- formItemLayout: {
- labelCol: { span: 8 },
- wrapperCol: { span: 16 }
- },
- form: {
- id: null,
- customerName: '', // 客户名称
- contactTel: '', // 联系电话
- contactName: '', // 联系人
- provinceSn: undefined, // 省
- provinceName: '',
- citySn: undefined, // 市
- cityName: '',
- countySn: undefined, // 区
- countyName: '',
- customerAddr: '', // 详细地址
- fax: '', // 客户传真
- dispatchType: '', // 配送方式
- satelliteFlag: 0, // 是否卫星仓客户
- customerTypeSn: undefined, // 客户类型
- priceType: '', // 价格类型
- settleStyleSn: undefined // 收款方式
- },
- rules: {
- customerName: [{ required: true, message: '请输入客户名称', trigger: 'blur' }],
- contactTel: [{ required: true, message: '请输入联系电话', trigger: 'blur' }, { pattern: /^\d{11}$/, message: '请输入正确的手机号' }],
- provinceSn: [{ required: true, message: '请选择省', trigger: 'change' }],
- citySn: [{ required: true, message: '请选择市', trigger: 'change' }],
- countySn: [{ required: true, message: '请选择区/县', trigger: 'change' }],
- customerAddr: [{ required: true, message: '请输入详细地址', trigger: 'blur' }],
- priceType: [{ required: true, message: '请选择价格类型', trigger: 'change' }],
- settleStyleSn: [{ required: true, message: '请选择收款方式', trigger: 'change' }]
- },
- addrProvinceList: [], // 省下拉
- addrCityList: [], // 市下拉
- addrDistrictList: [], // 区下拉
- custTypeList: [], // 客户类型 下拉数据
- settleStyleList: [] // 收款方式 下拉数据
- }
- },
- methods: {
- filterEmpty () {
- let str = this.form.customerName
- str = str.replace(/\ +/g, '')
- str = str.replace(/[ ]/g, '')
- str = str.replace(/[\r\n]/g, '')
- this.form.customerName = str
- },
- // 获取客户信息
- getDetail () {
- custFindById({ id: this.$route.params.id }).then(res => {
- if (res.status == 200) {
- if (res.data.provinceSn) { this.getArea('city', res.data.provinceSn) }
- if (res.data.citySn) { this.getArea('district', res.data.citySn) }
- this.form = Object.assign(this.form, res.data)
- } else {
- this.$refs.ruleForm.resetFields()
- }
- })
- },
- // 客户类型
- getCustTypeList () {
- custTypeFindAllList().then(res => {
- if (res.status == 200) {
- this.custTypeList = res.data
- } else {
- this.custTypeList = []
- }
- })
- },
- // 收款方式
- getSettleStyleList () {
- settleStyleFindAllList().then(res => {
- if (res.status == 200) {
- this.settleStyleList = res.data
- } else {
- this.settleStyleList = []
- }
- })
- },
- // 保存
- handleSubmit (e) {
- e.preventDefault()
- const _this = this
- this.$refs.ruleForm.validate(valid => {
- if (valid) {
- const form = _this.form
- form.id = this.$route.params.id && this.model == 'page' ? this.$route.params.id : null
- custSave(form).then(res => {
- if (res.status == 200) {
- _this.$message.success(res.message)
- if (_this.model == 'page') {
- setTimeout(() => {
- _this.$router.push({ path: '/customerManagement/customerInfo/list' })
- }, 600)
- } else {
- _this.$emit('ok', res.data)
- }
- }
- })
- } else {
- console.log('error submit!!')
- return false
- }
- })
- },
- // 返回列表
- handleBack () {
- this.$router.push({ path: '/customerManagement/customerInfo/list' })
- },
- // 获取城市列表
- getCityList (val) {
- const index = this.addrProvinceList.findIndex(item => item.sn == val)
- if (index >= 0) {
- this.form.provinceName = this.addrProvinceList[index].name
- }
- this.addrCityList = []
- this.addrDistrictList = []
- this.form.citySn = undefined
- this.form.countySn = undefined
- this.form.customerAddr = ''
- this.getArea('city', val)
- },
- // 获取区县列表
- getAreaList (val) {
- const index = this.addrCityList.findIndex(item => item.sn == val)
- if (index >= 0) {
- this.form.cityName = this.addrCityList[index].name
- }
- this.addrDistrictList = []
- this.form.countySn = undefined
- this.form.customerAddr = ''
- this.getArea('district', val)
- },
- // 区县变更
- areaCharged (val) {
- const index = this.addrDistrictList.findIndex(item => item.sn == val)
- if (index >= 0) {
- this.form.countyName = this.addrDistrictList[index].name
- }
- this.form.customerAddr = ''
- },
- // 省/市/区
- 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 = []
- }
- }
- })
- },
- // 获取基础数据
- getBaseData () {
- this.getArea('province') // 省市区
- this.getCustTypeList() // 客户类型
- this.getSettleStyleList() // 收款方式
- this.$refs.ruleForm.resetFields()
- }
- },
- beforeRouteEnter (to, from, next) {
- next(vm => {
- vm.getBaseData()
- if (vm.$route.params.id) {
- // 编辑页
- vm.getDetail()
- }
- })
- }
- }
- </script>
- <style lang="less">
- .customerManagementEdit-wrap {
- .customerManagementEdit-back {
- margin-bottom: 10px;
- }
- }
- </style>
|