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.

303 lines
7.2 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. this.setData({
  118. expiredSeconds: expiredSeconds
  119. })
  120. timer = setInterval(() => {
  121. if (expiredSeconds != 0) {
  122. this.setData({
  123. expiredSeconds: expiredSeconds
  124. })
  125. expiredSeconds--
  126. } else {
  127. clearInterval(timer)
  128. this.setData({
  129. showhieRq: true
  130. })
  131. }
  132. }, 1000);
  133. }
  134. let url = JSON.stringify({
  135. END: "C",
  136. TYPE: "Ecard",
  137. ID: res.data.dynamicId,
  138. TENANTID: res.data.cardTenantId,
  139. })
  140. this.createQrCode(url, "qrcode", 350, 350);
  141. }).catch(err => {
  142. console.log(err, 'err');
  143. wx.showToast({
  144. title: err.message,
  145. icon: 'none'
  146. })
  147. })
  148. },
  149. goGive() {
  150. wx.navigateTo({
  151. url: `/pages/ConsumeDetail/ConsumeDetail?cardId=${this.data.data.id}`,
  152. })
  153. },
  154. // 无法转赠
  155. goGiveNone() {
  156. if (this.data.data.amount !== this.data.data.remainingAmount) {
  157. wx.showToast({
  158. title: '该卡已消费,不支持转增',
  159. icon: 'none'
  160. })
  161. } else {
  162. wx.showToast({
  163. title: '该卡不支持转增',
  164. icon: "error"
  165. })
  166. }
  167. },
  168. // 扫一扫去支付
  169. gotoPay: function () {
  170. app.globalData.previewFlag = true
  171. let that = this;
  172. wx.scanCode({
  173. success: (res) => {
  174. if (util.isJSON(res.result)) {
  175. let value = JSON.parse(res.result);
  176. if (value.END == 'B' && value.TYPE == 'merchant' && value.ID) {
  177. Http.get({
  178. url: config.api.findByCode,
  179. data: {
  180. merchantCode: value.ID,
  181. }
  182. })
  183. .then(res => {
  184. if (res.code == 200) {
  185. let merChantDetail = JSON.stringify(res.data);
  186. if (merChantDetail && that.data.data.id && (that.data.data.remainingAmount)) {
  187. merChantDetail = encodeURIComponent(merChantDetail)
  188. console.log(that.data.data, 'data');
  189. wx.navigateTo({
  190. url: `/pages/scanPay/scanPay?merChant=${merChantDetail}&cardid=${that.data.data.id}&remainingAmount=${that.data.data.remainingAmount / 100}`,
  191. })
  192. }
  193. }
  194. })
  195. .catch(err => {
  196. console.log(err)
  197. })
  198. } else {
  199. wx.showToast({
  200. title: "未识别到商户二维码",
  201. icon: "none",
  202. mask: false
  203. })
  204. }
  205. } else {
  206. wx.showToast({
  207. title: "未识别到商户二维码",
  208. icon: "none",
  209. mask: false
  210. })
  211. }
  212. },
  213. fail: (res) => {
  214. wx.showToast({
  215. title: "未识别到商户二维码",
  216. icon: "none",
  217. mask: false
  218. })
  219. }
  220. })
  221. },
  222. createQrCode: function (url, canvasId, cavW, cavH) {
  223. console.log('createQrCode!');
  224. //调用插件中的draw方法,绘制二维码图片
  225. let that = this;
  226. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  227. that.setData({
  228. tempFilePath: res
  229. })
  230. });
  231. },
  232. /**
  233. * 生命周期函数--监听页面加载
  234. */
  235. onLoad(options) {
  236. console.log(options);
  237. if (options.cardId) {
  238. this.cardDetail(options.cardId);
  239. }
  240. },
  241. /**
  242. * 生命周期函数--监听页面初次渲染完成
  243. */
  244. onReady() {
  245. },
  246. /**
  247. * 生命周期函数--监听页面显示
  248. */
  249. onShow() {
  250. },
  251. /**
  252. * 生命周期函数--监听页面隐藏
  253. */
  254. onHide() {
  255. },
  256. /**
  257. * 生命周期函数--监听页面卸载
  258. */
  259. onUnload() {
  260. },
  261. /**
  262. * 页面相关事件处理函数--监听用户下拉动作
  263. */
  264. onPullDownRefresh() {
  265. },
  266. /**
  267. * 页面上拉触底事件的处理函数
  268. */
  269. onReachBottom() {
  270. },
  271. /**
  272. * 用户点击右上角分享
  273. */
  274. onShareAppMessage() {
  275. }
  276. })