C端小程序
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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