分类规格相关页面跳转

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) => { export const getSpecListData = (params) => {
return getRequest('/goods/spec/page', params) return getRequest('/goods/spec', params)
} }
// 添加或修改规格设置 // 添加或修改规格设置
export const insertSpec = (params) => { export const insertSpec = (params) => {
return postRequest('/goods/spec', params) return postRequest('/goods/spec', params)
} }
// 添加或修改规格设置 // 添加或修改规格设置
export const updateSpec = (params) => { export const updateSpec = (id,params) => {
return putRequest('/goods/spec', params) return putRequest(`/goods/spec/${id}`, params)
} }
//根据分类id获取关联规格 //根据分类id获取关联规格
export const getCategorySpecListData = (category_id, params) => { export const getCategorySpecListData = (category_id, params) => {
@ -94,15 +94,6 @@ export const getCategorySpecListData = (category_id, params) => {
export const delSpec = (id, params) => { export const delSpec = (id, params) => {
return deleteRequest(`/goods/spec/${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) => { export const getGoodsCategory = (parent_id) => {

View File

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

View File

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