Files
shoot-miniprograms/src/pages/point-book-create.vue
2026-01-09 18:12:27 +08:00

164 lines
3.7 KiB
Vue

<script setup>
import { ref, onMounted } from "vue";
import { onShow } from "@dcloudio/uni-app";
import Container from "@/components/Container.vue";
import EditOption from "@/components/EditOption.vue";
import SButton from "@/components/SButton.vue";
import { getPointBookDataAPI } from "@/apis";
const expandIndex = ref(0);
const bowType = ref("");
const distance = ref(0);
const bowtargetType = ref("");
const amountGroup = ref("");
const days = ref(0);
const arrows = ref(0);
const onExpandChange = (index, expand) => {
if (expandIndex.value !== -1) {
expandIndex.value = -1;
setTimeout(() => {
expandIndex.value = !expand ? -1 : index;
}, 100);
} else {
expandIndex.value = !expand ? -1 : index;
}
};
const toListPage = () => {
uni.navigateTo({
url: "/pages/point-book-list",
});
};
const onSelect = (itemIndex, value) => {
if (itemIndex === 0) bowType.value = value;
else if (itemIndex === 1) distance.value = value;
else if (itemIndex === 2) bowtargetType.value = value;
else if (itemIndex === 3) amountGroup.value = value;
};
const toEditPage = () => {
if (
bowType.value &&
distance.value &&
bowtargetType.value &&
amountGroup.value
) {
uni.setStorageSync("last-point-book", {
bowType: bowType.value,
distance: distance.value,
bowtargetType: bowtargetType.value,
amountGroup: amountGroup.value,
});
uni.redirectTo({
url: "/pages/point-book-edit",
});
} else {
uni.showToast({
title: "请完善信息",
icon: "none",
});
}
};
// onShow(async () => {
// const result = await getPointBookDataAPI();
// if (result) {
// days.value = result.total_day || 0;
// arrows.value = result.total_arrow || 0;
// }
// });
onMounted(async () => {
const pointBook = uni.getStorageSync("last-point-book");
if (pointBook) {
bowType.value = pointBook.bowType;
distance.value = pointBook.distance;
bowtargetType.value = pointBook.bowtargetType;
expandIndex.value = 3;
}
});
</script>
<template>
<Container
:bgType="2"
bgColor="#F5F5F5"
:whiteBackArrow="false"
title="选择参数"
>
<view class="container">
<EditOption
:itemIndex="0"
:expand="expandIndex === 0"
:onExpand="onExpandChange"
:onSelect="onSelect"
:value="bowType.name"
/>
<EditOption
:itemIndex="1"
:expand="expandIndex === 1"
:onExpand="onExpandChange"
:onSelect="onSelect"
:value="distance + ''"
/>
<EditOption
:itemIndex="2"
:expand="expandIndex === 2"
:onExpand="onExpandChange"
:onSelect="onSelect"
:value="bowtargetType.name"
/>
<EditOption
:itemIndex="3"
:expand="expandIndex === 3"
:onExpand="onExpandChange"
:onSelect="onSelect"
/>
</view>
<template #bottom>
<SButton :rounded="50" :onClick="toEditPage">下一步</SButton>
</template>
</Container>
</template>
<style scoped>
.container {
width: calc(100% - 20px);
padding: 0 10px;
display: flex;
flex-direction: column;
align-items: center;
}
.container > view:nth-child(2) {
margin: 0 10px;
}
.header {
width: 100%;
height: 27vw;
position: relative;
display: flex;
align-items: center;
color: #ffffffc7;
font-size: 14px;
margin-top: 10px;
}
.header > image {
position: absolute;
width: 100%;
border: 2px solid #fff;
box-sizing: border-box;
border-radius: 10px;
}
.header > view {
position: relative;
}
.header > view:nth-child(2) {
margin-left: 7vw;
margin-right: 7vw;
}
.header > view > view > text:first-child {
font-size: 27px;
font-weight: 500;
margin-right: 5px;
color: #fff4c9;
}
</style>