prizeDetail.js 3.0 KB

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