浏览代码

静态页面

1002884655 4 年前
父节点
当前提交
d2655325cd
共有 3 个文件被更改,包括 150 次插入13 次删除
  1. 1
    1
      src/pages/index/ZuQiu/index.vue
  2. 12
    12
      src/pages/index/ZuQiuDingDan/index.vue
  3. 137
    0
      src/util/Football.js

+ 1
- 1
src/pages/index/ZuQiu/index.vue 查看文件

@@ -92,7 +92,7 @@
92 92
       <a class="iconfont iconjian" @click="EmptyAllData"></a>
93 93
       <div class="flex-item"></div>
94 94
       <span>{{ResList.length ? `已选择${ResList.length}场比赛` : '非单关至少选两场比赛'}}</span>
95
-      <a class="Btn">投注</a>
95
+      <a class="Btn" @click="ToBetting">投注</a>
96 96
     </div>
97 97
 
98 98
   </div>

+ 12
- 12
src/pages/index/ZuQiuDingDan/index.vue 查看文件

@@ -51,7 +51,7 @@
51 51
         <span>金额:<em>{{TotalPrice}}</em>元</span>
52 52
         <span>预计奖金:<em>{{(PriceArr[0] * Multiple).toFixed(2)}} ~ {{(PriceArr[1] * Multiple).toFixed(2)}}</em>元</span>
53 53
       </div>
54
-      <a :class="{'active': CurrentStoreId !== null && LanQiuCart.length}" @click="ToPostBetting">立即购买</a>
54
+      <a :class="{'active': CurrentStoreId !== null && ZuQiuCart.length}" @click="ToPostBetting">立即购买</a>
55 55
     </div>
56 56
 
57 57
     <div class="Layer" v-if="ShowPassWay">
@@ -110,7 +110,7 @@
110 110
 <script>
111 111
 import { Switch } from 'vant'
112 112
 import GetAllParts from '../../../util/Sports'
113
-import GetPrice from '../../../util/Basketball'
113
+import GetPrice from '../../../util/FootballPrice'
114 114
 import { mapState, mapMutations, createNamespacedHelpers } from 'vuex'
115 115
 const { mapState: mapUserState, mapActions: mapUserActions, mapMutations: mapUserMutations } = createNamespacedHelpers('user')
116 116
 export default {
@@ -142,7 +142,7 @@ export default {
142 142
     }),
143 143
     ...mapUserState({
144 144
       UserInfo: x => x.UserInfo, // 用户信息
145
-      LanQiuCart: x => x.LanQiuCart // 篮球购物车
145
+      ZuQiuCart: x => x.ZuQiuCart // 篮球购物车
146 146
     })
147 147
   },
148 148
   components: {
@@ -165,15 +165,15 @@ export default {
165 165
       'EditMainData' // 配置页面框架数据
166 166
     ]),
167 167
     ...mapUserMutations([
168
-      'DeleteLanQiuCart',
169
-      'EmptyLanQiuCart'
168
+      'DeleteZuQiuCart',
169
+      'EmptyZuQiuCart'
170 170
     ]),
171 171
     ...mapUserActions([
172 172
       'PostBetting',
173 173
       'GetStoreList'
174 174
     ]),
175 175
     Init () { // 初始化
176
-      this.PageList = [...this.LanQiuCart] // 赋值页面数据
176
+      this.PageList = [...this.ZuQiuCart] // 赋值页面数据
177 177
       console.log(this.PageList)
178 178
       this.ToGetStoreList() // 获取店铺列表
179 179
       if (this.$route.query.type === 'single') { // 单关
@@ -182,11 +182,11 @@ export default {
182 182
       }
183 183
     },
184 184
     ToPostBetting () { // 去下注
185
-      if (this.DataLock || !this.LanQiuCart.length || this.CurrentStoreId === null || this.CurrentPassCode === null) return
185
+      if (this.DataLock || !this.ZuQiuCart.length || this.CurrentStoreId === null || this.CurrentPassCode === null) return
186 186
       this.DataLock = true
187 187
       let Data = null
188 188
       let ListData = []
189
-      this.LanQiuCart.map((item) => {
189
+      this.ZuQiuCart.map((item) => {
190 190
         ListData.push({
191 191
           matchId: item.id,
192 192
           awayTeamId: item.awayTeamId, // 客队id
@@ -214,7 +214,7 @@ export default {
214 214
         data: { ...Data }
215 215
       }).then((res) => {
216 216
         this.Toast('投注成功!')
217
-        this.EmptyLanQiuCart()
217
+        this.EmptyZuQiuCart()
218 218
         this.PageList = []
219 219
         this.PriceArr = [0, 0]
220 220
         this.TotalCount = 0
@@ -249,7 +249,7 @@ export default {
249 249
     },
250 250
     ToGetAllParts () { // 枚举投注
251 251
       let ListData = []
252
-      this.LanQiuCart.map((item) => {
252
+      this.ZuQiuCart.map((item) => {
253 253
         ListData.push({
254 254
           matchId: item.id,
255 255
           spreadPoints: item.rq,
@@ -317,8 +317,8 @@ export default {
317 317
     DeleteItem (index) { // 删除投注
318 318
       if (this.DataLock) return
319 319
       this.DataLock = true
320
-      this.DeleteLanQiuCart(index)
321
-      this.PageList = [...this.LanQiuCart]
320
+      this.DeleteZuQiuCart(index)
321
+      this.PageList = [...this.ZuQiuCart]
322 322
       if (this.$route.query.type === 'mix') {
323 323
         this.CurrentPassCode = null
324 324
       }

+ 137
- 0
src/util/Football.js 查看文件

@@ -0,0 +1,137 @@
1
+/* eslint-disable */
2
+// 模拟比赛得分
3
+const matches = [
4
+  [50, 46], [60, 52], [75, 62], [88, 71], [95, 72], [107, 80],
5
+  [46, 50], [52, 60], [62, 75], [71, 88], [72, 95], [80, 107],
6
+  [40, 40], [60, 55], [96, 80], [120, 110], [150, 106],
7
+]
8
+
9
+const playWayFunc = {
10
+  'bst-wl': computeWDL,
11
+  'bst-wls': computeWDLS,
12
+  'bst-score': computeScore,
13
+  'bst-points': computePoints
14
+}
15
+
16
+// 遍历模拟比赛获取最大, 最小奖金
17
+export function GetPrice (allParts) {
18
+  let minPrice
19
+  let maxPrice
20
+
21
+  // 遍历模拟比赛的各种可能
22
+  matches.forEach(match => {
23
+    const [min, max] = GetMinAndMax(allParts, match)
24
+    if (min < minPrice || minPrice === undefined) {
25
+      minPrice = min
26
+    }
27
+
28
+    if (max > maxPrice || maxPrice === undefined) {
29
+      maxPrice = max
30
+    }
31
+  })
32
+
33
+  return [minPrice, maxPrice]
34
+}
35
+
36
+function GetMinAndMax (allParts, match) {
37
+  let minPrice = 0
38
+  let maxPrice = 0
39
+
40
+  // 所有组合
41
+  allParts.forEach(parts => {
42
+    // 每种组合 比如 3串4 是 3个2串1, 1个3串1
43
+    const price = parts.map(part => {
44
+      // 场次组合 比如 2串1
45
+      return part.map(grp => {
46
+        const { detail, spreadPoints, presetPoints } = grp
47
+        const { wayCode } = detail
48
+        const fn = playWayFunc[wayCode]
49
+        return fn(grp, match, spreadPoints, presetPoints)
50
+      }).filter(Boolean).reduce((acc, x) => acc * x, 1)
51
+    }).reduce((acc, x) => acc + x, 0)
52
+
53
+    if (minPrice === 0 || minPrice > price) {
54
+      minPrice = price
55
+    }
56
+
57
+    maxPrice += price
58
+  })
59
+
60
+  return [minPrice, maxPrice]
61
+}
62
+
63
+// 胜平负
64
+function computeWDL (part, match) {
65
+  const [x, y] = match
66
+  const { ruleCode, odds } = part.detail
67
+
68
+  switch (ruleCode) {
69
+    case 'bst-win':
70
+      return x > y ? odds : 0
71
+    default:
72
+      return x < y ? odds : 0
73
+  }
74
+}
75
+
76
+// 让球胜平负
77
+function computeWDLS (part, match, rq) {
78
+  const [x, y] = match
79
+  const { ruleCode, odds } = part.detail
80
+
81
+  switch (ruleCode) {
82
+    case 'bst-sp-win':
83
+      return x + rq > y ? odds : 0
84
+    default:
85
+      return x + rq < y ? odds : 0
86
+  }
87
+}
88
+
89
+// 比分
90
+function computeScore (part, match, rq, ys) {
91
+  const [x, y] = match
92
+  const { ruleCode, odds } = part.detail
93
+
94
+  switch (ruleCode) {
95
+    case 'bst-big':
96
+      return x + y > ys ? odds : 0
97
+    default:
98
+      return x + y < ys ? odds : 0
99
+  }
100
+}
101
+
102
+// 进球数
103
+function computePoints (part, match) {
104
+  const [x, y] = match
105
+  const { ruleCode, odds } = part.detail
106
+
107
+  switch (ruleCode) {
108
+    case 'bst-w15':
109
+      return x - y >= 1 && x - y <= 5 ? odds : 0
110
+    case 'bst-w610':
111
+      return x - y >= 6 && x - y <= 10 ? odds : 0
112
+    case 'bst-w1115':
113
+      return x - y >= 11 && x - y <= 15  ? odds : 0
114
+    case 'bst-w1620':
115
+      return x - y >= 16 && x - y <= 20 ? odds : 0
116
+    case 'bst-w2125':
117
+      return x - y >= 21 && x - y <= 25 ? odds : 0
118
+    case 'bst-w99':
119
+      return x - y >= 26 ? odds : 0
120
+    case 'bst-l15':
121
+      return y - x >= 1 && y - x <= 5 ? odds : 0
122
+    case 'bst-l610':
123
+      return y - x >= 6 && y - x <= 10 ? odds : 0
124
+    case 'bst-l1115':
125
+      return y - x >= 11 && y - x <= 15  ? odds : 0
126
+    case 'bst-l1620':
127
+      return y - x >= 16 && y - x <= 20 ? odds : 0
128
+    case 'bst-l2125':
129
+      return y - x >= 21 && y - x <= 25 ? odds : 0
130
+    case 'bst-l99':
131
+      return y - x >= 26 ? odds : 0
132
+    default:
133
+      return 0
134
+  }
135
+}
136
+ 
137
+export default GetPrice