代码更新
This commit is contained in:
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user