tZpoint.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { match } from "assert";
  2. var app = getApp();
  3. var that;
  4. var setTime;
  5. Page({
  6. data: {
  7. textArea: '',
  8. point:0,
  9. review_id:0,
  10. isAdd:true,
  11. },
  12. onLoad(e) {
  13. that = this;
  14. dd.setNavigationBar({ title: "调整分数" });
  15. if (e.id) {
  16. let isAdd=true;
  17. let point=e.point;
  18. console.log(point)
  19. if(e.point<0){
  20. isAdd=false;
  21. point=Math.abs(point)
  22. }
  23. that.setData({
  24. review_id: e.id,
  25. point:point,
  26. isAdd:isAdd
  27. })
  28. }
  29. },
  30. bindKeyInput(e) {
  31. this.setData({
  32. point: e.detail.value,
  33. });
  34. },
  35. bindKeyInput2(e) {
  36. this.setData({
  37. textArea: e.detail.value,
  38. });
  39. },
  40. //选择奖还是扣(细则)
  41. bindPickerChange(e) {
  42. this.setData({
  43. isAdd:!this.data.isAdd,
  44. });
  45. },
  46. submit() {
  47. if (!this.data.point) {
  48. app.globalData.showToast('请输入分数');
  49. return false;
  50. }
  51. if (this.data.point<0||this.data.point=='0'||this.data.point===0) {
  52. app.globalData.showToast('分数不能小于等于0');
  53. return false;
  54. }
  55. if (!this.data.textArea) {
  56. app.globalData.showToast('请输调整原因');
  57. return false;
  58. }
  59. // let str = /^1[345789]\d{9}$/
  60. // if (!str.test(this.data.mobile)) {
  61. // app.globalData.showToast('手机号码格式不正确')
  62. // return false
  63. // }
  64. let data={
  65. type:'event_check',
  66. action:'agree',
  67. event_id:this.data.review_id,
  68. comment:this.data.textArea,
  69. point:this.data.isAdd? this.data.point:this.data.point-(this.data.point*2),
  70. }
  71. // console.log(data)
  72. // return
  73. that.setData({ disabled: true });
  74. this.opneWebSocket(data)
  75. },
  76. opneWebSocket(data) {
  77. setTime = setTimeout(() => {
  78. dd.alert({
  79. title: '温馨提示',
  80. content: '网络异常,请检查网络',
  81. buttonText: '我知道了',
  82. success: () => {
  83. clearTimeout(setTime);
  84. app.globalData.socketApi.closewebsocket();
  85. that.setData({
  86. disabled: false,
  87. isBh: false,
  88. textArea: '',
  89. });
  90. },
  91. });
  92. }, 15000)
  93. app.globalData.socketApi.sendData(data, this.onmessageWS);
  94. },
  95. onmessageWS(e) {
  96. // 因为作用域问题,这个函数不能使用this
  97. if (e.type == 'event_check') {
  98. clearTimeout(setTime);
  99. if(e.code==1){
  100. app.globalData.showToast("提交成功");
  101. that.setData({
  102. disabled: false,
  103. textArea: '',
  104. });
  105. app.globalData.socketApi.closewebsocket();
  106. setTimeout(() => {
  107. dd.navigateBack({ delta: 1 })
  108. }, 1000);
  109. }else{
  110. app.globalData.showToast(e.msg)
  111. app.globalData.socketApi.closewebsocket();
  112. }
  113. }
  114. if (e.type == 'error') {
  115. clearTimeout(setTime);
  116. that.setData({
  117. isShowError: true,
  118. })
  119. }
  120. },
  121. });