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. //备注输入
  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. }).catch(err => {
  51. this.setData({ disabled: false });
  52. }).finally(err => {
  53. this.setData({ disabled: false });
  54. })
  55. },
  56. //选择人
  57. onSelectUser(item) {
  58. //空数据
  59. var arr = [];
  60. if (item.length > 0) {
  61. item.forEach(user => {
  62. arr.push(user.id);
  63. })
  64. that.setData({
  65. users: item.length > 0 ? item : [],
  66. [`item.employee_id`]: arr
  67. })
  68. }
  69. },
  70. // 选择积分事件
  71. onSelectEnevt(item, key) {
  72. that.setData({
  73. [`item.remark`]:item.remark,
  74. [`item.id`]:item.id,
  75. defaultVal: key
  76. })
  77. },
  78. //选择弹窗
  79. openSelect(e) {
  80. var num = e.target.dataset.num;
  81. animation.translateY(0).step();
  82. that.setData({
  83. isShowType: num,
  84. popupCx: 'container__mask',
  85. animationInfo: animation.export()
  86. });
  87. },
  88. onShow() {
  89. animation = dd.createAnimation({
  90. duration: 200,
  91. timeFunction: "linear",
  92. });
  93. },
  94. //关闭规则
  95. onClose() {
  96. animation.translateY(1200).step();
  97. that.setData({
  98. popupCx: '',
  99. isShowType: '',
  100. animationInfo: animation.export()
  101. });
  102. },
  103. });