merchant-web/src/views/modules/logistics-fare/logistics-template/index.vue

337 lines
11 KiB
Vue
Raw Normal View History

2024-08-18 06:26:20 +00:00
<template>
<div>
2024-11-07 09:13:34 +00:00
<div v-if="shopId">
<obj-table-plus
style="height: calc(100vh - 132px)"
ref="oTable"
mode="flex"
:tableCols="tableCols"
v-model="dataList"
@query="queryList"
>
<template slot="flexEmpty">
<el-empty description="暂无数据"></el-empty>
</template>
<div slot="tableTop" class="mb-2">
<el-form inline>
<el-form-item label="模板名称:">
<el-input
placeholder="请输入模板名称"
v-model="searchForm.name"
></el-input>
</el-form-item>
2024-11-12 11:52:30 +00:00
<el-form-item v-if="marketList.length > 0" label="摊铺">
2024-11-13 11:02:08 +00:00
<el-select v-model="searchForm.linkId" placeholder="请选择摊铺">
2024-11-12 11:52:30 +00:00
<el-option
v-for="item in marketList"
:key="item.marketId"
:label="item.marketName"
:value="item.marketId"
></el-option>
</el-select>
</el-form-item>
2024-11-07 09:13:34 +00:00
<el-button type="primary" @click="$refs.oTable.reload()"
>搜索</el-button
>
2024-11-13 11:02:08 +00:00
<el-button type="primary" @click="Reset">重置</el-button>
2024-11-07 09:13:34 +00:00
</el-form>
<el-button type="primary" @click="addFareTemplate"
>添加运费模板</el-button
2024-08-21 08:05:34 +00:00
>
2024-11-07 09:13:34 +00:00
</div>
</obj-table-plus>
<add-template
ref="addTemplate"
@refresh="$refs.oTable.refresh()"
></add-template>
</div>
<div style="height: calc(100vh - 200px)" v-else>
<el-empty :image-size="200" description="请先去完成认证"></el-empty>
</div>
2024-08-18 06:26:20 +00:00
</div>
</template>
<script>
import addTemplate from "./popup/add-template.vue";
export default {
components: { addTemplate },
data() {
return {
dataList: [],
2024-08-20 10:01:45 +00:00
searchForm: {
name: "",
2024-11-12 11:52:30 +00:00
linkId: "",
2024-08-20 10:01:45 +00:00
},
2024-11-07 09:13:34 +00:00
shopId: "",
2024-11-12 11:52:30 +00:00
marketList: "",
2024-08-18 06:26:20 +00:00
};
},
2024-11-07 09:13:34 +00:00
created() {
2024-12-05 03:36:00 +00:00
if (JSON.parse(sessionStorage.getItem("userInfo")).markets?.length > 0) {
2024-11-12 10:18:33 +00:00
this.shopId = true;
2024-11-12 11:52:30 +00:00
this.searchForm.linkId = JSON.parse(
2024-11-12 10:18:33 +00:00
sessionStorage.getItem("userInfo")
).markets[0].marketId;
this.marketList = JSON.parse(sessionStorage.getItem("userInfo")).markets;
console.log(this.marketList);
} else if (JSON.parse(sessionStorage.getItem("userInfo")).shopId) {
2024-11-12 11:52:30 +00:00
this.searchForm.linkId = JSON.parse(
sessionStorage.getItem("userInfo")
).shopId;
2024-11-12 10:18:33 +00:00
this.shopId = true;
} else {
this.shopId = false;
}
2024-11-07 09:13:34 +00:00
},
2024-08-18 06:26:20 +00:00
methods: {
queryList(pageNo, pageSize) {
2024-08-20 10:01:45 +00:00
this.$api.mer_admin
.getShippingTemplatePage({
pageNumber: pageNo,
pageSize: pageSize,
...this.searchForm,
})
.then((res) => {
console.log(res);
2024-08-21 08:05:34 +00:00
this.$refs.oTable.complete(
res.data.data.data,
Number(res.data.data.total)
);
2024-08-20 10:01:45 +00:00
})
2024-08-21 08:05:34 +00:00
.catch((err) => {
2024-08-20 10:01:45 +00:00
this.$refs.oTable.complete(false);
2024-08-21 08:05:34 +00:00
});
2024-08-18 06:26:20 +00:00
},
2024-11-13 11:02:08 +00:00
Reset() {
this.searchForm = {
name: "",
linkId: JSON.parse(sessionStorage.getItem("userInfo")).markets[0]
.marketId,
};
this.$refs.oTable.reload();
},
2024-08-18 06:26:20 +00:00
addFareTemplate() {
2024-11-12 11:52:30 +00:00
this.$refs.addTemplate.toggle().add(this.searchForm.linkId);
2024-08-18 06:26:20 +00:00
},
},
computed: {
tableCols() {
return [
{
type: "jsx",
render: (row) => {
console.log(row);
2024-08-21 08:05:34 +00:00
this.$api.mer_admin.getShippingTemplateInfo(row.id).then((res) => {
console.log(res);
2024-08-22 04:58:29 +00:00
console.log("row.tableData", row.tableData);
if (!row.tableData) {
if (res.data.data.shippingTemplatesRegionResultList) {
this.$set(
row,
"tableData",
res.data.data.shippingTemplatesRegionResultList.map(
(item) => {
item.cityCodes = item.cityCodes?.split(",");
console.log("item.cityCodes", item.cityCodes);
return item;
}
)
);
} else {
//包邮,假数据写死
this.$set(row, "tableData", [
{
cityCodes: "0",
first: "1",
firstPrice: "0.00",
renewal: "1",
renewalPrice: "0.00",
},
]);
}
}
2024-08-21 08:05:34 +00:00
});
2024-08-22 04:58:29 +00:00
const findLabelsByCode = (tree, codes) => {
2024-08-23 08:29:43 +00:00
// 记录找到的路径
let paths = [];
2024-08-22 04:58:29 +00:00
if (codes == "0") {
2024-08-23 08:29:43 +00:00
return ["中国"];
2024-08-22 04:58:29 +00:00
}
2024-08-23 08:29:43 +00:00
// 在树中搜索节点的递归函数
function searchTree(node, currentPath) {
// 将当前节点添加到路径中
currentPath.push(node.name);
// 如果当前节点的 code 在 codes 数组中,记录路径
if (codes.includes(node.code)) {
paths.push([...currentPath]); // 深拷贝当前路径
2024-08-22 04:58:29 +00:00
}
2024-08-23 08:29:43 +00:00
2024-08-22 04:58:29 +00:00
// 如果有子节点,继续递归查找
if (node.children) {
for (let child of node.children) {
2024-08-23 08:29:43 +00:00
searchTree(child, currentPath);
2024-08-22 04:58:29 +00:00
}
}
2024-08-23 08:29:43 +00:00
// 回溯,移除当前节点
currentPath.pop();
2024-08-22 04:58:29 +00:00
}
// 对树的每个顶层节点调用 searchTree
for (let node of tree) {
2024-08-23 08:29:43 +00:00
searchTree(node, []);
2024-08-22 04:58:29 +00:00
}
2024-08-23 08:29:43 +00:00
// 将所有找到的路径合并成字符串返回
2024-11-07 09:13:34 +00:00
return paths.map((path) => <p>{path.join("/")}</p>);
2024-08-22 04:58:29 +00:00
};
2024-08-21 08:05:34 +00:00
const appointMapper = {
0: "(全国包邮)",
1: "(部分包邮)",
2: "(自定义运费)",
};
const edit = () => {
this.$api.mer_admin
.getShippingTemplateInfo(row.id)
.then((res) => {
console.log(res);
this.$refs.addTemplate.toggle().update(res.data.data);
});
};
const copy = () => {
this.$api.mer_admin
.getShippingTemplateInfo(row.id)
.then((res) => {
console.log(res);
this.$refs.addTemplate.toggle().copy(res.data.data);
});
};
const remove = () => {
2024-08-22 04:58:29 +00:00
this.$api.mer_admin.removeShippingTemplate(row.id).then((res) => {
2024-08-21 08:05:34 +00:00
this.$refs.oTable.refresh();
2024-08-22 04:58:29 +00:00
});
};
const groupMapper = {
1: {
first: "首件(个)",
renewal: "续件(个)",
},
2: {
first: "首重kg",
renewal: "续重kg",
},
};
//打开弹窗预览
const openPreview = (str) => {
2024-08-23 08:29:43 +00:00
this.$confirm(
<div style="max-height:50vh;overflow-y:auto;line-height:1.5rem;">
{str}
</div>,
"详情",
{
showCancelButton: false,
confirmButtonText: "好的",
}
);
2024-08-21 08:05:34 +00:00
};
2024-08-18 06:26:20 +00:00
return (
<div class="mb-5">
<div class="flex justify-between items-center bg-gray-100 px-4">
2024-08-21 08:05:34 +00:00
<div>
{row.name}
{appointMapper[row.appoint]}
</div>
2024-08-18 06:26:20 +00:00
<div class="flex justify-between items-center">
2024-08-20 10:01:45 +00:00
<div class="mr-5">最后编辑时间{row.updateTime}</div>
2024-08-18 06:26:20 +00:00
<div>
2024-08-21 08:05:34 +00:00
<el-button type="text" onClick={copy}>
复制模板
</el-button>
<el-button type="text" onClick={edit}>
修改
</el-button>
2024-08-22 04:58:29 +00:00
<el-popconfirm
class="ml-2"
title="确认删除模板?"
onConfirm={remove}
>
2024-08-21 08:05:34 +00:00
<el-button type="text" slot="reference">
删除
</el-button>
</el-popconfirm>
2024-08-18 06:26:20 +00:00
</div>
</div>
</div>
2024-08-22 04:58:29 +00:00
<vxe-table
max-height="300"
border
align="center"
show-overflow
data={row.tableData}
>
2024-08-18 06:26:20 +00:00
<vxe-column
width="180px"
2024-08-22 04:58:29 +00:00
field="cityCodes"
2024-08-18 06:26:20 +00:00
title="运送到"
2024-08-22 04:58:29 +00:00
scopedSlots={{
default: (scope) => {
console.log("scope", scope);
return (
<span
class="cursor-pointer"
onClick={() => {
openPreview(
findLabelsByCode(
this.$api.mer_admin.getCityOptions(),
scope.row.cityCodes
)
);
}}
>
{findLabelsByCode(
this.$api.mer_admin.getCityOptions(),
scope.row.cityCodes
)}
</span>
);
},
}}
2024-08-18 06:26:20 +00:00
></vxe-column>
<vxe-column
width="200px"
2024-08-22 04:58:29 +00:00
field="first"
title={groupMapper[row.groups].first}
2024-08-18 06:26:20 +00:00
></vxe-column>
<vxe-column
width="200px"
2024-08-22 04:58:29 +00:00
field="firstPrice"
2024-08-18 06:26:20 +00:00
title="首费(元)"
></vxe-column>
<vxe-column
width="200px"
2024-08-22 04:58:29 +00:00
field="renewal"
title={groupMapper[row.groups].renewal}
2024-08-18 06:26:20 +00:00
></vxe-column>
<vxe-column
width="200px"
2024-08-22 04:58:29 +00:00
field="renewalPrice"
2024-08-18 06:26:20 +00:00
title="运费(元)"
></vxe-column>
</vxe-table>
</div>
);
},
},
];
},
},
};
</script>
<style lang="scss" scoped></style>