addCustom.js 2.6 KB

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