exchange.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. const app = getApp()
  2. var util = require("../../../utils/util.js")
  3. Page({
  4. data: {
  5. xa_consignee: '',
  6. xa_city: '',
  7. xa_county: '',
  8. xa_address: '',
  9. xa_phone: '',
  10. now_date: '',
  11. presentId: '',
  12. collection_date: '',
  13. obj: {},
  14. sInd: 0, // 选择的兑换门店地址
  15. btnText: '立即兑换',
  16. success: false
  17. },
  18. onLoad: function (options) {
  19. this.setData({
  20. presentId: options.id,
  21. navH: app.globalData.navHeight
  22. })
  23. this.getPostInfo(options.id)
  24. this.getAddress()
  25. },
  26. // 获取地址
  27. getAddress() {
  28. let _this = this
  29. wx.request({
  30. url: app.globalData.url + '/getEqUserAddress',
  31. method: 'get',
  32. data: {xu_openid: app.globalData.openid},
  33. success: function (res) {
  34. if (res.data.length != 0) {
  35. _this.setData({
  36. xa_consignee: res.data.xa_consignee,
  37. xa_city: res.data.xa_city,
  38. xa_county: res.data.xa_county,
  39. xa_address: res.data.xa_address,
  40. xa_phone: res.data.xa_phone
  41. })
  42. }
  43. },
  44. fail() {
  45. app.timeOut()
  46. }
  47. })
  48. },
  49. // 获取兑换详情
  50. getPostInfo(id) {
  51. let date = new Date()
  52. let year = date.getFullYear()
  53. let month = (date.getMonth() + 1).toString().padStart(2, 0)
  54. let day = (date.getDate()).toString().padStart(2, 0)
  55. util.postData('/college/queryRedeemDetail', {
  56. openid: app.globalData.openid,
  57. presentId: id
  58. }).then(res => {
  59. this.setData({
  60. now_date: year + '-' + month + '-' + day,
  61. collection_date: year + '-' + month + '-' + day,
  62. obj: res
  63. })
  64. if (!res.redeem) { this.setData({ btnText: `LV${res.level} 开启兑换` }) }
  65. })
  66. },
  67. // 选择兑换门店
  68. selectMen(event) {
  69. let ind = event.currentTarget.dataset.index || 0;
  70. this.setData({ sInd: ind })
  71. },
  72. // 选择时间
  73. seletTim(e) {
  74. this.setData({
  75. collection_date: e.detail.value
  76. })
  77. },
  78. // 兑换
  79. duihuan() {
  80. if (!this.data.success) {
  81. if (!this.data.obj.redeem) { return }
  82. let params = {
  83. present_id: this.data.presentId,
  84. openid: app.globalData.openid
  85. }
  86. if (this.data.obj.presentType == 2) {
  87. params.collection_date = this.data.collection_date
  88. params.mkt_id = this.data.obj.mktInfo[this.data.sInd].id
  89. } else if (this.data.obj.presentType == 3) {
  90. params.address = this.data.xa_city + this.data.xa_county + this.data.xa_address
  91. if (!params.address || params.address == 'undefined') {
  92. wx.showToast({
  93. title: '收货地址不能为空',
  94. icon: 'none'
  95. })
  96. return
  97. }
  98. }
  99. util.postData('/college/userRedeem', params).then(res => {
  100. if (res.code == 1) {
  101. this.setData({
  102. success: true,
  103. btnText: '回到首页'
  104. })
  105. } else if (res.msg) {
  106. wx.showToast({
  107. title: res.msg,
  108. icon: 'none'
  109. })
  110. }
  111. })
  112. } else {
  113. wx.reLaunch({
  114. url: '/pages/scholarship/scholarship'
  115. })
  116. }
  117. },
  118. // 添加地址
  119. hrefAddress() {
  120. let toUrl = '/pages/mine/myaddress/myaddress?type=bill'
  121. if (this.data.xa_consignee == null || this.data.xa_consignee == '') {
  122. toUrl = '/pages/mine/myaddress/createaddress/createaddress?type=bill'
  123. }
  124. wx.navigateTo({
  125. url: toUrl
  126. })
  127. }
  128. })