2023-11-20 14:53:54 +08:00
|
|
|
<template>
|
2023-11-22 15:47:48 +08:00
|
|
|
<view class="page">
|
2023-11-21 19:13:43 +08:00
|
|
|
<view class="mode">
|
|
|
|
<view class="line">
|
|
|
|
<view class="title">规格模板</view>
|
2023-11-22 17:08:05 +08:00
|
|
|
<picker style="flex: 1;" mode="selector" :range="attr_mode_list" range-key="template_name" @change="changAttrMode">
|
|
|
|
<view class="input">
|
|
|
|
<view>{{template_name}}</view>
|
|
|
|
<uni-icons type="right"></uni-icons>
|
|
|
|
</view>
|
|
|
|
</picker>
|
2023-11-22 18:59:13 +08:00
|
|
|
<view class="btn" @click="preAddMode(3)">添加模板</view>
|
2023-11-21 19:13:43 +08:00
|
|
|
</view>
|
2023-11-22 15:47:48 +08:00
|
|
|
<view class="btn-box" @click="settingSpec()">
|
2023-11-21 19:13:43 +08:00
|
|
|
<view class="btn">点击设置规格</view>
|
|
|
|
</view>
|
|
|
|
<uni-popup ref="modeRef" type="top">
|
|
|
|
<view class="mode-ref" style="min-height: 300rpx;width: 100%;background-color: #fff;">
|
|
|
|
<view style="height: 1rpx;"></view>
|
|
|
|
<scroll-view scroll-y style="max-height: 550rpx;min-height: 220rpx;">
|
|
|
|
<view class="mode-item" v-for="(item, index) in attr" :key="item+index">
|
|
|
|
<view class="mode-head">{{item.value}}</view>
|
|
|
|
<view class="mode-body">
|
|
|
|
<view class="box mode-body-box" v-for="(t, i) in item.detail" :key="t+i"
|
|
|
|
@click="deleteAttrTow(index, i)">
|
|
|
|
{{t}}<uni-icons type="close" color="#f84221" style="margin-left: 10rpx;"></uni-icons>
|
|
|
|
</view>
|
|
|
|
<view class="box mode-body-add" @click="addSpecTow(index)"><uni-icons type="plus" color="#333"
|
|
|
|
style="margin-right: 10rpx;"></uni-icons>添加</view>
|
|
|
|
</view>
|
|
|
|
<view class="delete-spec" @click="deleteAttrOne(index)"><uni-icons type="close" color="#f84221"
|
|
|
|
style="margin-right: 10rpx;"></uni-icons>删除规格</view>
|
|
|
|
</view>
|
2023-11-22 15:47:48 +08:00
|
|
|
<view v-if="attr.length==0" style="color: #ccc;height: 220rpx;text-align: center;display: flex;flex-direction: column;justify-content: center;align-items: center;">
|
|
|
|
<view>暂无规格</view>
|
|
|
|
<view>点击下方按钮添加新规格</view>
|
|
|
|
</view>
|
2023-11-21 19:13:43 +08:00
|
|
|
</scroll-view>
|
|
|
|
<view class="tab">
|
|
|
|
<view class="add-btn" @click="addSpecOne()">添加新规格</view>
|
2023-11-22 18:59:13 +08:00
|
|
|
<view class="save" @click="saveAttrMode()">保存模板</view>
|
2023-11-21 19:13:43 +08:00
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</uni-popup>
|
|
|
|
|
|
|
|
<uni-popup ref="inputModeRef" type="center">
|
|
|
|
<view class="input-mode">
|
2023-11-22 18:59:13 +08:00
|
|
|
<view class="head-tips">
|
|
|
|
<view v-if="addAttrType==1">添加规格值</view>
|
|
|
|
<view v-else-if="addAttrType==2">添加新规格</view>
|
|
|
|
<view v-else>添加模板</view>
|
|
|
|
</view>
|
2023-11-21 19:13:43 +08:00
|
|
|
<view class="input-box">
|
2023-11-22 18:59:13 +08:00
|
|
|
<input v-if="addAttrType==4||addAttrType==3" v-model="attrMode" placeholder="请输入模板名称" />
|
|
|
|
<input v-if="addAttrType==2||addAttrType==3" v-model="attrName" placeholder="请输入规格名称" />
|
|
|
|
<input v-if="addAttrType!=4" v-model="attrDetail" placeholder="请输入规格值" />
|
2023-11-21 19:13:43 +08:00
|
|
|
</view>
|
|
|
|
<view class="show-btn-box">
|
|
|
|
<view class="cof prai" @click="addAttr()">确认</view>
|
|
|
|
<view class="can" @click="closeAddAttr()">取消</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</uni-popup>
|
|
|
|
</view>
|
2023-11-22 17:08:05 +08:00
|
|
|
<view style="height: 160rpx;"></view>
|
2023-11-21 19:13:43 +08:00
|
|
|
<avatar style="height: 1px;" @upload="doUpload" @getName="getImgName" quality="1" ref="avatar" selWidth="250upx"
|
|
|
|
selHeight="250upx">
|
2023-11-20 18:38:50 +08:00
|
|
|
</avatar>
|
|
|
|
<block v-for="(item,index) in attrValue" :key="item.uuid">
|
2023-11-21 19:13:43 +08:00
|
|
|
<view class="popup_group head_close">
|
2023-11-22 15:47:48 +08:00
|
|
|
<view class="popup_group_item " v-for="(value, key) in item.detail" :key="key">
|
2023-11-21 19:13:43 +08:00
|
|
|
<view class="popup_group_item_label">{{key}}</view>
|
|
|
|
<view class="popup_group_item_value">
|
|
|
|
<input :value="value" type="text" disabled placeholder="请填写规格名称" />
|
2023-11-20 18:38:50 +08:00
|
|
|
</view>
|
|
|
|
</view>
|
2023-11-21 19:13:43 +08:00
|
|
|
<view class="delete_btn" @click="deleteByIndex(index)">
|
|
|
|
<image style="width: 50%;height: 50%;" src="../static/images/close.png"></image>
|
|
|
|
</view>
|
2023-11-20 18:38:50 +08:00
|
|
|
<view class="popup_group_item">
|
|
|
|
<view class="popup_group_item_label">规格图片</view>
|
|
|
|
<view style="width: 120rpx;height: 120rpx;position: relative;">
|
|
|
|
<block v-if="item.image">
|
2023-11-21 19:13:43 +08:00
|
|
|
<image @click="clk(item.uuid)" style="width: 120rpx;height: 120rpx;border-radius: 10rpx;"
|
|
|
|
:src="item.image"></image>
|
2023-11-20 18:38:50 +08:00
|
|
|
<view class="close-icon" @click="deleteImage(item)">
|
|
|
|
<image style="width: 50%;height: 50%;" src="../static/images/close.png"></image>
|
|
|
|
</view>
|
|
|
|
</block>
|
2023-11-21 19:13:43 +08:00
|
|
|
<view v-else
|
|
|
|
style="width: 120rpx;height: 120rpx;display: flex;justify-content: center;align-items: center;border: 1rpx solid #ccc;border-radius: 10rpx;">
|
|
|
|
<image @click="clk(item.uuid)" style="height: 60rpx;width: 60rpx;" src="../static/images/creamer.png">
|
|
|
|
</image>
|
2023-11-20 18:38:50 +08:00
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
2023-11-21 19:13:43 +08:00
|
|
|
<priceComponent ref="priceRef" :product_id="product_id" :datas="item" :bar_code="item.bar_code"
|
|
|
|
@updateCode="updateCode" :show_sku="true">
|
2023-11-20 14:53:54 +08:00
|
|
|
</priceComponent>
|
|
|
|
</block>
|
2023-11-22 15:47:48 +08:00
|
|
|
<!-- <button class="add_btn" @click="addAttrValue">点击添加规格</button> -->
|
2023-11-20 18:38:50 +08:00
|
|
|
<view class="submit">
|
2023-11-21 19:13:43 +08:00
|
|
|
<button class="btn" @click="submitAttr">确认<text>({{attrValue.length}})</text></button>
|
2023-11-20 18:38:50 +08:00
|
|
|
</view>
|
2023-11-21 19:13:43 +08:00
|
|
|
<u-modal title="警告" content="删除后数据不可恢复,是否确认删除?" :show="showDelete" show-cancel-button @cancel="showDelete=false"
|
|
|
|
@confirm="deleteAttr()"></u-modal>
|
2023-11-20 14:53:54 +08:00
|
|
|
</view>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import priceComponent from "./components/price.vue";
|
2023-11-20 18:38:50 +08:00
|
|
|
import avatar from "@/components/yq-avatar/yq-avatar.vue";
|
|
|
|
import { TOKENNAME, HTTP_REQUEST_URL } from '@/config/app.js';
|
2023-11-21 19:13:43 +08:00
|
|
|
import { Toast } from "../../../libs/uniApi";
|
|
|
|
import {
|
2023-11-22 17:08:05 +08:00
|
|
|
specificationUpdate,
|
2023-11-22 18:59:13 +08:00
|
|
|
attrList,
|
|
|
|
specificationAdd
|
2023-11-21 19:13:43 +08:00
|
|
|
} from "@/api/product.js"
|
2023-11-20 14:53:54 +08:00
|
|
|
export default {
|
2023-11-21 19:13:43 +08:00
|
|
|
components: {
|
2023-11-20 18:38:50 +08:00
|
|
|
priceComponent,
|
|
|
|
avatar
|
2023-11-20 14:53:54 +08:00
|
|
|
},
|
2023-11-21 19:13:43 +08:00
|
|
|
data() {
|
|
|
|
return {
|
2023-11-20 14:53:54 +08:00
|
|
|
attrValue: [],
|
2023-11-21 19:13:43 +08:00
|
|
|
attr: [],
|
2023-11-22 17:08:05 +08:00
|
|
|
attr_mode_list: [], //规格模板列表
|
|
|
|
template_name: '点击选择模板', //选中的模板名字
|
|
|
|
attr_mode: { // 规格字段模板
|
2023-11-22 15:47:48 +08:00
|
|
|
"detail": {},
|
|
|
|
"sku": "",
|
|
|
|
"stock": 0,
|
|
|
|
"image": "",
|
|
|
|
"bar_code": "",
|
|
|
|
"cost": "",
|
|
|
|
"ot_price": "",
|
|
|
|
"price": "",
|
|
|
|
"volume": "",
|
|
|
|
"weight": "",
|
|
|
|
},
|
2023-11-20 18:38:50 +08:00
|
|
|
product_id: '',
|
|
|
|
uuid: '', //选择图片的id
|
|
|
|
deleteIndex: '', //删除图片下标
|
|
|
|
showDelete: false,
|
2023-11-21 19:13:43 +08:00
|
|
|
userInfo: {},
|
2023-11-22 18:59:13 +08:00
|
|
|
addAttrType: 1, // 规格类型, 1为添加规格值, 2为添加新规格, 3为添加新模板, 4为保存模板
|
2023-11-21 19:13:43 +08:00
|
|
|
attrName: '', // 规格名称
|
|
|
|
attrDetail: '', // 规格值
|
2023-11-22 18:59:13 +08:00
|
|
|
attrMode: '', //新增模板名称
|
2023-11-21 19:13:43 +08:00
|
|
|
changeAttr: 0, // 选中的规格
|
2023-11-20 14:53:54 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
onLoad(options) {
|
2023-11-20 18:38:50 +08:00
|
|
|
this.product_id = options.product_id;
|
2023-11-21 19:13:43 +08:00
|
|
|
this.attrValue = JSON.parse(uni.getStorageSync('attrValue') || '[]');
|
|
|
|
this.attr = JSON.parse(uni.getStorageSync('attr') || '[]');
|
|
|
|
this.getOpenerEventChannel().once('updateAttrValue', (e) => {
|
2024-01-26 11:20:18 +08:00
|
|
|
if(e.attrValue.length>0) e.attrValue.forEach((item, index) => {
|
2023-11-22 15:47:48 +08:00
|
|
|
item.uuid = Date.now() + '-' + Math.floor(Math.random() * 10000);
|
2023-11-20 18:38:50 +08:00
|
|
|
})
|
2023-11-21 19:13:43 +08:00
|
|
|
this.attrValue = e.attrValue;
|
|
|
|
uni.setStorageSync('attrValue', JSON.stringify(e.attrValue));
|
|
|
|
this.attr = e.attr;
|
|
|
|
uni.setStorageSync('attr', JSON.stringify(e.attr));
|
2023-11-20 18:38:50 +08:00
|
|
|
})
|
|
|
|
this.userInfo = this.$store.state.app.userInfo;
|
2023-11-21 19:13:43 +08:00
|
|
|
if (typeof this.userInfo == 'string') this.userInfo = JSON.parse(this.userInfo);
|
2023-11-22 17:08:05 +08:00
|
|
|
this.initAttrModeList();
|
2023-11-20 14:53:54 +08:00
|
|
|
},
|
2023-11-21 19:13:43 +08:00
|
|
|
methods: {
|
|
|
|
updateCode(e) {
|
2023-11-20 14:53:54 +08:00
|
|
|
console.log(e);
|
2023-11-21 19:13:43 +08:00
|
|
|
},
|
|
|
|
// 点击设置规格
|
2023-11-22 15:47:48 +08:00
|
|
|
settingSpec() {
|
2023-11-21 19:13:43 +08:00
|
|
|
this.$refs.modeRef.open();
|
|
|
|
},
|
|
|
|
// 添加规格二级
|
|
|
|
addSpecTow(index) {
|
2023-11-22 15:47:48 +08:00
|
|
|
this.attrDetail = '';
|
2023-11-21 19:13:43 +08:00
|
|
|
this.addAttrType = 1;
|
|
|
|
this.changeAttr = index;
|
|
|
|
this.$refs.inputModeRef.open();
|
|
|
|
},
|
|
|
|
// 添加规格一级
|
|
|
|
addSpecOne() {
|
2023-11-22 15:47:48 +08:00
|
|
|
this.attrName = '';
|
|
|
|
this.attrDetail = '';
|
2023-11-21 19:13:43 +08:00
|
|
|
this.addAttrType = 2;
|
|
|
|
this.$refs.inputModeRef.open();
|
|
|
|
},
|
|
|
|
// 删除规格二级
|
|
|
|
deleteAttrTow(i, j) {
|
2023-11-22 15:47:48 +08:00
|
|
|
if(this.attr[i].detail.length<=1){
|
|
|
|
return this.deleteAttrOne(i); // 当规格的最后一个属性被删除时,直接删除该规格
|
|
|
|
}
|
|
|
|
this.attrValue = this.attrValue.filter(item=>{
|
|
|
|
return !(item.detail[this.attr[i].value] == this.attr[i].detail[j]);
|
|
|
|
})
|
2023-11-21 19:13:43 +08:00
|
|
|
this.attr[i].detail.splice(j, 1);
|
|
|
|
},
|
|
|
|
// 删除规格一级
|
|
|
|
deleteAttrOne(i) {
|
2023-11-22 15:47:48 +08:00
|
|
|
let attr = this.attr[i];
|
|
|
|
if(this.attr.length==1){ // 如果只有一个规格, 并且删除这个规格时, 直接清空规格
|
|
|
|
this.$set(this, 'attrValue', []);
|
|
|
|
this.attr.splice(i, 1);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
// 删除多余的规格值
|
|
|
|
this.attrValue.forEach(item => {
|
|
|
|
let a = item.sku.split(',');
|
|
|
|
a = a.filter(e=>e!=item.detail[attr.value]);
|
|
|
|
item.sku = a.join(',');
|
|
|
|
delete item.detail[attr.value];
|
|
|
|
})
|
|
|
|
// 过滤掉重复的值
|
|
|
|
this.attrValue = Array.from(new Set(this.attrValue.map(item => item.sku))).map(sku => {
|
|
|
|
return this.attrValue.find(item => item.sku === sku);
|
|
|
|
});
|
2023-11-21 19:13:43 +08:00
|
|
|
this.attr.splice(i, 1);
|
|
|
|
},
|
2023-11-22 15:47:48 +08:00
|
|
|
// 添加商品规格卡片
|
|
|
|
addAttrValueCard(){
|
|
|
|
let arr = this.computeAttr(this.attr); // 计算出sku的值
|
|
|
|
let t = [];
|
|
|
|
let keys = this.attr.map(e => { // 获取规格名称
|
|
|
|
return e.value;
|
|
|
|
})
|
|
|
|
let temp = [];
|
|
|
|
arr.forEach((sku) => { // 根据sku遍历当前规格数组
|
|
|
|
if (this.attrValue.find(e => e.sku == sku)) return;
|
|
|
|
else {
|
|
|
|
let detail = {};
|
|
|
|
let t = sku.split(',');
|
|
|
|
keys.forEach((e, i) => { // 设置detail的值
|
|
|
|
detail[e] = t[i];
|
|
|
|
})
|
|
|
|
temp.push(Object.assign({}, this.attr_mode, {
|
|
|
|
sku: sku,
|
|
|
|
detail: detail,
|
|
|
|
uuid: Date.now() + '-' + Math.floor(Math.random() * 10000) // 重设uuid
|
|
|
|
})) // 追加数据
|
|
|
|
}
|
|
|
|
})
|
|
|
|
setTimeout(() => {
|
|
|
|
this.attrValue = [...this.attrValue, ...temp] // 延后追加数据
|
|
|
|
})
|
|
|
|
},
|
2023-11-21 19:13:43 +08:00
|
|
|
// 关闭添加规格
|
|
|
|
closeAddAttr() {
|
|
|
|
this.$refs.inputModeRef.close();
|
|
|
|
},
|
|
|
|
// 获取产品的组合
|
|
|
|
computeAttr(arr) {
|
|
|
|
let s = [];
|
|
|
|
arr.forEach(item => {
|
|
|
|
s.push(item.detail);
|
|
|
|
})
|
|
|
|
let t = this.getCombination(s);
|
2023-11-22 15:47:48 +08:00
|
|
|
t = t.map(item => {
|
|
|
|
if (typeof item == 'object') {
|
|
|
|
return item.join(',')
|
|
|
|
} else return item;
|
|
|
|
})
|
2023-11-21 19:13:43 +08:00
|
|
|
return t;
|
|
|
|
},
|
|
|
|
// 递归计算
|
|
|
|
getCombination(arr) {
|
|
|
|
if (arr.length === 1) {
|
|
|
|
return arr[0];
|
|
|
|
}
|
|
|
|
var result = [];
|
|
|
|
var first = arr[0];
|
|
|
|
var rest = arr.slice(1);
|
|
|
|
for (var i = 0; i < first.length; i++) {
|
|
|
|
var subResult = this.getCombination(rest);
|
|
|
|
for (var j = 0; j < subResult.length; j++) {
|
|
|
|
result.push([first[i]].concat(subResult[j]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
// 确认添加规格
|
|
|
|
addAttr() {
|
2023-11-22 15:47:48 +08:00
|
|
|
this.attrDetail = this.attrDetail.trim();
|
|
|
|
this.attrDetail = this.attrDetail.trim();
|
|
|
|
if (this.addAttrType == 1) { // 2级
|
2023-11-21 19:13:43 +08:00
|
|
|
if (this.attr[this.changeAttr].detail.find(name => name == this.attrDetail)) {
|
|
|
|
this.closeAddAttr();
|
|
|
|
this.$nextTick(() => {
|
|
|
|
Toast('该规格已存在')
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.attr[this.changeAttr].detail.push(this.attrDetail);
|
|
|
|
this.closeAddAttr();
|
2023-11-22 15:47:48 +08:00
|
|
|
setTimeout(()=>{
|
|
|
|
this.addAttrValueCard();
|
|
|
|
})
|
2023-11-21 19:13:43 +08:00
|
|
|
}
|
2023-11-22 18:59:13 +08:00
|
|
|
} else if (this.addAttrType == 2) { // 1级
|
2023-11-21 19:13:43 +08:00
|
|
|
if (this.attr.find(item => item.value == this.attrName)) {
|
|
|
|
this.closeAddAttr();
|
|
|
|
this.$nextTick(() => {
|
|
|
|
Toast('该规格已存在')
|
|
|
|
})
|
|
|
|
} else {
|
2023-11-22 15:47:48 +08:00
|
|
|
console.log('添加新规格');
|
2023-11-21 19:13:43 +08:00
|
|
|
this.attr.push({
|
|
|
|
value: this.attrName,
|
|
|
|
detail: [this.attrDetail]
|
|
|
|
});
|
2023-11-22 15:47:48 +08:00
|
|
|
if(this.attrValue.length){
|
|
|
|
this.attrValue.forEach((item) => {
|
|
|
|
item.detail[this.attrName] = this.attrDetail;
|
|
|
|
item.sku = item.sku + ',' + this.attrDetail;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let detail = {};
|
|
|
|
detail[this.attrName] = this.attrDetail;
|
|
|
|
this.attrValue.push(Object.assign({}, this.attr_mode, {
|
|
|
|
sku: this.attrDetail,
|
|
|
|
detail: detail,
|
|
|
|
uuid: Date.now() + '-' + Math.floor(Math.random() * 10000)
|
|
|
|
}))
|
|
|
|
}
|
2023-11-21 19:13:43 +08:00
|
|
|
this.closeAddAttr();
|
|
|
|
}
|
2023-11-22 18:59:13 +08:00
|
|
|
} else if (this.addAttrType == 3 || this.addAttrType == 4){
|
|
|
|
this.addNewAttrMode();
|
2023-11-21 19:13:43 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// 保存模板
|
|
|
|
saveAttrMode() {
|
2023-11-22 18:59:13 +08:00
|
|
|
if(this.attr.length<=0)return Toast('不可保存空模板');
|
|
|
|
if(this.attr_template_id){
|
|
|
|
this.addAttrType = 4;
|
|
|
|
let template = this.attr_mode_list.find(e=>e.attr_template_id==this.attr_template_id);
|
|
|
|
specificationUpdate(this.userInfo.service.mer_id, this.attr_template_id, {
|
|
|
|
attr_template_id: template.attr_template_id,
|
|
|
|
mer_id: template.attr_template_id,
|
|
|
|
template_name: template.template_name,
|
|
|
|
template_value: this.attr
|
|
|
|
}).then((res)=>{
|
|
|
|
this.$refs.modeRef.close();
|
|
|
|
this.$nextTick(()=>{
|
|
|
|
Toast('保存成功');
|
|
|
|
})
|
|
|
|
}).catch(err=>{
|
|
|
|
Toast(err)
|
|
|
|
})
|
|
|
|
}else {
|
|
|
|
this.preAddMode(4)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 添加新模板
|
|
|
|
addNewAttrMode(){
|
|
|
|
this.attrMode = this.attrMode.trim(' ');
|
|
|
|
if(this.attrMode==''||this.attrMode===undefined||this.attrMode===null){
|
|
|
|
return Toast('模板名称不可为空')
|
|
|
|
}
|
|
|
|
let attr = [];
|
|
|
|
if(this.addAttrType==3){
|
|
|
|
attr[0] = {};
|
|
|
|
attr[0].value = this.attrName;
|
|
|
|
attr[0].detail = [];
|
|
|
|
attr[0].detail[0] = this.attrDetail;
|
|
|
|
}else attr = this.attr;
|
|
|
|
specificationAdd(this.userInfo.service.mer_id, {
|
|
|
|
template_name: this.attrMode,
|
|
|
|
template_value: attr
|
|
|
|
}).then((res)=>{
|
|
|
|
this.initAttrModeList();
|
|
|
|
this.closeAddAttr();
|
|
|
|
this.$nextTick(()=>{
|
|
|
|
this.$refs.modeRef.close();
|
|
|
|
this.$nextTick(()=>{
|
|
|
|
Toast('保存成功');
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}).catch(err=>{
|
|
|
|
Toast(err)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 预添加模板
|
|
|
|
preAddMode(type=3){
|
|
|
|
this.attrName = '';
|
|
|
|
this.attrDetail = '';
|
|
|
|
this.attrMode = '';
|
|
|
|
this.addAttrType = type;
|
|
|
|
this.$refs.inputModeRef.open();
|
2023-11-20 18:38:50 +08:00
|
|
|
},
|
|
|
|
// 提交数据
|
2023-11-21 19:13:43 +08:00
|
|
|
submitAttr() {
|
|
|
|
if (this.attrValue.length < 1) return Toast('请至少添加一种规格');
|
2023-11-20 18:38:50 +08:00
|
|
|
let flag = true;
|
2023-11-22 15:47:48 +08:00
|
|
|
let str = '请填写完整信息';
|
2023-11-21 19:13:43 +08:00
|
|
|
this.attrValue.forEach((item, index) => {
|
|
|
|
Object.keys(this.$refs.priceRef[index].singleSpecification).forEach(key => {
|
|
|
|
item[key] = this.$refs.priceRef[index].singleSpecification[key];
|
2023-11-20 18:38:50 +08:00
|
|
|
})
|
2023-11-21 19:13:43 +08:00
|
|
|
if (flag) {
|
2023-11-22 15:47:48 +08:00
|
|
|
if (item.sku == undefined || item.sku == null || item.sku == '') {
|
|
|
|
flag = false;
|
|
|
|
str = '规格不能为空';
|
|
|
|
}
|
2023-11-22 18:16:45 +08:00
|
|
|
else if (!item.price||+item.price<=0) {
|
2023-11-22 15:47:48 +08:00
|
|
|
flag = false;
|
|
|
|
str = '零售价不能小于等于0';
|
|
|
|
}
|
2023-11-22 18:16:45 +08:00
|
|
|
else if (!item.stock||+item.stock<=0) {
|
2023-11-22 15:47:48 +08:00
|
|
|
flag = false;
|
|
|
|
str = '库存不能小于等于0';
|
|
|
|
}
|
2024-01-18 17:43:09 +08:00
|
|
|
// else if (!item.cost||+item.cost<=0) {
|
|
|
|
// flag = false;
|
|
|
|
// str = '成本价不能小于等于0';
|
|
|
|
// }
|
2023-11-22 18:16:45 +08:00
|
|
|
else if ((!item.procure_price||+item.procure_price<=0) && this.userInfo.mer_info.type_code == 'TypeSupplyChain') {
|
2023-11-22 15:47:48 +08:00
|
|
|
flag = false;
|
|
|
|
str = '批发价不能小于等于0';
|
|
|
|
}
|
2023-11-20 18:38:50 +08:00
|
|
|
}
|
|
|
|
})
|
2023-11-22 15:47:48 +08:00
|
|
|
if (!flag) return Toast(str);
|
2023-11-21 19:13:43 +08:00
|
|
|
else {
|
2023-11-22 15:47:48 +08:00
|
|
|
uni.$emit('updateSpecType', {
|
|
|
|
attr: this.attr,
|
|
|
|
attrValue: this.attrValue
|
|
|
|
});
|
2023-11-21 19:13:43 +08:00
|
|
|
uni.navigateBack();
|
|
|
|
}
|
2023-11-20 18:38:50 +08:00
|
|
|
},
|
|
|
|
// 选择图片
|
|
|
|
clk(uuid) {
|
|
|
|
this.uuid = uuid;
|
|
|
|
let avatar = this.$refs.avatar;
|
|
|
|
avatar.fChooseImg(1, { selWidth: '350upx', selHeight: '350upx', inner: true });
|
|
|
|
},
|
|
|
|
doUpload(rsp) {
|
|
|
|
// console.log(rsp);
|
|
|
|
let that = this
|
|
|
|
uni.uploadFile({
|
|
|
|
url: HTTP_REQUEST_URL + '/api/upload/image/field',
|
|
|
|
filePath: rsp.path,
|
|
|
|
name: 'field',
|
|
|
|
formData: {
|
|
|
|
'filename': rsp.path,
|
|
|
|
'name': that.imgName
|
|
|
|
},
|
|
|
|
header: {
|
|
|
|
// #ifdef MP
|
|
|
|
"Content-Type": "multipart/form-data",
|
|
|
|
// #endif
|
|
|
|
[TOKENNAME]: 'Bearer ' + this.$store.state.app.token
|
|
|
|
},
|
|
|
|
success: (uploadFileRes) => {
|
|
|
|
let imgData = JSON.parse(uploadFileRes.data)
|
2023-11-21 19:13:43 +08:00
|
|
|
let item = this.attrValue.find(item => item.uuid == this.uuid);
|
2023-11-20 18:38:50 +08:00
|
|
|
item.image = imgData.data.path;
|
|
|
|
},
|
|
|
|
complete(res) {
|
|
|
|
// console.log(res)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
getImgName(name) {
|
|
|
|
this.imgName = name
|
|
|
|
},
|
|
|
|
// 删除图片
|
|
|
|
deleteImage(item) {
|
|
|
|
item.image = '';
|
|
|
|
},
|
|
|
|
// 添加规格
|
2023-11-21 19:13:43 +08:00
|
|
|
addAttrValue() {
|
2023-11-22 15:47:48 +08:00
|
|
|
this.attrValue.push(Object.assign({}, this.attr_mode, {
|
|
|
|
uuid: Date.now() + '-' + Math.floor(Math.random() * 10000) // 重设uuid
|
|
|
|
}))
|
2023-11-20 18:38:50 +08:00
|
|
|
},
|
|
|
|
// 预删除
|
2023-11-21 19:13:43 +08:00
|
|
|
deleteByIndex(index) {
|
2023-11-20 18:38:50 +08:00
|
|
|
this.deleteIndex = index;
|
|
|
|
this.showDelete = true;
|
|
|
|
},
|
|
|
|
// 删除规格
|
2023-11-21 19:13:43 +08:00
|
|
|
deleteAttr() {
|
2023-11-20 18:38:50 +08:00
|
|
|
this.attrValue.splice(this.deleteIndex, 1);
|
|
|
|
this.showDelete = false;
|
2023-11-22 17:08:05 +08:00
|
|
|
},
|
|
|
|
// 初始化规格模板
|
|
|
|
initAttrModeList(){
|
|
|
|
attrList(this.userInfo.service.mer_id,{
|
|
|
|
page: 1,
|
|
|
|
limit: 10000
|
|
|
|
}).then((res)=>{
|
|
|
|
console.log(res);
|
|
|
|
this.attr_mode_list = res.data.list;
|
|
|
|
})
|
|
|
|
},
|
|
|
|
changAttrMode(e){
|
|
|
|
this.attr_template_id = this.attr_mode_list[e.detail.value].attr_template_id;
|
|
|
|
this.template_name = this.attr_mode_list[e.detail.value].template_name;
|
|
|
|
this.attr = JSON.parse(JSON.stringify(this.attr_mode_list[e.detail.value].template_value));
|
|
|
|
this.$set(this, 'attrValue', []);
|
|
|
|
this.addAttrValueCard();
|
2023-11-20 14:53:54 +08:00
|
|
|
}
|
2023-11-20 18:38:50 +08:00
|
|
|
},
|
|
|
|
onBackPress: () => {
|
2023-11-21 19:13:43 +08:00
|
|
|
|
2023-11-20 14:53:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2023-11-20 18:38:50 +08:00
|
|
|
<style lang="scss">
|
2023-11-21 19:13:43 +08:00
|
|
|
@import './scss/index.scss';
|
|
|
|
|
2023-11-22 15:47:48 +08:00
|
|
|
.page{
|
|
|
|
padding-bottom: 150rpx;
|
|
|
|
}
|
|
|
|
|
2023-11-21 19:13:43 +08:00
|
|
|
.popup_group {
|
|
|
|
margin-bottom: 0;
|
2023-11-20 18:38:50 +08:00
|
|
|
}
|
2023-11-21 19:13:43 +08:00
|
|
|
|
|
|
|
.popup_group_item {
|
|
|
|
border-bottom: 1rpx solid #eee;
|
|
|
|
padding-left: 18rpx !important;
|
|
|
|
|
|
|
|
.close-icon {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
width: 30rpx;
|
|
|
|
height: 30rpx;
|
|
|
|
border-radius: 10rpx;
|
|
|
|
overflow: hidden;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
background-color: rgba(#000, 0.4);
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
|
2023-11-20 18:38:50 +08:00
|
|
|
}
|
2023-11-21 19:13:43 +08:00
|
|
|
|
|
|
|
.head_close {
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
.delete_btn {
|
|
|
|
position: absolute;
|
|
|
|
top: -15rpx;
|
|
|
|
right: -15rpx;
|
|
|
|
width: 40rpx;
|
|
|
|
height: 40rpx;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
background-color: red;
|
|
|
|
color: #fff;
|
|
|
|
border-radius: 50%;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
.add_btn {
|
|
|
|
width: 710rpx;
|
|
|
|
margin: 28rpx auto;
|
|
|
|
margin-bottom: 160rpx;
|
|
|
|
font-size: 30rpx;
|
|
|
|
padding: 28rpx;
|
|
|
|
color: #333;
|
|
|
|
}
|
|
|
|
|
|
|
|
.submit {
|
|
|
|
position: fixed;
|
|
|
|
bottom: 0;
|
|
|
|
left: 0;
|
|
|
|
width: 100%;
|
|
|
|
background-color: #fff;
|
|
|
|
padding: 20rpx 0;
|
|
|
|
|
|
|
|
.btn {
|
|
|
|
width: 694rpx;
|
|
|
|
height: 80rpx;
|
|
|
|
margin: 0 auto;
|
|
|
|
background: #e93323;
|
|
|
|
border-radius: 43px;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
font-size: 15px;
|
|
|
|
color: #ffffff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.mode {
|
|
|
|
width: 100%;
|
|
|
|
background-color: #fff;
|
2023-11-22 17:08:05 +08:00
|
|
|
position: fixed;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
z-index: 1;
|
2023-11-21 19:13:43 +08:00
|
|
|
|
|
|
|
.line {
|
2023-11-22 17:08:05 +08:00
|
|
|
padding: 0 28rpx;
|
|
|
|
height: 80rpx;
|
2023-11-21 19:13:43 +08:00
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: center;
|
|
|
|
font-size: 28rpx;
|
|
|
|
|
|
|
|
.btn {
|
|
|
|
background-color: #f84221;
|
|
|
|
color: #fff;
|
|
|
|
width: 140rpx;
|
|
|
|
height: 50rpx;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
border-radius: 10rpx;
|
|
|
|
}
|
|
|
|
|
|
|
|
.input {
|
|
|
|
flex: 1;
|
|
|
|
padding: 0 16rpx;
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.btn-box {
|
2023-11-22 17:08:05 +08:00
|
|
|
height: 80rpx;
|
2023-11-21 19:13:43 +08:00
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
2023-11-22 17:08:05 +08:00
|
|
|
align-items: center;
|
2023-11-21 19:13:43 +08:00
|
|
|
border-top: 1rpx solid #eee;
|
2023-11-22 17:08:05 +08:00
|
|
|
border-bottom: 1rpx solid #eee;
|
2023-11-21 19:13:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
.mode-ref {
|
|
|
|
|
|
|
|
.mode-item {
|
|
|
|
margin: 20rpx;
|
|
|
|
border: 1rpx solid #eee;
|
|
|
|
border-radius: 10rpx;
|
|
|
|
font-size: 26rpx;
|
|
|
|
position: relative;
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
.mode-head {
|
|
|
|
padding-top: 20rpx;
|
|
|
|
padding-left: 20rpx;
|
|
|
|
font-size: 32rpx;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
.mode-body {
|
|
|
|
display: flex;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
padding: 20rpx;
|
|
|
|
padding-left: 0;
|
|
|
|
|
|
|
|
.box {
|
|
|
|
padding: 10rpx 20rpx;
|
|
|
|
border: 1px solid #f84221;
|
|
|
|
margin-left: 20rpx;
|
|
|
|
border-radius: 10rpx;
|
|
|
|
margin-bottom: 10rpx;
|
|
|
|
background-color: rgba(#f84221, 0.1);
|
|
|
|
color: #f84221;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.mode-body-add {
|
|
|
|
border: 1rpx solid #ddd;
|
|
|
|
background-color: #fff;
|
|
|
|
color: #333;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.delete-spec {
|
|
|
|
position: absolute;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
background-color: #eee;
|
|
|
|
padding: 5rpx;
|
|
|
|
border-radius: 0 0 0 10rpx;
|
|
|
|
color: #f84221;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.tab {
|
|
|
|
padding: 20rpx;
|
|
|
|
border-top: 1rpx solid #eee;
|
|
|
|
display: flex;
|
|
|
|
font-size: 28rpx;
|
|
|
|
|
|
|
|
.add-btn {
|
|
|
|
flex: 1;
|
|
|
|
background-color: #f84221;
|
|
|
|
color: #fff;
|
|
|
|
padding: 10rpx;
|
|
|
|
text-align: center;
|
|
|
|
border-radius: 10rpx;
|
|
|
|
}
|
|
|
|
|
|
|
|
.save {
|
|
|
|
color: #333;
|
|
|
|
border: 1rpx solid #ddd;
|
|
|
|
padding: 10rpx;
|
|
|
|
text-align: center;
|
|
|
|
border-radius: 10rpx;
|
|
|
|
margin-left: 20rpx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.input-mode {
|
|
|
|
width: 694rpx;
|
|
|
|
padding: 28rpx;
|
|
|
|
font-size: 28rpx;
|
|
|
|
border-radius: 10rpx;
|
|
|
|
background-color: #fff;
|
|
|
|
|
|
|
|
.head-tips {
|
|
|
|
font-size: 32rpx;
|
|
|
|
font-weight: bold;
|
|
|
|
text-align: center;
|
|
|
|
padding-bottom: 20rpx;
|
|
|
|
}
|
|
|
|
|
|
|
|
.input-box {
|
|
|
|
input {
|
|
|
|
height: 80rpx;
|
|
|
|
margin-bottom: 20rpx;
|
|
|
|
font-size: 28rpx;
|
|
|
|
border: 1rpx solid #ddd;
|
|
|
|
padding: 0 20rpx;
|
|
|
|
border-radius: 10rpx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.show-btn-box {
|
|
|
|
width: 100%;
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
|
|
.cof,
|
|
|
|
.can {
|
|
|
|
height: 80rpx;
|
|
|
|
line-height: 80rpx;
|
|
|
|
width: 300rpx;
|
|
|
|
text-align: center;
|
|
|
|
border: 1rpx solid #ddd;
|
|
|
|
border-radius: 10rpx;
|
|
|
|
}
|
|
|
|
|
|
|
|
.prai {
|
|
|
|
background-color: #f84221;
|
|
|
|
border: 1rpx solid #f84221;
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-20 18:38:50 +08:00
|
|
|
}
|
2023-11-20 14:53:54 +08:00
|
|
|
</style>
|