更新订单列表详情,更新商品管理,更新代客下单
This commit is contained in:
@@ -1,53 +1,62 @@
|
||||
<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-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="规格值">
|
||||
<!-- <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="选项值">
|
||||
<view class="option">
|
||||
<view class="">
|
||||
<view class="u-flex option-item" v-for="(option,optionIndex) in item.options"
|
||||
:key="optionIndex">
|
||||
<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="u-flex-1">
|
||||
<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].name"
|
||||
@input="inpuChange(index,optionIndex)"
|
||||
<uni-forms-item :key="optionIndex" :name="['options',optionIndex,'optionName']"
|
||||
: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"
|
||||
@input="inpuChange(index,optionIndex)"
|
||||
|
||||
:placeholderStyle="placeholderStyle" :inputBorder="inputBorder"
|
||||
placeholder="请输入规格值,如:S、M" />
|
||||
placeholder="选项名" />
|
||||
</uni-forms-item>
|
||||
|
||||
</view>
|
||||
<view class=" u-flex">
|
||||
<uni-forms-item :key="optionIndex" label-width="0" label=""
|
||||
:showRequired="false">
|
||||
<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-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)">
|
||||
@@ -70,7 +79,7 @@
|
||||
|
||||
</view>
|
||||
</uni-forms-item>
|
||||
|
||||
|
||||
<view class="u-flex u-m-t-48 u-m-b-24" @click="delSpecificationsGroup(index)">
|
||||
<view class="icon icon-reduce u-m-r-22 ">
|
||||
|
||||
@@ -97,14 +106,10 @@
|
||||
|
||||
<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,
|
||||
@@ -112,9 +117,8 @@
|
||||
ref,
|
||||
onBeforeMount
|
||||
} from 'vue';
|
||||
const nameFormRef = ref(null)
|
||||
// 表单样式
|
||||
const placeholderStyle = ref('font-size:28rpx;')
|
||||
const placeholderStyle = ref('font-size:28rpx;')
|
||||
//表单边框
|
||||
const inputBorder = ref(false)
|
||||
const form = ref(null)
|
||||
@@ -139,6 +143,12 @@
|
||||
errorMessage: '必填'
|
||||
}]
|
||||
},
|
||||
optionName: {
|
||||
rules: [{
|
||||
required: true,
|
||||
errorMessage: '必填'
|
||||
}]
|
||||
},
|
||||
optionPrice: {
|
||||
rules: [{
|
||||
required: true,
|
||||
@@ -147,10 +157,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 构造规格的选项值的基础数据
|
||||
const specificationsOptionsBasicData = {
|
||||
name: '',
|
||||
optionName: '',
|
||||
optionPrice: '0.00'
|
||||
}
|
||||
|
||||
@@ -162,8 +172,8 @@
|
||||
// 构造规格的基础数据
|
||||
const specificationsBasicData = {
|
||||
name: '',
|
||||
// MinOptional: 1,
|
||||
// MaxOptional: 1,
|
||||
MinOptional: 1,
|
||||
MaxOptional: 1,
|
||||
options: []
|
||||
}
|
||||
|
||||
@@ -179,7 +189,6 @@
|
||||
}
|
||||
// 规格列表
|
||||
const specifications = reactive({
|
||||
name: '',
|
||||
list: [returnSpecificationsOptionsBasicData()]
|
||||
})
|
||||
|
||||
@@ -226,8 +235,7 @@
|
||||
};
|
||||
}
|
||||
// 绑定option input元素
|
||||
const refFormInput = ref([])
|
||||
|
||||
const refFormInput=ref([])
|
||||
function setFormInputRef(index, index1) {
|
||||
const newIndex = index * 10000 + index1
|
||||
return (el) => {
|
||||
@@ -244,104 +252,61 @@
|
||||
console.log(refFormInput.value[newIndex]);
|
||||
refFormInput.value[newIndex].onFieldChange()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const option = {
|
||||
type: 'add',
|
||||
id: undefined
|
||||
|
||||
|
||||
let emitName=''
|
||||
function triggerEvent (emitName,data){
|
||||
if(emitName){
|
||||
uni.$emit(emitName,data)
|
||||
}
|
||||
}
|
||||
onLoad(opt => {
|
||||
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.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
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if(opt&&JSON.stringify(opt)!=='{}'&&opt.emitName){
|
||||
emitName=opt.emitName
|
||||
}
|
||||
uni.setNavigationBarTitle({
|
||||
title: option.type === 'edit' ? '编辑规格模版' : '添加规格模版'
|
||||
title:emitName?'编辑规格模版':'添加规格模版'
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
|
||||
function returnPromise(prosise, index) {
|
||||
return new Promise((resolve, reject) => {
|
||||
prosise.then(res => {
|
||||
function emitspecificationsSave(){
|
||||
// emitspecificationsSave 触发规格保存事件将数据给到添加商品页面
|
||||
// guigeEdit 触发规格保存事件将数据给到添加规格页面
|
||||
uni.removeStorageSync('guige')
|
||||
triggerEvent(emitName,specifications.list)
|
||||
}
|
||||
function returnPromise(index,prosise){
|
||||
return new Promise((resolve,reject)=>{
|
||||
prosise.then(res=>{
|
||||
console.log(res);
|
||||
resolve({
|
||||
sucees: true
|
||||
})
|
||||
}).catch(err => {
|
||||
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
|
||||
}
|
||||
async function save() {
|
||||
let isAllPassForm=0
|
||||
for (let i in specifications.list) {
|
||||
const res = await returnPromise(formRefs.value[i].validate(), i)
|
||||
isAllPassForm += res.sucees ? 1 : 0
|
||||
const res=await returnPromise(i,formRefs.value[i].validate())
|
||||
isAllPassForm+=res.sucees?1:0
|
||||
}
|
||||
//判断验证是否通过
|
||||
if (isAllPassForm === specifications.list.length) {
|
||||
if(isAllPassForm===specifications.list.length){
|
||||
console.log('pass');
|
||||
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)
|
||||
})
|
||||
emitspecificationsSave()
|
||||
go.back()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user