dcdf16fd5d856a0e3fb497fce27c2aa0914b84ff.svn-base 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. import { type } from "os";
  2. export default {
  3. /**
  4. * 获取缓存sessionStorage数据
  5. * @param {*str} key
  6. * @param {* obj||str} val
  7. */
  8. setCache: function (key, val) {
  9. if (val instanceof Array) {
  10. let str = JSON.stringify(val);
  11. window.sessionStorage.setItem(key, str);
  12. } else {
  13. window.sessionStorage.setItem(key, val);
  14. }
  15. },
  16. /**
  17. * 获取缓存sessionStorage数据
  18. * @param {*str} key
  19. */
  20. getCache: function (key) {
  21. return window.sessionStorage.getItem(key);
  22. },
  23. /**
  24. * 获取缓存localStorage数据
  25. * @param {*str} key
  26. * @param {* obj||str} val
  27. */
  28. setItem: function (key,val) {
  29. if (val instanceof Array) {
  30. let str = JSON.stringify(val);
  31. localStorage.setItem(key, str);
  32. } else {
  33. localStorage.setItem(key, val);
  34. }
  35. //return localStorage.setItem(key,val);
  36. },
  37. /**
  38. * 获取缓存localStorage数据
  39. * @param {*str} key
  40. */
  41. getItem: function (key) {
  42. return localStorage.getItem(key);
  43. },
  44. /**
  45. * 比赛时间计时器
  46. * @param {分钟} f
  47. * @param {秒} s
  48. * @param {回掉方法} fun
  49. */
  50. timer: function (f, s, fun) {
  51. let timing = setInterval(function () {
  52. s++;
  53. if (s < 10) {
  54. s = "0" + s;
  55. }
  56. if (s == 60) {
  57. f++;
  58. s = '00';
  59. }
  60. fun && fun(f, s);
  61. }, 1000)
  62. },
  63. /**
  64. * 移动端玩法投注公共方法
  65. * @param {obj} betting 玩法组件的选择赔率id数组
  66. * @param {*obj} bettingInfo 当前玩法赔率及相关数据
  67. * @param {*obj} data当前玩法赔率数据信息列表
  68. * @param {*obj} getBettingList Vuex里面的投注列表
  69. * @param {*str} name 当前组的玩法的title
  70. * @param {*int} dataNum 判断当前组件是否已有投注
  71. * @param {*int} limit 投注数量
  72. * @param {*function} callback 修改当前样式回调方法
  73. * @param {*function} fun 更新Vuex投注列表
  74. */
  75. bettingFunction: function (betting, bettingInfo, data, getBettingList, name, dataNum,limit,callback, fun) {
  76. let isTrue = true;
  77. let isAlert = false;
  78. betting.forEach((e, index) => {
  79. //删除投注数据
  80. if (bettingInfo.id == e.id) {
  81. data.forEach((res) => {
  82. if (bettingInfo.id == res.id) {
  83. callback && callback(res, false);
  84. betting.splice(index, 1);
  85. }
  86. })
  87. isTrue = false;
  88. }
  89. });
  90. //添加投注数据
  91. if (isTrue) {
  92. if(limit >= 10 ) {
  93. isAlert =true;
  94. }else{
  95. betting.push(bettingInfo);
  96. betting.forEach((e) => {
  97. if (bettingInfo.id == e.id) {
  98. data.forEach(res => {
  99. if (bettingInfo.id == res.id) {
  100. callback && callback(res, true);
  101. }
  102. })
  103. }
  104. })
  105. }
  106. }
  107. //初始化添加投注数据
  108. let obj = {
  109. title: name,
  110. data: betting
  111. };
  112. let array = [];
  113. if (dataNum != 10000) {
  114. getBettingList[dataNum] = obj;
  115. } else {
  116. if (getBettingList) {
  117. if (getBettingList.length > 0) {
  118. getBettingList.push(obj);
  119. }
  120. } else {
  121. array.push(obj);
  122. }
  123. }
  124. fun && fun(getBettingList, array,isAlert);
  125. },
  126. /**
  127. * pc端赛事详情投注方法
  128. * @param {array} data 当前玩法数据信息
  129. * @param {string} title 当前玩法
  130. * @param {int} id 当前玩法id
  131. * @param {int} index 当前玩法数据下标
  132. * @param {array} betting 玩法投注数据
  133. * @param {obj} teamName 比赛队伍名称
  134. * @param {string} playName 玩法名称
  135. * @param {string} match_id 赛事id
  136. * @param {string} ballId 球类
  137. * @param {string} limit 投注数量
  138. * @param {function} callback 回掉方法
  139. */
  140. publicBetMethod(data,title,id,index,betting,teamName,playName,name,match_id,ballId,limit,callback){
  141. let isAre = true;
  142. let isAdd = true,isAlert =false;
  143. data[index].home_team =teamName.home;
  144. data[index].guest_team =teamName.guest;
  145. data[index].playName =playName;
  146. data[index].name =name;
  147. data[index].match_id =match_id;
  148. data[index].ballId =ballId;
  149. let obj = {
  150. title:title,
  151. data:[data[index]]
  152. }
  153. if(betting.length >0){
  154. betting.forEach(e=>{
  155. if(e.title == title){
  156. //投注数据删除
  157. e.data.forEach((res,num) =>{
  158. if(res.id ==id){
  159. e.data.splice(num, 1);
  160. isAdd =false;
  161. }
  162. })
  163. //投注数据添加
  164. if(isAdd){
  165. if(limit >= 10 ) {
  166. isAlert =true;
  167. }else{
  168. e.data.push(data[index]);
  169. }
  170. }
  171. isAre =false;
  172. }
  173. })
  174. //投注数据添加新玩法
  175. if(isAre){
  176. if(limit >= 10 ) {
  177. isAlert =true;
  178. }else{
  179. betting.push(obj);
  180. }
  181. }
  182. }else{
  183. //初次添加投注玩法
  184. betting.push(obj);
  185. }
  186. callback && callback(betting,isAlert)
  187. },
  188. /**
  189. * pc端赛事页面串式
  190. * @param {array} data 当前玩法数据信息
  191. * @param {string} title 当前玩法
  192. * @param {int} id 当前玩法id
  193. * @param {int} idx 当前玩法数据下标
  194. * @param {int} index 当前赛事玩法数据下标
  195. * @param {int} i 当前赔率玩法数据下标
  196. * @param {int} activity 玩法
  197. * @param {array} betting 玩法投注数据
  198. * @param {string} match_id 赛事id玩法数据
  199. * @param {string} ballId 球类别名
  200. * @param {string} limit 投注数量
  201. * @param {function} callback 回掉方法
  202. */
  203. publicBetting(data,title,id,index,idx,i,betting,activity,match_id,teamName,playName,name,ballId,limit,callback){
  204. let isAre = true;
  205. let isAdd = true,isAlert =false;
  206. data[index].matchData[idx].oddsData[i].home_team = teamName.home;
  207. data[index].matchData[idx].oddsData[i].guest_team = teamName.guest;
  208. data[index].matchData[idx].oddsData[i].playName = playName;
  209. data[index].matchData[idx].oddsData[i].name = name;
  210. data[index].matchData[idx].oddsData[i].ballId = ballId;
  211. let obj = {
  212. title:title,
  213. data:[data[index].matchData[idx].oddsData[i]]
  214. }
  215. if(betting.length >0){
  216. betting.forEach(e=>{
  217. if(e.title == title){
  218. e.data.forEach((res,num) =>{
  219. if(res.id ==id){
  220. e.data.splice(num, 1);
  221. isAdd =false;
  222. }
  223. })
  224. if(isAdd){
  225. if(limit >= 10 ) {
  226. isAlert =true;
  227. }else{
  228. e.data.push(data[index].matchData[idx].oddsData[i]);
  229. }
  230. }
  231. isAre =false;
  232. }
  233. })
  234. if(isAre){
  235. if(limit >= 10 ) {
  236. isAlert =true;
  237. }else{
  238. betting.push(obj);
  239. }
  240. }
  241. }else{
  242. betting.push(obj);
  243. }
  244. callback && callback(betting,isAlert)
  245. },
  246. /**
  247. * pc端赛事页面串式
  248. * @param {array} data 当前玩法数据信息
  249. * @param {string} title 当前玩法
  250. * @param {int} id 当前玩法id
  251. * @param {int} idx 当前玩法数据下标
  252. * @param {int} index 当前赛事玩法数据下标
  253. * @param {int} i 当前赔率玩法数据下标
  254. * @param {int} activity 玩法
  255. * @param {array} betting 玩法投注数据
  256. * @param {array} match_id 赛事id玩法数据
  257. * @param {array} ballId 球类别名
  258. * @param {string} limit 投注数据
  259. * @param {function} callback 回掉方法
  260. */
  261. strandPublicBetting(data,title,id,index,idx,i,betting,activity,match_id,playName,name,ballId,home_team,guest_team,limit,callback){
  262. let isAre = true;
  263. let isAdd = true,isAlert =false;
  264. data[index].matchData[idx].oddsData[i].playName = playName;
  265. data[index].matchData[idx].oddsData[i].home_team = home_team;
  266. data[index].matchData[idx].oddsData[i].guest_team = guest_team;
  267. data[index].matchData[idx].oddsData[i].name = name;
  268. data[index].matchData[idx].oddsData[i].ballId = ballId;
  269. let obj = {
  270. title:title,
  271. data:[data[index].matchData[idx].oddsData[i]]
  272. }
  273. if(betting.length >0){
  274. betting.forEach(e=>{
  275. if(e.title == title){
  276. e.data.forEach((res,num) =>{
  277. if(res.id ==id){
  278. e.data.splice(num, 1);
  279. isAdd =false;
  280. }
  281. })
  282. if(isAdd){
  283. if(limit >= 10 ) {
  284. isAlert =true;
  285. }else{
  286. betting.forEach(res=>{
  287. if(res.data.length > 0 ){
  288. for(let i=0;i< res.data.length;i++){
  289. if(res.data[i].match_id == match_id){
  290. res.data.splice(i, 1);
  291. break;
  292. }
  293. }
  294. }
  295. })
  296. e.data.push(data[index].matchData[idx].oddsData[i]);
  297. }
  298. }
  299. isAre =false;
  300. }
  301. })
  302. if(isAre){
  303. if(limit >= 10 ) {
  304. isAlert =true;
  305. }else{
  306. betting.forEach(res=>{
  307. if(res.data.length > 0 ){
  308. for(let i=0;i< res.data.length;i++){
  309. if(res.data[i].match_id == match_id){
  310. res.data.splice(i, 1);
  311. break;
  312. }
  313. }
  314. }
  315. })
  316. betting.push(obj);
  317. }
  318. }
  319. }else{
  320. betting.push(obj);
  321. }
  322. callback && callback(betting,isAlert)
  323. },
  324. /**
  325. * 获取vuex相对应玩法index下标和投注数据集合
  326. * @param {组件类所有玩法数据集合} data
  327. * @param {组件里玩法别名} title
  328. * @param {从Vuex里面的投注列表的匹配对应的投注数据集合} betting
  329. * @param {相对应玩法index下标} dataNum
  330. */
  331. getBettingId(data, title, callback) {
  332. if (data) {
  333. data.forEach((res, index) => {
  334. if (res.title == title) {
  335. callback && callback(res.data, index);
  336. }
  337. });
  338. }
  339. },
  340. /**
  341. * 接口轮询定时器
  342. * @param {function} callback 定时器回调方法
  343. */
  344. ajaxTimerFun(callback,timers=1000*10){
  345. //到计时
  346. let timing = setInterval(function(){
  347. callback && callback(timing)
  348. },timers);
  349. // },5000);
  350. },
  351. /**
  352. * 复合算法
  353. * @param {int} data 第几场赛事
  354. * @param {array} dataList 投注赛事列表
  355. */
  356. betPlay(data,dataList){
  357. let addSum =0;
  358. let listLenth = dataList.length;
  359. //调用赔率算法
  360. addSum = this.oddsAlgorithm(data,dataList);
  361. //组合算法分母
  362. function denominator (num){
  363. let group =1;
  364. for(let i = listLenth ; i >(listLenth -num);i--){
  365. let add = group*i
  366. group = add;
  367. }
  368. return group;
  369. }
  370. //组合算法分子
  371. function molecule (num){
  372. let son =1;
  373. for(let i = num ; i >1;i--){
  374. let add = son*i;
  375. son = add;
  376. }
  377. return son;
  378. }
  379. //组合算法
  380. function algorithm(data) {
  381. return {
  382. title:`${data}串1`,//algorithm
  383. index:denominator(data)/molecule(data),
  384. odds:addSum,
  385. };
  386. }
  387. return algorithm(data);
  388. },
  389. /**
  390. * 赔率算法
  391. * @param {int} index 第几次赛事
  392. * @param {[]} dataList 赛事列表
  393. */
  394. oddsAlgorithm(index,dataList){
  395. let oddsArray=[];
  396. let num = index;
  397. let list = [];
  398. dataList.forEach((res)=>{
  399. oddsArray.push(res.odds);
  400. })
  401. for (let i=0;i<Math.pow(2, oddsArray.length);i++){
  402. let a = 0;
  403. let b = "";
  404. for (let j=0;j<oddsArray.length;j++){
  405. if (i>>j&1){
  406. a++;
  407. b += oddsArray[j]+',';
  408. }
  409. }
  410. if(a==num){
  411. let array = b.split(',');
  412. array.pop();
  413. list.push(array);
  414. }
  415. }
  416. let odds =0;
  417. list.forEach(e=>{
  418. let h =1;
  419. e.forEach(res=>{
  420. h = h*(1+res*1)
  421. })
  422. odds +=h*1-1;
  423. })
  424. return odds;
  425. },
  426. /**
  427. * 赔率数据更新
  428. * @param {*} current 当时数据源
  429. * @param {*} previous 上一次数据源
  430. * @param {*} type 应用场景
  431. * @param {*} callback 回掉方法
  432. */
  433. oddsDataUpdate(current,previous,type,callback){
  434. if(type == '1'){
  435. current.forEach((c_dat)=>{
  436. previous.forEach((p_dat,index)=>{
  437. //匹配获取联赛下的数据
  438. if(c_dat.lg_id == p_dat.lg_id){
  439. c_dat.matchData.forEach(c_dat1=>{
  440. p_dat.matchData.forEach((p_dat1,i)=>{
  441. //匹配获取赛事下的赔率数据
  442. if(c_dat1.match_id == p_dat1.match_id){
  443. c_dat1.oddsData.forEach(c_dat2 =>{
  444. p_dat1.oddsData.forEach(p_dat2=>{
  445. //匹配赛事赔率数据
  446. if(c_dat2.id == p_dat2.id){
  447. if(c_dat2.odds > p_dat2.odds){
  448. c_dat2.change ='rising';
  449. }else if(c_dat2.odds < p_dat2.odds){
  450. c_dat2.change = 'falling';
  451. }else{
  452. c_dat2.change ='';
  453. }
  454. p_dat1.oddsData.splice(i,1)
  455. }
  456. })
  457. })
  458. p_dat.matchData.splice(i,1)
  459. }
  460. })
  461. })
  462. previous.splice(index,1)
  463. }
  464. })
  465. })
  466. callback&&callback()
  467. }else if(type == '2'){
  468. // console.log('111111')
  469. current.forEach(e=>{
  470. previous.forEach((res,index)=>{
  471. if(e[0].p_code == res[0].p_code){
  472. e.forEach(dat=>{
  473. res.forEach((val,i)=>{
  474. if(dat.id == val.id){
  475. if(dat.odds > val.odds){
  476. dat.change ='rising';
  477. }else if(dat.odds < val.odds){
  478. dat.change = 'falling';
  479. }else{
  480. dat.change ='';
  481. }
  482. res.splice(i,1)
  483. }
  484. })
  485. })
  486. previous.splice(index,1)
  487. }
  488. })
  489. })
  490. callback&&callback()
  491. }
  492. },
  493. getGameType(val) {
  494. let type = [
  495. {value: 'lq', label: '篮球'},
  496. {value: 'wq', label: '网球'},
  497. {value: 'zq', label: '足球'},
  498. {value: 'bq', label: '棒球'}
  499. ]
  500. let name = val
  501. for(let item of type) {
  502. if(item.value === val) {
  503. name = item.label
  504. break;
  505. }
  506. }
  507. return name;
  508. }
  509. }