addCustom.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. var app = getApp()
  2. var that;
  3. var animation;
  4. Page({
  5. data: {
  6. selectUser: [],
  7. title: '',
  8. id: '',
  9. isCompile: true,
  10. disabled:false,
  11. },
  12. onLoad(e) {
  13. that = this;
  14. if (e.id) {
  15. this.getData(e.id);
  16. this.setData({ isbj: e.id, });
  17. dd.setNavigationBar({ title: "编辑分组" });
  18. }else{
  19. dd.setNavigationBar({ title: "新建分组" });
  20. }
  21. },
  22. onShow() {
  23. animation = dd.createAnimation({
  24. duration: 200,
  25. timeFunction: "linear",
  26. });
  27. },
  28. setTitle(e) {
  29. this.setData({
  30. title: e.detail.value,
  31. });
  32. },
  33. //确定人员选择
  34. onSelectUser(e) {
  35. this.setData({
  36. selectUser: e
  37. })
  38. },
  39. //选择人员
  40. openAdd() {
  41. animation.translateY(0).step();
  42. that.setData({
  43. animationInfo: animation.export()
  44. });
  45. },
  46. //关闭选择人员
  47. onClose() {
  48. animation.translateY(1200).step();
  49. that.setData({
  50. animationInfo: animation.export()
  51. });
  52. },
  53. //编辑
  54. compile() {
  55. if (!this.data.title) {
  56. app.globalData.showToast("请输入分组名称");
  57. return;
  58. }
  59. var arr = [];
  60. this.data.selectUser.forEach(element => {
  61. arr.push(element.id);
  62. });
  63. if (arr.length == 0) {
  64. app.globalData.showToast("至少选择一名员工参与");
  65. return
  66. }
  67. var data = {
  68. group_id: that.data.isbj,
  69. group_name: this.data.title,
  70. employees: arr.join(',')
  71. }
  72. this.setData({ disabled: true });
  73. app.$post("api/integral/statistics/groups", data).then((res) => {
  74. app.globalData.showToast("保存成功");
  75. setTimeout(() => {
  76. this.setData({ disabled: false });
  77. dd.navigateBack({
  78. delta: 1
  79. })
  80. }, 1000);
  81. }).catch(err => {
  82. this.setData({ disabled: false });
  83. })
  84. },
  85. //保存
  86. save() {
  87. if (!this.data.title) {
  88. app.globalData.showToast("请输入分组名称");
  89. return;
  90. }
  91. if (this.data.selectUser.length==0) {
  92. app.globalData.showToast("请选择员工");
  93. return;
  94. }
  95. var arr = [];
  96. this.data.selectUser.forEach(element => {
  97. arr.push(element.id);
  98. });
  99. var data = {
  100. group_name: this.data.title,
  101. employees: arr.join(',')
  102. }
  103. this.setData({ disabled: true });
  104. app.$post("api/integral/statistics/groups/create", data).then((res) => {
  105. app.globalData.showToast("新建分组成功");
  106. setTimeout(() => {
  107. this.setData({ disabled: false });
  108. dd.navigateBack({
  109. delta: 1
  110. })
  111. }, 1000);
  112. }).catch(err => {
  113. this.setData({ disabled: false });
  114. })
  115. },
  116. //删除
  117. delete() {
  118. dd.confirm({
  119. title: '温馨提示',
  120. content: '确定删除该分组吗?',
  121. confirmButtonText: '确定',
  122. cancelButtonText: '取消',
  123. success: (result) => {
  124. if (result.confirm) {
  125. app.$post("api/integral/statistics/groups/drop", { group_id: that.data.isbj }).then((res) => {
  126. app.globalData.showToast("已删除");
  127. setTimeout(() => {
  128. dd.navigateBack({
  129. delta: 1
  130. })
  131. }, 1000);
  132. })
  133. }
  134. },
  135. });
  136. },
  137. getData(id) {
  138. app.$get("api/integral/statistics/groups/info", { group_id: id }).then((res) => {
  139. this.setData({
  140. selectUser: res.data.data.employees,
  141. title: res.data.data.name,
  142. id: res.data.data.id,
  143. isCompile: true
  144. })
  145. })
  146. }
  147. });