diff --git a/hwe/ts/PageNationBetting.vue b/hwe/ts/PageNationBetting.vue
index 51d03996..909bd86d 100644
--- a/hwe/ts/PageNationBetting.vue
+++ b/hwe/ts/PageNationBetting.vue
@@ -2,90 +2,7 @@
-
-
-
- {{ info.name }}
- (종료)
- ({{ parseYearMonth(info.closeYearMonth)[0] }}년 {{ parseYearMonth(info.closeYearMonth)[1] }}월까지)
- (베팅 마감)
- (총액: {{ bettingAmount.toLocaleString() }})
-
-
-
-
-
-
{{ candidate.title }}
-
-
선택율: {{ ((partialBet.get(idx) ?? 0) / pureBettingAmount * 100).toFixed(1) }}%
-
-
-
-
-
잔여 {{ info.reqInheritancePoint ? '포인트' : '금' }} : {{ bettingInfo.remainPoint.toLocaleString() }}
-
사용 포인트: {{ sum(Array.from(myBettings.values())).toLocaleString() }}
-
대상: {{ getTypeStr(pickedBetTypeKey) }}
-
-
-
-
- 베팅
-
-
-
-
-
배당 순위
-
-
-
{{ getTypeStr(betType) }}
-
{{ amount.toLocaleString() }}
-
{{ myBettings.has(betType) ? `(${myBettings.get(betType)?.toLocaleString()} -> ${((myBettings.get(betType) ?? 0) * bettingAmount / amount / ((info.isExclusive && info.selectCnt > 1) ? 1 : 2)).toLocaleString()})` : '' }}
-
{{ (bettingAmount / amount / ((info.isExclusive && info.selectCnt > 1) ? 1 : 2)).toFixed(1) }}배
-
-
-
-
+
로딩 중...
베팅 목록
@@ -93,10 +10,12 @@
class="bettingItem"
v-for="info of Object.values(bettingList).reverse()"
:key="info.id"
- @click="loadBetting(info.id)"
+ @click="targetBettingID = info.id"
>
[{{ parseYearMonth(info.openYearMonth)[0] }}년 {{ parseYearMonth(info.openYearMonth)[1] }}월] {{ info.name }}
-
(종료)
+
(종료)
({{ parseYearMonth(info.closeYearMonth)[0] }}년 {{ parseYearMonth(info.closeYearMonth)[1] }}월까지)
@@ -112,33 +31,13 @@
import MyToast from "@/components/MyToast.vue";
import TopBackBar from "@/components/TopBackBar.vue";
import BottomBar from "@/components/BottomBar.vue";
-import { ToastType } from "@/defs";
+import { BettingInfo, ToastType } from "@/defs";
import { onMounted, ref } from "vue";
import { SammoAPI, ValidResponse } from "./SammoAPI";
-import { isString, sum } from "lodash";
+import { isString } from "lodash";
import { parseYearMonth } from "@/util/parseYearMonth";
import { joinYearMonth } from "./util/joinYearMonth";
-
-type SelectItem = {
- title: string;
- info?: string;
- isHtml?: boolean;
- aux?: Record
;
-}
-
-type BettingInfo = {
- id: number;
- type: 'nationBetting',
- name: string;
- finished: boolean;
- selectCnt: number;
- isExclusive?: boolean;
- reqInheritancePoint: boolean;
- openYearMonth: number;
- closeYearMonth: number;
- candidates: SelectItem[];
- winner?: number[];
-}
+import BettingDetail from "@/components/BettingDetail.vue";
type BettingListResponse = ValidResponse & {
bettingList: Record>,
@@ -146,187 +45,22 @@ type BettingListResponse = ValidResponse & {
month: number,
};
-type BettingDetailResponse = ValidResponse & {
- bettingInfo: BettingInfo;
- bettingDetail: [string, number][];
- myBetting: [string, number][];
- remainPoint: number;
- year: number;
- month: number;
-}
+
const toasts = ref([]);
const year = ref();
const month = ref();
const yearMonth = ref();
const bettingList = ref();
-const bettingInfo = ref();
-const bettingAmount = ref(0);
-const pureBettingAmount = ref(0);
-const partialBet = ref(new Map());
-const detailBet = ref<[string, number][]>([]);
+const targetBettingID = ref();
-const typeMap = ref(new Map());
-function getTypeStr(type: string): string {
- const typeResult = typeMap.value.get(type);
- if (typeResult !== undefined) {
- return typeResult;
- }
- const bettingSubTypes = JSON.parse(type) as number[];
- if (bettingSubTypes[0] < -1) {
- return 'Invalid';
- }
- const textBettingType = bettingSubTypes.map((idx) => {
- return bettingInfo.value?.bettingInfo.candidates[idx].title;
- }).join(', ');
- typeMap.value.set(type, textBettingType);
- return textBettingType;
+function addToast(msg: ToastType){
+ toasts.value.push(msg);
}
-const pickedBetType = ref(new Set());
-const pickedBetTypeKey = ref('[]');
-
-const betPoint = ref(0);
-const myBettings = ref(new Map());
-
-function toggleCandidate(idx: number) {
- if (bettingInfo.value === undefined) {
- return;
- }
- const selectCnt = bettingInfo.value.bettingInfo.selectCnt;
-
- if (selectCnt == 1) {
- pickedBetType.value.clear();
- pickedBetType.value.add(idx);
- pickedBetTypeKey.value = JSON.stringify([idx]);
- return;
- }
-
- if (pickedBetType.value.has(idx)) {
- pickedBetType.value.delete(idx);
- }
- else if (pickedBetType.value.size < selectCnt) {
- pickedBetType.value.add(idx);
- }
- else {
- toasts.value.push({
- title: '오류',
- type: 'warning',
- content: `이미 ${selectCnt}개를 선택했습니다.`,
- })
- return;
- }
-
- const typeArr = Array.from(pickedBetType.value.values());
- pickedBetTypeKey.value = JSON.stringify(typeArr.sort((lhs, rhs) => lhs - rhs));
-}
-
-async function loadBetting(bettingID: number) {
- try {
- const result = await SammoAPI.Betting.GetBettingDetail({
- betting_id: bettingID
- });
- year.value = result.year;
- month.value = result.month;
- yearMonth.value = joinYearMonth(result.year, result.month);
- bettingInfo.value = result;
-
- partialBet.value.clear();
-
- const betSort = new Map();
-
-
- let _bettingAmount = 0;
- let adminBettingAmount = 0;
- for (const [bettingType, amount] of result.bettingDetail) {
- console.log(amount, typeof (amount));
- let userBet = true;
- const bettingSubTypes = JSON.parse(bettingType) as number[];
- for (const bettingSubType of bettingSubTypes) {
- if (bettingSubType < 0) {
- userBet = false;
- continue;
- }
- const oldValue = partialBet.value.get(bettingSubType) ?? 0;
- partialBet.value.set(bettingSubType, oldValue + amount);
- }
-
- if (userBet) {
- const oldValue = betSort.get(bettingType) ?? 0;
- betSort.set(bettingType, oldValue + amount);
- }
-
- _bettingAmount += amount;
- if (!userBet) {
- adminBettingAmount += amount;
- }
- }
- console.log(_bettingAmount);
- bettingAmount.value = _bettingAmount;
- pureBettingAmount.value = _bettingAmount - adminBettingAmount;
-
- detailBet.value = Array.from(betSort.entries());
- detailBet.value.sort(([, lhsVal], [, rhsVal]) => {
- return rhsVal - lhsVal;
- })
-
- pickedBetType.value.clear();
- pickedBetTypeKey.value = '[]';
- myBettings.value.clear();
-
- for (const [betType, amount] of result.myBetting) {
- myBettings.value.set(betType, amount);
- }
-
-
- } catch (e) {
- if (isString(e)) {
- toasts.value.push({
- title: "에러",
- content: e,
- type: "danger",
- });
- }
- console.error(e);
- }
-}
-
-async function submitBet(): Promise {
- const info = bettingInfo.value;
- if (info === undefined) {
- return;
- }
-
- const bettingID = info.bettingInfo.id;
- const bettingType = JSON.parse(pickedBetTypeKey.value);
- const amount = betPoint.value;
- try {
- await SammoAPI.Betting.Bet({
- bettingID,
- bettingType,
- amount,
- });
- toasts.value.push({
- title: '완료',
- content: '베팅했습니다',
- type: 'success'
- });
- await loadBetting(info.bettingInfo.id);
- } catch (e) {
- if (isString(e)) {
- toasts.value.push({
- title: "에러",
- content: e,
- type: "danger",
- });
- }
- console.error(e);
- }
-
-}
console.log('시작!');
onMounted(async () => {
diff --git a/hwe/ts/components/BettingDetail.vue b/hwe/ts/components/BettingDetail.vue
new file mode 100644
index 00000000..caafdd1f
--- /dev/null
+++ b/hwe/ts/components/BettingDetail.vue
@@ -0,0 +1,436 @@
+
+
+
+ {{ info.name }}
+ (종료)
+ ({{ parseYearMonth(info.closeYearMonth)[0] }}년 {{ parseYearMonth(info.closeYearMonth)[1] }}월까지)
+ (베팅 마감)
+ (총액: {{ bettingAmount.toLocaleString() }})
+
+
+
+
+
+
{{ candidate.title }}
+
+
선택율: {{ ((partialBet.get(idx) ?? 0) / pureBettingAmount * 100).toFixed(1) }}%
+
+
+
+
+
잔여 {{ info.reqInheritancePoint ? '포인트' : '금' }} : {{ bettingDetailInfo.remainPoint.toLocaleString() }}
+
사용 포인트: {{ sum(Array.from(myBettings.values())).toLocaleString() }}
+
대상: {{ getTypeStr(pickedBetTypeKey) }}
+
+
+
+
+ 베팅
+
+
+
+
+
배당 순위
+
+
대상
+
베팅액
+
내 베팅
+
{{ info.finished? '배율':'기대 배율' }}
+
+
+
+
+ {{ getTypeStr(betType) }}
+ {{ amount.toLocaleString() }}
+
+ ({{ subPoint.toLocaleString() }} -> {{ calculatedReward[matchPoint] == 0? 0 : (subPoint * calculatedReward[matchPoint] / (calculatedSubAmount.get(matchPoint)??1)).toFixed(1).toLocaleString() }})
+
+
+ {{ (calculatedReward[matchPoint] == 0? 0 : (calculatedReward[matchPoint] / (calculatedSubAmount.get(matchPoint)??1))).toFixed(1).toLocaleString() }}배
+
+
+
+
+
+
{{ getTypeStr(betType) }}
+
{{ amount.toLocaleString() }}
+
+ ({{ subPoint.toLocaleString() }} -> {{ (subPoint * maxBettingReward / amount).toFixed(1).toLocaleString() }})
+
+
+
{{ (maxBettingReward / amount).toFixed(1).toLocaleString() }}배
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/hwe/ts/defs.ts b/hwe/ts/defs.ts
index c5840288..173e5c22 100644
--- a/hwe/ts/defs.ts
+++ b/hwe/ts/defs.ts
@@ -223,3 +223,25 @@ export const diplomacyStateInfo: Record = {
2: { name: '통상' },
7: { name: '불가침', color: 'green' },
}
+
+
+export type SelectItem = {
+ title: string;
+ info?: string;
+ isHtml?: boolean;
+ aux?: Record;
+}
+
+export type BettingInfo = {
+ id: number;
+ type: 'nationBetting',
+ name: string;
+ finished: boolean;
+ selectCnt: number;
+ isExclusive?: boolean;
+ reqInheritancePoint: boolean;
+ openYearMonth: number;
+ closeYearMonth: number;
+ candidates: SelectItem[];
+ winner?: number[];
+}
\ No newline at end of file