2022-08-02 10:16:07 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<el-card class="box-card">
|
2022-08-06 20:03:35 +08:00
|
|
|
|
<div class="goods" style="margin: 20px">
|
|
|
|
|
|
<div
|
|
|
|
|
|
class="add-item-info"
|
|
|
|
|
|
style="margin-bottom: 10px; margin-left: 52px"
|
|
|
|
|
|
>
|
2022-08-04 18:59:32 +08:00
|
|
|
|
<div>
|
2022-08-06 20:03:35 +08:00
|
|
|
|
<div style="font-size: 14px">商品列表:</div>
|
|
|
|
|
|
<el-select v-model="lid" placeholder="选择商品">
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
v-for="item in goodschoose"
|
|
|
|
|
|
:key="item.id"
|
|
|
|
|
|
:label="item.title"
|
|
|
|
|
|
:value="item.id"
|
|
|
|
|
|
>
|
2022-08-04 18:59:32 +08:00
|
|
|
|
</el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</div>
|
2022-08-06 20:03:35 +08:00
|
|
|
|
<span style="font-size: 14px"
|
|
|
|
|
|
>商品图片:
|
|
|
|
|
|
<UploadTem />
|
|
|
|
|
|
</span>
|
2022-08-04 18:59:32 +08:00
|
|
|
|
<!-- <UploadTem @urlimg='hanleurlimg'
|
|
|
|
|
|
:number="2"
|
|
|
|
|
|
:file='file' /> -->
|
|
|
|
|
|
<!-- <el-upload class="upload"
|
|
|
|
|
|
action="https://ct-upimg.yx090.com/api/upload"
|
2022-08-02 10:16:07 +08:00
|
|
|
|
list-type="picture-card"
|
2022-08-04 18:59:32 +08:00
|
|
|
|
:on-success="successUpload"
|
|
|
|
|
|
:on-error="errorUpload"
|
|
|
|
|
|
:on-remove="removeUpload"
|
|
|
|
|
|
:headers="headers"
|
|
|
|
|
|
:limit="1">
|
2022-08-02 10:16:07 +08:00
|
|
|
|
<img v-if="imageUrl"
|
|
|
|
|
|
:src="imageUrl"
|
|
|
|
|
|
class="avatar">
|
|
|
|
|
|
<i v-else
|
|
|
|
|
|
class="el-icon-plus avatar-uploader-icon"></i>
|
2022-08-04 18:59:32 +08:00
|
|
|
|
</el-upload> -->
|
2022-08-02 10:16:07 +08:00
|
|
|
|
</div>
|
2022-08-06 20:03:35 +08:00
|
|
|
|
<el-form ref="form" :inline="true" :model="form">
|
2022-08-02 10:16:07 +08:00
|
|
|
|
<div>
|
|
|
|
|
|
<el-form-item label="商品名称:">
|
2022-08-06 20:03:35 +08:00
|
|
|
|
<el-input placeholder="商品名称" v-model="form.title"></el-input>
|
2022-08-04 18:59:32 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="商品编码:">
|
2022-08-06 20:03:35 +08:00
|
|
|
|
<el-input
|
|
|
|
|
|
placeholder="商品编码"
|
|
|
|
|
|
v-model="form.goods_code"
|
|
|
|
|
|
></el-input>
|
2022-08-02 10:16:07 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="商品种类:">
|
2022-08-06 20:03:35 +08:00
|
|
|
|
<el-select v-model="form.type_id" placeholder="商品种类">
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
v-for="item in cate"
|
|
|
|
|
|
:key="item.id"
|
|
|
|
|
|
:label="item.name"
|
|
|
|
|
|
:value="item.id"
|
|
|
|
|
|
>
|
2022-08-02 10:16:07 +08:00
|
|
|
|
</el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="商品品牌:">
|
2022-08-06 20:03:35 +08:00
|
|
|
|
<el-select v-model="form.brand_id" placeholder="商品品牌">
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
v-for="item in brand"
|
|
|
|
|
|
:key="item.id"
|
|
|
|
|
|
:label="item.name"
|
|
|
|
|
|
:value="item.id"
|
|
|
|
|
|
>
|
2022-08-02 10:16:07 +08:00
|
|
|
|
</el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</div>
|
2022-08-06 20:03:35 +08:00
|
|
|
|
<div v-for="(item, i) in skus" :key="i">
|
|
|
|
|
|
<span style="margin-right: -15px">{{ i + 1 }}.</span>
|
2022-08-02 10:16:07 +08:00
|
|
|
|
<el-form-item label="商品规格:">
|
2022-08-06 20:03:35 +08:00
|
|
|
|
<el-input
|
|
|
|
|
|
placeholder="商品规格"
|
|
|
|
|
|
v-model="skus[i].title"
|
|
|
|
|
|
></el-input>
|
2022-08-02 10:16:07 +08:00
|
|
|
|
</el-form-item>
|
2022-08-06 20:03:35 +08:00
|
|
|
|
<span class="addto" v-if="!gid" @click="handleAdd()">+</span>
|
2022-08-04 18:59:32 +08:00
|
|
|
|
<el-form-item label="规格编码:">
|
2022-08-06 20:03:35 +08:00
|
|
|
|
<el-input v-model="skus[i].sku_code" placeholder="商品编码">
|
2022-08-04 18:59:32 +08:00
|
|
|
|
</el-input>
|
2022-08-02 10:16:07 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="商品状态:">
|
2022-08-06 20:03:35 +08:00
|
|
|
|
<el-select v-model="skus[i].status" placeholder="下架(默认)">
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
v-for="item in options"
|
|
|
|
|
|
:key="item.id"
|
|
|
|
|
|
:label="item.label"
|
|
|
|
|
|
:value="item.id"
|
|
|
|
|
|
>
|
2022-08-04 18:59:32 +08:00
|
|
|
|
</el-option>
|
2022-08-02 10:16:07 +08:00
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<el-form-item label="商品数量:">
|
2022-08-06 20:03:35 +08:00
|
|
|
|
<el-input v-model="skus[i].num" placeholder="商品数量">
|
2022-08-04 18:59:32 +08:00
|
|
|
|
</el-input>
|
2022-08-02 10:16:07 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="商品成本:">
|
2022-08-06 20:03:35 +08:00
|
|
|
|
<el-input v-model="skus[i].cost" placeholder="商品成本">
|
2022-08-04 18:59:32 +08:00
|
|
|
|
</el-input>
|
2022-08-02 10:16:07 +08:00
|
|
|
|
</el-form-item>
|
2022-08-06 20:03:35 +08:00
|
|
|
|
<el-button type="primary" @click="handleDelete(i)"
|
|
|
|
|
|
>删除</el-button
|
|
|
|
|
|
>
|
2022-08-02 10:16:07 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="btn">
|
|
|
|
|
|
<el-form-item>
|
2022-08-06 20:03:35 +08:00
|
|
|
|
<el-button type="primary" @click="handleSave()">保存</el-button>
|
2022-08-02 10:16:07 +08:00
|
|
|
|
<el-button plain>取消</el-button>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2022-08-06 20:03:35 +08:00
|
|
|
|
import UploadTem from "../../../components/upload/index.vue";
|
2022-08-04 18:59:32 +08:00
|
|
|
|
import {
|
|
|
|
|
|
addGoods,
|
|
|
|
|
|
checkGoods,
|
|
|
|
|
|
goodsList,
|
|
|
|
|
|
updateGoods,
|
2022-08-06 20:03:35 +08:00
|
|
|
|
} from "../../../api/goods.js";
|
|
|
|
|
|
import { goods_types, Brand_goods_types } from "../../../api/rankingData.js";
|
|
|
|
|
|
import axios from "axios";
|
2022-08-02 10:16:07 +08:00
|
|
|
|
export default {
|
2022-08-04 18:59:32 +08:00
|
|
|
|
components: {
|
|
|
|
|
|
UploadTem,
|
|
|
|
|
|
},
|
2022-08-02 10:16:07 +08:00
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
2022-08-06 20:03:35 +08:00
|
|
|
|
gallery: "",
|
|
|
|
|
|
imageUrl: "",
|
|
|
|
|
|
lid: "", // 选择的商品列表id
|
|
|
|
|
|
gid: "", // 商品id
|
2022-08-04 18:59:32 +08:00
|
|
|
|
brand: [], // 品牌列表
|
|
|
|
|
|
cate: [], // 种类列表
|
|
|
|
|
|
goodschoose: [], // 商品列表
|
|
|
|
|
|
// 规格列表
|
|
|
|
|
|
skus: [
|
2022-08-02 10:16:07 +08:00
|
|
|
|
{
|
2022-08-06 20:03:35 +08:00
|
|
|
|
title: "",
|
|
|
|
|
|
sku_code: "",
|
|
|
|
|
|
status: "",
|
|
|
|
|
|
num: "",
|
|
|
|
|
|
cost: "",
|
2022-08-02 10:16:07 +08:00
|
|
|
|
},
|
2022-08-04 18:59:32 +08:00
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
|
|
// 增加商品表单
|
2022-08-02 10:16:07 +08:00
|
|
|
|
form: {
|
2022-08-06 20:03:35 +08:00
|
|
|
|
goods_id: "",
|
|
|
|
|
|
title: "",
|
|
|
|
|
|
img_url: "https://cn.vuejs.org/images/logo.svg",
|
|
|
|
|
|
type_id: "",
|
|
|
|
|
|
brand_id: "",
|
|
|
|
|
|
goods_code: "",
|
2022-08-02 10:16:07 +08:00
|
|
|
|
},
|
2022-08-04 18:59:32 +08:00
|
|
|
|
// 商品状态
|
2022-08-02 10:16:07 +08:00
|
|
|
|
options: [
|
|
|
|
|
|
{
|
2022-08-06 20:03:35 +08:00
|
|
|
|
id: "1",
|
|
|
|
|
|
label: "在售",
|
2022-08-02 10:16:07 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2022-08-06 20:03:35 +08:00
|
|
|
|
id: "2",
|
|
|
|
|
|
label: "预警",
|
2022-08-02 10:16:07 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2022-08-06 20:03:35 +08:00
|
|
|
|
id: "0",
|
|
|
|
|
|
label: "下架",
|
2022-08-02 10:16:07 +08:00
|
|
|
|
},
|
|
|
|
|
|
],
|
2022-08-04 18:59:32 +08:00
|
|
|
|
file: [],
|
2022-08-06 20:03:35 +08:00
|
|
|
|
};
|
2022-08-02 10:16:07 +08:00
|
|
|
|
},
|
2022-08-04 18:59:32 +08:00
|
|
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
|
|
lid: {
|
|
|
|
|
|
handler(newVal, oldVal) {
|
|
|
|
|
|
if (newVal) {
|
|
|
|
|
|
this.goodschoose.forEach((item) => {
|
|
|
|
|
|
if (item.id == newVal) {
|
2022-08-06 20:03:35 +08:00
|
|
|
|
this.form = { ...item };
|
2022-08-04 18:59:32 +08:00
|
|
|
|
}
|
2022-08-06 20:03:35 +08:00
|
|
|
|
});
|
2022-08-04 18:59:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
deep: true, // 深度监听
|
|
|
|
|
|
immediate: true, // 第一次改变就执行
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2022-08-02 10:16:07 +08:00
|
|
|
|
methods: {
|
2022-08-04 18:59:32 +08:00
|
|
|
|
// 查看一个商品
|
|
|
|
|
|
handleUpdate() {
|
2022-08-06 20:03:35 +08:00
|
|
|
|
this.gid = this.$route.query;
|
2022-08-04 18:59:32 +08:00
|
|
|
|
if (this.gid.id) {
|
|
|
|
|
|
checkGoods(this.gid.id).then((res) => {
|
2022-08-06 20:03:35 +08:00
|
|
|
|
console.log(res.data.data, "oooppuu");
|
|
|
|
|
|
const data = res.data.data;
|
|
|
|
|
|
const sku = this.skus[0];
|
|
|
|
|
|
const list = {};
|
2022-08-04 18:59:32 +08:00
|
|
|
|
Object.keys(data).map((key) => {
|
|
|
|
|
|
Object.keys(sku).map((i) => {
|
|
|
|
|
|
if (key == i) {
|
2022-08-06 20:03:35 +08:00
|
|
|
|
list[i] = data[key];
|
2022-08-04 18:59:32 +08:00
|
|
|
|
}
|
2022-08-06 20:03:35 +08:00
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2022-08-04 18:59:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
// 商品列表
|
|
|
|
|
|
handleList() {
|
|
|
|
|
|
goodsList().then((res) => {
|
2022-08-06 20:03:35 +08:00
|
|
|
|
this.goodschoose = res.data.data;
|
|
|
|
|
|
});
|
2022-08-04 18:59:32 +08:00
|
|
|
|
},
|
|
|
|
|
|
// 保存,增加一个商品
|
|
|
|
|
|
handleSave() {
|
2022-08-06 20:03:35 +08:00
|
|
|
|
const goods = this.form;
|
|
|
|
|
|
const sku2 = this.skus[0];
|
|
|
|
|
|
const skus = [];
|
|
|
|
|
|
skus.push(sku2);
|
|
|
|
|
|
// console.log(goods, skus);
|
|
|
|
|
|
|
|
|
|
|
|
const updata = {
|
|
|
|
|
|
...goods,
|
|
|
|
|
|
goods_id: this.lid,
|
|
|
|
|
|
skus: skus,
|
|
|
|
|
|
};
|
|
|
|
|
|
// console.log(updata);
|
|
|
|
|
|
|
|
|
|
|
|
axios
|
|
|
|
|
|
.post("/api/goods", updata, {
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Authorization:
|
|
|
|
|
|
"Bearer w1rr6IsxZIud46dIrGIivNAroFpqN52sSpXhk3azpPq2ZTbUXhgKTOLheoRm",
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
.then((res) => {
|
|
|
|
|
|
if (res.statusText === "OK") {
|
2022-08-04 18:59:32 +08:00
|
|
|
|
this.$message({
|
2022-08-06 20:03:35 +08:00
|
|
|
|
message: "商品添加成功!",
|
|
|
|
|
|
type: "success",
|
|
|
|
|
|
});
|
|
|
|
|
|
this.updateForm();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.$message({
|
|
|
|
|
|
message: "商品添加失败!",
|
|
|
|
|
|
type: "error",
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// if (this.gid) {
|
|
|
|
|
|
// const goods = this.form;
|
|
|
|
|
|
// const sku = this.skus[0];
|
|
|
|
|
|
// const updata = {
|
|
|
|
|
|
// ...goods,
|
|
|
|
|
|
// ...sku,
|
|
|
|
|
|
// goods_id: this.lid,
|
|
|
|
|
|
// };
|
|
|
|
|
|
// console.log(updata);
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// console.log(1111);
|
|
|
|
|
|
// const datas = {
|
|
|
|
|
|
// ...this.form,
|
|
|
|
|
|
// skus: this.skus,
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
// addGoods(datas)
|
|
|
|
|
|
// .then((res) => {
|
|
|
|
|
|
// console.log("请求发起");
|
|
|
|
|
|
// if (res.data.httpCode == 200) {
|
|
|
|
|
|
// this.$message({
|
|
|
|
|
|
// type: "success",
|
|
|
|
|
|
// message: "添加成功",
|
|
|
|
|
|
// });
|
|
|
|
|
|
// this.updateForm();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// })
|
|
|
|
|
|
// .catch((e) => {
|
|
|
|
|
|
// this.$message({
|
|
|
|
|
|
// type: "error",
|
|
|
|
|
|
// message: e.response.data.errorMessage.goods_code[0],
|
|
|
|
|
|
// });
|
|
|
|
|
|
// });
|
|
|
|
|
|
// }
|
2022-08-04 18:59:32 +08:00
|
|
|
|
},
|
2022-08-06 20:03:35 +08:00
|
|
|
|
|
2022-08-04 18:59:32 +08:00
|
|
|
|
// 修改成功后重置表单
|
|
|
|
|
|
updateForm() {
|
|
|
|
|
|
this.form = {
|
2022-08-06 20:03:35 +08:00
|
|
|
|
title: "",
|
|
|
|
|
|
img_url: "abc.jpg",
|
|
|
|
|
|
type_id: "",
|
|
|
|
|
|
brand_id: "",
|
|
|
|
|
|
goods_code: "",
|
|
|
|
|
|
};
|
2022-08-04 18:59:32 +08:00
|
|
|
|
this.skus = [
|
|
|
|
|
|
{
|
2022-08-06 20:03:35 +08:00
|
|
|
|
title: "",
|
|
|
|
|
|
sku_code: "",
|
|
|
|
|
|
status: "",
|
|
|
|
|
|
num: "",
|
|
|
|
|
|
cost: "",
|
2022-08-04 18:59:32 +08:00
|
|
|
|
},
|
2022-08-06 20:03:35 +08:00
|
|
|
|
];
|
2022-08-04 18:59:32 +08:00
|
|
|
|
},
|
2022-08-02 10:16:07 +08:00
|
|
|
|
// 增加一个商品规格
|
|
|
|
|
|
handleAdd() {
|
2022-08-04 18:59:32 +08:00
|
|
|
|
this.skus.push({
|
2022-08-06 20:03:35 +08:00
|
|
|
|
title: "",
|
|
|
|
|
|
sku_code: "",
|
|
|
|
|
|
status: "",
|
|
|
|
|
|
num: "",
|
|
|
|
|
|
cost: "",
|
|
|
|
|
|
});
|
2022-08-02 10:16:07 +08:00
|
|
|
|
},
|
|
|
|
|
|
// 删除一个商品规格
|
|
|
|
|
|
handleDelete(index) {
|
2022-08-06 20:03:35 +08:00
|
|
|
|
this.skus.splice(index, 1);
|
2022-08-04 18:59:32 +08:00
|
|
|
|
},
|
|
|
|
|
|
hanleurlimg(val) {
|
2022-08-06 20:03:35 +08:00
|
|
|
|
console.log(val, "=+++++++++");
|
2022-08-04 18:59:32 +08:00
|
|
|
|
},
|
|
|
|
|
|
// 上传商品图片
|
|
|
|
|
|
successUpload(file, fileList) {
|
2022-08-06 20:03:35 +08:00
|
|
|
|
console.log(file, fileList, 5555);
|
2022-08-02 10:16:07 +08:00
|
|
|
|
},
|
2022-08-04 18:59:32 +08:00
|
|
|
|
errorUpload(file, fileList) {
|
2022-08-06 20:03:35 +08:00
|
|
|
|
console.log(file, fileList, 5555);
|
2022-08-04 18:59:32 +08:00
|
|
|
|
},
|
|
|
|
|
|
// 移除商品图片
|
|
|
|
|
|
removeUpload() {},
|
|
|
|
|
|
},
|
|
|
|
|
|
mounted() {
|
2022-08-06 20:03:35 +08:00
|
|
|
|
this.gid = this.$route.query;
|
2022-08-04 18:59:32 +08:00
|
|
|
|
// 获取商品种类
|
|
|
|
|
|
goods_types().then((res) => {
|
2022-08-06 20:03:35 +08:00
|
|
|
|
this.cate = res.data.data;
|
|
|
|
|
|
});
|
2022-08-04 18:59:32 +08:00
|
|
|
|
// 获取商品品牌
|
|
|
|
|
|
Brand_goods_types().then((res) => {
|
2022-08-06 20:03:35 +08:00
|
|
|
|
this.brand = res.data.data;
|
|
|
|
|
|
});
|
|
|
|
|
|
this.handleList();
|
|
|
|
|
|
this.handleUpdate();
|
2022-08-02 10:16:07 +08:00
|
|
|
|
},
|
2022-08-06 20:03:35 +08:00
|
|
|
|
};
|
2022-08-02 10:16:07 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.el-upload--picture-card {
|
|
|
|
|
|
width: 50px;
|
|
|
|
|
|
height: 50px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.el-form-item {
|
|
|
|
|
|
margin-left: 60px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.addto {
|
|
|
|
|
|
display: inline-block;
|
|
|
|
|
|
width: 28px;
|
|
|
|
|
|
height: 28px;
|
|
|
|
|
|
background-color: blue;
|
|
|
|
|
|
color: #fff;
|
|
|
|
|
|
font-size: 25px;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
line-height: 28px;
|
|
|
|
|
|
}
|
|
|
|
|
|
/* .btn {
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
} */
|
|
|
|
|
|
</style>
|