Files
shoot-miniprograms/src/pages/point-book-edit.vue

282 lines
7.1 KiB
Vue
Raw Normal View History

2025-07-30 09:55:15 +08:00
<script setup>
2025-07-30 14:20:38 +08:00
import { ref, onMounted } from "vue";
2025-07-30 09:55:15 +08:00
import Container from "@/components/Container.vue";
import ScreenHint2 from "@/components/ScreenHint2.vue";
import SButton from "@/components/SButton.vue";
2025-07-30 17:38:48 +08:00
import BowTargetEdit from "@/components/BowTargetEdit.vue";
2025-08-04 17:54:59 +08:00
import { savePointBookAPI } from "@/apis";
2025-07-30 09:55:15 +08:00
const clickable = ref(false);
const showTip = ref(false);
2025-07-30 14:20:38 +08:00
const groups = ref(0);
const amount = ref(0);
const currentGroup = ref(1);
const currentArrow = ref(0);
const arrowGroups = ref({});
2025-08-04 16:28:34 +08:00
const bowtarget = ref({});
const ringTypes = ref([
{ ring: "X", color: "#FADB80" },
{ ring: "10", color: "#FADB80" },
{ ring: "9", color: "#FADB80" },
{ ring: "8", color: "#F97E81" },
{ ring: "7", color: "#F97E81" },
{ ring: "6", color: "#7AC7FF" },
{ ring: "5", color: "#7AC7FF" },
{ ring: "4", color: "#9B9B9B" },
{ ring: "3", color: "#9B9B9B" },
{ ring: "2", color: "#d8d8d8" },
{ ring: "1", color: "#d8d8d8" },
]);
2025-07-30 09:55:15 +08:00
const onBack = () => {
uni.navigateBack();
};
2025-08-04 17:54:59 +08:00
const onSubmit = async () => {
2025-07-30 14:20:38 +08:00
if (currentGroup.value < groups.value) {
currentGroup.value++;
currentArrow.value = 0;
clickable.value = false;
} else {
2025-08-04 17:54:59 +08:00
const pointBook = uni.getStorageSync("point-book");
const res = await savePointBookAPI(
pointBook.bowType.id,
pointBook.distance,
pointBook.bowtargetType.id,
groups.value,
amount.value,
Object.values(arrowGroups.value)
);
2025-08-05 11:51:09 +08:00
if (res.record_id) {
2025-08-04 17:54:59 +08:00
uni.redirectTo({
2025-08-05 11:51:09 +08:00
url: `/pages/point-book-detail?id=${res.record_id}`,
2025-08-04 17:54:59 +08:00
});
}
2025-07-30 14:20:38 +08:00
}
};
const onClickRing = (ring) => {
if (arrowGroups.value[currentGroup.value]) {
2025-07-31 14:32:14 +08:00
arrowGroups.value[currentGroup.value][currentArrow.value] = { ring };
2025-07-30 14:20:38 +08:00
clickable.value = arrowGroups.value[currentGroup.value].every(
2025-07-31 14:32:14 +08:00
(item) => !!item.ring
2025-07-30 14:20:38 +08:00
);
2025-07-31 14:32:14 +08:00
if (currentArrow.value < amount.value - 1) currentArrow.value++;
2025-07-30 14:20:38 +08:00
}
};
2025-07-30 17:38:48 +08:00
const deleteArrow = () => {
2025-07-31 14:32:14 +08:00
arrowGroups.value[currentGroup.value][currentArrow.value] = {};
};
const onEditDone = (arrow) => {
2025-08-01 09:20:10 +08:00
arrowGroups.value[currentGroup.value][currentArrow.value] = arrow;
2025-08-04 17:54:59 +08:00
clickable.value = arrowGroups.value[currentGroup.value].every(
(item) => !!item.ring
);
2025-07-31 14:32:14 +08:00
if (currentArrow.value < amount.value - 1) currentArrow.value++;
2025-07-30 17:38:48 +08:00
};
2025-07-30 14:20:38 +08:00
onMounted(() => {
const pointBook = uni.getStorageSync("point-book");
2025-08-04 16:28:34 +08:00
if (pointBook.bowtargetType) {
bowtarget.value = pointBook.bowtargetType;
if (bowtarget.value.id > 3) {
ringTypes.value = ringTypes.value.slice(0, 6);
if (bowtarget.value.id > 8) {
ringTypes.value = ringTypes.value.slice(1);
}
}
}
2025-07-30 14:20:38 +08:00
if (pointBook.amountGroup) {
groups.value = Number(pointBook.amountGroup.split("/")[0]);
amount.value = Number(pointBook.amountGroup.split("/")[1]);
for (let i = 1; i <= groups.value; i++) {
2025-07-31 14:32:14 +08:00
arrowGroups.value[i] = new Array(amount.value).fill({});
2025-07-30 14:20:38 +08:00
}
}
});
2025-07-30 09:55:15 +08:00
</script>
<template>
<Container
:bgType="2"
bgColor="#F5F5F5"
:whiteBackArrow="false"
:onBack="() => (showTip = true)"
>
2025-07-30 14:20:38 +08:00
<view class="container">
2025-07-31 14:32:14 +08:00
<BowTargetEdit
:onChange="onEditDone"
:arrows="arrowGroups[currentGroup]"
2025-08-04 16:28:34 +08:00
:id="bowtarget.id"
:src="bowtarget.icon"
2025-07-31 14:32:14 +08:00
/>
2025-07-30 14:20:38 +08:00
<view class="title-bar">
2025-07-30 17:38:48 +08:00
<view>
<view />
<text> {{ currentGroup }} </text>
</view>
<view @click="deleteArrow">
<image src="../static/delete.png" />
<text>删除</text>
</view>
2025-07-30 14:20:38 +08:00
</view>
<view class="bow-arrows">
<view
v-if="arrowGroups[currentGroup]"
v-for="(arrow, index) in arrowGroups[currentGroup]"
:key="index"
@click="currentArrow = index"
:style="{
borderColor: currentArrow === index ? '#FED847' : '#eeeeee',
borderWidth: currentArrow === index ? '2px' : '1px',
}"
2025-07-31 14:32:14 +08:00
>{{
isNaN(arrow.ring)
? arrow.ring
: arrow.ring
? arrow.ring + " 环"
: ""
}}</view
2025-07-30 14:20:38 +08:00
>
</view>
2025-08-05 17:28:11 +08:00
<text>推荐在靶纸上落点计分这样可获得稳定性分析</text>
2025-07-30 14:20:38 +08:00
<view class="bow-rings">
<view
2025-08-04 16:28:34 +08:00
v-for="(item, index) in ringTypes"
:key="index"
@click="() => onClickRing(item.ring)"
:style="{ backgroundColor: item.color }"
>{{ item.ring }}</view
>
<view
:style="{ backgroundColor: '#d8d8d8' }"
@click="() => onClickRing('M')"
>M</view
2025-07-30 14:20:38 +08:00
>
</view>
2025-07-30 09:55:15 +08:00
<ScreenHint2 :show="showTip">
<view class="tip-content">
<text>现在离开会导致</text>
<text>未提交的数据丢失是否继续</text>
<view>
<button hover-class="none" @click="onBack">退出</button>
<button hover-class="none" @click="showTip = false">
继续记录
</button>
</view>
</view>
</ScreenHint2>
</view>
<view :style="{ marginBottom: '20px' }">
<SButton
2025-08-05 15:58:43 +08:00
:rounded="50"
2025-07-30 09:55:15 +08:00
:disabled="!clickable"
2025-07-30 14:20:38 +08:00
:onClick="onSubmit"
2025-07-30 09:55:15 +08:00
disabledColor="#DDDDDD"
:color="clickable ? '#000' : '#fff'"
>
2025-07-30 14:20:38 +08:00
{{ currentGroup === groups ? "记完了,提交看分析" : "下一组" }}
2025-07-30 09:55:15 +08:00
</SButton>
</view>
</Container>
</template>
<style scoped>
2025-07-30 14:20:38 +08:00
.container {
width: 100%;
}
.container > text {
margin: 15px;
color: #999;
font-size: 13px;
font-weight: 200;
}
.bow-arrows,
.bow-rings {
margin: 15px;
display: grid;
column-gap: 1vw;
grid-template-columns: repeat(6, 1fr);
2025-08-07 18:13:14 +08:00
position: relative;
2025-07-30 14:20:38 +08:00
}
.bow-arrows > view,
.bow-rings > view {
background: #ffffff;
border-radius: 6px;
border: 1px solid #eeeeee;
box-sizing: border-box;
font-size: 12px;
color: #333;
text-align: center;
padding: 5px 0;
height: 32px;
line-height: 20px;
margin-bottom: 5px;
}
.bow-rings > view {
font-size: 13px;
height: 36px;
line-height: 24px;
color: #fff;
background-color: #d8d8d8;
}
2025-07-30 09:55:15 +08:00
.tip-content {
width: 100%;
padding: 25px;
display: flex;
flex-direction: column;
}
.tip-content > text {
width: 100%;
text-align: center;
font-size: 14px;
margin-top: 5px;
}
.tip-content > view {
display: flex;
justify-content: space-between;
margin-top: 20px;
}
.tip-content > view > button {
width: 48%;
background: linear-gradient(180deg, #fbfbfb 0%, #f5f5f5 100%);
border-radius: 22px;
border: 1px solid #eeeeee;
padding: 12px 0;
font-size: 14px;
}
.tip-content > view > button:last-child {
background: #fed847;
}
2025-07-30 14:20:38 +08:00
.title-bar {
2025-07-30 17:38:48 +08:00
width: calc(100% - 30px);
2025-07-30 14:20:38 +08:00
display: flex;
align-items: center;
2025-07-30 17:38:48 +08:00
justify-content: space-between;
2025-07-30 14:20:38 +08:00
font-size: 13px;
2025-07-30 17:38:48 +08:00
margin: 0 15px;
2025-08-07 18:13:14 +08:00
position: relative;
2025-07-30 17:38:48 +08:00
}
.title-bar > view:first-child {
display: flex;
align-items: center;
2025-07-30 14:20:38 +08:00
color: #333;
font-weight: 500;
}
2025-07-30 17:38:48 +08:00
.title-bar > view:first-child > view:first-child {
2025-07-30 14:20:38 +08:00
width: 5px;
height: 15px;
border-radius: 10px;
background-color: #fed847;
margin-right: 7px;
2025-07-30 17:38:48 +08:00
}
.title-bar > view:nth-child(2) {
color: #287fff;
display: flex;
align-items: center;
}
.title-bar > view:nth-child(2) image {
width: 14px;
height: 14px;
margin-right: 5px;
2025-07-30 14:20:38 +08:00
}
2025-07-30 09:55:15 +08:00
</style>