addCustom.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. var data = {
  61. group_id:that.data.isbj,
  62. group_name: this.data.title,
  63. employees: arr.join(',')
  64. }
  65. app.$post("api/integral/statistics/groups", data).then((res) => {
  66. app.globalData.showToast("保存成功");
  67. setTimeout(() => {
  68. dd.navigateBack({
  69. delta: 1
  70. })
  71. }, 1000);
  72. })
  73. },
  74. //保存
  75. save() {
  76. if (!this.data.title) {
  77. app.globalData.showToast("请输入分组名称");
  78. return;
  79. }
  80. var arr = [];
  81. this.data.selectUser.forEach(element => {
  82. arr.push(element.id);
  83. });
  84. var data = {
  85. group_name: this.data.title,
  86. employees: arr.join(',')
  87. }
  88. app.$post("api/integral/statistics/groups/create", data).then((res) => {
  89. app.globalData.showToast("保存成功");
  90. setTimeout(() => {
  91. dd.navigateBack({
  92. delta: 1
  93. })
  94. }, 1000);
  95. })
  96. },
  97. //删除
  98. delete() {
  99. app.$post("api/integral/statistics/groups/drop", { group_id: that.data.isbj }).then((res) => {
  100. app.globalData.showToast("已删除");
  101. setTimeout(() => {
  102. dd.navigateBack({
  103. delta: 1
  104. })
  105. }, 1000);
  106. })
  107. },
  108. getData(id) {
  109. app.$get("api/integral/statistics/groups/info", { group_id: id }).then((res) => {
  110. this.setData({
  111. selectUser: res.data.data.employees,
  112. title: res.data.data.name,
  113. id: res.data.data.id,
  114. isCompile: true
  115. })
  116. console.log(this.data.selectUser)
  117. })
  118. }
  119. });