grant.js 2.2 KB

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