diff --git a/src/views/dataCenter/goods/Create.vue b/src/views/dataCenter/goods/Create.vue index 1360f69..38ae47a 100644 --- a/src/views/dataCenter/goods/Create.vue +++ b/src/views/dataCenter/goods/Create.vue @@ -324,6 +324,44 @@ +
+ 销售区域 + + + + + + 点击添加销售区域 + +
+
积分设置 提交 + + @@ -459,6 +499,18 @@ import * as GoodsApi from '@/api/goods' import { SelectImage, SelectVideo, Ueditor, InputNumberGroup } from '@/components' import GoodsModel from '@/common/model/goods/Index' import { GoodsType, MultiSpec } from './modules' +import { AreasModal } from '@/components/Modal' +import Region from '@/common/model/Region' + +const defaultItem = { + key: 0, + // first: 1, + // first_fee: 0, + // additional: 0, + // additional_fee: 0, + region: [], + region_text: [] +} export default { components: { @@ -467,7 +519,8 @@ export default { SelectVideo, Ueditor, InputNumberGroup, - MultiSpec + MultiSpec, + AreasModal }, data () { return { @@ -483,7 +536,42 @@ export default { // 当前表单元素 form: this.$form.createForm(this), // 表单数据 - formData: GoodsModel.formData + formData: GoodsModel.formData, + + columns: [ + { + title: '销售区域', + dataIndex: 'region_text', + width: '400px', + scopedSlots: { customRender: 'region_text' } + } + // { + // title: '首件 (个)', + // dataIndex: 'first', + // scopedSlots: { customRender: 'first' } + // }, + // { + // title: '运费(元)', + // dataIndex: 'first_fee', + // scopedSlots: { customRender: 'first_fee' } + // }, + // { + // title: '续件 (个)', + // dataIndex: 'additional', + // scopedSlots: { customRender: 'additional' } + // }, + // { + // title: '续费(元)', + // dataIndex: 'additional_fee', + // scopedSlots: { customRender: 'additional_fee' } + // } + ], + // table内容 + ruleList: [], + // 计费方式 + method: 10, + // 城市总数 + citysCount: null } }, // 初始化数据 @@ -494,6 +582,11 @@ export default { .then(() => { this.isLoading = false }) + + // 城市总数 + Region.getCitysCount().then(count => { + this.citysCount = count + }) }, methods: { @@ -540,7 +633,8 @@ export default { handleSubmit (e) { e.preventDefault() // 表单验证 - const { form: { validateFields } } = this + console.log(this.form) + const { form: { validateFields }, ruleList } = this validateFields((errors, values) => { // 定位到错误的tab选项卡 if (errors) { @@ -561,6 +655,7 @@ export default { values.categoryIds = values.categorys.map(item => item.value) delete values.categorys // 提交到后端api + values.rules = ruleList this.onFormSubmit(values) return true }) @@ -602,6 +697,67 @@ export default { this.isBtnLoading = false }) .finally(() => this.isLoading = false) + }, + + // 新增记录 + handleAdd () { + const index = this.ruleList.length + const newItem = { ...defaultItem, key: index } + // 排除的城市id集(已存在的城市id集) + const excludedCityIds = this.getExcludedCityIds() + if (excludedCityIds.length === this.citysCount) { + this.$message.error('已选择了所有的区域', 0.8) + return false + } + // 显示选择地区对话框 + this.handleAreasModal('add', index, newItem, excludedCityIds) + }, + + // 编辑记录 + handleEdit (index, item) { + // 排除的城市id集(已存在的城市id集) + const excludedCityIds = this.getExcludedCityIds() + // 显示选择地区对话框 + this.handleAreasModal('edit', index, item, excludedCityIds) + }, + + // 选择地区后的回调 + handleAreaSubmit (result) { + console.log(JSON.stringify(this.ruleList)) + const { custom: { scene, item } } = result + item.region = result.selectedCityIds + item.region_text = result.selectedText + if (scene === 'add') { + this.ruleList.push(item) + } + }, + + // 排除的城市id集(已存在的城市id集) + getExcludedCityIds () { + const excludedCityIds = [] + this.ruleList.forEach(item => { + item.region.forEach(cityId => { + excludedCityIds.push(cityId) + }) + }) + return excludedCityIds + }, + + // 显示选择地区对话框 + handleAreasModal (scene, index, item, excludedCityIds) { + this.$refs.AreasModal.handle({ scene, index, item }, item.region, excludedCityIds) + }, + + // 删除记录 + handleDelete (index) { + const app = this + const modal = this.$confirm({ + title: '您确定要删除该记录吗?', + onOk () { + app.ruleList.splice(index, 1) + modal.destroy() + } + }) } } @@ -610,4 +766,21 @@ export default { diff --git a/src/views/dataCenter/goods/Update.vue b/src/views/dataCenter/goods/Update.vue index 5432fe2..441115a 100644 --- a/src/views/dataCenter/goods/Update.vue +++ b/src/views/dataCenter/goods/Update.vue @@ -56,7 +56,7 @@ @@ -65,7 +65,7 @@ @@ -340,6 +340,44 @@ +
+ 销售区域 + + + + + + 点击添加销售区域 + +
+
积分设置
@@ -466,16 +504,25 @@ 提交
+