代码更新

This commit is contained in:
GaoHao
2025-03-03 09:44:11 +08:00
parent b4a0393d2d
commit fd0c452a76
55 changed files with 2263 additions and 2658 deletions

View File

@@ -466,7 +466,8 @@
getProductDetail,
addProduct,
updateProduct,
delProduct
delProduct,
productBindCons
} from '@/api/product.js'
import {
uploadFile
@@ -575,6 +576,7 @@
watch(() => FormData.type, (newval) => {
if (option.type == 'edit') {
FormData.specId = newval != 'sku' ? '' : ($goodsData.specId || '')
console.log($goodsData)
if (newval == $goodsData.type) {
skuList.list = $goodsData.skuList
if ($goodsData.groupSnap) {
@@ -665,17 +667,17 @@
url: v
}
})
for (let i in res.conInfos) {
const con = res.conInfos[i]
const item = res.skuList.find(v => v.id == con.productSkuId)
res.consList.map(v=>{
const item = res.skuList.find(v => v.productId == v.productId)
if (item) {
if (item.hasOwnProperty('haoCaiList')) {
item.haoCaiList.push(con)
item.haoCaiList.push(v)
} else {
item.haoCaiList = [con]
item.haoCaiList = [v]
}
}
}
})
res.skuList = (res.skuList.length ? res.skuList : [])
$goodsData = res
@@ -758,6 +760,7 @@
}else{
FormData.groupType = null
}
console.log(FormData)
}
/**
@@ -1074,7 +1077,7 @@
}
}
if (type == 'single') {
if (type != 'sku') {
let lowPrice = skuList.list[0] ? skuList.list[0].salePrice : FormData.salePrice
let suitNum = skuList.list[0] ? skuList.list[0].suitNum : 0
if (lowPrice === '') {
@@ -1088,7 +1091,9 @@
}
}
if (type == 'sku') {
if ( selectSpecInfo.length ==0 || JSON.stringify(selectSpecInfo) == '{}') {
return infoBox.showToast('请选择规格!')
}
}
if (type == 'package') {
if (groupType == 0 && FormData.proGroupVo[0].goods.length <= 0) {
@@ -1218,6 +1223,9 @@
*/
function toTimerPage() {
go.to('PAGES_PRODUCT_TIMER', {
days: FormData.days,
startTime: FormData.startTime,
endTime: FormData.endTime
})
}

View File

@@ -3,131 +3,63 @@
<view class="default-box-padding bg-fff border-r-18">
<view class="u-flex u-row-between">
<view>商品名称</view>
<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="pageData.isBindGuige" :disabled="!isSku">绑定至规格</up-switch>
<view class="u-absolute position-all" style="z-index: 1;" v-if="!isSku"
@click="infoBox.showToast('只有单规格或者多规格商品可绑定至规格',3)"></view>
</view>
</view>
</view>
<view class="border-bottom u-m-t-16 u-p-b-32">{{skuList.length}}{{goods.name}}</view>
<view class="">
<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.specInfo}}</view>
<view class="color-666 u-m-t-24 u-flex">
<view class="xuhao">序号</view>
<view class="list">
<view class="u-p-b-32 u-p-t-32 border-bottom" v-for="(item,index) in consList" :key="index">
<view class="color-666 u-flex">
<view class="xuhao">序号</view>
<view class="u-flex u-flex-1 u-p-l-32 gap-20">
<view class="u-flex-1">耗材名称</view>
<view class="u-flex-1">单位</view>
<view class="u-flex-1">用量</view>
</view>
</view>
<view class="u-m-t-32 color-666">
<view class=" u-m-t-24 u-flex">
<view class="xuhao">{{index+1}}</view>
<view class="u-flex u-flex-1 u-p-l-32 gap-20">
<view class="u-flex-1">耗材名称</view>
<view class="u-flex-1">单位</view>
<view class="u-flex-1">用量</view>
</view>
</view>
<view class="u-m-t-32 color-666">
<view class="u-m-t-24" v-for="(item,haocaiIndex) in sku.haoCaiList" :key="haocaiIndex">
<view class=" u-flex">
<view class="xuhao">{{haocaiIndex+1}}</view>
<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.consInfoId"></choose-haocai>
</view>
<view class="u-flex-1 ">
<choose-danwei :listMap="$danweiMap" :list="danweiList"
v-model="item.conUnit"></choose-danwei>
</view>
<view class="u-flex input">
<up-input border="none" v-model="item.surplusStock"></up-input>
<up-icon @click="delGuigeHaocao(index,haocaiIndex)" color="#EA4025"
:size="16" name="minus-circle-fill"></up-icon>
</view>
<view class="u-flex-1 ">
<choose-haocai @change="conInfosChange($event,item)" :listMap="$haocaiMap"
:list="haoCaiList" v-model="item.consInfoId"></choose-haocai>
</view>
<view class="u-flex-1 ">
<choose-danwei v-model="item.conUnit"></choose-danwei>
</view>
<view class="u-flex-1 ">
<view class="u-flex input">
<up-input border="none" v-model="item.surplusStock"></up-input>
<up-icon @click="delHaocai(index)" color="#EA4025" :size="16"
name="minus-circle-fill"></up-icon>
</view>
</view>
<view class="u-flex u-m-t-16 color-666 u-font-24">
<view class="xuhao">
</view>
<view class="u-flex u-flex-1 u-p-l-32 gap-20">库存{{item.stockNumber}}
</view>
</view>
</view>
</view>
<view class="u-flex">
<view class=" u-p-t-32 u-flex" @click="addGuigeHaocai(index)">
<up-icon :size="18" color="#318AFE" name="plus-circle-fill"></up-icon>
<view class="u-m-l-16">添加耗材</view>
<view class="u-flex u-m-t-16 u-font-24" v-if="item.stockNumber">
<view class="xuhao">
</view>
<view class="u-flex u-flex-1 u-p-l-32 gap-20">库存{{item.stockNumber}}
{{item.conUnit}}
</view>
</view>
</view>
</view>
</template>
<template v-else>
<view class="list">
<view class="u-p-b-32 u-p-t-32 border-bottom" v-for="(item,index) in conInfos" :key="index">
<view class="color-666 u-flex">
<view class="xuhao">序号</view>
<view class="u-flex u-flex-1 u-p-l-32 gap-20">
<view class="u-flex-1">耗材名称</view>
<view class="u-flex-1">单位</view>
<view class="u-flex-1">用量</view>
</view>
</view>
<view class="u-m-t-32 color-666">
<view class=" u-m-t-24 u-flex">
<view class="xuhao">{{index+1}}</view>
<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.consInfoId"></choose-haocai>
</view>
<view class="u-flex-1 ">
<choose-danwei v-model="item.conUnit"></choose-danwei>
</view>
<view class="u-flex-1 ">
<view class="u-flex input">
<up-input border="none" v-model="item.surplusStock"></up-input>
<up-icon @click="delHaocai(index)" color="#EA4025" :size="16"
name="minus-circle-fill"></up-icon>
</view>
</view>
</view>
</view>
<view class="u-flex u-m-t-16 u-font-24" v-if="item.stockNumber">
<view class="xuhao">
</view>
<view class="u-flex u-flex-1 u-p-l-32 gap-20">库存{{item.stockNumber}}
{{item.conUnit}}
</view>
</view>
</view>
</view>
</view>
<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>
<view class="u-m-l-16">添加耗材</view>
</view>
</template>
<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>
<view class="u-m-l-16">添加耗材</view>
</view>
</view>
</template>
</view>
</view>
</view>
<view class="default-box-padding bg-fff border-r-18 u-flex u-row-between u-m-t-32">
<view>当某个耗材的使用库存不足时商品自动
售罄</view>
<view>当某个耗材的使用库存不足时商品自动售罄</view>
</view>
<view class="bottom">
@@ -146,10 +78,10 @@
import infoBox from '@/commons/utils/infoBox.js'
import chooseHaocai from './choose-haocai.vue';
import chooseDanwei from './choose-danwei.vue';
import { hasPermission } from '@/commons/utils/hasPermission.js';
import { getConsList } from '@/api/cons.js';
import { productBind } from '@/api/product.js';
import { productBindCons } from '@/api/product.js';
const emits = defineEmits(['cancel', 'updateGoods'])
@@ -158,9 +90,9 @@
type: Object,
default: () => {
return {
conInfos: [],
consList: [],
skuList: [],
typeEnum: ''
type: ''
}
}
}
@@ -173,30 +105,19 @@
let haoCaiList = ref([])
let $haocaiMap = reactive({})
const skuList = ref(props.goods.skuList)
const conInfos = ref(props.goods.conInfos||[])
watch(() => props.goods.conInfos, (newval) => {
conInfos.value = newval
const consList = ref(props.goods.consList||[])
watch(() => props.goods.consList, (newval) => {
consList.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 => {
@@ -227,101 +148,35 @@
item.conUnit = newval.conUnit
}
const $baseicHaocaiData = {
consInfoId: '',
conUnit: '',
surplusStock: ''
}
/**
* 添加商品耗材
*/
function addHaocai() {
conInfos.value.push({
...$baseicHaocaiData
consList.value.push({
consInfoId: '',
conUnit: '',
surplusStock: ''
})
}
/**
* 添加规格耗材
* @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'] = [{
...$baseicHaocaiData
}]
}
console.log(skuList.value[index]);
}
/**
* 删除商品耗材
* @param {Object} index
*/
function delHaocai(index) {
const item = conInfos.value[index]
console.log(item);
const item = consList.value[index]
uni.showModal({
title: '提示',
content: '是否删除该耗材',
success(res) {
if (res.confirm) {
if (item.id) {
deletetbProskuCon([item.id]).then(res1 => {
conInfos.value.splice(index, 1)
})
} else {
conInfos.value.splice(index, 1)
}
consList.value.splice(index, 1)
}
}
})
}
/**
* 删除规格耗材
* @param {Object} guigeIndex
* @param {Object} haocaiIndex
*/
function delGuigeHaocao(guigeIndex, haocaiIndex) {
const item = skuList.value[guigeIndex].haoCaiList[haocaiIndex]
console.log(item);
uni.showModal({
title: '提示',
content: '是否删除该耗材',
success(res) {
if (res.confirm) {
if (item && item.id) {
deletetbProskuCon([item.id]).then(res1 => {
skuList.value[guigeIndex].haoCaiList.splice(haocaiIndex, 1)
})
} else {
skuList.value[guigeIndex].haoCaiList.splice(haocaiIndex, 1)
}
}
}
})
}
/**
* 是否是多规格商品
*/
const isSku = computed(() => {
return props.goods.type == 'sku'||props.goods.type == 'single'
})
/**
* 保存
*/
@@ -330,21 +185,9 @@
if (!bol) {
return
}
console.log('save');
let isPas = false
if (!pageData.isBindGuige) {
//绑定至商品
isPas = conInfos.value.every(v => {
return v.consInfoId && v.conUnit && v.surplusStock > 0
})
} else {
//绑定至规格
isPas = skuList.value.filter(v => v.haoCaiList && v.haoCaiList.length).every(sku => {
return sku.haoCaiList.every(v => {
return v.consInfoId && v.conUnit && v.surplusStock > 0
})
})
}
let isPas = consList.value.every(v => {
return v.consInfoId && v.conUnit && v.surplusStock > 0
})
if (!isPas) {
return infoBox.showToast('请填写全部耗材选项值')
@@ -353,33 +196,15 @@
id: props.goods.id,
consList: []
}
if (!pageData.isBindGuige) {
//绑定至商品
ajaxData.consList = conInfos.value.map(v => {
return {
id: v.id || '',
consInfoId: v.consInfoId,
productId: props.goods.id,
surplusStock: v.surplusStock * 1,
}
})
} else {
for (let i in skuList.value) {
const haocaiList = skuList.value[i].haoCaiList || []
for (let k in haocaiList) {
const v = haocaiList[k]
ajaxData.consList.push({
id: v.id || '',
consInfoId: v.consInfoId,
productId: props.goods.id,
surplusStock: v.surplusStock * 1,
})
}
ajaxData.consList = consList.value.map(v => {
return {
id: v.id || '',
consInfoId: v.consInfoId,
productId: props.goods.id,
surplusStock: v.surplusStock * 1,
}
}
console.log(ajaxData);
await productBind(ajaxData)
})
await productBindCons(ajaxData)
emits('updateGoods')
infoBox.showToast('修改成功')
}

View File

@@ -40,74 +40,20 @@
</view>
<view class="u-flex u-row-center u-m-t-60">
<my-button width="580" shape="circle" @click="save">保存</my-button>
<my-button width="580" shape="circle" @click="emitTimerSave">保存</my-button>
</view>
</view>
</template>
<script setup>
import {
onLoad,
onReady
} from '@dcloudio/uni-app';
import {
computed,
ref
} from 'vue';
import { onLoad, onReady } from '@dcloudio/uni-app';
import { computed, ref } from 'vue';
import go from '@/commons/utils/go.js';
import color from '@/commons/color.js'
import {
$getProductDetail,
} from '@/http/yskApi/goods.js'
//返回一天的时间 时分格式
function returnDayTime() {
return new Array(3).fill(1).map((v, index) => {
if (index === 0) {
return new Array(24).fill(1).map((hour, index) => {
return `0${index}`.slice(-2)
})
}
if (index === 1 || index === 2) {
return new Array(60).fill(1).map((hour, index) => {
return `0${index}`.slice(-2)
})
}
})
}
const times = ref(returnDayTime())
let defaultTimeIndex = ref(0)
function getTime(indexArr) {
const hour = times.value[0][indexArr[0]]
const month = times.value[1][indexArr[1]]
const s = times.value[2][indexArr[2]]
// return `${hour}:${month}:${s}`
return `${hour}:${month}`
}
//获取$event.detail.value
function getEnentDetailValue(e) {
return e.detail.value
}
function setListTimeValue(index, key, time) {
list.value[index][key].value = time
}
function startTimeChange(e, index) {
const indexArr = getEnentDetailValue(e)
const time = getTime(indexArr)
setListTimeValue(index, 'startTime', time)
}
function endTimeChange(e, index) {
const indexArr = getEnentDetailValue(e)
const time = getTime(indexArr)
setListTimeValue(index, 'endTime', time)
}
import { getProductDetail } from '@/api/product.js'
const cycle = [{
value: 'Monday',
text: '星期一'
@@ -140,15 +86,89 @@
const ListDataconstructor = {
cycleChecked: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
}
let goodsDetail = ref({})
onLoad(async (opt) => {
console.log(opt)
const arr = opt ? returnTimer(opt) : [];
console.log(arr);
if (arr.length) {
list.value = arr
}
})
function returnTimer(res) {
return [{
cycleChecked: res.days ? res.days.split(',').filter(v => v) : [],
startTime: res.startTime ? {
value: res.startTime,
index: returnTimeIndex(res.startTime)
} : returnBasicTimeConstructor.startTime,
endTime: res.endTime ? {
value: res.endTime,
index: returnTimeIndex(res.endTime)
} : returnBasicTimeConstructor.endTime
}]
}
function returnTimeIndex(time) {
return time.split(':').map(v => {
return v * 1
})
}
const times = ref(returnDayTime())
//返回一天的时间 时分格式
function returnDayTime() {
return new Array(3).fill(1).map((v, index) => {
if (index === 0) {
return new Array(24).fill(1).map((hour, index) => {
return `0${index}`.slice(-2)
})
}
if (index === 1 || index === 2) {
return new Array(60).fill(1).map((hour, index) => {
return `0${index}`.slice(-2)
})
}
})
}
let defaultTimeIndex = ref(0)
function getTime(indexArr) {
const hour = times.value[0][indexArr[0]]
const month = times.value[1][indexArr[1]]
const s = times.value[2][indexArr[2]]
// return `${hour}:${month}:${s}`
return `${hour}:${month}:${s}`
}
//获取$event.detail.value
function getEnentDetailValue(e) {
return e.detail.value
}
function setListTimeValue(index, key, time) {
list.value[index][key].value = time
}
function startTimeChange(e, index) {
const indexArr = getEnentDetailValue(e)
const time = getTime(indexArr)
setListTimeValue(index, 'startTime', time)
}
function endTimeChange(e, index) {
const indexArr = getEnentDetailValue(e)
const time = getTime(indexArr)
setListTimeValue(index, 'endTime', time)
}
function returnBasicTimeConstructor() {
return {
startTime: {
value: '00:00',
value: '00:00:00',
index: [0, 0, 0]
},
endTime: {
value: '23:59',
value: '23:59:59',
index: [0, 0, 0]
}
}
@@ -184,51 +204,17 @@
function emitTimerSave() {
const par = {
days: list.value[0].cycleChecked.join(','),
startTime: list.value[0].startTime.value+':00',
endTime: list.value[0].endTime.value+':00'
startTime: list.value[0].startTime.value,
endTime: list.value[0].endTime.value
}
console.log(par);
uni.$emit('timerSave', par)
go.back()
}
function save() {
emitTimerSave()
}
let goodsDetail = ref({})
function returnTimeIndex(time) {
console.log(time);
return time.split(':').map(v => {
return v * 1
})
}
function returnTimer(res) {
return [{
cycleChecked: res.days ? res.days.split(',').filter(v => v) : [],
startTime: res.startTime ? {
value: res.startTime,
index: returnTimeIndex(res.startTime)
} : returnBasicTimeConstructor.startTime,
endTime: res.endTime ? {
value: res.endTime,
index: returnTimeIndex(res.endTime)
} : returnBasicTimeConstructor.endTime
}]
}
onLoad(async (opt) => {
let res = null
if (opt.productId) {
res = await $getProductDetail(opt.productId)
goodsDetail.value = res
}
const arr = res ? returnTimer(res) : [];
console.log(arr);
if (arr.length) {
list.value = arr
}
})
</script>
<style lang="scss">