C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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