2022-08-18 22:38:51 +08:00
|
|
|
|
<template>
|
|
|
|
|
<div class="container">
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-tabs v-model="activeName" class="tabs" :before-leave="confirmLeave">
|
2022-08-18 22:38:51 +08:00
|
|
|
|
<!-- 基础设置 -->
|
|
|
|
|
<el-tab-pane label="基础设置" name="base">
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-form ref="base" :model="baseForm" :rules="rules" label-width="100px" style="width: 95%">
|
2022-08-18 22:38:51 +08:00
|
|
|
|
<el-form-item label="商品名称" prop="name">
|
|
|
|
|
<el-input v-model="baseForm.name" placeholder="请输入商品名称"/>
|
|
|
|
|
</el-form-item>
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-form-item label="卖点">
|
2022-08-18 22:38:51 +08:00
|
|
|
|
<el-input v-model="baseForm.sellPoint" placeholder="请输入卖点"/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="分类id" prop="categoryIds">
|
|
|
|
|
<el-cascader
|
|
|
|
|
v-model="baseForm.categoryIds"
|
|
|
|
|
placeholder="请输入分类id"
|
|
|
|
|
style="width: 100%"
|
|
|
|
|
:options="categoryList"
|
|
|
|
|
:props="propName"
|
|
|
|
|
clearable
|
|
|
|
|
></el-cascader>
|
|
|
|
|
</el-form-item>
|
2022-08-22 20:43:12 +08:00
|
|
|
|
<el-form-item label="商品轮播图" prop="picUrls">
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<ImageUpload v-model="baseForm.picUrls" :value="baseForm.picUrls" :limit="10"/>
|
2022-08-18 22:38:51 +08:00
|
|
|
|
</el-form-item>
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-form-item label="排序字段">
|
|
|
|
|
<el-input v-model="baseForm.sort" placeholder="请输入排序字段" oninput="value=value.replace(/^(0+)|[^\d]+/g,'')"/>
|
2022-08-18 22:38:51 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</el-tab-pane>
|
|
|
|
|
|
|
|
|
|
<!-- 价格库存 -->
|
|
|
|
|
<el-tab-pane label="价格库存" name="rates" class="rates">
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-form ref="rates" :model="ratesForm" :rules="rules">
|
2022-08-18 22:38:51 +08:00
|
|
|
|
<el-form-item label="商品规格">
|
|
|
|
|
<el-radio-group v-model="ratesForm.spec" @change="changeRadio">
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-radio :label="1">单规格</el-radio>
|
|
|
|
|
<el-radio :label="2">多规格</el-radio>
|
2022-08-18 22:38:51 +08:00
|
|
|
|
</el-radio-group>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
<!-- 动态添加规格属性 -->
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<div v-show="ratesForm.spec === 2">
|
2022-08-18 22:38:51 +08:00
|
|
|
|
<div
|
|
|
|
|
v-for="(specs, index) in dynamicSpec"
|
|
|
|
|
:key="index"
|
|
|
|
|
class="dynamic-spec"
|
|
|
|
|
>
|
|
|
|
|
<!-- 删除按钮 -->
|
|
|
|
|
<el-button
|
|
|
|
|
type="danger"
|
|
|
|
|
icon="el-icon-delete"
|
|
|
|
|
circle
|
|
|
|
|
class="spec-delete"
|
2022-08-23 21:06:59 +08:00
|
|
|
|
@click="removeSpec(index)"
|
2022-08-18 22:38:51 +08:00
|
|
|
|
></el-button>
|
|
|
|
|
<div class="spec-header">
|
|
|
|
|
规格项:
|
2022-08-22 20:43:12 +08:00
|
|
|
|
<el-select v-model="specs.specId" filterable placeholder="请选择" @change="changeSpec">
|
|
|
|
|
<el-option
|
|
|
|
|
v-for="item in propertyPageList"
|
|
|
|
|
:key="item.id"
|
|
|
|
|
:label="item.name"
|
|
|
|
|
:value="item.id">
|
|
|
|
|
</el-option>
|
|
|
|
|
</el-select>
|
2022-08-18 22:38:51 +08:00
|
|
|
|
</div>
|
|
|
|
|
<div class="spec-values">
|
2022-08-22 20:43:12 +08:00
|
|
|
|
<template v-for="(v, i) in specs.specValue">
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-input v-model="v.name" class="spec-value" :key="i" disabled/>
|
2022-08-18 22:38:51 +08:00
|
|
|
|
</template>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2022-08-22 20:43:12 +08:00
|
|
|
|
<el-button type="primary" @click="dynamicSpec.push({specValue: []}); ratesForm.rates = []"
|
2022-08-18 22:38:51 +08:00
|
|
|
|
>添加规格项目
|
|
|
|
|
</el-button
|
|
|
|
|
>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- 规格明细 -->
|
|
|
|
|
<el-form-item label="规格明细">
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-table :data="ratesForm.rates" border style="width: 100%" ref="ratesTable">
|
|
|
|
|
<template v-if="ratesForm.spec == 2">
|
2022-08-22 20:43:12 +08:00
|
|
|
|
<el-table-column :key="index" v-for="(item, index) in dynamicSpec.filter(v=>v.specName != undefined)"
|
|
|
|
|
:label="item.specName">
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
<el-input
|
|
|
|
|
v-if="scope.row.spec"
|
|
|
|
|
v-model="scope.row.spec[index]"
|
|
|
|
|
disabled
|
|
|
|
|
></el-input>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2022-08-18 22:38:51 +08:00
|
|
|
|
</template>
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-table-column label="规格图片" width="120px" :render-header="addRedStar" key="90">
|
2022-08-18 22:38:51 +08:00
|
|
|
|
<template slot-scope="scope">
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<ImageUpload v-model="scope.row.picUrl" :limit="1" :isShowTip="false"
|
2022-08-22 20:43:12 +08:00
|
|
|
|
style="width: 100px; height: 50px"/>
|
2022-08-18 22:38:51 +08:00
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<template v-if="ratesForm.spec == 2">
|
|
|
|
|
<el-table-column label="sku名称" :render-header="addRedStar" key="91">
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
<el-form-item :prop="'rates.'+ scope.$index + '.name'" :rules="[{required: true, trigger: 'change'}]">
|
|
|
|
|
<el-input
|
|
|
|
|
v-model="scope.row.name"
|
|
|
|
|
></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<el-table-column label="市场价(元)" :render-header="addRedStar" key="92">
|
2022-08-18 22:38:51 +08:00
|
|
|
|
<template slot-scope="scope">
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-form-item :prop="'rates.'+ scope.$index + '.marketPrice'" :rules="[{required: true, trigger: 'change'}]">
|
|
|
|
|
<el-input
|
|
|
|
|
v-model="scope.row.marketPrice"
|
|
|
|
|
oninput="value= value.match(/\d+(\.\d{0,2})?/) ? value.match(/\d+(\.\d{0,2})?/)[0] : ''"
|
|
|
|
|
></el-input>
|
|
|
|
|
</el-form-item>
|
2022-08-18 22:38:51 +08:00
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-table-column label="销售价(元)" :render-header="addRedStar" key="93">
|
2022-08-18 22:38:51 +08:00
|
|
|
|
<template slot-scope="scope">
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-form-item :prop="'rates.'+ scope.$index + '.price'" :rules="[{required: true, trigger: 'change'}]">
|
|
|
|
|
<el-input v-model="scope.row.price" oninput="value= value.match(/\d+(\.\d{0,2})?/) ? value.match(/\d+(\.\d{0,2})?/)[0] : ''"></el-input>
|
|
|
|
|
</el-form-item>
|
2022-08-18 22:38:51 +08:00
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-table-column label="成本价" :render-header="addRedStar" key="94">
|
2022-08-18 22:38:51 +08:00
|
|
|
|
<template slot-scope="scope">
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-form-item :prop="'rates.'+ scope.$index + '.costPrice'" :rules="[{required: true, trigger: 'change'}]">
|
2022-08-18 22:38:51 +08:00
|
|
|
|
<el-input
|
|
|
|
|
v-model="scope.row.costPrice"
|
2022-08-23 20:27:39 +08:00
|
|
|
|
oninput="value= value.match(/\d+(\.\d{0,2})?/) ? value.match(/\d+(\.\d{0,2})?/)[0] : ''"
|
2022-08-18 22:38:51 +08:00
|
|
|
|
></el-input>
|
2022-08-23 20:27:39 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column label="库存" :render-header="addRedStar" key="95">
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
<el-form-item :prop="'rates.'+ scope.$index + '.stock'" :rules="[{required: true, trigger: 'change'}]">
|
|
|
|
|
<el-input v-model="scope.row.stock" oninput="value=value.replace(/^(0+)|[^\d]+/g,'')"></el-input>
|
|
|
|
|
</el-form-item>
|
2022-08-18 22:38:51 +08:00
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-table-column label="预警库存" key="96">
|
2022-08-18 22:38:51 +08:00
|
|
|
|
<template slot-scope="scope">
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-input v-model="scope.row.warnStock" oninput="value=value.replace(/^(0+)|[^\d]+/g,'')"></el-input>
|
2022-08-18 22:38:51 +08:00
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-table-column label="体积" key="97">
|
2022-08-18 22:38:51 +08:00
|
|
|
|
<template slot-scope="scope">
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-input v-model="scope.row.volume" ></el-input>
|
2022-08-18 22:38:51 +08:00
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-table-column label="重量" key="98">
|
2022-08-18 22:38:51 +08:00
|
|
|
|
<template slot-scope="scope">
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-input v-model="scope.row.weight" ></el-input>
|
2022-08-18 22:38:51 +08:00
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-table-column label="条码" key="99">
|
2022-08-18 22:38:51 +08:00
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
<el-input v-model="scope.row.barCode"></el-input>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<template v-if="ratesForm.spec == 2">
|
|
|
|
|
<el-table-column
|
|
|
|
|
fixed="right"
|
|
|
|
|
label="操作"
|
|
|
|
|
width="50"
|
|
|
|
|
key="100">
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
<el-button @click="scope.row.status = 1" type="text" size="small" v-show="scope.row.status == undefined || scope.row.status == 0 ">禁用</el-button>
|
|
|
|
|
<el-button @click="scope.row.status = 0" type="text" size="small" v-show="scope.row.status == 1">启用</el-button>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</template>
|
2022-08-18 22:38:51 +08:00
|
|
|
|
</el-table>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</el-tab-pane>
|
|
|
|
|
|
|
|
|
|
<!-- 商品详情 -->
|
|
|
|
|
<el-tab-pane label="商品描述" name="third">
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-form ref="third" :model="baseForm" :rules="rules">
|
|
|
|
|
<el-form-item prop="description">
|
|
|
|
|
<editor v-model="baseForm.description" :min-height="380"/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
2022-08-18 22:38:51 +08:00
|
|
|
|
</el-tab-pane>
|
|
|
|
|
|
|
|
|
|
<!-- 销售设置 -->
|
|
|
|
|
<el-tab-pane label="销售设置" name="fourth">
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-form ref="fourth" :model="baseForm" :rules="rules" label-width="100px" style="width: 95%">
|
|
|
|
|
<el-form-item label="虚拟销量" prop="virtualSalesCount">
|
|
|
|
|
<el-input v-model="baseForm.virtualSalesCount" placeholder="请输入虚拟销量" oninput="value=value.replace(/^(0+)|[^\d]+/g,'')"/>
|
2022-08-22 20:43:12 +08:00
|
|
|
|
</el-form-item>
|
2022-08-23 20:27:39 +08:00
|
|
|
|
<el-form-item label="是否展示库存" prop="showStock">
|
|
|
|
|
<el-radio-group v-model="baseForm.showStock">
|
|
|
|
|
<el-radio :label="true">是</el-radio>
|
|
|
|
|
<el-radio :label="false">否</el-radio>
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="商品状态" prop="status">
|
2022-08-22 20:43:12 +08:00
|
|
|
|
<el-radio-group v-model="baseForm.status">
|
|
|
|
|
<el-radio :label="0">上架</el-radio>
|
|
|
|
|
<el-radio :label="1">下架</el-radio>
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
</el-form-item>
|
2022-08-18 22:38:51 +08:00
|
|
|
|
</el-form>
|
|
|
|
|
</el-tab-pane>
|
|
|
|
|
</el-tabs>
|
|
|
|
|
|
2022-08-22 20:43:12 +08:00
|
|
|
|
<div class="buttons">
|
|
|
|
|
<el-button type="info" round @click="cancel">取消</el-button>
|
|
|
|
|
<el-button type="success" round @click="submit">确认</el-button>
|
|
|
|
|
</div>
|
2022-08-18 22:38:51 +08:00
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2022-08-22 20:43:12 +08:00
|
|
|
|
import {getProductCategoryList} from "@/api/mall/product/category";
|
|
|
|
|
import {createSpu,} from "@/api/mall/product/spu";
|
|
|
|
|
import {getPropertyPage,} from "@/api/mall/product/property";
|
2022-08-18 22:38:51 +08:00
|
|
|
|
import Editor from "@/components/Editor";
|
|
|
|
|
import ImageUpload from "@/components/ImageUpload";
|
2022-08-22 20:43:12 +08:00
|
|
|
|
|
2022-08-18 22:38:51 +08:00
|
|
|
|
export default {
|
|
|
|
|
components: {
|
|
|
|
|
Editor,
|
|
|
|
|
ImageUpload
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
activeName: "base",
|
|
|
|
|
propName: {
|
|
|
|
|
checkStrictly: true,
|
|
|
|
|
label: "name",
|
|
|
|
|
value: "id",
|
|
|
|
|
},
|
|
|
|
|
// 基础设置
|
|
|
|
|
baseForm: {
|
|
|
|
|
name: null,
|
|
|
|
|
sellPoint: null,
|
|
|
|
|
categoryIds: null,
|
|
|
|
|
sort: null,
|
|
|
|
|
description: null,
|
2022-08-23 20:27:39 +08:00
|
|
|
|
picUrls: null,
|
|
|
|
|
status: 0,
|
|
|
|
|
virtualSalesCount: 0,
|
|
|
|
|
showStock: true,
|
2022-08-18 22:38:51 +08:00
|
|
|
|
},
|
|
|
|
|
categoryList: [],
|
|
|
|
|
// 价格库存
|
|
|
|
|
ratesForm: {
|
2022-08-23 20:27:39 +08:00
|
|
|
|
spec: 1,
|
2022-08-18 22:38:51 +08:00
|
|
|
|
// 规格明细
|
|
|
|
|
rates: [{}]
|
|
|
|
|
},
|
|
|
|
|
dynamicSpec: [
|
|
|
|
|
// {
|
2022-08-22 20:43:12 +08:00
|
|
|
|
// specId: 86,
|
|
|
|
|
// specName: "颜色",
|
|
|
|
|
// specValue:[{
|
|
|
|
|
// name: "红色",
|
|
|
|
|
// id: 225,
|
|
|
|
|
// }]
|
2022-08-18 22:38:51 +08:00
|
|
|
|
// },
|
|
|
|
|
],
|
2022-08-22 20:43:12 +08:00
|
|
|
|
propertyPageList: [],
|
2022-08-18 22:38:51 +08:00
|
|
|
|
specValue: null,
|
|
|
|
|
|
|
|
|
|
// 表单校验
|
|
|
|
|
rules: {
|
2022-08-23 20:27:39 +08:00
|
|
|
|
name:[{required: true, message: "商品名称不能为空", trigger: "blur"},],
|
|
|
|
|
description: [{required: true, message: "描述不能为空", trigger: "blur"},],
|
|
|
|
|
categoryIds: [{required: true, message: "分类id不能为空", trigger: "blur"},],
|
|
|
|
|
status: [{required: true, message: "商品状态不能为空", trigger: "blur"}],
|
|
|
|
|
picUrls: [{required: true, message: "商品轮播图地址不能为空", trigger: "blur"}],
|
|
|
|
|
virtualSalesCount: [{required: true, message: "虚拟销量不能为空", trigger: "blur"}],
|
2022-08-18 22:38:51 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
},
|
2022-08-23 20:27:39 +08:00
|
|
|
|
|
2022-08-18 22:38:51 +08:00
|
|
|
|
created() {
|
2022-08-23 21:06:59 +08:00
|
|
|
|
|
2022-08-18 22:38:51 +08:00
|
|
|
|
this.getListCategory();
|
2022-08-22 20:43:12 +08:00
|
|
|
|
this.getPropertyPageList();
|
2022-08-18 22:38:51 +08:00
|
|
|
|
},
|
|
|
|
|
methods: {
|
2022-08-23 21:06:59 +08:00
|
|
|
|
removeSpec(index){
|
|
|
|
|
this.dynamicSpec.splice(index, 1);
|
|
|
|
|
this.changeRadio()
|
|
|
|
|
},
|
2022-08-23 20:27:39 +08:00
|
|
|
|
async confirmLeave(active, old){
|
|
|
|
|
await this.$refs[old].validate((valid) => {
|
|
|
|
|
console.log(valid)
|
|
|
|
|
if (!valid) {
|
|
|
|
|
return reject();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
// 必选标识
|
|
|
|
|
addRedStar(h, { column }) {
|
|
|
|
|
return [
|
|
|
|
|
h('span', { style: 'color: #F56C6C' }, '*'),
|
|
|
|
|
h('span', ' ' + column.label)
|
|
|
|
|
];
|
|
|
|
|
},
|
2022-08-18 22:38:51 +08:00
|
|
|
|
changeRadio() {
|
2022-08-23 21:06:59 +08:00
|
|
|
|
this.$refs.ratesTable.doLayout();
|
2022-08-23 20:27:39 +08:00
|
|
|
|
if (this.ratesForm.spec == 1) {
|
2022-08-18 22:38:51 +08:00
|
|
|
|
this.ratesForm.rates = [{}]
|
2022-08-22 20:43:12 +08:00
|
|
|
|
} else {
|
2022-08-18 22:38:51 +08:00
|
|
|
|
this.ratesForm.rates = []
|
2022-08-22 20:43:12 +08:00
|
|
|
|
if (this.dynamicSpec.length > 0) {
|
2022-08-23 21:06:59 +08:00
|
|
|
|
console.log( this.dynamicSpec)
|
2022-08-18 22:38:51 +08:00
|
|
|
|
this.buildRatesFormRates()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 构建规格明细笛卡尔积
|
2022-08-22 20:43:12 +08:00
|
|
|
|
buildRatesFormRates() {
|
2022-08-18 22:38:51 +08:00
|
|
|
|
let rates = [];
|
2022-08-22 20:43:12 +08:00
|
|
|
|
this.dynamicSpec.map(v => v.specValue.map(m => m.name))
|
|
|
|
|
.reduce((last, current) => {
|
|
|
|
|
const array = [];
|
|
|
|
|
last.forEach(par1 => {
|
2022-08-18 22:38:51 +08:00
|
|
|
|
current.forEach(par2 => {
|
2022-08-22 20:43:12 +08:00
|
|
|
|
let v
|
|
|
|
|
if (par1 instanceof Array) {
|
2022-08-18 22:38:51 +08:00
|
|
|
|
v = par1.concat(par2)
|
2022-08-22 20:43:12 +08:00
|
|
|
|
} else {
|
2022-08-18 22:38:51 +08:00
|
|
|
|
v = [par1, par2];
|
|
|
|
|
}
|
|
|
|
|
array.push(v)
|
|
|
|
|
});
|
2022-08-22 20:43:12 +08:00
|
|
|
|
});
|
|
|
|
|
return array;
|
|
|
|
|
})
|
|
|
|
|
.forEach(v => {
|
2022-08-23 20:27:39 +08:00
|
|
|
|
rates.push({spec: v, status: 0, name: Array.of(v).join()})
|
2022-08-18 22:38:51 +08:00
|
|
|
|
});
|
2022-08-22 20:43:12 +08:00
|
|
|
|
this.ratesForm.rates = rates
|
2022-08-18 22:38:51 +08:00
|
|
|
|
},
|
|
|
|
|
/** 查询分类 */
|
|
|
|
|
getListCategory() {
|
|
|
|
|
// 执行查询
|
|
|
|
|
getProductCategoryList().then((response) => {
|
|
|
|
|
this.categoryList = this.handleTree(response.data, "id", "parentId");
|
|
|
|
|
});
|
|
|
|
|
},
|
2022-08-22 20:43:12 +08:00
|
|
|
|
cancel() {
|
|
|
|
|
this.$emit("closeDialog");
|
|
|
|
|
},
|
|
|
|
|
submit() {
|
2022-08-23 20:27:39 +08:00
|
|
|
|
this.$refs[this.activeName].validate((valid) => {
|
|
|
|
|
if (!valid) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-08-22 20:43:12 +08:00
|
|
|
|
let rates = this.ratesForm.rates;
|
|
|
|
|
// 动态规格调整字段
|
2022-08-23 20:27:39 +08:00
|
|
|
|
if (this.ratesForm.spec == 2) {
|
2022-08-22 20:43:12 +08:00
|
|
|
|
rates.forEach(r => {
|
|
|
|
|
let properties = []
|
2022-08-23 21:06:59 +08:00
|
|
|
|
Array.of(r.spec).forEach(s => {
|
|
|
|
|
Array.of(s).forEach((v, i) => {
|
|
|
|
|
console.log(this.dynamicSpec, r, s, v, i)
|
|
|
|
|
let specValue = this.dynamicSpec[i].specValue.find(o => o.name == v);
|
|
|
|
|
console.log(specValue)
|
|
|
|
|
let propertie = {};
|
|
|
|
|
propertie.propertyId = this.dynamicSpec[i].specId;
|
|
|
|
|
propertie.valueId = specValue.id;
|
|
|
|
|
properties.push(propertie);
|
|
|
|
|
})
|
2022-08-22 21:20:49 +08:00
|
|
|
|
})
|
2022-08-22 20:43:12 +08:00
|
|
|
|
r.properties = properties;
|
|
|
|
|
})
|
2022-08-23 20:27:39 +08:00
|
|
|
|
}else{
|
|
|
|
|
rates[0].name = this.baseForm.name;
|
|
|
|
|
rates[0].status = this.baseForm.status;
|
2022-08-22 20:43:12 +08:00
|
|
|
|
}
|
2022-08-23 20:27:39 +08:00
|
|
|
|
|
|
|
|
|
console.log(rates)
|
|
|
|
|
|
|
|
|
|
let form = this.baseForm
|
|
|
|
|
if(form.picUrls instanceof Array){
|
|
|
|
|
form.picUrls = form.picUrls.flatMap(m=>m.split(','))
|
|
|
|
|
}else if(form.picUrls.split(',') instanceof Array){
|
|
|
|
|
form.picUrls = form.picUrls.split(',').flatMap(m=>m.split(','))
|
|
|
|
|
}else{
|
|
|
|
|
form.picUrls = Array.of(form.picUrls)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
form.skus = rates;
|
|
|
|
|
form.specType = this.ratesForm.spec;
|
|
|
|
|
form.categoryId = form.categoryIds[this.baseForm.categoryIds.length - 1];
|
|
|
|
|
createSpu(form).then((response) => {
|
2022-08-22 21:20:49 +08:00
|
|
|
|
console.log(response)
|
2022-08-22 20:43:12 +08:00
|
|
|
|
this.$modal.msgSuccess("新增成功");
|
2022-08-18 22:38:51 +08:00
|
|
|
|
this.$emit("closeDialog");
|
2022-08-23 20:27:39 +08:00
|
|
|
|
}).catch((err) => {
|
|
|
|
|
console.log(this.baseForm.picUrls)
|
|
|
|
|
});
|
2022-08-22 20:43:12 +08:00
|
|
|
|
});
|
2022-08-18 22:38:51 +08:00
|
|
|
|
},
|
2022-08-22 20:43:12 +08:00
|
|
|
|
/** 查询规格 */
|
|
|
|
|
getPropertyPageList() {
|
|
|
|
|
// 执行查询
|
|
|
|
|
getPropertyPage().then((response) => {
|
|
|
|
|
this.propertyPageList = response.data.list;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
changeSpec(val) {
|
|
|
|
|
let obj = this.propertyPageList.find(o => o.id == val);
|
|
|
|
|
let dynamicSpec = this.dynamicSpec;
|
|
|
|
|
let spec = dynamicSpec.find(o => o.specId == val)
|
|
|
|
|
spec.specId = obj.id;
|
|
|
|
|
spec.specName = obj.name;
|
|
|
|
|
spec.specValue = obj.propertyValueList;
|
|
|
|
|
this.dynamicSpec = dynamicSpec;
|
|
|
|
|
this.buildRatesFormRates();
|
|
|
|
|
}
|
2022-08-18 22:38:51 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
.spec-dialog {
|
|
|
|
|
width: 400px;
|
|
|
|
|
height: 300px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.dynamic-spec {
|
|
|
|
|
background-color: #f2f2f2;
|
|
|
|
|
width: 85%;
|
|
|
|
|
margin: auto;
|
|
|
|
|
margin-bottom: 10px;
|
|
|
|
|
|
|
|
|
|
.spec-header {
|
|
|
|
|
padding: 30px;
|
2022-08-22 20:43:12 +08:00
|
|
|
|
padding-bottom: 20px;
|
2022-08-18 22:38:51 +08:00
|
|
|
|
|
|
|
|
|
.spec-name {
|
|
|
|
|
display: inline;
|
|
|
|
|
|
|
|
|
|
input {
|
|
|
|
|
width: 30%;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.spec-values {
|
|
|
|
|
width: 84%;
|
|
|
|
|
padding: 25px;
|
|
|
|
|
margin: auto;
|
2022-08-22 20:43:12 +08:00
|
|
|
|
padding-top: 5px;
|
2022-08-18 22:38:51 +08:00
|
|
|
|
|
|
|
|
|
.spec-value {
|
|
|
|
|
display: inline-block;
|
|
|
|
|
margin-right: 10px;
|
|
|
|
|
margin-bottom: 10px;
|
|
|
|
|
width: 13%;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.spec-delete {
|
|
|
|
|
float: right;
|
|
|
|
|
margin-top: 10px;
|
|
|
|
|
margin-right: 10px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-22 20:43:12 +08:00
|
|
|
|
.tabs {
|
2022-08-18 22:38:51 +08:00
|
|
|
|
height: 500px;
|
|
|
|
|
border-bottom: 2px solid #f2f2f2;
|
2022-08-22 20:43:12 +08:00
|
|
|
|
|
|
|
|
|
.el-tab-pane {
|
2022-08-18 22:38:51 +08:00
|
|
|
|
height: 445px;
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 库存价格图片样式修改
|
2022-08-22 20:43:12 +08:00
|
|
|
|
.rates {
|
|
|
|
|
.component-upload-image {
|
|
|
|
|
margin: auto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.el-upload--picture-card {
|
|
|
|
|
width: 100px;
|
|
|
|
|
height: 50px;
|
|
|
|
|
line-height: 60px;
|
|
|
|
|
margin: auto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.el-upload-list__item {
|
|
|
|
|
width: 100px !important;
|
|
|
|
|
height: 50px !important;
|
|
|
|
|
}
|
2022-08-18 22:38:51 +08:00
|
|
|
|
}
|
2022-08-22 20:43:12 +08:00
|
|
|
|
|
|
|
|
|
.buttons {
|
2022-08-18 22:38:51 +08:00
|
|
|
|
margin-top: 20px;
|
|
|
|
|
height: 36px;
|
2022-08-22 20:43:12 +08:00
|
|
|
|
|
|
|
|
|
button {
|
2022-08-18 22:38:51 +08:00
|
|
|
|
float: right;
|
|
|
|
|
margin-left: 15px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|