2022-08-02 10:16:07 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<el-card class="box-card">
|
|
|
|
|
|
<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>
|
|
|
|
|
|
<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">
|
|
|
|
|
|
</el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</div>
|
2022-08-02 10:16:07 +08:00
|
|
|
|
<span style="font-size:14px;">商品图片:</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>
|
|
|
|
|
|
<el-form ref="form"
|
|
|
|
|
|
:inline="true"
|
|
|
|
|
|
:model="form">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<el-form-item label="商品名称:">
|
2022-08-04 18:59:32 +08:00
|
|
|
|
<el-input placeholder="商品名称"
|
|
|
|
|
|
v-model="form.title"></el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="商品编码:">
|
|
|
|
|
|
<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-04 18:59:32 +08:00
|
|
|
|
<el-select v-model="form.type_id"
|
2022-08-02 10:16:07 +08:00
|
|
|
|
placeholder="商品种类">
|
2022-08-04 18:59:32 +08:00
|
|
|
|
<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-04 18:59:32 +08:00
|
|
|
|
<el-select v-model="form.brand_id"
|
2022-08-02 10:16:07 +08:00
|
|
|
|
placeholder="商品品牌">
|
2022-08-04 18:59:32 +08:00
|
|
|
|
<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-04 18:59:32 +08:00
|
|
|
|
<div v-for="(item,i) in skus"
|
|
|
|
|
|
:key="i">
|
2022-08-02 10:16:07 +08:00
|
|
|
|
<span style="margin-right:-15px">{{i+1}}.</span>
|
|
|
|
|
|
<el-form-item label="商品规格:">
|
2022-08-04 18:59:32 +08:00
|
|
|
|
<el-input placeholder="商品规格"
|
|
|
|
|
|
v-model="skus[i].title"></el-input>
|
2022-08-02 10:16:07 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<span class="addto"
|
2022-08-04 18:59:32 +08:00
|
|
|
|
v-if="!gid"
|
2022-08-02 10:16:07 +08:00
|
|
|
|
@click="handleAdd()">+</span>
|
2022-08-04 18:59:32 +08:00
|
|
|
|
<el-form-item label="规格编码:">
|
|
|
|
|
|
<el-input v-model="skus[i].sku_code"
|
|
|
|
|
|
placeholder="商品编码">
|
|
|
|
|
|
</el-input>
|
2022-08-02 10:16:07 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="商品状态:">
|
2022-08-04 18:59:32 +08:00
|
|
|
|
<el-select v-model="skus[i].status"
|
|
|
|
|
|
placeholder="下架(默认)">
|
|
|
|
|
|
<el-option v-for="item in options"
|
|
|
|
|
|
:key="item.id"
|
2022-08-02 10:16:07 +08:00
|
|
|
|
:label="item.label"
|
2022-08-04 18:59:32 +08:00
|
|
|
|
:value="item.id">
|
|
|
|
|
|
</el-option>
|
2022-08-02 10:16:07 +08:00
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<el-form-item label="商品数量:">
|
2022-08-04 18:59:32 +08:00
|
|
|
|
<el-input v-model="skus[i].num"
|
|
|
|
|
|
placeholder="商品数量">
|
|
|
|
|
|
</el-input>
|
2022-08-02 10:16:07 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="商品成本:">
|
2022-08-04 18:59:32 +08:00
|
|
|
|
<el-input v-model="skus[i].cost"
|
|
|
|
|
|
placeholder="商品成本">
|
|
|
|
|
|
</el-input>
|
2022-08-02 10:16:07 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-button type="primary"
|
|
|
|
|
|
@click="handleDelete(i)">删除</el-button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="btn">
|
|
|
|
|
|
<el-form-item>
|
2022-08-04 18:59:32 +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-04 18:59:32 +08:00
|
|
|
|
import UploadTem from '../../../components/upload/index.vue'
|
|
|
|
|
|
import {
|
|
|
|
|
|
addGoods,
|
|
|
|
|
|
checkGoods,
|
|
|
|
|
|
goodsList,
|
|
|
|
|
|
updateGoods,
|
|
|
|
|
|
} from '../../../api/goods.js'
|
|
|
|
|
|
import { goods_types, Brand_goods_types } from '../../../api/rankingData.js'
|
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 {
|
|
|
|
|
|
gallery: '',
|
|
|
|
|
|
imageUrl: '',
|
2022-08-04 18:59:32 +08:00
|
|
|
|
lid: '', // 选择的商品列表id
|
|
|
|
|
|
gid: '', // 商品id
|
|
|
|
|
|
brand: [], // 品牌列表
|
|
|
|
|
|
cate: [], // 种类列表
|
|
|
|
|
|
goodschoose: [], // 商品列表
|
|
|
|
|
|
// 规格列表
|
|
|
|
|
|
skus: [
|
2022-08-02 10:16:07 +08:00
|
|
|
|
{
|
2022-08-04 18:59:32 +08:00
|
|
|
|
title: '',
|
|
|
|
|
|
sku_code: '',
|
|
|
|
|
|
status: '',
|
|
|
|
|
|
num: '',
|
2022-08-02 10:16:07 +08:00
|
|
|
|
cost: '',
|
|
|
|
|
|
},
|
2022-08-04 18:59:32 +08:00
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
|
|
// 增加商品表单
|
2022-08-02 10:16:07 +08:00
|
|
|
|
form: {
|
2022-08-04 18:59:32 +08:00
|
|
|
|
goods_id: '',
|
|
|
|
|
|
title: '',
|
|
|
|
|
|
img_url: 'abc.jpg',
|
|
|
|
|
|
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-04 18:59:32 +08:00
|
|
|
|
id: '1',
|
|
|
|
|
|
label: '在售',
|
2022-08-02 10:16:07 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2022-08-04 18:59:32 +08:00
|
|
|
|
id: '2',
|
|
|
|
|
|
label: '预警',
|
2022-08-02 10:16:07 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2022-08-04 18:59:32 +08:00
|
|
|
|
id: '0',
|
|
|
|
|
|
label: '下架',
|
2022-08-02 10:16:07 +08:00
|
|
|
|
},
|
|
|
|
|
|
],
|
2022-08-04 18:59:32 +08:00
|
|
|
|
file: [],
|
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) {
|
|
|
|
|
|
this.form = { ...item }
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
deep: true, // 深度监听
|
|
|
|
|
|
immediate: true, // 第一次改变就执行
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2022-08-02 10:16:07 +08:00
|
|
|
|
methods: {
|
2022-08-04 18:59:32 +08:00
|
|
|
|
// 查看一个商品
|
|
|
|
|
|
handleUpdate() {
|
|
|
|
|
|
this.gid = this.$route.query
|
|
|
|
|
|
if (this.gid.id) {
|
|
|
|
|
|
checkGoods(this.gid.id).then((res) => {
|
|
|
|
|
|
console.log(res.data.data, 'oooppuu')
|
|
|
|
|
|
const data = res.data.data
|
|
|
|
|
|
const sku = this.skus[0]
|
|
|
|
|
|
const list = {}
|
|
|
|
|
|
Object.keys(data).map((key) => {
|
|
|
|
|
|
Object.keys(sku).map((i) => {
|
|
|
|
|
|
if (key == i) {
|
|
|
|
|
|
list[i] = data[key]
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
// 商品列表
|
|
|
|
|
|
handleList() {
|
|
|
|
|
|
goodsList().then((res) => {
|
|
|
|
|
|
this.goodschoose = res.data.data
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
// 保存,增加一个商品
|
|
|
|
|
|
handleSave() {
|
|
|
|
|
|
if (this.gid) {
|
|
|
|
|
|
const goods = this.form
|
|
|
|
|
|
const sku = this.skus[0]
|
|
|
|
|
|
const updata = {
|
|
|
|
|
|
...goods,
|
|
|
|
|
|
...sku,
|
|
|
|
|
|
goods_id: this.lid,
|
|
|
|
|
|
}
|
|
|
|
|
|
console.log(updata, '24235345')
|
|
|
|
|
|
// updateGoods(updata, this.gid).then((res) => {
|
|
|
|
|
|
// console.log(res, '66666666')
|
|
|
|
|
|
// })
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const datas = {
|
|
|
|
|
|
...this.form,
|
|
|
|
|
|
skus: this.skus,
|
|
|
|
|
|
}
|
|
|
|
|
|
addGoods(datas)
|
|
|
|
|
|
.then((res) => {
|
|
|
|
|
|
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],
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
// 修改成功后重置表单
|
|
|
|
|
|
updateForm() {
|
|
|
|
|
|
this.form = {
|
|
|
|
|
|
title: '',
|
|
|
|
|
|
img_url: 'abc.jpg',
|
|
|
|
|
|
type_id: '',
|
|
|
|
|
|
brand_id: '',
|
|
|
|
|
|
goods_code: '',
|
|
|
|
|
|
}
|
|
|
|
|
|
this.skus = [
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '',
|
|
|
|
|
|
sku_code: '',
|
|
|
|
|
|
status: '',
|
|
|
|
|
|
num: '',
|
|
|
|
|
|
cost: '',
|
|
|
|
|
|
},
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
2022-08-02 10:16:07 +08:00
|
|
|
|
// 增加一个商品规格
|
|
|
|
|
|
handleAdd() {
|
2022-08-04 18:59:32 +08:00
|
|
|
|
this.skus.push({
|
|
|
|
|
|
title: '',
|
|
|
|
|
|
sku_code: '',
|
|
|
|
|
|
status: '',
|
|
|
|
|
|
num: '',
|
2022-08-02 10:16:07 +08:00
|
|
|
|
cost: '',
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
// 删除一个商品规格
|
|
|
|
|
|
handleDelete(index) {
|
2022-08-04 18:59:32 +08:00
|
|
|
|
this.skus.splice(index, 1)
|
|
|
|
|
|
},
|
|
|
|
|
|
hanleurlimg(val) {
|
|
|
|
|
|
console.log(val, '=+++++++++')
|
|
|
|
|
|
},
|
|
|
|
|
|
// 上传商品图片
|
|
|
|
|
|
successUpload(file, fileList) {
|
|
|
|
|
|
console.log(file, fileList, 5555)
|
2022-08-02 10:16:07 +08:00
|
|
|
|
},
|
2022-08-04 18:59:32 +08:00
|
|
|
|
errorUpload(file, fileList) {
|
|
|
|
|
|
console.log(file, fileList, 5555)
|
|
|
|
|
|
},
|
|
|
|
|
|
// 移除商品图片
|
|
|
|
|
|
removeUpload() {},
|
|
|
|
|
|
},
|
|
|
|
|
|
mounted() {
|
|
|
|
|
|
this.gid = this.$route.query
|
|
|
|
|
|
// 获取商品种类
|
|
|
|
|
|
goods_types().then((res) => {
|
|
|
|
|
|
this.cate = res.data.data
|
|
|
|
|
|
})
|
|
|
|
|
|
// 获取商品品牌
|
|
|
|
|
|
Brand_goods_types().then((res) => {
|
|
|
|
|
|
this.brand = res.data.data
|
|
|
|
|
|
})
|
|
|
|
|
|
this.handleList()
|
|
|
|
|
|
this.handleUpdate()
|
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>
|