C端小程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

307 righe
7.3 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. upDataRqUrlF: imgurl.upDataRqF.url,
  18. data: {},
  19. showIdFalg: false,
  20. code: '',
  21. codeS: '',
  22. tempFilePath: '',
  23. QRdata: {},
  24. isShowQR: true,
  25. showhieRq: false,
  26. cardId: ''
  27. },
  28. cardDetail(couponOrderId) {
  29. let that = this;
  30. Http.get({
  31. url: config.api.cardDetail,
  32. data: {
  33. couponOrderId: couponOrderId,
  34. }
  35. })
  36. .then(res => {
  37. console.log(res)
  38. if (res.code == 200) {
  39. res.data.expiredTime = util.formatTime(res.data.expiredTime, "yyyy-MM-dd hh:mm:ss")
  40. that.setData({
  41. showPage: true,
  42. data: res.data,
  43. supportTransfer: res.data.supportTransfer,
  44. code: res.data.id,
  45. codeS: res.data.id.slice(0, 4) + `******` + res.data.id.slice(14),
  46. })
  47. if (res.data.wxCardInfo.status) {
  48. this.setData({
  49. isShowQR: false
  50. })
  51. } else {
  52. that.getQR(res.data.id, res.data.tenantId, res.data.wxCardInfo.ownerUserId)
  53. const tempObj = {
  54. id: res.data.id,
  55. tenantId: res.data.tenantId,
  56. ownerUserId: res.data.wxCardInfo.ownerUserId
  57. }
  58. this.setData({
  59. QRdata: tempObj
  60. })
  61. }
  62. /**
  63. * 若可转赠获取用户头像信息
  64. */
  65. if (that.data.merchantVoList && that.data.merchantVoList.length <= 4) {
  66. that.setData({
  67. height: that.data.merchantVoList.length * 140 + 'rpx',
  68. showMore: false
  69. })
  70. } else if (that.data.merchantVoList && that.data.cardDetail.length > 4) {
  71. that.setData({
  72. height: 4 * 140 + 'rpx'
  73. })
  74. }
  75. }
  76. })
  77. .catch(err => {
  78. console.log(err)
  79. })
  80. },
  81. showId() {
  82. let this_ = this;
  83. if (!this_.data.showIdFalg) {
  84. wx.showModal({
  85. content: '是否查看完整券码',
  86. success(res) {
  87. if (res.confirm) {
  88. this_.setData({
  89. showIdFalg: true
  90. })
  91. } else if (res.cancel) {
  92. console.log('用户点击取消')
  93. }
  94. }
  95. })
  96. } else {
  97. this.setData({
  98. showIdFalg: false
  99. })
  100. }
  101. },
  102. reQR() {
  103. this.setData({
  104. showhieRq: false
  105. })
  106. const QRdata = this.data.QRdata
  107. this.getQR(QRdata.id, QRdata.tenantId, QRdata.ownerUserId)
  108. },
  109. // 获取动态二维码
  110. getQR(cardId, cardTenantId, cUserId) {
  111. Http.get({
  112. url: `/couponOrder/cardDynamicId?cardId=${cardId}&cardTenantId=${cardTenantId}&cUserId=${cUserId}`,
  113. }).then(res => {
  114. console.log(res.data);
  115. let timer
  116. let expiredSeconds = res.data.expiredSeconds
  117. if (expiredSeconds) {
  118. this.setData({
  119. expiredSeconds: expiredSeconds
  120. })
  121. timer = setInterval(() => {
  122. if (expiredSeconds != 0) {
  123. this.setData({
  124. expiredSeconds: expiredSeconds
  125. })
  126. expiredSeconds--
  127. } else {
  128. clearInterval(timer)
  129. this.setData({
  130. showhieRq: true
  131. })
  132. }
  133. }, 1000);
  134. }
  135. let url = JSON.stringify({
  136. END: "C",
  137. TYPE: "Ecard",
  138. ID: res.data.dynamicId,
  139. TENANTID: res.data.cardTenantId,
  140. })
  141. this.createQrCode(url, "qrcode", 350, 350);
  142. }).catch(err => {
  143. console.log(err, 'err');
  144. wx.showToast({
  145. title: err.message,
  146. icon: 'none'
  147. })
  148. })
  149. },
  150. goGive() {
  151. wx.navigateTo({
  152. url: `/pages/ConsumeDetail/ConsumeDetail?cardId=${this.data.data.id}`,
  153. })
  154. },
  155. // 无法转赠
  156. goGiveNone() {
  157. if (this.data.data.amount !== this.data.data.remainingAmount) {
  158. wx.showToast({
  159. title: '该卡已消费,不支持转增',
  160. icon: 'none'
  161. })
  162. } else {
  163. wx.showToast({
  164. title: '该卡不支持转增',
  165. icon: "error"
  166. })
  167. }
  168. },
  169. // 扫一扫去支付
  170. gotoPay: function () {
  171. app.globalData.previewFlag = true
  172. let that = this;
  173. wx.scanCode({
  174. success: (res) => {
  175. if (util.isJSON(res.result)) {
  176. let value = JSON.parse(res.result);
  177. if (value.END == 'B' && value.TYPE == 'merchant' && value.ID) {
  178. Http.get({
  179. url: config.api.findByCode,
  180. data: {
  181. merchantCode: value.ID,
  182. }
  183. })
  184. .then(res => {
  185. if (res.code == 200) {
  186. let merChantDetail = JSON.stringify(res.data);
  187. if (merChantDetail && that.data.data.id && (that.data.data.remainingAmount)) {
  188. merChantDetail = encodeURIComponent(merChantDetail)
  189. console.log(that.data.data, 'data');
  190. wx.navigateTo({
  191. url: `/pages/scanPay/scanPay?merChant=${merChantDetail}&cardid=${that.data.data.id}&remainingAmount=${that.data.data.remainingAmount / 100}`,
  192. })
  193. }
  194. }
  195. })
  196. .catch(err => {
  197. console.log(err)
  198. })
  199. } else {
  200. wx.showToast({
  201. title: "未识别到商户二维码",
  202. icon: "none",
  203. mask: false
  204. })
  205. }
  206. } else {
  207. wx.showToast({
  208. title: "未识别到商户二维码",
  209. icon: "none",
  210. mask: false
  211. })
  212. }
  213. },
  214. fail: (res) => {
  215. wx.showToast({
  216. title: "未识别到商户二维码",
  217. icon: "none",
  218. mask: false
  219. })
  220. }
  221. })
  222. },
  223. createQrCode: function (url, canvasId, cavW, cavH) {
  224. console.log('createQrCode!');
  225. //调用插件中的draw方法,绘制二维码图片
  226. let that = this;
  227. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  228. that.setData({
  229. tempFilePath: res
  230. })
  231. });
  232. },
  233. /**
  234. * 生命周期函数--监听页面加载
  235. */
  236. onLoad(options) {
  237. console.log(options);
  238. if (options.cardId) {
  239. this.cardDetail(options.cardId);
  240. this.setData({
  241. cardId: options.cardId
  242. })
  243. }
  244. },
  245. /**
  246. * 生命周期函数--监听页面初次渲染完成
  247. */
  248. onReady() {
  249. },
  250. /**
  251. * 生命周期函数--监听页面显示
  252. */
  253. onShow() {
  254. this.cardDetail(this.data.cardId);
  255. },
  256. /**
  257. * 生命周期函数--监听页面隐藏
  258. */
  259. onHide() {
  260. },
  261. /**
  262. * 生命周期函数--监听页面卸载
  263. */
  264. onUnload() {
  265. },
  266. /**
  267. * 页面相关事件处理函数--监听用户下拉动作
  268. */
  269. onPullDownRefresh() {
  270. this.cardDetail(this.data.cardId);
  271. },
  272. /**
  273. * 页面上拉触底事件的处理函数
  274. */
  275. onReachBottom() {
  276. },
  277. /**
  278. * 用户点击右上角分享
  279. */
  280. onShareAppMessage() {
  281. }
  282. })