grant.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. var app = getApp();
  2. var that;
  3. var animation;
  4. Page({
  5. data: {
  6. users: [],
  7. item: {
  8. remark: '',
  9. employee_id: []
  10. },
  11. defaultVal: '',
  12. },
  13. onLoad() {
  14. that = this;
  15. dd.setNavigationBar({ title: "发放奖票" });
  16. this.setData({ isAdministrator: app.globalData.isAdministrator })
  17. },
  18. //备注输入
  19. bindTextAreaBlur: function (e) {
  20. this.setData({
  21. [`item.remark`]: e.detail.value,
  22. });
  23. },
  24. formSubmit() {
  25. if (that.data.users.length == 0) {
  26. app.globalData.showToast('请选择奖扣对象');
  27. return;
  28. }
  29. if (!that.data.item.remark) {
  30. app.globalData.showToast('请输入奖票原因');
  31. return;
  32. }
  33. var items=[];
  34. var obj;
  35. that.data.users.forEach(item=>{
  36. obj={
  37. employee_id:item.id,
  38. count:1,
  39. remark:this.data.item.remark,
  40. }
  41. items.push(obj);
  42. })
  43. this.setData({ disabled: true });
  44. app.$post('api/integral/ticket/create', {items:JSON.stringify(items)}).then((res) => {
  45. app.globalData.showToast("奖票成功")
  46. setTimeout(() => {
  47. dd.navigateBack({ delta: 1 })
  48. }, 1000);
  49. }).finally(err => {
  50. this.setData({ disabled: false });
  51. })
  52. },
  53. //选择人
  54. onSelectUser(item) {
  55. //空数据
  56. var arr = [];
  57. if (item.length > 0) {
  58. item.forEach(user => {
  59. arr.push(user.id);
  60. })
  61. that.setData({
  62. users: item.length > 0 ? item : [],
  63. [`item.employee_id`]: arr
  64. })
  65. }
  66. },
  67. // 选择积分事件
  68. onSelectEnevt(item, key) {
  69. that.setData({
  70. [`item.remark`]:item.remark,
  71. [`item.id`]:item.id,
  72. defaultVal: key
  73. })
  74. },
  75. //选择弹窗
  76. openSelect(e) {
  77. var num = e.target.dataset.num;
  78. that.setData({
  79. isShowType: num,
  80. });
  81. animation.translateY(0).step();
  82. that.setData({
  83. animationInfo: animation.export()
  84. });
  85. },
  86. onShow() {
  87. animation = dd.createAnimation({
  88. duration: 200,
  89. timeFunction: "linear",
  90. });
  91. },
  92. //关闭规则
  93. onClose() {
  94. animation.translateY(1200).step();
  95. that.setData({
  96. animationInfo: animation.export()
  97. });
  98. that.setData({ isShowType: '' });
  99. },
  100. });