var app = getApp() var that; var animation; Page({ data: { selectUser: [], title: '', id: '', isCompile: true, disabled:false, }, onLoad(e) { that = this; if (e.id) { this.getData(e.id); this.setData({ isbj: e.id, }); dd.setNavigationBar({ title: "编辑分组" }); }else{ dd.setNavigationBar({ title: "新建分组" }); } }, onShow() { animation = dd.createAnimation({ duration: 200, timeFunction: "linear", }); }, setTitle(e) { this.setData({ title: e.detail.value, }); }, //确定人员选择 onSelectUser(e) { this.setData({ selectUser: e }) }, //选择人员 openAdd() { animation.translateY(0).step(); that.setData({ animationInfo: animation.export() }); }, //关闭选择人员 onClose() { animation.translateY(1200).step(); that.setData({ animationInfo: animation.export() }); }, //编辑 compile() { if (!this.data.title) { app.globalData.showToast("请输入分组名称"); return; } var arr = []; this.data.selectUser.forEach(element => { arr.push(element.id); }); if (arr.length == 0) { app.globalData.showToast("至少选择一名员工参与"); return } var data = { group_id: that.data.isbj, group_name: this.data.title, employees: arr.join(',') } this.setData({ disabled: true }); app.$post("api/integral/statistics/groups", data).then((res) => { app.globalData.showToast("保存成功"); setTimeout(() => { this.setData({ disabled: false }); dd.navigateBack({ delta: 1 }) }, 1000); }).catch(err => { this.setData({ disabled: false }); }) }, //保存 save() { if (!this.data.title) { app.globalData.showToast("请输入分组名称"); return; } if (this.data.selectUser.length==0) { app.globalData.showToast("请选择员工"); return; } var arr = []; this.data.selectUser.forEach(element => { arr.push(element.id); }); var data = { group_name: this.data.title, employees: arr.join(',') } this.setData({ disabled: true }); app.$post("api/integral/statistics/groups/create", data).then((res) => { app.globalData.showToast("新建分组成功"); setTimeout(() => { this.setData({ disabled: false }); dd.navigateBack({ delta: 1 }) }, 1000); }).catch(err => { this.setData({ disabled: false }); }) }, //删除 delete() { dd.confirm({ title: '温馨提示', content: '确定删除该分组吗?', confirmButtonText: '确定', cancelButtonText: '取消', success: (result) => { if (result.confirm) { app.$post("api/integral/statistics/groups/drop", { group_id: that.data.isbj }).then((res) => { app.globalData.showToast("已删除"); setTimeout(() => { dd.navigateBack({ delta: 1 }) }, 1000); }) } }, }); }, getData(id) { app.$get("api/integral/statistics/groups/info", { group_id: id }).then((res) => { this.setData({ selectUser: res.data.data.employees, title: res.data.data.name, id: res.data.data.id, isCompile: true }) }) } });