分类规格相关页面跳转

master
Chopper 2021-06-23 16:48:43 +08:00
parent 8e239a5bbf
commit 8032f3bda1
3 changed files with 60 additions and 112 deletions

View File

@ -76,15 +76,15 @@ export const disableCategory = (id, type) => {
// 获取商品规格分页列表
export const getSpecListData = (params) => {
return getRequest('/goods/spec/page', params)
return getRequest('/goods/spec', params)
}
// 添加或修改规格设置
export const insertSpec = (params) => {
return postRequest('/goods/spec', params)
}
// 添加或修改规格设置
export const updateSpec = (params) => {
return putRequest('/goods/spec', params)
export const updateSpec = (id,params) => {
return putRequest(`/goods/spec/${id}`, params)
}
//根据分类id获取关联规格
export const getCategorySpecListData = (category_id, params) => {
@ -94,15 +94,6 @@ export const getCategorySpecListData = (category_id, params) => {
export const delSpec = (id, params) => {
return deleteRequest(`/goods/spec/${id}`, params)
}
// 获取商品规格值列表
export const getSpecValuesListData = (id, params) => {
return getRequest(`/goods/specValues/values/${id}`, params)
}
// 添加商品规格值
export const saveSpecValues = (id, params) => {
return postRequest(`/goods/specValues/save/${id}`, params)
}
// 查询某分类下的全部子分类列表
export const getGoodsCategory = (parent_id) => {

View File

@ -261,7 +261,6 @@ export default {
getCategorySpecListData(v.id).then((res) => {
this.categoryId = v.id;
this.modalSpecTitle = "规格关联";
console.log(res);
this.specForm.categorySpecs = res.map((item) => item.id);
this.modalSpecVisible = true;
});

View File

@ -23,8 +23,8 @@
</Form>
</Row>
<Row class="operation padding-row">
<Button @click="add" type="primary" >添加</Button>
<Button @click="delAll" >批量删</Button>
<Button @click="add" type="primary">添加</Button>
<Button @click="delAll"></Button>
</Row>
<Table
:loading="loading"
@ -60,53 +60,33 @@
>
<Form ref="form" :model="form" :label-width="100" :rules="formValidate">
<FormItem label="规格名称" prop="specName">
<Input v-model="form.specName" maxlength="30" clearable style="width: 100%" />
<Input v-model="form.specName" maxlength="30" clearable style="width: 100%"/>
</FormItem>
<FormItem label="规格值" prop="specValue">
<Select
v-model="form.specValue"
placeholder="输入后回车添加"
multiple
filterable
allow-create
:popper-append-to-body="false"
popper-class="spec-values-popper"
style="width: 100%; text-align: left; margin-right: 10px"
>
<Option
v-for="item in specValue"
:value="item"
:label="item"
>
</Option>
</Select>
</FormItem>
</Form>
<div slot="footer">
<Button type="text" @click="modalVisible = false">取消</Button>
<Button type="primary" :loading="submitLoading" @click="saveSpec"
>提交</Button
>
</div>
</Modal>
<Modal
:title="modalTitle"
v-model="dialogSpecValuesVisible"
:mask-closable="false"
:width="500"
:styles="{ top: '30px' }"
class="permModal"
>
<Form ref="specForm" :model="specForm" :label-width="100">
<Select
v-model="specForm.specValue"
placeholder="输入后回车添加"
multiple
filterable
allow-create
:popper-append-to-body="false"
popper-class="spec-values-popper"
style="width: 100%; text-align: left; margin-right: 10px"
>
<Option
v-for="item in specValues"
:value="item.specValue"
:key="item.id"
:label="item.specValue"
>
</Option>
</Select>
</Form>
<div slot="footer">
<Button type="text" @click="dialogSpecValuesVisible = false"
>取消</Button
>
<Button
type="primary"
:loading="submitLoading"
@click="submitSpecValuesForm"
>提交</Button
>提交
</Button
>
</div>
</Modal>
@ -118,10 +98,9 @@ import {
getSpecListData,
insertSpec,
updateSpec,
delSpec,
getSpecValuesListData,
saveSpecValues,
delSpec
} from "@/api/goods";
export default {
name: "spec",
components: {},
@ -131,7 +110,6 @@ export default {
modalType: 0, //
modalVisible: false, //
modalTitle: "", //
dialogSpecValuesVisible: false, //
specTitle: "", //
searchForm: {
//
@ -145,9 +123,8 @@ export default {
specName: "",
specValue: "",
},
specForm: {},
/** 编辑规格值 */
specValues: [],
specValue: [],
//
formValidate: {},
submitLoading: false, //
@ -179,24 +156,7 @@ export default {
width: 250,
render: (h, params) => {
return h("div", [
h(
"Button",
{
props: {
type: "primary",
size: "small",
},
style: {
marginRight: "5px",
},
on: {
click: () => {
this.editSpec(params.row);
},
},
},
"编辑规格值"
),
h(
"Button",
{
@ -239,23 +199,28 @@ export default {
};
},
methods: {
//
init() {
this.getDataList();
},
//
changePage(v) {
this.searchForm.pageNumber = v;
this.getDataList();
this.clearSelectAll();
},
//
changePageSize(v) {
this.searchForm.pageSize = v;
this.getDataList();
},
//
handleSearch() {
this.searchForm.pageNumber = 1;
this.searchForm.pageSize = 10;
this.getDataList();
},
//
handleReset() {
this.$refs.searchForm.resetFields();
this.searchForm.pageNumber = 1;
@ -263,6 +228,7 @@ export default {
//
this.getDataList();
},
//
changeSort(e) {
this.searchForm.sort = e.key;
this.searchForm.order = e.order;
@ -271,36 +237,27 @@ export default {
}
this.getDataList();
},
//
clearSelectAll() {
this.$refs.table.selectAll(false);
},
//
changeSelect(e) {
this.selectList = e;
this.selectCount = e.length;
},
//
getDataList() {
this.loading = true;
//
getSpecListData(this.searchForm).then((res) => {
this.loading = false;
if (res.success) {
this.data = res.result.records;
this.total = res.result.total;
}
this.data = res.records;
this.total = res.total;
});
this.loading = false;
},
submitSpecValuesForm() {
saveSpecValues(this.specForm.specId, this.specForm).then((res) => {
this.submitLoading = false;
if (res.success) {
this.$Message.success("规格值保存成功");
this.getDataList();
this.modalVisible = false;
this.dialogSpecValuesVisible = false;
}
});
},
//
saveSpec() {
this.$refs.form.validate((valid) => {
if (valid) {
@ -318,7 +275,7 @@ export default {
});
} else {
//
updateSpec(this.form).then((res) => {
updateSpec(this.form.id, this.form).then((res) => {
this.submitLoading = false;
if (res.success) {
this.$Message.success("操作成功");
@ -330,6 +287,7 @@ export default {
}
});
},
//
add() {
this.modalType = 0;
this.modalTitle = "添加";
@ -337,31 +295,31 @@ export default {
delete this.form.id;
this.modalVisible = true;
},
//
edit(v) {
this.modalType = 1;
this.modalTitle = "编辑";
this.$refs.form.resetFields();
// null""
for (let attr in v) {
if (v[attr] === null) {
v[attr] = "";
}
}
let str = JSON.stringify(v);
let data = JSON.parse(str);
this.form = data;
let localVal = v.specValue;
this.form.specName = v.specName;
this.form.id = v.id;
this.form.specValue = v.specValue;
if (localVal && localVal.indexOf("," > 0)) {
this.form.specValue = localVal.split(",")
this.specValue = this.form.specValue
this.$set(this, 'specValue', this.form.specValue)
} else {
this.specValue = [];
}
this.modalVisible = true;
},
editSpec(v) {
getSpecValuesListData(v.id).then((res) => {
this.modalType = 1;
this.modalTitle = "编辑";
this.specValues = res.result;
this.specForm.specValue = res.result.map(item => item.specValue)
this.specForm.specId = v.id;
this.dialogSpecValuesVisible = true;
});
},
remove(v) {
this.$Modal.confirm({
title: "确认删除",
@ -415,5 +373,5 @@ export default {
};
</script>
<style lang="scss">
@import "@/styles/table-common.scss";
@import "@/styles/table-common.scss";
</style>