|
@@ -6,62 +6,41 @@ Page({
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
- id: {},
|
|
|
+ id: '',
|
|
|
form: {},
|
|
|
- // 性别
|
|
|
- genderList: [],
|
|
|
+ // 胜者
|
|
|
+ winnerList: [],
|
|
|
// 状态
|
|
|
statusList: [],
|
|
|
+ userList: []
|
|
|
},
|
|
|
- initValidate() {
|
|
|
- const rules = { red_score: { required: true }, blue_score: { required: true }, status: { required: true } }
|
|
|
- const messages = { red_score: { required: '请输入红方比分' }, blue_score: { required: '请输入蓝方比分' }, status: { required: '请选择状态' } };
|
|
|
- this.WxValidate = new WxValidate(rules, messages)
|
|
|
- },
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面加载
|
|
|
- */
|
|
|
- async onLoad(options) {
|
|
|
+ // 选择胜者
|
|
|
+ winnerChange(e) {
|
|
|
const that = this;
|
|
|
- that.setData({ id: options.id });
|
|
|
- wx.showLoading({ title: '加载中', mask: true })
|
|
|
- //验证规则函数
|
|
|
- that.initValidate();
|
|
|
- await that.searchOther()
|
|
|
- await that.search()
|
|
|
- wx.hideLoading()
|
|
|
- },
|
|
|
- search() {
|
|
|
- const that = this;
|
|
|
- wx.getStorage({
|
|
|
- key: 'token',
|
|
|
- async success(res) {
|
|
|
- let form = {}
|
|
|
- let aee = await app.$api(`course/${that.data.id}`, 'GET', {})
|
|
|
- if (aee.errcode == '0') {
|
|
|
- form = aee.data;
|
|
|
- if (form && form._id) {
|
|
|
- // 状态
|
|
|
- if (form.status) form.status_name = that.getDict(form.status, 'status')
|
|
|
- }
|
|
|
- } else {
|
|
|
- wx.showToast({ title: `${aee.errmsg}`, icon: 'error' });
|
|
|
- }
|
|
|
- that.setData({ form })
|
|
|
- },
|
|
|
- fail(err) {
|
|
|
- console.log(err);
|
|
|
- }
|
|
|
- })
|
|
|
+ const index = e.detail.value;
|
|
|
+ let data = that.data.winnerList[index];
|
|
|
+ if (data) {
|
|
|
+ that.setData({ 'form.winner': data._id })
|
|
|
+ that.setData({ 'form.winner_name': data.name })
|
|
|
+ }
|
|
|
},
|
|
|
// 过滤字典表
|
|
|
getDict(value, model) {
|
|
|
const that = this;
|
|
|
- if (value) {
|
|
|
- let list = that.data[model + 'List']
|
|
|
- let data = list.find(i => i.value == value);
|
|
|
- if (data) return data.label
|
|
|
- else return '暂无'
|
|
|
+ if (model == 'winner') {
|
|
|
+ if (value) {
|
|
|
+ let list = that.data[model + 'List']
|
|
|
+ let data = list.find(i => i._id == value);
|
|
|
+ if (data) return data.name
|
|
|
+ else return '暂无'
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (value) {
|
|
|
+ let list = that.data[model + 'List']
|
|
|
+ let data = list.find(i => i.value == value);
|
|
|
+ if (data) return data.label
|
|
|
+ else return '暂无'
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
// 选择状态
|
|
@@ -96,15 +75,64 @@ Page({
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面加载
|
|
|
+ */
|
|
|
+ async onLoad(options) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ id: options.id });
|
|
|
+ wx.showLoading({ title: '加载中', mask: true })
|
|
|
+ //验证规则函数
|
|
|
+ that.initValidate();
|
|
|
+ await that.searchOther()
|
|
|
+ await that.search()
|
|
|
+ wx.hideLoading()
|
|
|
+ },
|
|
|
+ initValidate() {
|
|
|
+ const rules = { red_score: { required: true }, blue_score: { required: true }, status: { required: true } }
|
|
|
+ const messages = { red_score: { required: '请输入红方比分' }, blue_score: { required: '请输入蓝方比分' }, status: { required: '请选择状态' } };
|
|
|
+ this.WxValidate = new WxValidate(rules, messages)
|
|
|
+ },
|
|
|
// 查询其他信息
|
|
|
async searchOther() {
|
|
|
const that = this;
|
|
|
let res;
|
|
|
- // 性别
|
|
|
+ // 状态
|
|
|
res = await app.$api('dictData', 'GET', { type: 'course_status', is_use: '0' })
|
|
|
if (res.errcode == '0') that.setData({ statusList: res.data })
|
|
|
+ // 团队
|
|
|
+ res = await app.$api('team', 'GET', { status: '1' })
|
|
|
+ if (res.errcode == '0') that.setData({ userList: res.data })
|
|
|
+ },
|
|
|
+ search() {
|
|
|
+ const that = this;
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'token',
|
|
|
+ async success(res) {
|
|
|
+ let form = {}
|
|
|
+ let aee = await app.$api(`course/${that.data.id}`, 'GET', {})
|
|
|
+ if (aee.errcode == '0') {
|
|
|
+ form = aee.data;
|
|
|
+ if (form && form._id) {
|
|
|
+ const red = that.data.userList.filter(i => i._id == form.red_team_id)
|
|
|
+ const blue = that.data.userList.filter(i => i._id == form.blue_team_id)
|
|
|
+ that.setData({ winnerList: [...red, ...blue] })
|
|
|
+ // 状态
|
|
|
+ if (form.status) form.status_name = that.getDict(form.status, 'status')
|
|
|
+ // 胜者
|
|
|
+ if (form.winner) form.winner_name = that.getDict(form.winner, 'winner')
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ wx.showToast({ title: `${aee.errmsg}`, icon: 'error' });
|
|
|
+ }
|
|
|
+ that.setData({ form })
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ console.log(err);
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
-
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|