224 lines
5.0 KiB
Vue
224 lines
5.0 KiB
Vue
<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> |