123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- <template>
- <a-modal
- centered
- class="supplierInfoEdit-modal"
- :footer="null"
- :maskClosable="false"
- :title="modalTit"
- v-model="isShow"
- @cancel="isShow=false"
- :width="800">
- <a-spin :spinning="spinning" tip="Loading...">
- <!-- 表单 -->
- <div>
- <a-form-model
- id="supplierInfoEdit-form"
- ref="ruleForm"
- :model="form"
- :rules="rules"
- :label-col="formItemLayout.labelCol"
- :wrapper-col="formItemLayout.wrapperCol"
- >
- <a-form-model-item label="供应商名称" prop="supplierName">
- <a-input
- id="supplierInfoEdit-supplierName"
- :maxLength="30"
- v-model.trim="form.supplierName"
- @change="filterEmpty"
- placeholder="请输入供应商名称(最多30个字符)"
- allowClear />
- </a-form-model-item>
- <a-form-model-item label="所在地区" required style="margin: 0;">
- <a-row :gutter="20">
- <!-- 所在地区 -->
- <a-col span="8">
- <a-form-model-item prop="provinceSn">
- <a-select id="supplierInfoEdit-provinceSn" allowClear @change="getCityList" v-model="form.provinceSn" placeholder="请选择省">
- <a-select-option v-for="item in addrProvinceList" :id="item.areaSn" :value="item.areaSn" :key="item.areaSn + '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="supplierInfoEdit-citySn" allowClear @change="getAreaList" v-model="form.citySn" placeholder="请选择市">
- <a-select-option v-for="item in addrCityList" :id="item.areaSn" :value="item.areaSn" :key="item.areaSn + '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="supplierInfoEdit-countySn" allowClear @change="areaCharged" v-model="form.countySn" placeholder="请选择区/县">
- <a-select-option v-for="item in addrDistrictList" :id="item.areaSn" :value="item.areaSn" :key="item.areaSn + 'c'">{{ item.name }}</a-select-option>
- </a-select>
- </a-form-model-item>
- </a-col>
- </a-row>
- </a-form-model-item>
- <a-form-model-item label="详细地址" prop="supplierAddress">
- <a-input
- id="supplierInfoEdit-supplierAddress"
- :maxLength="60"
- v-model.trim="form.supplierAddress"
- placeholder="请输入详细地址(最多60个字符)"
- allowClear />
- </a-form-model-item>
- <a-form-model-item label="联系人" prop="contactPerson">
- <a-input
- id="supplierInfoEdit-contactPerson"
- :maxLength="30"
- v-model.trim="form.contactPerson"
- placeholder="请输入联系人(最多30个字符)"
- allowClear />
- </a-form-model-item>
- <a-form-model-item label="联系电话" prop="contactTel">
- <a-input
- id="supplierInfoEdit-contactTel"
- :maxLength="20"
- v-model.trim="form.contactTel"
- placeholder="请输入联系电话(最多20个字符)"
- allowClear />
- </a-form-model-item>
- <a-form-model-item label="主营内容" prop="businessScope">
- <a-textarea
- id="supplierInfoEdit-businessScope"
- :maxLength="200"
- v-model="form.businessScope"
- placeholder="请输入主营内容(最多200个字符)"
- allowClear />
- </a-form-model-item>
- <a-form-model-item label="状态" prop="enabledFlag" v-if="isState">
- <a-radio-group
- name="radioGroup"
- v-model="form.enabledFlag"
- id="supplierInfoEdit-enabledFlag" >
- <a-radio :value="1">启用</a-radio>
- <a-radio :value="0">禁用</a-radio>
- </a-radio-group>
- </a-form-model-item>
- </a-form-model>
- <div class="btn-cont">
- <a-button type="primary" id="supplierInfoEdit-btn-submit" @click="handleSubmit">保存</a-button>
- <a-button id="supplierInfoEdit-btn-back" @click="isShow = false" style="margin-left: 15px;">取消</a-button>
- </div>
- </div>
- </a-spin>
- </a-modal>
- </template>
- <script>
- import { getArea } from '@/api/data'
- import { supplierDetail, supplierSave } from '@/api/supplier'
- import { commonMixin } from '@/utils/mixin'
- export default {
- name: 'SupplierInfoEditModal',
- mixins: [commonMixin],
- props: {
- openModal: { // 弹框显示状态
- type: Boolean,
- default: false
- },
- itemId: {
- type: [Number, String],
- default: ''
- },
- isState: { // 是否显示状态
- type: Boolean,
- default: true
- }
- },
- computed: {
- modalTit () {
- return this.itemId ? '编辑' : '新增'
- }
- },
- data () {
- return {
- spinning: false,
- isShow: this.openModal, // 是否打开弹框
- formItemLayout: {
- labelCol: { span: 6 },
- wrapperCol: { span: 16 }
- },
- form: {
- supplierName: '', // 供应商名称
- provinceSn: undefined, // 省
- provinceName: '',
- citySn: undefined, // 市
- cityName: '',
- countySn: undefined, // 区
- countyName: '',
- supplierAddress: '', // 详细地址
- contactPerson: '', // 联系人
- contactTel: '', // 联系电话
- businessScope: '', // 主营内容
- enabledFlag: 1 // 启禁用
- },
- rules: {
- supplierName: [
- { required: true, message: '请输入供应商名称', trigger: 'blur' }
- ],
- provinceSn: [
- { required: true, message: '请选择省', trigger: 'change' }
- ],
- citySn: [
- { required: true, message: '请选择市', trigger: 'change' }
- ],
- countySn: [
- { required: true, message: '请选择区/县', trigger: 'change' }
- ],
- supplierAddress: [
- { required: true, message: '请输入详细地址', trigger: 'blur' }
- ],
- contactPerson: [
- { required: true, message: '请输入联系人', trigger: 'blur' }
- ],
- contactTel: [
- { required: true, message: '请输入联系人电话', trigger: 'blur' }
- ],
- enabledFlag: [
- { required: true, message: '请选择状态', trigger: 'change' }
- ]
- },
- addrProvinceList: [], // 省下拉
- addrCityList: [], // 市下拉
- addrDistrictList: [] // 区下拉
- }
- },
- methods: {
- // 过滤空格
- filterEmpty () {
- let str = this.form.supplierName
- str = str.replace(/\ +/g, '')
- str = str.replace(/[ ]/g, '')
- str = str.replace(/[\r\n]/g, '')
- this.form.supplierName = str
- },
- // 获取供应商信息
- getDetail () {
- supplierDetail({ id: this.itemId }).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)
- this.form.enabledFlag = Number(this.form.enabledFlag)
- if (!this.itemId) {
- this.form.supplierSn = undefined
- this.form.sysFlag = undefined
- }
- }
- })
- },
- // 保存
- handleSubmit (e) {
- e.preventDefault()
- const _this = this
- this.$refs.ruleForm.validate(valid => {
- if (valid) {
- const form = _this.form
- form.id = this.itemId ? this.itemId : null
- _this.spinning = true
- supplierSave(form).then(res => {
- if (res.status == 200) {
- _this.$message.success(res.message)
- _this.$emit('ok')
- _this.isShow = false
- _this.spinning = false
- } else {
- _this.spinning = false
- }
- })
- } else {
- return false
- }
- })
- },
- // 获取城市列表
- getCityList (val) {
- this.addrCityList = []
- this.addrDistrictList = []
- this.form.citySn = undefined
- this.form.countySn = undefined
- if (val) {
- this.getArea('city', val)
- this.form.provinceName = this.addrProvinceList.find(item => item.areaSn == val).name
- } else {
- this.form.provinceName = ''
- }
- },
- // 获取区县列表
- getAreaList (val) {
- this.addrDistrictList = []
- this.form.countySn = undefined
- if (val) {
- this.getArea('district', val)
- this.form.cityName = this.addrCityList.find(item => item.areaSn == val).name
- } else {
- this.form.cityName = ''
- }
- },
- // 区县变更
- areaCharged (val) {
- if (val) {
- this.form.countyName = this.addrDistrictList.find(item => item.areaSn == val).name
- } else {
- this.form.countyName = ''
- }
- },
- // 省/市/区
- getArea (leve, sn) {
- let params
- if (leve == 'province') {
- params = { type: '2' }
- } else {
- params = { parentId: sn, type: leve == 'city' ? '3' : '4' }
- }
- getArea(params).then(res => {
- if (res.status == 200) {
- if (leve == 'province') {
- this.addrProvinceList = res.data || []
- } else if (leve == 'city') {
- this.addrCityList = res.data || []
- } else if (leve == 'district') {
- this.addrDistrictList = res.data || []
- }
- } else {
- if (leve == 'province') {
- this.addrProvinceList = []
- } else if (leve == 'city') {
- this.addrCityList = []
- } else if (leve == 'district') {
- this.addrDistrictList = []
- }
- }
- })
- },
- resetSearchForm () {
- this.form.supplierName = ''
- this.form.provinceSn = undefined
- this.form.provinceName = ''
- this.form.citySn = undefined
- this.form.cityName = ''
- this.form.countySn = undefined
- this.form.countyName = ''
- this.form.supplierAddress = ''
- this.form.contactPerson = ''
- this.form.contactTel = ''
- this.form.businessScope = undefined
- this.form.enabledFlag = 1
- this.form.supplierSn = undefined
- this.addrCityList = []
- this.addrDistrictList = []
- this.$refs.ruleForm.resetFields()
- }
- },
- watch: {
- // 父页面传过来的弹框状态
- openModal (newValue, oldValue) {
- this.isShow = newValue
- },
- // 重定义的弹框状态
- isShow (newValue, oldValue) {
- if (!newValue) {
- this.$emit('close')
- this.resetSearchForm()
- } else {
- this.getArea('province')
- }
- },
- itemId (newValue, oldValue) {
- if (this.isShow && newValue) { // 编辑
- this.getDetail()
- }
- }
- }
- }
- </script>
- <style lang="less">
- .supplierInfoEdit-modal{
- .ant-modal-body {
- padding: 40px 40px 24px;
- }
- .btn-cont {
- text-align: center;
- margin: 35px 0 10px;
- }
- }
- </style>
|