|
@@ -1,345 +0,0 @@
|
|
|
-const app = getApp()
|
|
|
-
|
|
|
-Page({
|
|
|
- query: {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- },
|
|
|
- data: {
|
|
|
- view: 'graph',
|
|
|
- frameStyle: { useTop: true, name: '淘汰赛管理', leftArrow: false, useBar: false },
|
|
|
- canvasWidth: 375,
|
|
|
- canvasHeight: 600,
|
|
|
- pixelRatio: 1,
|
|
|
- forceMini: false,
|
|
|
-
|
|
|
-
|
|
|
- data: undefined,
|
|
|
- riseList: [],
|
|
|
- arrangeList: [],
|
|
|
- raceList: [],
|
|
|
- groundList: [],
|
|
|
- refereeList: [],
|
|
|
-
|
|
|
- arrangeData: {},
|
|
|
-
|
|
|
-
|
|
|
- show: false,
|
|
|
- personList: [],
|
|
|
- selectNode: undefined
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- computedTreeData() {
|
|
|
- const getWinnerNumList = this.data.riseList;
|
|
|
- const getWinnerNum = getWinnerNumList.reduce((p, n) => p + n, 0);
|
|
|
- let level = 1;
|
|
|
- let loop = true;
|
|
|
- while (loop) {
|
|
|
- const needUserNum = 2 ** (level - 1);
|
|
|
-
|
|
|
- if (needUserNum === getWinnerNum) loop = false;
|
|
|
-
|
|
|
- else if (needUserNum < getWinnerNum) level++;
|
|
|
- else {
|
|
|
-
|
|
|
- loop = false;
|
|
|
- level = NaN
|
|
|
- }
|
|
|
- }
|
|
|
- if (!level) {
|
|
|
- console.log('不继续,返回了,编不了数据')
|
|
|
- return;
|
|
|
- }
|
|
|
- const levelList = [];
|
|
|
-
|
|
|
- for (let i = 0; i < level - 1; i++) {
|
|
|
- const t = level - i - 1;
|
|
|
-
|
|
|
- const number = 2 ** t;
|
|
|
- const arr = [];
|
|
|
- for (let j = 1; j <= number; j++) {
|
|
|
- const obj = { id: `${i}-${j}`, num: `${i}-${j}`, pos: [i, j] }
|
|
|
- arr.push(obj);
|
|
|
- }
|
|
|
- levelList.push(arr)
|
|
|
- }
|
|
|
-
|
|
|
- let getLevelIndex = levelList.length - 1;
|
|
|
- const data = this.resetData(levelList, getLevelIndex)
|
|
|
- let obj = { id: `${levelList.length}`, num: `${levelList.length}`, children: data }
|
|
|
- return obj;
|
|
|
- },
|
|
|
- resetData(dataList, index = 0) {
|
|
|
- const thisLevelList = dataList[index]
|
|
|
-
|
|
|
- const p1 = thisLevelList[0]
|
|
|
- const p2 = thisLevelList[1]
|
|
|
-
|
|
|
- dataList[index].shift()
|
|
|
- dataList[index].shift()
|
|
|
- if (index - 1 < 0) return [p1, p2]
|
|
|
- const p1c = this.resetData(dataList, index - 1)
|
|
|
- const p2c = this.resetData(dataList, index - 1)
|
|
|
- p1.children = p1c
|
|
|
- p2.children = p2c;
|
|
|
- return [p1, p2]
|
|
|
- },
|
|
|
-
|
|
|
- nodeTap(e) {
|
|
|
- const node = e.detail;
|
|
|
- if (!node) return;
|
|
|
- this.setData({ selectNode: node })
|
|
|
- this.toOpen();
|
|
|
- },
|
|
|
-
|
|
|
- getFirstLevelNodes(node) {
|
|
|
- if (!node.children) return node;
|
|
|
- const res = [];
|
|
|
- const nodes = node.children;
|
|
|
- for (const node of nodes) {
|
|
|
- if (node?.children) {
|
|
|
- let list = this.getFirstLevelNodes(node);
|
|
|
- res.push(list);
|
|
|
- } else {
|
|
|
- res.push(node)
|
|
|
- }
|
|
|
- }
|
|
|
- return res.flat();
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
- selectChange(changeNode, selectNode) {
|
|
|
- const obj = { player_name: changeNode.label, player_id: changeNode.value, node_id: selectNode.id, label: 'player_name', pos: selectNode.pos }
|
|
|
- const arrangeList = this.data.arrangeList;
|
|
|
- const i = arrangeList.findIndex(f => f.player_id === obj.player_id && f.pos && obj.pos && f.pos[0] === obj.pos[0])
|
|
|
- if (i >= 0) arrangeList.splice(i, 1)
|
|
|
- arrangeList.push(obj)
|
|
|
- this.setData({ arrangeList })
|
|
|
-
|
|
|
-
|
|
|
- this.getRaceList();
|
|
|
- },
|
|
|
-
|
|
|
- getRaceList() {
|
|
|
- const arrangeList = this.data.arrangeList;
|
|
|
- arrangeList.sort((a, b) => {
|
|
|
- if (!a.pos) return b - a
|
|
|
- else if (!b.pos) return a - b
|
|
|
- else {
|
|
|
-
|
|
|
- const a1 = a.pos[0]
|
|
|
- const b1 = b.pos[0]
|
|
|
- if (a1 - b1 !== 0) return a1 - b1
|
|
|
- else {
|
|
|
- const a2 = a.pos[1]
|
|
|
- const b2 = b.pos[1]
|
|
|
- return a2 - b2
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- const raceList = [];
|
|
|
- for (let i = 0; i < arrangeList.length; i += 2) {
|
|
|
- const d1 = arrangeList[i]
|
|
|
- const d2 = arrangeList[i + 1]
|
|
|
-
|
|
|
- if (!(d1 && d2)) continue;
|
|
|
- const { pos: d1pos } = d1
|
|
|
- const { pos: d2pos } = d2;
|
|
|
-
|
|
|
- if (d1pos[0] !== d2pos[0]) continue
|
|
|
-
|
|
|
- if (d1pos[1] + 1 !== d2pos[1]) continue
|
|
|
- const { player_id: player_one, player_name: player_name_one, node_id: node_id_one } = d1
|
|
|
- const { player_id: player_two, player_name: player_name_two, node_id: node_id_two } = d2
|
|
|
- raceList.push({ player_one, player_name_one, node_id_one, player_two, player_name_two, node_id_two })
|
|
|
- }
|
|
|
-
|
|
|
- for (let i = 0; i < raceList.length; i++) {
|
|
|
- const d = raceList[i];
|
|
|
- d.groundModelName = `ground_id-${i}`;
|
|
|
- d.refereeModelName = `referee_id-${i}`;
|
|
|
- d.timeModelName = `match_time-${i}`;
|
|
|
- }
|
|
|
- const oRaceList = this.data.raceList;
|
|
|
- for (const race of raceList) {
|
|
|
- const { node_id_one, node_id_two } = race;
|
|
|
- const r = oRaceList.find(f => f.node_id_one === node_id_one && f.node_id_two === node_id_two)
|
|
|
- if (r) {
|
|
|
- const ri = oRaceList.findIndex(f => f.node_id_one === node_id_one && f.node_id_two === node_id_two)
|
|
|
- const { groundModelName, refereeModelName, timeModelName } = race
|
|
|
- r = { ...r, groundModelName, refereeModelName, timeModelName }
|
|
|
- oRaceList.splice(ri, 1, r)
|
|
|
- } else {
|
|
|
- oRaceList.push(race)
|
|
|
- }
|
|
|
- }
|
|
|
- this.setData({ raceList: oRaceList })
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
- async onLoad(options) {
|
|
|
- const { match_id, grouping_id, project_id } = options
|
|
|
- this.query = { match_id, grouping_id, project_id }
|
|
|
- await this.getTeams()
|
|
|
-
|
|
|
- const data = this.computedTreeData();
|
|
|
- this.setData({ data })
|
|
|
-
|
|
|
- await this.searchWinnerList();
|
|
|
- await this.search();
|
|
|
- await this.searchOthers()
|
|
|
- },
|
|
|
-
|
|
|
- async search() {
|
|
|
- let res = await app.$get(`/newCourt/api/eliminatArrange/getOne`, this.query)
|
|
|
- if (app.$checkRes(res)) {
|
|
|
- const { arrange } = res.data;
|
|
|
- this.setData({
|
|
|
- arrangeData: res.data,
|
|
|
- arrangeList: arrange
|
|
|
- })
|
|
|
- }
|
|
|
- res = await app.$get(`/newCourt/api/eliminateRace`, this.query)
|
|
|
- if (app.$checkRes(res)) {
|
|
|
- this.setData({
|
|
|
- raceList: res.data
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- this.getRaceList();
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
- async getTeams() {
|
|
|
- const res = await app.$get(`/newCourt/api/raceTeam`, this.query)
|
|
|
- if (app.$checkRes(res)) {
|
|
|
- const { data } = res
|
|
|
- const riseList = data.map(i => i.rise)
|
|
|
- this.setData({ riseList })
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- async searchWinnerList() {
|
|
|
- const res = await app.$post(`/newCourt/api/race/getWinnerList`, this.query)
|
|
|
- if (app.$checkRes(res)) {
|
|
|
- const { data } = res;
|
|
|
- const arr = [];
|
|
|
- for (const i of data) {
|
|
|
- const { personList, name } = i;
|
|
|
- for (const person of personList) {
|
|
|
-
|
|
|
- const obj = { label: person.player_name, value: person.player_id }
|
|
|
- arr.push(obj)
|
|
|
- }
|
|
|
- }
|
|
|
- this.setData({
|
|
|
- personList: arr
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
- toAutoInitData() {
|
|
|
- const personList = this.data.personList;
|
|
|
- const data = this.data.data
|
|
|
- const getBaseList = data => {
|
|
|
- if (!data.children) return data;
|
|
|
- const arr = [];
|
|
|
- for (const d of data.children) {
|
|
|
- const r = getBaseList(d)
|
|
|
- arr.push(r);
|
|
|
- }
|
|
|
- return arr.flat();
|
|
|
-
|
|
|
- }
|
|
|
- const firstList = getBaseList(data);
|
|
|
- for (let i = 0; i < firstList.length; i++) {
|
|
|
- const f = firstList[i];
|
|
|
- const p = personList[i];
|
|
|
- this.selectChange(p, f);
|
|
|
- }
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- async searchOthers() {
|
|
|
- let res;
|
|
|
- res = await app.$get(`/newCourt/api/ground`)
|
|
|
- if (app.$checkRes(res)) {
|
|
|
- this.setData({ groundList: res.data })
|
|
|
- }
|
|
|
- res = await app.$get(`/newCourt/api/user`, { type: '1' })
|
|
|
- if (app.$checkRes(res)) {
|
|
|
- this.setData({ refereeList: res.data })
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
- turnView(e) {
|
|
|
- const view = e?.target?.dataset?.view || 'graph';
|
|
|
- this.setData({ view })
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
- onChange(event) {
|
|
|
- const obj = event?.detail?.value;
|
|
|
- this.selectChange(obj, this.data.selectNode);
|
|
|
- this.toClose();
|
|
|
- },
|
|
|
- toOpen() {
|
|
|
- this.setData({ show: true })
|
|
|
- },
|
|
|
- toClose() {
|
|
|
- this.setData({ show: false, selectNode: undefined })
|
|
|
- },
|
|
|
- toSelected(event) {
|
|
|
- const data = event?.detail;
|
|
|
- const { value, model } = data;
|
|
|
- if (!model) return;
|
|
|
- const arr = model.split('-')
|
|
|
- const modelName = arr[0]
|
|
|
- const index = arr[1]
|
|
|
- const raceList = this.data.raceList;
|
|
|
- raceList[index][modelName] = value;
|
|
|
- this.setData({ raceList })
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- async toSubmit() {
|
|
|
-
|
|
|
- let raceList = this.data.raceList;
|
|
|
-
|
|
|
- let arrangeList = this.data.arrangeList;
|
|
|
-
|
|
|
-
|
|
|
- let arrange = this.data.arrangeData;
|
|
|
- if (!arrange._id) {
|
|
|
- arrange = { arrange: arrangeList, ...this.query }
|
|
|
- }
|
|
|
-
|
|
|
- raceList = raceList.map(i => {
|
|
|
- const { groundModelName, refereeModelName, timeModelName, ...others } = i
|
|
|
- return { ...others, ...this.query }
|
|
|
- })
|
|
|
-
|
|
|
- let res
|
|
|
- if (arrange._id) {
|
|
|
- res = await app.$post(`/newCourt/api/eliminatArrange/${arrange._id}`, arrange)
|
|
|
- if (app.$checkRes(res)) {
|
|
|
- console.log('淘汰赛安排创建成功')
|
|
|
- }
|
|
|
- } else {
|
|
|
- res = await app.$post(`/newCourt/api/eliminatArrange`, arrange)
|
|
|
- if (app.$checkRes(res)) {
|
|
|
- console.log('淘汰赛安排创建成功')
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- res = await app.$post('/newCourt/api/eliminateRace/saveAll', raceList)
|
|
|
- wx.showToast({
|
|
|
- title: '保存成功',
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
-});
|