更新了添加模板, 保存模板的功能

This commit is contained in:
weipengfei 2023-11-22 18:59:13 +08:00
parent 9408cb41f0
commit 088beed4e9
1 changed files with 74 additions and 9 deletions

View File

@ -9,7 +9,7 @@
<uni-icons type="right"></uni-icons> <uni-icons type="right"></uni-icons>
</view> </view>
</picker> </picker>
<view class="btn">添加模板</view> <view class="btn" @click="preAddMode(3)">添加模板</view>
</view> </view>
<view class="btn-box" @click="settingSpec()"> <view class="btn-box" @click="settingSpec()">
<view class="btn">点击设置规格</view> <view class="btn">点击设置规格</view>
@ -38,17 +38,22 @@
</scroll-view> </scroll-view>
<view class="tab"> <view class="tab">
<view class="add-btn" @click="addSpecOne()">添加新规格</view> <view class="add-btn" @click="addSpecOne()">添加新规格</view>
<view class="save">保存模板</view> <view class="save" @click="saveAttrMode()">保存模板</view>
</view> </view>
</view> </view>
</uni-popup> </uni-popup>
<uni-popup ref="inputModeRef" type="center"> <uni-popup ref="inputModeRef" type="center">
<view class="input-mode"> <view class="input-mode">
<view class="head-tips">{{addAttrType==1?'添加规格值': '添加新规格'}}</view> <view class="head-tips">
<view v-if="addAttrType==1">添加规格值</view>
<view v-else-if="addAttrType==2">添加新规格</view>
<view v-else>添加模板</view>
</view>
<view class="input-box"> <view class="input-box">
<input v-if="addAttrType==2" v-model="attrName" placeholder="请输入规格名称" /> <input v-if="addAttrType==4||addAttrType==3" v-model="attrMode" placeholder="请输入模板名称" />
<input v-model="attrDetail" placeholder="请输入规格值" /> <input v-if="addAttrType==2||addAttrType==3" v-model="attrName" placeholder="请输入规格名称" />
<input v-if="addAttrType!=4" v-model="attrDetail" placeholder="请输入规格值" />
</view> </view>
<view class="show-btn-box"> <view class="show-btn-box">
<view class="cof prai" @click="addAttr()">确认</view> <view class="cof prai" @click="addAttr()">确认</view>
@ -110,7 +115,8 @@
import { Toast } from "../../../libs/uniApi"; import { Toast } from "../../../libs/uniApi";
import { import {
specificationUpdate, specificationUpdate,
attrList attrList,
specificationAdd
} from "@/api/product.js" } from "@/api/product.js"
export default { export default {
components: { components: {
@ -140,9 +146,10 @@
deleteIndex: '', // deleteIndex: '', //
showDelete: false, showDelete: false,
userInfo: {}, userInfo: {},
addAttrType: 1, // , 1, 2 addAttrType: 1, // , 1, 2, 3, 4
attrName: '', // attrName: '', //
attrDetail: '', // attrDetail: '', //
attrMode: '', //
changeAttr: 0, // changeAttr: 0, //
} }
}, },
@ -294,7 +301,7 @@
this.addAttrValueCard(); this.addAttrValueCard();
}) })
} }
} else { // 1 } else if (this.addAttrType == 2) { // 1
if (this.attr.find(item => item.value == this.attrName)) { if (this.attr.find(item => item.value == this.attrName)) {
this.closeAddAttr(); this.closeAddAttr();
this.$nextTick(() => { this.$nextTick(() => {
@ -323,11 +330,69 @@
} }
this.closeAddAttr(); this.closeAddAttr();
} }
} else if (this.addAttrType == 3 || this.addAttrType == 4){
this.addNewAttrMode();
} }
}, },
// //
saveAttrMode() { saveAttrMode() {
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();
}, },
// //
submitAttr() { submitAttr() {