提交 c6b441d6 authored 作者: 郑伟娜's avatar 郑伟娜

数据组装

上级 113449c9
...@@ -45,3 +45,12 @@ export function delFreight(ids) { ...@@ -45,3 +45,12 @@ export function delFreight(ids) {
}) })
} }
// 获取全部地址
export function addressList(data) {
return request({
url: '/local/address/getAddressList',
method: 'post',
data: data
})
}
...@@ -79,18 +79,20 @@ ...@@ -79,18 +79,20 @@
:modal='false' :modal='false'
:modal-append-to-body='false' :modal-append-to-body='false'
:visible.sync="isOpen" :visible.sync="isOpen"
v-if="isOpen"
direction="rtl" direction="rtl"
style="position:absolute;height:100%;" style="position:absolute;height:100%;"
size="100%" size="100%"
> >
<template-freight :option="form" @closeIndexbtn="closeDialog"/> <template-freight :option="form" :address-all="addressAll" @closeIndexbtn="closeDialog"/>
</el-drawer> </el-drawer>
</el-card> </el-card>
</div> </div>
</template> </template>
<script> <script>
import TemplateFreight from './templateFreight' import TemplateFreight from './templateFreight'
import {listFreight, getFreight, delFreight, addFreight, updateFreight} from '@/api/module/freight' // import IndexBtn from './indexbtn'
import {listFreight, getFreight, delFreight, addFreight, updateFreight, addressList} from '@/api/module/freight'
import {dateFormat} from '@/utils' import {dateFormat} from '@/utils'
export default { export default {
...@@ -137,18 +139,20 @@ ...@@ -137,18 +139,20 @@
name: [ name: [
{required: true, message: "模板名称不能为空", trigger: "blur"} {required: true, message: "模板名称不能为空", trigger: "blur"}
], ],
} },
addressAll: []
}; };
}, },
components: { components: {
TemplateFreight TemplateFreight,
// IndexBtn
}, },
created() { created() {
this.getList(); this.getList();
this.$nextTick(() => { this.$nextTick(() => {
this.fullHeight = document.getElementsByClassName('box-card')[0].clientHeight this.fullHeight = document.getElementsByClassName('box-card')[0].clientHeight
}) })
this.getaddressList()
}, },
watch: { watch: {
fullHeight(val) { fullHeight(val) {
...@@ -157,6 +161,25 @@ ...@@ -157,6 +161,25 @@
} }
}, },
methods: { methods: {
// 获取全部地区
getaddressList() {
addressList().then(res => {
if (res.code == 1) {
this.addressAll = this.getTreeData(res.data)
}
})
},
// 处理最后一级显示暂无数据
getTreeData(data) {
for(let i = 0, len = data.length; i < len; i++ ) {
if (!data[i].children.length) {
data[i].children = undefined
} else {
this.getTreeData(data[i].children)
}
}
return data
},
closeDialog(val) { closeDialog(val) {
this.isOpen = val; this.isOpen = val;
this.getList(); this.getList();
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<el-card style="margin: 20px;"> <el-card style="margin: 20px;">
<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px" class="demo-ruleForm" style="width: 80%;"> <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px" class="demo-ruleForm" style="width: 80%;">
<el-form-item label="排序" prop="sort" style="width: 400px;"> <el-form-item label="排序" prop="sort" style="width: 400px;">
<el-input v-model="ruleForm.sort"></el-input> <el-input v-model="ruleForm.sort" @input="onClickInputKeyBoard3('ruleForm', 'sort')"></el-input>
</el-form-item> </el-form-item>
<el-form-item label="模板名称" prop="name" style="width: 400px;"> <el-form-item label="模板名称" prop="name" style="width: 400px;">
<el-input v-model="ruleForm.name"></el-input> <el-input v-model="ruleForm.name"></el-input>
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
@selection-change="handleSelectionChange"> @selection-change="handleSelectionChange">
<el-table-column <el-table-column
type="selection" type="selection"
:selectable="selectEnable"
width="55"> width="55">
</el-table-column> </el-table-column>
<el-table-column <el-table-column
...@@ -127,7 +128,7 @@ ...@@ -127,7 +128,7 @@
<div style="display: flex; justify-content: space-between; margin-bottom: 5px;"> <div style="display: flex; justify-content: space-between; margin-bottom: 5px;">
<span style="font-size: 12px; color: #85878A;">收货地址在限制下单区域内的用户将无法完成下单</span> <span style="font-size: 12px; color: #85878A;">收货地址在限制下单区域内的用户将无法完成下单</span>
<div> <div>
<el-button type="primary" plain size="mini" @click="dialogAddress = true">添加地区</el-button> <el-button type="primary" plain size="mini" @click="addNoDelivery" v-if="!noDeliveryTableData.length">添加地区</el-button>
</div> </div>
</div> </div>
<div style="background: #F9F9FA; padding: 20px;"> <div style="background: #F9F9FA; padding: 20px;">
...@@ -145,9 +146,10 @@ ...@@ -145,9 +146,10 @@
</el-table-column> </el-table-column>
<el-table-column <el-table-column
label="限制配送地区" label="限制配送地区"
prop="dis_dispatching"
> >
<template slot-scope="scope"> <template slot-scope="scope">
安徽省、重庆市、广东省、安徽 {{ scope.row.a }}
</template> </template>
</el-table-column> </el-table-column>
<!-- 样式占位 --> <!-- 样式占位 -->
...@@ -161,8 +163,8 @@ ...@@ -161,8 +163,8 @@
width="120" width="120"
> >
<template slot-scope="scope"> <template slot-scope="scope">
<el-button type="text" size="small">删除</el-button> <el-button type="text" size="small" @click="noDeliveryTableData = []">删除</el-button>
<el-button type="text" size="small">修改地区</el-button> <el-button type="text" size="small" @click="editAddress(scope.row, scope.$index, 2)">修改地区</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
...@@ -178,18 +180,18 @@ ...@@ -178,18 +180,18 @@
</el-form> </el-form>
<div style="text-align: center;"> <div style="text-align: center;">
<el-button size="mini" @click="closeDialog">取消</el-button> <el-button size="mini" @click="closeDialog">取消</el-button>
<el-button type="primary" size="mini">提交</el-button> <el-button type="primary" size="mini" @click="handleSubmit">提交</el-button>
</div> </div>
</el-card> </el-card>
<el-dialog <el-dialog
title="选择地区" title="选择地区"
:visible.sync="dialogAddress" :visible.sync="dialogAddress"
v-if="dialogAddress" v-if="dialogAddress"
width="40%" width="600px"
:close-on-click-modal="false" :close-on-click-modal="false"
:append-to-body="true"> :append-to-body="true">
<div style="height: 500px;"> <div style="height: 500px;">
<el-cascader-panel v-model="selectAddress" :options="options" :props="props" style="height: 100%;"></el-cascader-panel> <el-cascader-panel ref="cascaderPanel" v-model="selectAddress" :options="addressOptions" :props="props" style="height: 100%;"></el-cascader-panel>
</div> </div>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button @click="dialogAddress = false" size="mini">取消</el-button> <el-button @click="dialogAddress = false" size="mini">取消</el-button>
...@@ -200,10 +202,24 @@ ...@@ -200,10 +202,24 @@
</template> </template>
<script> <script>
import { addressList } from '@/api/module/freight'
import { addFreight, updateFreight} from '@/api/module/freight'
export default { export default {
props: {
option: {
type: Object,
required: true
},
addressAll: {
type: Array,
required: true
}
},
data() { data() {
return { return {
ruleForm: { ruleForm: {
id: 0,
sort: 0, sort: 0,
name: '', name: '',
is_default: 0, is_default: 0,
...@@ -222,6 +238,7 @@ ...@@ -222,6 +238,7 @@
deliveryTableData: [ deliveryTableData: [
{ {
a: [0], a: [0],
name: [],
f: '', f: '',
fp: '', fp: '',
n: '', n: '',
...@@ -231,75 +248,111 @@ ...@@ -231,75 +248,111 @@
noDeliveryTableData: [], noDeliveryTableData: [],
multipleSelection: [], multipleSelection: [],
dialogAddress: false, dialogAddress: false,
props: { multiple: true }, props: {
options: [{ multiple: true,
value: 1, value: 'id',
label: '东南', label: 'name'
children: [{ },
value: 2, addressOptions: [],
label: '上海',
children: [
{ value: 3, label: '普陀' },
{ value: 4, label: '黄埔' },
{ value: 5, label: '徐汇' }
]
}, {
value: 7,
label: '江苏',
children: [
{ value: 8, label: '南京' },
{ value: 9, label: '苏州' },
{ value: 10, label: '无锡' }
]
}, {
value: 12,
label: '浙江',
children: [
{ value: 13, label: '杭州' },
{ value: 14, label: '宁波' },
{ value: 15, label: '嘉兴' }
]
}]
}, {
value: 17,
label: '西北',
children: [{
value: 18,
label: '陕西',
children: [
{ value: 19, label: '西安' },
{ value: 20, label: '延安' }
]
}, {
value: 21,
label: '新疆维吾尔族自治区',
children: [
{ value: 22, label: '乌鲁木齐' },
{ value: 23, label: '克拉玛依' }
]
}]
},],
rowItem: null, rowItem: null,
selectAddress: [] rowItem2: null,
selectAddress: [],
addType: 1 // 1 配送添加 2不配送添加
} }
}, },
mounted() {
this.addressOptions = this.addressAll
this.initData()
// this.getaddressList()
},
methods: { methods: {
// 初始化数据
initData() {
if (this.option.id == 0) {
this.ruleForm = {
id: 0,
sort: 0,
name: '',
is_default: 0,
charge_type: 1,
publish: 0
}
this.deliveryTableData = [
{
a: [0],
f: '',
fp: '',
n: '',
np: ''
}
]
this.noDeliveryTableData = []
} else {
this.ruleForm = {
id: this.option.id,
sort: this.option.sort,
name: this.option.name,
is_default: this.option.is_default,
charge_type: this.option.charge_type,
publish: this.option.publish
}
this.deliveryTableData = this.option.dispatching
this.deliveryTableData.forEach(item=>{
item.fp = Number(item.fp / 100)
item.np = Number(item.np / 100)
})
this.noDeliveryTableData[0] = {
a: this.option.dis_dispatching
}
}
},
// 获取全部地区
getaddressList() {
addressList().then(res => {
if (res.code == 1) {
this.addressOptions = this.getTreeData(res.data)
}
})
},
// 处理最后一级显示暂无数据
getTreeData(data) {
for(let i = 0, len = data.length; i < len; i++ ) {
if (!data[i].children.length) {
data[i].children = undefined
} else {
this.getTreeData(data[i].children)
}
}
return data
},
// 设置全国选项不可选
selectEnable(row) {
if (row.a.length && row.a[0] == 0) {
return false
} else {
return true
}
},
onClickInputKeyBoard(str, index, from) { onClickInputKeyBoard(str, index, from) {
this[str][index][from] = this[str][index][from].toString().match(/^\d*(\.?\d{0,2})/g)[0] this[str][index][from] = this[str][index][from].toString().match(/^\d*(\.?\d{0,2})/g)[0]
}, },
onClickInputKeyBoard2(str, index, from) { onClickInputKeyBoard2(str, index, from) {
this[str][index][from] = this[str][index][from].toString().match(/^\d*/g)[0] this[str][index][from] = this[str][index][from].toString().match(/^\d*/g)[0]
}, },
onClickInputKeyBoard3(str, from) {
this[str][from] = this[str][from].toString().match(/^\d*/g)[0]
},
closeDialog() { closeDialog() {
this.$emit('closeIndexbtn', false) this.$emit('closeIndexbtn', false)
}, },
// 多选数据 // 多选数据
handleSelectionChange(val) { handleSelectionChange(val) {
this.multipleSelection = val; this.multipleSelection = val;
console.log(this.multipleSelection)
}, },
// 添加配送地区 // 添加配送地区
addDelivery() { addDelivery() {
this.selectAddress = []
this.addType = 1
this.deliveryTableData.push( this.deliveryTableData.push(
{ {
a: [], a: [],
...@@ -310,24 +363,181 @@ ...@@ -310,24 +363,181 @@
} }
) )
}, },
// 添加不配送地区
addNoDelivery() {
this.selectAddress = []
this.addType = 2
this.dialogAddress = true
},
// 删除配送地区 // 删除配送地区
delDelivery(type, index) { delDelivery(type, index) {
if (type == 1) { if (type == 1) {
this.deliveryTableData.splice(index, 1); this.deliveryTableData.splice(index, 1);
} else { } else {
for(let i = 0, len = this.multipleSelection.length; i < len; i++) {
for(let j = 0, len = this.deliveryTableData.length; j < len; j++) {
if (this.multipleSelection[i] == this.deliveryTableData[j]) {
this.deliveryTableData.splice(j, 1);
}
}
}
} }
}, },
// 修改地区 // 修改地区
editAddress(row, index) { editAddress(row, index, type) {
this.selectAddress = []
if (type == 2) {
this.rowItem2 = row
this.addType = 2
} else {
this.rowItem = row
this.addType = 1
}
this.selectAddress = row.a this.selectAddress = row.a
this.rowItem = row
this.dialogAddress = true this.dialogAddress = true
}, },
// 选择的地区赋值 // 选择的地区赋值
saveAddress() { saveAddress() {
this.rowItem.a = this.selectAddress if (this.addType == 1) {
this.rowItem.a = this.selectAddress
console.log(this.selectAddress)
console.log(this.addressOptions)
this.getAddressName()
} else {
this.noDeliveryTableData.push({
a: this.selectAddress
})
}
this.dialogAddress = false this.dialogAddress = false
},
// 将数据组合成省市县及是否选中的是全部地区 山东省【济南市(市中区,天桥区,长清区,济阳县)】 河北省(全部地区)
getAddressName() {
let a = []
let b = []
let c = [] // 将每个省的数据组合到一个数组中
for(let i = 0; i < this.selectAddress.length; i++) {
a.push(this.selectAddress[i][0])
}
b = Array.from(new Set(a))
for(let i = 0; i < b.length; i++) {
c[i] = []
for(let j = 0; j < this.selectAddress.length; j++) {
console.log('---',b[i] ,this.selectAddress[j][0])
if (b[i] == this.selectAddress[j][0]) {
c[i].push(this.selectAddress[j])
}
}
}
console.log(c)
debugger
let addressName = []
for(let i = 0; i < c.length; i++) {
let name1 = []
let name2 = []
let name3 = []
let str = ''
for(let j = 0; j < this.addressOptions.length; j++) {
if (c[i][0][0] == this.addressOptions[j].id) {
name1.push(this.addressOptions[j].name)
let d = []
let e = []
c[i].map(item => {
d.push(item[1])
})
e = Array.from(new Set(d))
if ('children' in this.addressOptions[j]) {
if (e.length == this.addressOptions[j].children.length) {
debugger
name2.push('(全部地区)')
} else {
debugger
for(let k = 0; k < e.length; k++) {
for(let l = 0; l < this.addressOptions[j].children.length; l++) {
if (e[k] == this.addressOptions[j].children[l].id) {
name2.push(this.addressOptions[j].children[l].name)
let f = []
let g = []
c[i].map(item => {
if (e[k] == item[1]) {
g.push(item[2])
}
})
if ('children' in this.addressOptions[j].children[l]) {
if (c[i].length == this.addressOptions[j].children[l].children.length) {
debugger
name3.push('全部地区')
} else {
debugger
for(let m = 0; m < g.length; m++) {
for(let n = 0; n < this.addressOptions[j].children[l].children.length; n++) {
if (g[m] == this.addressOptions[j].children[l].children[n].id) {
name3.push(this.addressOptions[j].children[l].children[n].name)
}
}
}
}
str = name1.join() + `【${name2.join()}】` + `(${name3.join()})`
addressName.push(str)
name2 = []
name3 = []
}
}
}
}
}
}
}
}
// let str = name1.join() + `【${name2.join()}】` + `(${name3.join()})`
// addressName.push(name2)
// addressName.push(name3)
}
console.log('-------------')
console.log(addressName)
},
// 提交
handleSubmit() {
this.$refs['ruleForm'].validate((valid) => {
if (valid) {
if (this.option.id == 0) {
let params = JSON.parse(JSON.stringify(Object.assign({}, this.ruleForm, {dispatching: this.deliveryTableData})))
if (params.dispatching.length) {
params.dispatching.forEach(item=>{
item.fp = Number(item.fp * 100)
item.np = Number(item.np * 100)
})
}
params.dis_dispatching = this.noDeliveryTableData.length ? this.noDeliveryTableData[0].a : []
addFreight(params).then(res => {
if (res.code == 1) {
this.$message.success('新增成功')
this.closeDialog()
}
})
} else {
let params = JSON.parse(JSON.stringify(Object.assign({}, this.ruleForm, {dispatching: this.deliveryTableData})))
if (params.dispatching.length) {
params.dispatching.forEach(item=>{
item.fp = Number(item.fp * 100)
item.np = Number(item.np * 100)
})
}
params.dis_dispatching = this.noDeliveryTableData.length ? this.noDeliveryTableData[0].a : []
updateFreight(params).then(res => {
if (res.code == 1) {
this.$message.success('修改成功')
this.closeDialog()
}
})
}
}
})
} }
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论