prizeDetail.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. var app = getApp()
  2. var that;
  3. Page({
  4. data: {
  5. detail: {},
  6. id: '',
  7. is: true,//是否是发放员进来
  8. disabled: false,
  9. sn:'',
  10. image:'',
  11. isShowYy:false,
  12. corpId:'',
  13. },
  14. onLoad(e) {
  15. that = this;
  16. dd.setNavigationBar({ title: "奖品兑换详情" });
  17. if (e.id) {
  18. this.setData({ id: e.id })
  19. }
  20. if (e.is) {
  21. this.setData({ is: false })
  22. }
  23. if (e.corpId) {
  24. this.setData({ corpId: e.corpId })
  25. }
  26. },
  27. onShow() {
  28. if (app.globalData.userData) {
  29. app.globalData.userData.employee_detail.role_list.forEach(item=>{
  30. if(item.name=='admin'||item.name=='creator'|| item.name == 'point_manager'){
  31. that.setData({ isShowYy: true })
  32. }
  33. })
  34. that.getData();
  35. } else {
  36. app.login(that.data.corpId||app.globalData.corpId, function (is) {
  37. if (is) {
  38. app.globalData.userData.employee_detail.role_list.forEach(item=>{
  39. if(item.name=='admin'||item.name=='creator'|| item.name == 'point_manager'){
  40. that.setData({ isShowYy: true })
  41. }
  42. })
  43. that.getData();
  44. } else {
  45. dd.reLaunch({
  46. url: '../../noJurisdiction/noJurisdiction'
  47. })
  48. }
  49. }, function () { })
  50. }
  51. },
  52. showImg(e) {
  53. var url = e.target.dataset.url
  54. dd.previewImage({
  55. current: 0,
  56. urls:[url]
  57. });
  58. },
  59. openText() {
  60. this.setData({ disabled: true });
  61. app.$post("api/shop/exchange/deal", { id: this.data.id }).then((res) => {
  62. app.globalData.showToast("已发放");
  63. setTimeout(() => {
  64. this.setData({ disabled: false });
  65. this.getData()
  66. }, 1000);
  67. }).catch(err => {
  68. this.setData({ disabled: false });
  69. })
  70. },
  71. showText() {
  72. app.$get('api/shop/exchange/qrcode', { id: this.data.id, employee_id: app.globalData.userData.id }).then((res) => {
  73. this.setData({
  74. image: app.globalData.baseUrl + res.data.data,
  75. })
  76. })
  77. this.setData({
  78. isBh: !this.data.isBh,
  79. })
  80. },
  81. showText2() {
  82. this.setData({
  83. isBh: !this.data.isBh,
  84. })
  85. },
  86. handleCopy() {
  87. dd.setClipboard({
  88. text: this.data.detail.sn,
  89. })
  90. app.globalData.showToast("已复制");
  91. },
  92. getData() {
  93. app.$get('api/shop/exchange/detail', { id: this.data.id }).then((res) => {
  94. let data = res.data.data;
  95. data.date = this.timestampToTime(data.create_time)
  96. data.date2 = this.timestampToTime(data.complete_time)
  97. this.setData({ detail: res.data.data })
  98. })
  99. },
  100. timestampToTime(timestamp) {
  101. var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
  102. var Y = date.getFullYear() + '-';
  103. var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  104. var D = date.getDate() + ' ';
  105. var h = date.getHours() + ':';
  106. var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes() ) + ':';
  107. var s = date.getSeconds();
  108. return Y + M + D + h + m + s;
  109. },
  110. });