代码更新
This commit is contained in:
@@ -3,24 +3,22 @@
|
||||
<view class="default-box-padding bg-fff border-r-18">
|
||||
<view class="u-flex u-row-between">
|
||||
<view>商品名称</view>
|
||||
<!-- <template v-if="isSku"> -->
|
||||
<view class="u-flex u-font-24 color-666">
|
||||
<view class="u-m-r-20">绑定至规格</view>
|
||||
<view class="u-flex u-relative">
|
||||
<up-switch :size="18" v-model="isBindGuige" :disabled="!isSku">绑定至规格</up-switch>
|
||||
<up-switch :size="18" v-model="pageData.isBindGuige" :disabled="!isSku">绑定至规格</up-switch>
|
||||
<view class="u-absolute position-all" style="z-index: 1;" v-if="!isSku"
|
||||
@click="infoBox.showToast('该商品是单规格商品,只有多规格商品可绑定至规格',3)"></view>
|
||||
@click="infoBox.showToast('只有单规格或者多规格商品可绑定至规格',3)"></view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- </template> -->
|
||||
</view>
|
||||
<view class="border-bottom u-m-t-16 u-p-b-32">{{goods.name}}</view>
|
||||
<view class="border-bottom u-m-t-16 u-p-b-32">{{skuList.length}}{{goods.name}}</view>
|
||||
<view class="">
|
||||
<template v-if="isBindGuige&&isSku">
|
||||
<template v-if="pageData.isBindGuige&&isSku">
|
||||
<view class="list">
|
||||
<view class="u-p-b-32 u-p-t-32 border-bottom" v-for="(sku,index) in skuList" :key="index">
|
||||
<view>规格名称</view>
|
||||
<view class="u-m-t-16">{{sku.specSnap}}</view>
|
||||
<view class="u-m-t-16">{{sku.specInfo}}</view>
|
||||
<view class="color-666 u-m-t-24 u-flex">
|
||||
<view class="xuhao">序号</view>
|
||||
<view class="u-flex u-flex-1 u-p-l-32 gap-20">
|
||||
@@ -37,7 +35,7 @@
|
||||
<view class="u-flex-1 ">
|
||||
<choose-haocai @change="conInfosChange($event,item)"
|
||||
:listMap="$haocaiMap" :list="haoCaiList"
|
||||
v-model="item.conInfoId"></choose-haocai>
|
||||
v-model="item.consInfoId"></choose-haocai>
|
||||
</view>
|
||||
<view class="u-flex-1 ">
|
||||
<choose-danwei :listMap="$danweiMap" :list="danweiList"
|
||||
@@ -88,19 +86,10 @@
|
||||
<view class="u-flex u-flex-1 u-p-l-32 gap-20">
|
||||
<view class="u-flex-1 ">
|
||||
<choose-haocai @change="conInfosChange($event,item)" :listMap="$haocaiMap"
|
||||
:list="haoCaiList" v-model="item.conInfoId"></choose-haocai>
|
||||
<!-- <view class="u-flex input">
|
||||
<view>{{item.conName}}</view>
|
||||
<up-icon :size="10" name="arrow-down-fill"></up-icon>
|
||||
</view> -->
|
||||
:list="haoCaiList" v-model="item.consInfoId"></choose-haocai>
|
||||
</view>
|
||||
<view class="u-flex-1 ">
|
||||
<choose-danwei :listMap="$danweiMap" :list="danweiList"
|
||||
v-model="item.conUnit"></choose-danwei>
|
||||
<!-- <view class="u-flex input">
|
||||
<view>{{item.conUnit}}</view>
|
||||
<up-icon :size="10" name="arrow-down-fill"></up-icon>
|
||||
</view> -->
|
||||
<choose-danwei v-model="item.conUnit"></choose-danwei>
|
||||
</view>
|
||||
<view class="u-flex-1 ">
|
||||
<view class="u-flex input">
|
||||
@@ -124,7 +113,7 @@
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<template v-if="!isBindGuige">
|
||||
<template v-if="!pageData.isBindGuige">
|
||||
<view class="u-flex">
|
||||
<view class=" u-p-t-32 u-flex" @click="addHaocai">
|
||||
<up-icon :size="18" color="#318AFE" name="plus-circle-fill"></up-icon>
|
||||
@@ -139,9 +128,7 @@
|
||||
<view class="default-box-padding bg-fff border-r-18 u-flex u-row-between u-m-t-32">
|
||||
<view>当某个耗材的使用库存不足时,商品自动
|
||||
售罄。</view>
|
||||
<!-- <view class="u-flex u-p-l-32">
|
||||
<up-switch :size="20"></up-switch>
|
||||
</view> -->
|
||||
|
||||
</view>
|
||||
<view class="bottom">
|
||||
<my-button type="primary" shape="circle" font-weight="700" @click="save">保存</my-button>
|
||||
@@ -153,46 +140,19 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {
|
||||
ref,
|
||||
reactive,
|
||||
toRefs,
|
||||
watch,
|
||||
computed,
|
||||
onMounted
|
||||
}
|
||||
from 'vue';
|
||||
import {
|
||||
getviewConSku,
|
||||
gettbProductSpec,
|
||||
gettbConsInfo,
|
||||
posttbProskuCons,
|
||||
puttbProskuCon,
|
||||
deletetbProskuCon,
|
||||
} from "@/http/yskApi/consumable.js";
|
||||
import {
|
||||
tbShopCurrencyGet,
|
||||
$hasPermission
|
||||
} from '@/http/yskApi/shop.js'
|
||||
import { ref, reactive, watch, computed, onMounted } from 'vue';
|
||||
import { deletetbProskuCon, } from "@/http/yskApi/consumable.js";
|
||||
|
||||
import infoBox from '@/commons/utils/infoBox.js'
|
||||
import chooseHaocai from './choose-haocai.vue';
|
||||
import chooseDanwei from './choose-danwei.vue';
|
||||
import {
|
||||
$tbProskuConV2
|
||||
} from '@/http/yskApi/goods.js'
|
||||
import {
|
||||
cloneWith
|
||||
} from 'lodash';
|
||||
|
||||
import {
|
||||
hasPermission
|
||||
} from '@/commons/utils/hasPermission.js';
|
||||
import { hasPermission } from '@/commons/utils/hasPermission.js';
|
||||
import { getConsList } from '@/api/cons.js';
|
||||
import { productBind } from '@/api/product.js';
|
||||
|
||||
const emits = defineEmits(['cancel', 'updateGoods'])
|
||||
|
||||
function cancel() {
|
||||
emits('cancel')
|
||||
}
|
||||
const props = defineProps({
|
||||
goods: {
|
||||
type: Object,
|
||||
@@ -205,56 +165,108 @@
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const conInfos = ref(props.goods.conInfos)
|
||||
|
||||
const pageData = reactive({
|
||||
isBindGuige: false, //是否绑定至规格
|
||||
})
|
||||
|
||||
let haoCaiList = ref([])
|
||||
let $haocaiMap = reactive({})
|
||||
const skuList = ref(props.goods.skuList)
|
||||
const conInfos = ref(props.goods.conInfos||[])
|
||||
watch(() => props.goods.conInfos, (newval) => {
|
||||
console.log(newval);
|
||||
conInfos.value = newval
|
||||
})
|
||||
watch(() => props.goods.skuList, (newval) => {
|
||||
skuList.value = newval
|
||||
})
|
||||
watch(() => props.goods.type, (newval) => {
|
||||
if(!newval){
|
||||
pageData.isBindGuige = false
|
||||
}
|
||||
})
|
||||
onMounted(() => {
|
||||
init()
|
||||
if(props.goods.conInfos){
|
||||
const firstItem= props.goods.conInfos[0]
|
||||
pageData.isBindGuige = firstItem?(firstItem.productSkuId==0?false:true):false
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
function init() {
|
||||
console.log(skuList)
|
||||
getConsList({
|
||||
"status": 1,
|
||||
}).then(res => {
|
||||
for (let i in res) {
|
||||
const item = res[i]
|
||||
$haocaiMap[item.id] = item
|
||||
}
|
||||
haoCaiList.value = res
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消耗材绑定
|
||||
*/
|
||||
function cancel() {
|
||||
emits('cancel')
|
||||
}
|
||||
|
||||
/**
|
||||
* 耗材选择
|
||||
* @param {Object} newval
|
||||
* @param {Object} item
|
||||
*/
|
||||
function conInfosChange(newval, item) {
|
||||
console.log(newval);
|
||||
item.stockNumber = newval.balance
|
||||
item.conUnit = newval.conUnit
|
||||
}
|
||||
|
||||
const skuList = ref(props.goods.skuList)
|
||||
watch(() => props.goods.skuList, (newval) => {
|
||||
console.log(newval);
|
||||
skuList.value = newval
|
||||
})
|
||||
|
||||
|
||||
|
||||
const $baseicHaocaiData = {
|
||||
conInfoId: '',
|
||||
consInfoId: '',
|
||||
conUnit: '',
|
||||
surplusStock: ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加商品耗材
|
||||
*/
|
||||
function addHaocai() {
|
||||
conInfos.value.push({
|
||||
...$baseicHaocaiData
|
||||
})
|
||||
}
|
||||
const popup = reactive({
|
||||
haocai: {
|
||||
show: true
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* 添加规格耗材
|
||||
* @param {Object} index
|
||||
*/
|
||||
function addGuigeHaocai(index) {
|
||||
console.log(skuList.value[index])
|
||||
if (skuList.value[index].haoCaiList) {
|
||||
skuList.value[index].haoCaiList.push({
|
||||
...$baseicHaocaiData
|
||||
})
|
||||
} else {
|
||||
skuList.value[index].haoCaiList = [{
|
||||
skuList.value[index]['haoCaiList'] = [{
|
||||
...$baseicHaocaiData
|
||||
}]
|
||||
}
|
||||
console.log(skuList.value[index]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除商品耗材
|
||||
* @param {Object} index
|
||||
*/
|
||||
function delHaocai(index) {
|
||||
const item = conInfos.value[index]
|
||||
console.log(item);
|
||||
@@ -276,7 +288,12 @@
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除规格耗材
|
||||
* @param {Object} guigeIndex
|
||||
* @param {Object} haocaiIndex
|
||||
*/
|
||||
function delGuigeHaocao(guigeIndex, haocaiIndex) {
|
||||
const item = skuList.value[guigeIndex].haoCaiList[haocaiIndex]
|
||||
console.log(item);
|
||||
@@ -298,19 +315,16 @@
|
||||
})
|
||||
}
|
||||
|
||||
// 是否是多规格商品
|
||||
/**
|
||||
* 是否是多规格商品
|
||||
*/
|
||||
const isSku = computed(() => {
|
||||
return props.goods.typeEnum == 'sku'
|
||||
return props.goods.type == 'sku'||props.goods.type == 'single'
|
||||
})
|
||||
let isBindGuige = ref(false)
|
||||
watch(() => props.goods.typeEnum, (newval) => {
|
||||
if(!newval){
|
||||
isBindGuige.value = false
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
async function save() {
|
||||
const bol = await hasPermission('允许修改商品')
|
||||
if (!bol) {
|
||||
@@ -318,17 +332,16 @@
|
||||
}
|
||||
console.log('save');
|
||||
let isPas = false
|
||||
if (!isBindGuige.value) {
|
||||
if (!pageData.isBindGuige) {
|
||||
//绑定至商品
|
||||
isPas = conInfos.value.every(v => {
|
||||
return v.conInfoId && v.conUnit && v.surplusStock > 0
|
||||
return v.consInfoId && v.conUnit && v.surplusStock > 0
|
||||
})
|
||||
} else {
|
||||
//绑定至规格
|
||||
isPas = skuList.value.filter(v => v.haoCaiList && v.haoCaiList.length).every(sku => {
|
||||
console.log(sku.haoCaiList);
|
||||
return sku.haoCaiList.every(v => {
|
||||
return v.conInfoId && v.conUnit && v.surplusStock > 0
|
||||
return v.consInfoId && v.conUnit && v.surplusStock > 0
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -337,20 +350,17 @@
|
||||
return infoBox.showToast('请填写全部耗材选项值')
|
||||
}
|
||||
let ajaxData = {
|
||||
productId: props.goods.id,
|
||||
cons: []
|
||||
id: props.goods.id,
|
||||
consList: []
|
||||
}
|
||||
if (!isBindGuige.value) {
|
||||
if (!pageData.isBindGuige) {
|
||||
//绑定至商品
|
||||
ajaxData.cons = conInfos.value.map(v => {
|
||||
ajaxData.consList = conInfos.value.map(v => {
|
||||
return {
|
||||
id: v.id || '',
|
||||
conInfoId: v.conInfoId,
|
||||
consInfoId: v.consInfoId,
|
||||
productId: props.goods.id,
|
||||
shopId: uni.getStorageSync('shopId'),
|
||||
productSkuId: 0,
|
||||
surplusStock: v.surplusStock * 1,
|
||||
status: 1
|
||||
}
|
||||
})
|
||||
} else {
|
||||
@@ -358,56 +368,22 @@
|
||||
const haocaiList = skuList.value[i].haoCaiList || []
|
||||
for (let k in haocaiList) {
|
||||
const v = haocaiList[k]
|
||||
ajaxData.cons.push({
|
||||
ajaxData.consList.push({
|
||||
id: v.id || '',
|
||||
conInfoId: v.conInfoId,
|
||||
consInfoId: v.consInfoId,
|
||||
productId: props.goods.id,
|
||||
shopId: uni.getStorageSync('shopId'),
|
||||
productSkuId: skuList.value[i].id,
|
||||
surplusStock: v.surplusStock * 1,
|
||||
status: 1
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
console.log(ajaxData);
|
||||
await $tbProskuConV2(ajaxData)
|
||||
await productBind(ajaxData)
|
||||
emits('updateGoods')
|
||||
infoBox.showToast('修改成功')
|
||||
}
|
||||
|
||||
let haoCaiList = ref([])
|
||||
let $haocaiMap = reactive({})
|
||||
let danweiList = ref([])
|
||||
let $danweiMap = reactive({})
|
||||
|
||||
function init() {
|
||||
gettbConsInfo({
|
||||
"status": 1,
|
||||
}).then(res => {
|
||||
for (let i in res.content) {
|
||||
const item = res.content[i]
|
||||
$haocaiMap[item.id] = item
|
||||
}
|
||||
haoCaiList.value = res.content
|
||||
})
|
||||
tbShopCurrencyGet({
|
||||
page: 0,
|
||||
size: 200
|
||||
}).then(res => {
|
||||
for (let i in res.content) {
|
||||
const item = res.content[i]
|
||||
$danweiMap[item.id] = item
|
||||
}
|
||||
danweiList.value = res.content
|
||||
})
|
||||
}
|
||||
onMounted(() => {
|
||||
init()
|
||||
const firstItem= props.goods.conInfos[0]
|
||||
isBindGuige.value=firstItem?(firstItem.productSkuId==0?false:true):false
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
Reference in New Issue
Block a user