代码更新

This commit is contained in:
GaoHao
2025-02-26 19:46:20 +08:00
parent 7519ffced3
commit b4a0393d2d
413 changed files with 7483 additions and 60762 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,125 +1,31 @@
<template>
<view class="u-relative choose-haocai">
<!-- <view class="input u-flex" @click="toggle" >
<up-input @blur="blur" @change="filterHaocaiList" border="none" v-model="text" placeholder="请选择"></up-input>
<up-icon :size="10" name="arrow-down-fill"></up-icon>
</view> -->
<view class="input u-flex" >
<view>{{text||''}}</view>
<!-- <up-input @blur="blur" disabled="true" @change="filterHaocaiList" border="none" v-model="text" placeholder="请选择"></up-input> -->
</view>
<view class="u-absolute" v-if="popShow">
<scroll-view scroll-y="true" class="scroll">
<view class="item" v-for="(item,index) in $haocaiList" :key="index" @click="haocaiClick(item,index)">
{{item.name}}
</view>
<view class="item no-wrap" @click="toggle" v-if="text&&!$haocaiList.length">没有该单位</view>
</scroll-view>
</view>
</view>
</template>
<script setup>
import {
reactive,
ref,
watch,
onMounted
} from 'vue';
import { reactive, ref, watch, onMounted } from 'vue';
const props = defineProps({
listMap: {
type: Object,
default: () => {}
},
list: {
type: Array,
default: () => []
},
modelValue: {
type: [String, Number],
default: ''
},
show: {
type: Boolean,
default: false
},
})
let text = ref('')
let popShow = ref(props.show)
const emits = defineEmits(['update:show', 'close', 'confirm', 'update:modelValue'])
function close() {
popShow.value = false
}
function confirm() {
popShow.value = false
}
watch(() => props.show, (newval) => {
popShow.value = newval
})
watch(() => popShow.value, (newval) => {
console.log(newval);
emits('update:show', newval)
})
let $haocaiList = ref(props.list)
watch(() => props.list, (newval) => {
$haocaiList.value = newval
setText()
})
watch(() => props.modelValue, (newval) => {
console.log(newval);
setText()
})
function setText() {
// const item = props.listMap[props.modelValue]
// text.value = item ? item.name : ''
text.value=props.modelValue
}
function toggle(e) {
popShow.value = !popShow.value
}
function filterHaocaiList(e) {
if (e === '') {
return $haocaiList.value = props.list
}
const arr = props.list.filter(v => v.name.match(e))
$haocaiList.value = arr
}
function haocaiClick(item, index) {
console.log(item);
// if (item.id != props.modelValue) {
// emits('update:modelValue', item.id)
// }
if(item.name!=props.modelValue){
emits('update:modelValue', item.name)
}
popShow.value = false
}
function focus(){
console.log('focus');
popShow.value = true
}
function blur() {
console.log('blur');
// setTimeout(()=>{
// popShow.value = false
// },100)
}
onMounted(() => {
setText()
})
function setText() {
text.value=props.modelValue
}
</script>
<style lang="scss" scoped>
@@ -137,27 +43,5 @@
border: 2rpx solid #E5E5E5;
overflow: hidden;
}
.u-absolute {
top: calc(100% + 10rpx);
border: 1px solid #E5E5E5;
left: 0;
background-color: #fff;
z-index: 10;
right: 0;
border-radius: 8rpx;
.scroll {
$line-h: 60rpx;
max-height: calc($line-h * 4);
.item {
line-height: $line-h;
padding: 0 20rpx;
}
}
}
}
</style>

View File

@@ -22,7 +22,7 @@
</view>
<scroll-view :scroll-x="false" scroll-y="true" :style="computedStyle()">
<scroll-view :scroll-x="true" :scroll-y="true" :style="computedStyle()">
<view class="u-p-l-30 u-p-r-30 table">
<view class="u-flex u-row-between no-wrap title">
<view>
@@ -31,8 +31,6 @@
</view>
<view>商品信息</view>
<view>规格</view>
<!-- <view>是否售尽</view> -->
<!-- <view>是否分销</view> -->
<view>售价</view>
<view>销量/库存</view>
<view>分类名称</view>
@@ -41,23 +39,19 @@
<view class="">
<my-radio @change="radioChange($event,item)" v-model="item.checked" shape="square" :size="20"></my-radio>
</view>
<view class="u-text-left u-flex-1 u-p-l-20">
<!-- <view class="u-flex">
<image lazy-load class="coverImg" :src="item.coverImg" mode=""></image>
</view> -->
<view class="u-text-left u-flex-1 u-p-l-20" style="flex-shrink: 0;">
<view class="">{{item.name}}</view>
</view>
<view class="u-flex-1 u-p-l-4 u-p-r-4 box-size-border">
{{item.typeEnum}}
{{isType(item.type)}}
</view>
<view class="u-flex-1">
{{ item.lowPrice }}
</view>
<view class="u-flex-1">
<!-- {{ item.realSalesNumber }}/{{ item.stockNumber }} -->
{{ item.stockNumber }}
{{ item.stockNumber }}
</view>
<view class="u-flex-1">
<view class="u-flex-1" style="text-overflow: ellipsis;overflow: hidden;word-break: break-all;white-space: nowrap;">
{{item.categoryName}}
</view>
</view>
@@ -80,15 +74,9 @@
</template>
<script setup>
import {
$tbProductList
} from '@/http/yskApi/goods.js';
import {
reactive,
onMounted,
ref,
watch
} from 'vue';
import { reactive, onMounted, ref, watch, computed } from 'vue';
import { getProductList} from '@/api/product.js';
const props = defineProps({
modelValue: {
type: Boolean,
@@ -105,6 +93,98 @@
}
}
})
const emits = defineEmits(['update:modelValue', 'confirm'])
const $quey = {
categoryId: "",
id: "",
name: "",
orderBy: "create_time desc",
page: 1,
size: 10,
}
const query = reactive({
...$quey
})
const goods = reactive({
list: [],
allChecked: false,
totalElements: 0,
query: {
...$quey
}
})
//页面全部数据
const pageData = reactive({
// 商品类型
types: [{
name: '单规格',
value: 'single'
},
{
name: '多规格',
value: 'sku'
},
{
name: '套餐',
value: 'package'
},
{
name: '称重',
value: 'weigh'
},
// {
// name: '团购券',
// value: 'coupon'
// },
],
})
function isType (e) {
let obj = pageData.types.find(item=> item.value == e)
return obj.name
}
getGoods()
/**
* 获取商品列表
*/
function getGoods() {
const arr=selArr
getProductList(goods.query).then(res => {
let selLen=0;
goods.list = res.records.map(v => {
const checked=$selGoodsMap[v.id]?true:false
selLen+=(checked?1:0)
return {
...v,
checked
}
})
goods.allChecked = selLen==res.records.length?true:false
goods.totalElements = res.totalRow
})
}
/**
* 单个商品选中
* @param {Object} newval
* @param {Object} item
*/
function radioChange(newval,item) {
if(!newval&&$selGoodsMap[item.id]){
delete $selGoodsMap[item.id]
}else{
$selGoodsMap[item.id]=item
}
goods.allChecked = goods.list.filter(v => v.checked).length != 0
}
/**
* 全选
* @param {Object} item
*/
function changeChecked(item){
item.checked=!item.checked
if(!item.checked&&$selGoodsMap[item.id]){
@@ -128,8 +208,7 @@
selArr=arr
console.log(arr);
for(let i in arr){
$selGoodsMap[arr[i].proId
]=arr[i]
$selGoodsMap[arr[i].proId]=arr[i]
}
getGoods()
}
@@ -150,60 +229,11 @@
return `height:${typeof props.height==='string'?props.height:props.height+'rpx'};`
}
const emits = defineEmits(['update:modelValue', 'confirm'])
const $quey = {
categoryId: "",
createdAt: [],
id: "",
name: "",
sort: "createdAt,desc",
type: "",
page: 0,
size: 10,
}
const query = reactive({
...$quey
})
const goods = reactive({
list: [],
allChecked: false,
totalElements: 0,
query: {
...$quey
}
})
getGoods()
function getGoods() {
const arr=selArr
$tbProductList(goods.query).then(res => {
let selLen=0;
goods.list = res.content.map(v => {
const checked=$selGoodsMap[v.id]?true:false
selLen+=(checked?1:0)
return {
...v,
checked
}
})
goods.allChecked = selLen==res.content.length?true:false
goods.totalElements = res.totalElements
})
}
function pageChange(page) {
goods.query.page = page - 1
goods.query.page = page
getGoods()
}
function radioChange(newval,item) {
if(!newval&&$selGoodsMap[item.id]){
delete $selGoodsMap[item.id]
}else{
$selGoodsMap[item.id]=item
}
goods.allChecked = goods.list.filter(v => v.checked).length != 0
}
function radioAllChange(newval) {
goods.list.forEach(i => {
@@ -223,7 +253,6 @@
delete $selGoodsMap[item.id]
}
}
console.log($selGoodsMap);
const arr = Object.values($selGoodsMap)
emits('confirm', arr)
}

View File

@@ -11,7 +11,7 @@
<view class="skd" v-for="(item,index) in skuList" :key="index"
:class="{active:sel.id==item.id}"
@click="guigeClick(item,index)">
<text>{{item.specSnap||item.name}}</text>
<text>{{item.specInfo||item.name}}</text>
<view class="tag-primary tag" v-if="item.isGrounding">上架中</view>
<view class="tag-gray tag" v-if="item.isPauseSale">已售罄</view>
<view class="tag-gray tag" v-if="!item.isGrounding">已下架</view>
@@ -35,15 +35,9 @@
</template>
<script setup>
import {
$tbProduct
} from '@/http/yskApi/goods.js';
import {
reactive,
onMounted,
ref,
watch
} from 'vue';
import { reactive, ref, watch } from 'vue';
import { $tbProduct } from '@/http/yskApi/goods.js';
import infoBox from '@/commons/utils/infoBox.js'
const props = defineProps({
modelValue: {

View File

@@ -1,57 +0,0 @@
<template>
<up-popup :round="10" :show="popShow" :closeable="true" @close="close">
<view class="u-text-center font-bold u-font-32 u-p-t-30">选择状态</view>
<view style="height: 20rpx;"></view>
<view class="u-p-30 all-list u-flex u-flex-wrap gap-20">
<view class="all-list-item" :class="{active:statusItemIndex==statusData.allListSel}" @click="changeAllListSel(statusItemIndex)" v-for="(statusItem,statusItemIndex) in statusData.allList" :key="statusItemIndex">
{{statusItem.label}}
</view>
</view>
<view class="u-flex u-p-t-30 u-p-b-30 u-p-l-20 u-p-r-20 gap-20">
<up-button @click="close">取消</up-button>
<up-button type="primary" @click="confirm">确定</up-button>
</view>
</up-popup>
</template>
<script setup>
import { ref, watch } from 'vue';
const props=defineProps({
show:{
type:Boolean,
default:false
}
})
let popShow=ref(props.show)
const emits=defineEmits(['update:show','close','confirm'])
function close(){
popShow.value=false
}
function confirm(){
popShow.value=false
}
watch(()=>props.show,(newval)=>{
popShow.value=newval
})
watch(()=>popShow.value,(newval)=>{
emits('update:show',newval)
})
</script>
<style lang="scss" scoped>
.all-list-item{
text-align: center;
width: 156rpx;
white-space: nowrap;
color: #666;
padding: 10rpx 20rpx;
border-radius: 8rpx;
transition: all .2s ease-in-out;
border: 1px solid #eee;
&.active {
color: $my-main-color;
border-color: $my-main-color;
}
}
</style>

View File

@@ -1,11 +1,7 @@
<template>
<view class="u-relative choose-haocai">
<view class="input u-flex" @click="toggle">
<!-- <view>
<text v-if="modelValue">{{modelValue}}</text>
<text v-else class="color-666">请选择</text>
</view> -->
<up-input @blur="blur" @change="filterHaocaiList" border="none" v-model="text" placeholder="请选择"></up-input>
<up-input @change="filterHaocaiList" border="none" v-model="text" placeholder="请选择"></up-input>
<up-icon :size="10" name="arrow-down-fill"></up-icon>
</view>
<view class="u-absolute" v-if="popShow">
@@ -21,12 +17,7 @@
</template>
<script setup>
import {
reactive,
ref,
watch,
onMounted
} from 'vue';
import { reactive, ref, watch, onMounted } from 'vue';
const props = defineProps({
listMap: {
type: Object,
@@ -48,15 +39,11 @@
})
let text = ref('')
let popShow = ref(props.show)
const emits = defineEmits(['update:show', 'close', 'confirm', 'update:modelValue','change'])
const emits = defineEmits(['update:show', 'update:modelValue','change'])
onMounted(() => {
setText()
})
function close() {
popShow.value = false
}
function confirm() {
popShow.value = false
}
watch(() => props.show, (newval) => {
popShow.value = newval
})
@@ -81,6 +68,10 @@
popShow.value = !popShow.value
}
/**
* 耗材选择监听
* @param {Object} e
*/
function filterHaocaiList(e) {
if (e === '') {
return $haocaiList.value = props.list
@@ -88,9 +79,13 @@
const arr = props.list.filter(v => v.conName.match(e))
$haocaiList.value = arr
}
/**
* 耗材选择确认
* @param {Object} item
* @param {Object} index
*/
function haocaiClick(item, index) {
console.log(item);
if (item.id != props.modelValue) {
emits('update:modelValue', item.id)
emits('change', item)
@@ -98,14 +93,7 @@
popShow.value = false
}
function blur() {
// setTimeout(()=>{
// popShow.value = false
// },100)
}
onMounted(() => {
setText()
})
</script>
<style lang="scss" scoped>

View File

@@ -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>

View File

@@ -1,224 +0,0 @@
<template>
<view class="u-p-30 min-page u-font-28">
<!-- <view class="u-flex">
<view style="width: 210rpx;">
<my-button shape="circle" @click="addTimer">添加定时器</my-button>
</view>
</view> -->
<view class="list u-m-t-20" v-if="list.length">
<view class="block" v-for="(item,index) in list" :key="index">
<!-- <view class="u-flex u-row-between">
<view>定时器{{index+1}}</view>
<uni-icons @click="delTimer(index)" type="trash"></uni-icons>
</view> -->
<view class="u-flex u-row-between">
<view>周期</view>
<view class="color-main" @click="selectAllClick(index)">
{{isAllChecked?'取消全选':'全选'}}
</view>
</view>
<view class="u-m-t-24">
<uni-data-checkbox :selectedColor="color.ColorMain" multiple v-model="item.cycleChecked" :localdata="cycle"></uni-data-checkbox>
</view>
<view class="u-m-t-24">
<view class="u-flex">
<view>上架时间:</view>
<view class="u-flex-1 u-m-l-10">
<picker mode="multiSelector" @change="listingTimeChange($event,index)"
:value="item.listingTime.index" :range="times">
<view class="bg-gray u-p-l-20 u-p-t-6 u-p-b-6 u-p-r-20 ">
{{item.listingTime.value}}
</view>
</picker>
</view>
</view>
<view class="u-flex u-m-t-16">
<view>下架时间:</view>
<view class="u-flex-1 u-m-l-10">
<picker mode="multiSelector" @change="offShelfChange($event,index)"
:value="item.offShelf.index" :range="times">
<view class="bg-gray u-p-l-20 u-p-t-6 u-p-b-6 u-p-r-20 ">
{{item.offShelf.value}}
</view>
</picker>
</view>
</view>
</view>
</view>
</view>
<view class="u-flex u-row-center u-m-t-60">
<my-button width="580" shape="circle" @click="save">保存</my-button>
</view>
</view>
</template>
<script setup>
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(2).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) {
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]]
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 listingTimeChange(e, index) {
const indexArr = getEnentDetailValue(e)
const time = getTime(indexArr)
setListTimeValue(index, 'listingTime', time)
}
function offShelfChange(e, index) {
const indexArr = getEnentDetailValue(e)
const time = getTime(indexArr)
setListTimeValue(index, 'offShelf', time)
}
const cycle = [{
value: 0,
text: '星期一'
},
{
value: 1,
text: '星期二'
},
{
value: 2,
text: '星期三'
},
{
value: 3,
text: '星期四'
},
{
value: 4,
text: '星期五'
},
{
value: 5,
text: '星期六'
},
{
value: 6,
text: '星期日'
}
]
const ListDataconstructor = {
cycleChecked: [0, 1, 2, 3, 4, 5, 6],
}
function returnBasicTimeConstructor() {
return {
listingTime: {
value: '00:00',
index: [0, 0]
},
offShelf: {
value: '00:00',
index: [0, 0]
}
}
}
const list = ref([returnBasicDataConstructor()])
function returnBasicDataConstructor() {
return {
...ListDataconstructor,
...returnBasicTimeConstructor()
}
}
function addTimer() {
list.value.push(returnBasicDataConstructor())
}
function delTimer(index) {
list.value.splice(index,1)
}
const isAllChecked=computed(()=>{
return list.value[0].cycleChecked.length==cycle.length?true:false
})
function selectAllClick(index){
if(isAllChecked.value){
list.value[index].cycleChecked=[]
}else{
list.value[index].cycleChecked=ListDataconstructor.cycleChecked
}
}
// 触发定时器保存事件将数据给到添加商品页面
function emitTimerSave(){
uni.$emit('timerSave',list.value)
go.back()
}
function save(){
console.log(list.value);
emitTimerSave()
}
let goodsDetail=ref({})
function returnTimer(res){
return []
}
onLoad(async(opt)=>{
let res=null
if(opt.productId){
res=await $getProductDetail(opt.productId)
goodsDetail.value=res
}
const arr=res?returnTimer(res):[]
if(arr.length){
list.value=arr
}
})
</script>
<style lang="scss">
.min-page {
background-color: #F9F9F9;
}
.block {
background: #FFFFFF;
border-radius: 18rpx 18rpx 18rpx 18rpx;
padding: 32rpx 28rpx;
margin-bottom: 32rpx;
}
</style>

View File

@@ -1,16 +1,7 @@
<template>
<view class="u-p-30 min-page u-font-28">
<!-- <view class="u-flex">
<view style="width: 210rpx;">
<my-button shape="circle" @click="addTimer">添加定时器</my-button>
</view>
</view> -->
<view class="list u-m-t-20" v-if="list.length">
<view class="block" v-for="(item,index) in list" :key="index">
<!-- <view class="u-flex u-row-between">
<view>定时器{{index+1}}</view>
<uni-icons @click="delTimer(index)" type="trash"></uni-icons>
</view> -->
<view class="u-flex u-row-between">
<view>周期</view>
<view class="color-main" @click="selectAllClick(index)">
@@ -193,8 +184,8 @@
function emitTimerSave() {
const par = {
days: list.value[0].cycleChecked.join(','),
startTime: list.value[0].startTime.value,
endTime: list.value[0].endTime.value
startTime: list.value[0].startTime.value+':00',
endTime: list.value[0].endTime.value+':00'
}
console.log(par);
uni.$emit('timerSave', par)