Skip to content

Commit

Permalink
feat: handle exceed off campus to on campus.
Browse files Browse the repository at this point in the history
  • Loading branch information
7086cmd committed Sep 27, 2024
1 parent dcdf319 commit b209a03
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/components/activity/ZActivityMember.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ watch(height, () => {
class="py-2"
v-if="userStore.position.includes('department') || userStore.position.includes('admin')"
:user="id"
discount
/>
<ElButton
v-if="
Expand Down
11 changes: 7 additions & 4 deletions src/components/activity/ZUserTimeJudge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const base = reactive({
const exceed = ref(discount.value)
function getDiscount(on: number, exceed: number = 30, rate: number = 3) {
function getDiscount(on: number, exceed: number, rate: number) {
if (on <= exceed) return 0
console.log(on, exceed, rate)
const result = Math.round((on - exceed) / rate)
Expand All @@ -61,7 +61,8 @@ async function getTime() {
base.onCampus = result.onCampus
base.offCampus = result.offCampus
base.socialPractice = result.socialPractice
off.value = base.offCampus + (exceed.value ? getDiscount(base.onCampus) : 0)
off.value = base.offCampus + (exceed.value ? getDiscount(base.onCampus, 30, 3) : 0)
on.value = base.onCampus + (exceed.value ? getDiscount(base.offCampus, 15, 2) : 0)
if (user.value === userStore._id) {
userStore.setTime(result)
}
Expand All @@ -72,11 +73,13 @@ async function getTime() {
getTime()
const off = ref(base.offCampus)
const on = ref(base.onCampus)
watch(
exceed,
() => {
off.value = base.offCampus + (exceed.value ? getDiscount(base.onCampus) : 0)
off.value = base.offCampus + (exceed.value ? getDiscount(base.onCampus, 30, 3) : 0)
on.value = base.onCampus + (exceed.value ? getDiscount(base.offCampus, 15, 2) : 0)
},
{ immediate: true }
)
Expand Down Expand Up @@ -110,7 +113,7 @@ watch(
</ElCol>
<ElCol :span="2"><ElDivider direction="vertical" class="height-full" /></ElCol>
<ElCol :span="width < height ? 10 : 4">
<ZActivityMemberTimeJudge type="on-campus" :realTime="base.onCampus" />
<ZActivityMemberTimeJudge type="on-campus" :realTime="on" />
<ElDivider v-if="width < height" />
</ElCol>
<ElCol v-if="width > height" :span="1"
Expand Down
1 change: 1 addition & 0 deletions src/views/user/UserHome.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ async function refreshUser() {
:on-campus="user.time.onCampus"
:off-campus="time.offCampus"
:social-practice="time.socialPractice"
discount
/>
</div>
<div class="pt-4 pb-8">
Expand Down

0 comments on commit b209a03

Please sign in to comment.