grant.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. popupCx: ''
  13. },
  14. onLoad() {
  15. that = this;
  16. dd.setNavigationBar({ title: "发放奖票" });
  17. this.setData({ isAdministrator: app.globalData.isAdministrator })
  18. },
  19. //备注输入
  20. bindTextAreaBlur: function (e) {
  21. this.setData({
  22. [`item.remark`]: e.detail.value,
  23. });
  24. },
  25. formSubmit() {
  26. if (that.data.users.length == 0) {
  27. app.globalData.showToast('请选择奖扣对象');
  28. return;
  29. }
  30. if (!that.data.item.remark) {
  31. app.globalData.showToast('请输入奖票原因');
  32. return;
  33. }
  34. var items=[];
  35. var obj;
  36. that.data.users.forEach(item=>{
  37. obj={
  38. employee_id:item.id,
  39. count:1,
  40. remark:this.data.item.remark,
  41. }
  42. items.push(obj);
  43. })
  44. this.setData({ disabled: true });
  45. app.$post('api/integral/ticket/create', {items:JSON.stringify(items)}).then((res) => {
  46. app.globalData.showToast("奖票成功")
  47. setTimeout(() => {
  48. dd.navigateBack({ delta: 1 })
  49. }, 1000);
  50. }).finally(err => {
  51. this.setData({ disabled: false });
  52. })
  53. },
  54. //选择人
  55. onSelectUser(item) {
  56. //空数据
  57. var arr = [];
  58. if (item.length > 0) {
  59. item.forEach(user => {
  60. arr.push(user.id);
  61. })
  62. that.setData({
  63. users: item.length > 0 ? item : [],
  64. [`item.employee_id`]: arr
  65. })
  66. }
  67. },
  68. // 选择积分事件
  69. onSelectEnevt(item, key) {
  70. that.setData({
  71. [`item.remark`]:item.remark,
  72. [`item.id`]:item.id,
  73. defaultVal: key
  74. })
  75. },
  76. //选择弹窗
  77. openSelect(e) {
  78. var num = e.target.dataset.num;
  79. animation.translateY(0).step();
  80. that.setData({
  81. isShowType: num,
  82. popupCx: 'container__mask',
  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. popupCx: '',
  97. isShowType: '',
  98. animationInfo: animation.export()
  99. });
  100. },
  101. });