C端小程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

249 linhas
5.9 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px';
  2. const util = require("../../../utils/util.js");
  3. const config = require("../../../config/config.js");
  4. const Http = require("../../../utils/HttpBasics");
  5. let app = getApp();
  6. const imgurl = require("../../../utils/imgurl");
  7. const QR = require("../../../utils/memberqrcode.js");
  8. Page({
  9. // https://formall.oss-accelerate.aliyuncs.com/cimg/wm01.jpg
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. navigationBarHeight,
  15. topLine: imgurl.topLine.url,
  16. btomLine: imgurl.btomLine.url,
  17. data: {},
  18. showIdFalg: false,
  19. code: '',
  20. codeS: '',
  21. tempFilePath: '',
  22. isShowQR: true
  23. },
  24. cardDetail(couponOrderId) {
  25. let that = this;
  26. Http.get({
  27. url: config.api.cardDetail,
  28. data: {
  29. couponOrderId: couponOrderId,
  30. }
  31. })
  32. .then(res => {
  33. console.log(res)
  34. if (res.code == 200) {
  35. res.data.expiredTime = util.formatTime(res.data.expiredTime, "yyyy-MM-dd hh:mm:ss")
  36. that.setData({
  37. showPage: true,
  38. data: res.data,
  39. supportTransfer: res.data.supportTransfer,
  40. code: res.data.id,
  41. codeS: res.data.id.slice(0, 4) + `******` + res.data.id.slice(14),
  42. })
  43. if (res.data.wxCardInfo.status) {
  44. this.setData({
  45. isShowQR: false
  46. })
  47. } else {
  48. that.getQR(res.data.id, res.data.tenantId)
  49. }
  50. /**
  51. * 若可转赠获取用户头像信息
  52. */
  53. if (that.data.merchantVoList && that.data.merchantVoList.length <= 4) {
  54. that.setData({
  55. height: that.data.merchantVoList.length * 140 + 'rpx',
  56. showMore: false
  57. })
  58. } else if (that.data.merchantVoList && that.data.cardDetail.length > 4) {
  59. that.setData({
  60. height: 4 * 140 + 'rpx'
  61. })
  62. }
  63. }
  64. })
  65. .catch(err => {
  66. console.log(err)
  67. })
  68. },
  69. showId() {
  70. let this_ = this;
  71. if (!this_.data.showIdFalg) {
  72. wx.showModal({
  73. content: '是否查看完整券码',
  74. success(res) {
  75. if (res.confirm) {
  76. this_.setData({
  77. showIdFalg: true
  78. })
  79. } else if (res.cancel) {
  80. console.log('用户点击取消')
  81. }
  82. }
  83. })
  84. } else {
  85. this.setData({
  86. showIdFalg: false
  87. })
  88. }
  89. },
  90. // 获取动态二维码
  91. getQR(cardId, cardTenantId) {
  92. Http.get({
  93. url: `/couponOrder/cardDynamicId?cardId=${cardId}&cardTenantId=${cardTenantId}`,
  94. }).then(res => {
  95. console.log(res.data);
  96. this.setData({
  97. expiredSeconds: res.data.expiredSeconds
  98. })
  99. let url = JSON.stringify({
  100. END: "C",
  101. TYPE: "card",
  102. ID: res.data.dynamicRq,
  103. TENANTID: res.data.cardTenantId
  104. })
  105. this.createQrCode(url, "qrcode", 350, 350);
  106. }).catch(err => {
  107. wx.showToast({
  108. title: err.message,
  109. icon: none
  110. })
  111. })
  112. },
  113. goGive() {
  114. wx.navigateTo({
  115. url: `/pages/ConsumeDetail/ConsumeDetail?cardId=${this.data.data.id}`,
  116. })
  117. },
  118. // 扫一扫去支付
  119. gotoPay: function () {
  120. app.globalData.previewFlag = true
  121. let that = this;
  122. console.log(that.data.data.id, that.data.data.remainingAmount / 100);
  123. wx.scanCode({
  124. success: (res) => {
  125. if (util.isJSON(res.result)) {
  126. let value = JSON.parse(res.result);
  127. if (value.END == 'B' && value.TYPE == 'merchant' && value.ID) {
  128. Http.get({
  129. url: config.api.findByCode,
  130. data: {
  131. merchantCode: value.ID,
  132. }
  133. })
  134. .then(res => {
  135. if (res.code == 200) {
  136. let merChantDetail = JSON.stringify(res.data);
  137. if (merChantDetail && that.data.data.id && that.data.data.remainingamount / 100) {
  138. merChantDetail = encodeURIComponent(merChantDetail)
  139. wx.navigateTo({
  140. url: `/pages/scanPay/scanPay?merChant=${merChantDetail}&cardid=${that.data.data.id}&remainingAmount=${that.data.data.remainingamount}`,
  141. })
  142. }
  143. }
  144. })
  145. .catch(err => {
  146. console.log(err)
  147. })
  148. } else {
  149. wx.showToast({
  150. title: "未识别到商户二维码",
  151. icon: "none",
  152. mask: false
  153. })
  154. }
  155. } else {
  156. wx.showToast({
  157. title: "未识别到商户二维码",
  158. icon: "none",
  159. mask: false
  160. })
  161. }
  162. },
  163. fail: (res) => {
  164. wx.showToast({
  165. title: "未识别到商户二维码",
  166. icon: "none",
  167. mask: false
  168. })
  169. }
  170. })
  171. },
  172. createQrCode: function (url, canvasId, cavW, cavH) {
  173. console.log('createQrCode!');
  174. //调用插件中的draw方法,绘制二维码图片
  175. let that = this;
  176. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  177. that.setData({
  178. tempFilePath: res
  179. })
  180. });
  181. },
  182. /**
  183. * 生命周期函数--监听页面加载
  184. */
  185. onLoad(options) {
  186. console.log(options);
  187. if (options.cardId) {
  188. this.cardDetail(options.cardId);
  189. }
  190. },
  191. /**
  192. * 生命周期函数--监听页面初次渲染完成
  193. */
  194. onReady() {
  195. },
  196. /**
  197. * 生命周期函数--监听页面显示
  198. */
  199. onShow() {
  200. },
  201. /**
  202. * 生命周期函数--监听页面隐藏
  203. */
  204. onHide() {
  205. },
  206. /**
  207. * 生命周期函数--监听页面卸载
  208. */
  209. onUnload() {
  210. },
  211. /**
  212. * 页面相关事件处理函数--监听用户下拉动作
  213. */
  214. onPullDownRefresh() {
  215. },
  216. /**
  217. * 页面上拉触底事件的处理函数
  218. */
  219. onReachBottom() {
  220. },
  221. /**
  222. * 用户点击右上角分享
  223. */
  224. onShareAppMessage() {
  225. }
  226. })