|
|
|
|
@@ -1,62 +1,53 @@
|
|
|
|
|
<template>
|
|
|
|
|
<view class="page">
|
|
|
|
|
<view class="box">
|
|
|
|
|
<view class="block border-top-0">
|
|
|
|
|
<uni-forms ref="nameFormRef" :model="specifications" :rules="rules" :label-width="350"
|
|
|
|
|
label-position="top" validateTrigger="blur">
|
|
|
|
|
<uni-forms-item label="模版名称" required name="name">
|
|
|
|
|
<uni-easyinput :placeholderStyle="placeholderStyle" :inputBorder="inputBorder"
|
|
|
|
|
v-model="specifications.name" placeholder="模版名称,如:衣服" />
|
|
|
|
|
</uni-forms-item>
|
|
|
|
|
</uni-forms>
|
|
|
|
|
</view>
|
|
|
|
|
<view v-for="(item,index) in specifications.list" :key="index">
|
|
|
|
|
<uni-forms :model="item" :rules="rules" err-show-type="undertext" validateTrigger="blur"
|
|
|
|
|
:ref="setFormRef(index)" :border="true" label-position="top" label-width="350">
|
|
|
|
|
|
|
|
|
|
<view class="block">
|
|
|
|
|
<view class="border-top-0">
|
|
|
|
|
<uni-forms-item label="规格组名" required name="name">
|
|
|
|
|
<uni-easyinput :placeholderStyle="placeholderStyle" :inputBorder="inputBorder"
|
|
|
|
|
v-model="item.name" placeholder="规格组名" />
|
|
|
|
|
v-model="item.name" placeholder="规格组名,如:尺码" />
|
|
|
|
|
</uni-forms-item>
|
|
|
|
|
</view>
|
|
|
|
|
<!-- <uni-forms-item label="最少可选" required name="MinOptional" >
|
|
|
|
|
<uni-easyinput :placeholderStyle="placeholderStyle" :inputBorder="inputBorder"
|
|
|
|
|
v-model="item.MinOptional" type="number" placeholder="填写最小数量" />
|
|
|
|
|
</uni-forms-item>
|
|
|
|
|
<uni-forms-item label="最大可选" required name="MaxOptional" >
|
|
|
|
|
<uni-easyinput :placeholderStyle="placeholderStyle" :inputBorder="inputBorder"
|
|
|
|
|
v-model="item.MaxOptional" type="number" placeholder="填写最大数量" />
|
|
|
|
|
</uni-forms-item> -->
|
|
|
|
|
<uni-forms-item label="选项值">
|
|
|
|
|
<uni-forms-item label="规格值">
|
|
|
|
|
<view class="option">
|
|
|
|
|
<view class="u-flex">
|
|
|
|
|
<view class="u-flex-1">名称</view>
|
|
|
|
|
<view class="u-flex-1 u-p-l-60">加价</view>
|
|
|
|
|
</view>
|
|
|
|
|
<view class="u-m-t-32">
|
|
|
|
|
<view class="u-flex option-item"
|
|
|
|
|
|
|
|
|
|
v-for="(option,optionIndex) in item.options"
|
|
|
|
|
:key="optionIndex"
|
|
|
|
|
>
|
|
|
|
|
<view class="">
|
|
|
|
|
<view class="u-flex option-item" v-for="(option,optionIndex) in item.options"
|
|
|
|
|
:key="optionIndex">
|
|
|
|
|
<view class="u-flex-1">
|
|
|
|
|
<uni-forms-item :key="optionIndex" :name="['options',optionIndex,'optionName']"
|
|
|
|
|
<uni-forms-item :key="optionIndex" :name="['options',optionIndex,'name']"
|
|
|
|
|
:ref="setFormInputRef(index,optionIndex)"
|
|
|
|
|
:rules="[{'required': true,errorMessage: '必填'}]"
|
|
|
|
|
label-width="0" label="" required :showRequired="false"
|
|
|
|
|
>
|
|
|
|
|
<uni-easyinput v-model="specifications.list[index].options[optionIndex].optionName"
|
|
|
|
|
:rules="[{'required': true,errorMessage: '必填'}]" label-width="0"
|
|
|
|
|
label="" required :showRequired="false">
|
|
|
|
|
<uni-easyinput
|
|
|
|
|
v-model="specifications.list[index].options[optionIndex].name"
|
|
|
|
|
@input="inpuChange(index,optionIndex)"
|
|
|
|
|
|
|
|
|
|
:placeholderStyle="placeholderStyle" :inputBorder="inputBorder"
|
|
|
|
|
placeholder="选项名" />
|
|
|
|
|
placeholder="请输入规格值,如:S、M" />
|
|
|
|
|
</uni-forms-item>
|
|
|
|
|
|
|
|
|
|
</view>
|
|
|
|
|
<view class="u-p-l-60 u-flex-1 u-flex">
|
|
|
|
|
<uni-forms-item :key="optionIndex"
|
|
|
|
|
:rules="[{'required': true,errorMessage: '必填'}]"
|
|
|
|
|
:ref="setFormInputRef(index,optionIndex)"
|
|
|
|
|
:name="['options',optionIndex,'optionPrice']" label-width="0" label="" required :showRequired="false"
|
|
|
|
|
>
|
|
|
|
|
<view class=" u-flex">
|
|
|
|
|
<uni-easyinput v-model="specifications.list[index].options[optionIndex].optionPrice"
|
|
|
|
|
<uni-forms-item :key="optionIndex" label-width="0" label=""
|
|
|
|
|
:showRequired="false">
|
|
|
|
|
<view class="u-flex">
|
|
|
|
|
<!-- <uni-easyinput v-model="specifications.list[index].options[optionIndex].optionPrice"
|
|
|
|
|
@input="inpuChange(index,optionIndex)"
|
|
|
|
|
|
|
|
|
|
:placeholderStyle="placeholderStyle" :inputBorder="inputBorder"
|
|
|
|
|
type="digit" placeholder="填写价格" />
|
|
|
|
|
type="digit" placeholder="填写价格" /> -->
|
|
|
|
|
|
|
|
|
|
<view class="icon icon-reduce u-m-l-38"
|
|
|
|
|
@click="delOption(index,optionIndex)">
|
|
|
|
|
@@ -106,10 +97,14 @@
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
import go from '@/commons/utils/go.js';
|
|
|
|
|
import {
|
|
|
|
|
$productSpec
|
|
|
|
|
} from '@/http/yskApi/goods.js'
|
|
|
|
|
import {
|
|
|
|
|
onLoad,
|
|
|
|
|
onReady
|
|
|
|
|
onReady,
|
|
|
|
|
} from '@dcloudio/uni-app';
|
|
|
|
|
import infoBox from '@/commons/utils/infoBox.js'
|
|
|
|
|
import {
|
|
|
|
|
onMounted,
|
|
|
|
|
reactive,
|
|
|
|
|
@@ -117,6 +112,7 @@
|
|
|
|
|
ref,
|
|
|
|
|
onBeforeMount
|
|
|
|
|
} from 'vue';
|
|
|
|
|
const nameFormRef = ref(null)
|
|
|
|
|
// 表单样式
|
|
|
|
|
const placeholderStyle = ref('font-size:28rpx;')
|
|
|
|
|
//表单边框
|
|
|
|
|
@@ -143,12 +139,6 @@
|
|
|
|
|
errorMessage: '必填'
|
|
|
|
|
}]
|
|
|
|
|
},
|
|
|
|
|
optionName: {
|
|
|
|
|
rules: [{
|
|
|
|
|
required: true,
|
|
|
|
|
errorMessage: '必填'
|
|
|
|
|
}]
|
|
|
|
|
},
|
|
|
|
|
optionPrice: {
|
|
|
|
|
rules: [{
|
|
|
|
|
required: true,
|
|
|
|
|
@@ -160,7 +150,7 @@
|
|
|
|
|
|
|
|
|
|
// 构造规格的选项值的基础数据
|
|
|
|
|
const specificationsOptionsBasicData = {
|
|
|
|
|
optionName: '',
|
|
|
|
|
name: '',
|
|
|
|
|
optionPrice: '0.00'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -172,8 +162,8 @@
|
|
|
|
|
// 构造规格的基础数据
|
|
|
|
|
const specificationsBasicData = {
|
|
|
|
|
name: '',
|
|
|
|
|
MinOptional: 1,
|
|
|
|
|
MaxOptional: 1,
|
|
|
|
|
// MinOptional: 1,
|
|
|
|
|
// MaxOptional: 1,
|
|
|
|
|
options: []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -189,6 +179,7 @@
|
|
|
|
|
}
|
|
|
|
|
// 规格列表
|
|
|
|
|
const specifications = reactive({
|
|
|
|
|
name: '',
|
|
|
|
|
list: [returnSpecificationsOptionsBasicData()]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
@@ -236,6 +227,7 @@
|
|
|
|
|
}
|
|
|
|
|
// 绑定option input元素
|
|
|
|
|
const refFormInput = ref([])
|
|
|
|
|
|
|
|
|
|
function setFormInputRef(index, index1) {
|
|
|
|
|
const newIndex = index * 10000 + index1
|
|
|
|
|
return (el) => {
|
|
|
|
|
@@ -258,55 +250,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let emitName=''
|
|
|
|
|
function triggerEvent (emitName,data){
|
|
|
|
|
if(emitName){
|
|
|
|
|
uni.$emit(emitName,data)
|
|
|
|
|
}
|
|
|
|
|
const option = {
|
|
|
|
|
type: 'add',
|
|
|
|
|
id: undefined
|
|
|
|
|
}
|
|
|
|
|
onLoad(opt => {
|
|
|
|
|
const arr=uni.getStorageSync('guige')
|
|
|
|
|
if(arr.length){
|
|
|
|
|
specifications.list=arr
|
|
|
|
|
console.log(arr);
|
|
|
|
|
}
|
|
|
|
|
console.log(opt);
|
|
|
|
|
if(opt&&JSON.stringify(opt)!=='{}'&&opt.emitName){
|
|
|
|
|
emitName=opt.emitName
|
|
|
|
|
if (opt && JSON.stringify(opt) !== '{}' && opt.type) {
|
|
|
|
|
option.type = opt.type
|
|
|
|
|
const data = uni.getStorageSync('spec')
|
|
|
|
|
uni.removeStorageSync('spec')
|
|
|
|
|
if(data){
|
|
|
|
|
specifications.name = data.name
|
|
|
|
|
specifications.id = data.id
|
|
|
|
|
specifications.list = data.specList.map(v => {
|
|
|
|
|
return {
|
|
|
|
|
...v,
|
|
|
|
|
options: v.value.map(v => {
|
|
|
|
|
return {
|
|
|
|
|
name: v
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
uni.setNavigationBarTitle({
|
|
|
|
|
title:emitName?'编辑规格模版':'添加规格模版'
|
|
|
|
|
title: option.type === 'edit' ? '编辑规格模版' : '添加规格模版'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
function emitspecificationsSave(){
|
|
|
|
|
// emitspecificationsSave 触发规格保存事件将数据给到添加商品页面
|
|
|
|
|
// guigeEdit 触发规格保存事件将数据给到添加规格页面
|
|
|
|
|
uni.removeStorageSync('guige')
|
|
|
|
|
triggerEvent(emitName,specifications.list)
|
|
|
|
|
}
|
|
|
|
|
function returnPromise(index,prosise){
|
|
|
|
|
|
|
|
|
|
function returnPromise(prosise, index) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
prosise.then(res => {
|
|
|
|
|
console.log(res);
|
|
|
|
|
resolve({sucees:true})
|
|
|
|
|
resolve({
|
|
|
|
|
sucees: true
|
|
|
|
|
})
|
|
|
|
|
}).catch(err => {
|
|
|
|
|
console.log(err);
|
|
|
|
|
resolve({sucees:false})
|
|
|
|
|
resolve({
|
|
|
|
|
sucees: false
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let timer = null
|
|
|
|
|
|
|
|
|
|
function settimeoutBack(time) {
|
|
|
|
|
clearTimeout(timer)
|
|
|
|
|
timer = setTimeout(() => {
|
|
|
|
|
uni.navigateBack()
|
|
|
|
|
}, time)
|
|
|
|
|
}
|
|
|
|
|
async function save() {
|
|
|
|
|
let isAllPassForm = 0
|
|
|
|
|
const nameFormRes = await returnPromise(nameFormRef.value.validate())
|
|
|
|
|
console.log(nameFormRes);
|
|
|
|
|
if (!nameFormRes.sucees) {
|
|
|
|
|
isAllPassForm -= 1
|
|
|
|
|
}
|
|
|
|
|
for (let i in specifications.list) {
|
|
|
|
|
const res=await returnPromise(i,formRefs.value[i].validate())
|
|
|
|
|
const res = await returnPromise(formRefs.value[i].validate(), i)
|
|
|
|
|
isAllPassForm += res.sucees ? 1 : 0
|
|
|
|
|
}
|
|
|
|
|
//判断验证是否通过
|
|
|
|
|
if (isAllPassForm === specifications.list.length) {
|
|
|
|
|
console.log('pass');
|
|
|
|
|
emitspecificationsSave()
|
|
|
|
|
go.back()
|
|
|
|
|
const data = {
|
|
|
|
|
name: specifications.name,
|
|
|
|
|
id:specifications.id,
|
|
|
|
|
specList: specifications.list.map(v => {
|
|
|
|
|
return {
|
|
|
|
|
...v,
|
|
|
|
|
value: v.options.map(v => v.name),
|
|
|
|
|
options: undefined
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if (option.type === 'add') {
|
|
|
|
|
return $productSpec.add(data).then(res => {
|
|
|
|
|
infoBox.showSuccessToast('添加成功')
|
|
|
|
|
settimeoutBack(1500)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$productSpec.update(data).then(res => {
|
|
|
|
|
infoBox.showSuccessToast('修改成功')
|
|
|
|
|
settimeoutBack(1500)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|