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

数据组装

上级 113449c9
......@@ -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 @@
:modal='false'
:modal-append-to-body='false'
:visible.sync="isOpen"
v-if="isOpen"
direction="rtl"
style="position:absolute;height:100%;"
size="100%"
>
<template-freight :option="form" @closeIndexbtn="closeDialog"/>
<template-freight :option="form" :address-all="addressAll" @closeIndexbtn="closeDialog"/>
</el-drawer>
</el-card>
</div>
</template>
<script>
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'
export default {
......@@ -137,18 +139,20 @@
name: [
{required: true, message: "模板名称不能为空", trigger: "blur"}
],
}
},
addressAll: []
};
},
components: {
TemplateFreight
TemplateFreight,
// IndexBtn
},
created() {
this.getList();
this.$nextTick(() => {
this.fullHeight = document.getElementsByClassName('box-card')[0].clientHeight
})
this.getaddressList()
},
watch: {
fullHeight(val) {
......@@ -157,6 +161,25 @@
}
},
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) {
this.isOpen = val;
this.getList();
......
......@@ -15,7 +15,7 @@
<el-card style="margin: 20px;">
<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-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 label="模板名称" prop="name" style="width: 400px;">
<el-input v-model="ruleForm.name"></el-input>
......@@ -52,6 +52,7 @@
@selection-change="handleSelectionChange">
<el-table-column
type="selection"
:selectable="selectEnable"
width="55">
</el-table-column>
<el-table-column
......@@ -127,7 +128,7 @@
<div style="display: flex; justify-content: space-between; margin-bottom: 5px;">
<span style="font-size: 12px; color: #85878A;">收货地址在限制下单区域内的用户将无法完成下单</span>
<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 style="background: #F9F9FA; padding: 20px;">
......@@ -145,9 +146,10 @@
</el-table-column>
<el-table-column
label="限制配送地区"
prop="dis_dispatching"
>
<template slot-scope="scope">
安徽省、重庆市、广东省、安徽
{{ scope.row.a }}
</template>
</el-table-column>
<!-- 样式占位 -->
......@@ -161,8 +163,8 @@
width="120"
>
<template slot-scope="scope">
<el-button type="text" size="small">删除</el-button>
<el-button type="text" size="small">修改地区</el-button>
<el-button type="text" size="small" @click="noDeliveryTableData = []">删除</el-button>
<el-button type="text" size="small" @click="editAddress(scope.row, scope.$index, 2)">修改地区</el-button>
</template>
</el-table-column>
</el-table>
......@@ -178,18 +180,18 @@
</el-form>
<div style="text-align: center;">
<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>
</el-card>
<el-dialog
title="选择地区"
:visible.sync="dialogAddress"
v-if="dialogAddress"
width="40%"
width="600px"
:close-on-click-modal="false"
:append-to-body="true">
<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>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogAddress = false" size="mini">取消</el-button>
......@@ -200,10 +202,24 @@
</template>
<script>
import { addressList } from '@/api/module/freight'
import { addFreight, updateFreight} from '@/api/module/freight'
export default {
props: {
option: {
type: Object,
required: true
},
addressAll: {
type: Array,
required: true
}
},
data() {
return {
ruleForm: {
id: 0,
sort: 0,
name: '',
is_default: 0,
......@@ -222,6 +238,7 @@
deliveryTableData: [
{
a: [0],
name: [],
f: '',
fp: '',
n: '',
......@@ -231,75 +248,111 @@
noDeliveryTableData: [],
multipleSelection: [],
dialogAddress: false,
props: { multiple: true },
options: [{
value: 1,
label: '东南',
children: [{
value: 2,
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: '克拉玛依' }
]
}]
},],
props: {
multiple: true,
value: 'id',
label: 'name'
},
addressOptions: [],
rowItem: null,
selectAddress: []
rowItem2: null,
selectAddress: [],
addType: 1 // 1 配送添加 2不配送添加
}
},
mounted() {
this.addressOptions = this.addressAll
this.initData()
// this.getaddressList()
},
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) {
this[str][index][from] = this[str][index][from].toString().match(/^\d*(\.?\d{0,2})/g)[0]
},
onClickInputKeyBoard2(str, index, from) {
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() {
this.$emit('closeIndexbtn', false)
},
// 多选数据
handleSelectionChange(val) {
this.multipleSelection = val;
console.log(this.multipleSelection)
},
// 添加配送地区
addDelivery() {
this.selectAddress = []
this.addType = 1
this.deliveryTableData.push(
{
a: [],
......@@ -310,24 +363,181 @@
}
)
},
// 添加不配送地区
addNoDelivery() {
this.selectAddress = []
this.addType = 2
this.dialogAddress = true
},
// 删除配送地区
delDelivery(type, index) {
if (type == 1) {
this.deliveryTableData.splice(index, 1);
} 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.rowItem = row
this.dialogAddress = true
},
// 选择的地区赋值
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
},
// 将数据组合成省市县及是否选中的是全部地区 山东省【济南市(市中区,天桥区,长清区,济阳县)】 河北省(全部地区)
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论