C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

368 lines
8.7 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. goSetSecurity() {
  157. wx.showModal({
  158. title: '设置支付密码',
  159. placeholderText: '请设置密码,不设则默认为无密码',
  160. editable: true,
  161. complete: (res) => {
  162. if (res.cancel) {
  163. console.log(res);
  164. }
  165. if (res.confirm) {
  166. const numReg = /^\d+$/
  167. const isNum = numReg.test(res.content)
  168. if (res.content) {
  169. if (!isNum || (res.content.length != 6)) {
  170. wx.showToast({
  171. title: '密码只能为6位数字',
  172. icon: 'none'
  173. })
  174. return
  175. } else {
  176. this.setPassword(1, res.content)
  177. }
  178. } else {
  179. this.setPassword(0, '')
  180. }
  181. }
  182. }
  183. })
  184. },
  185. setPassword(payCheck, pwd) {
  186. Http.post({
  187. url: config.api.updatePayPassword,
  188. data: {
  189. id: this.data.data.id,
  190. payCheck: payCheck,
  191. payPassword: pwd
  192. }
  193. }).then(res => {
  194. wx.showToast({
  195. title: '设置成功!',
  196. icon: 'success'
  197. })
  198. }).catch(err => {
  199. wx.showToast({
  200. title: err.message,
  201. icon: 'error'
  202. })
  203. })
  204. },
  205. goCheck() {
  206. wx.navigateTo({
  207. url: `/pages/ConsumeDetail/ConsumeDetail?cardId=${this.data.data.id}`,
  208. })
  209. },
  210. // 无法转赠
  211. goGiveNone() {
  212. if (this.data.data.amount !== this.data.data.remainingAmount) {
  213. wx.showToast({
  214. title: '该卡已消费,不支持转增',
  215. icon: 'none'
  216. })
  217. } else {
  218. wx.showToast({
  219. title: '该卡不支持转增',
  220. icon: "error"
  221. })
  222. }
  223. },
  224. // 扫一扫去支付
  225. gotoPay: function () {
  226. app.globalData.previewFlag = true
  227. let that = this;
  228. wx.scanCode({
  229. success: (res) => {
  230. if (util.isJSON(res.result)) {
  231. let value = JSON.parse(res.result);
  232. if (value.END == 'B' && value.TYPE == 'merchant' && value.ID) {
  233. Http.get({
  234. url: config.api.findByCode,
  235. data: {
  236. merchantCode: value.ID,
  237. }
  238. })
  239. .then(res => {
  240. if (res.code == 200) {
  241. let merChantDetail = JSON.stringify(res.data);
  242. if (merChantDetail && that.data.data.id && (that.data.data.remainingAmount)) {
  243. merChantDetail = encodeURIComponent(merChantDetail)
  244. console.log(that.data.data, 'data');
  245. wx.navigateTo({
  246. url: `/pages/scanPay/scanPay?merChant=${merChantDetail}&cardid=${that.data.data.id}&remainingAmount=${that.data.data.remainingAmount / 100}`,
  247. })
  248. }
  249. }
  250. })
  251. .catch(err => {
  252. console.log(err)
  253. })
  254. } else {
  255. wx.showToast({
  256. title: "未识别到商户二维码",
  257. icon: "none",
  258. mask: false
  259. })
  260. }
  261. } else {
  262. wx.showToast({
  263. title: "未识别到商户二维码",
  264. icon: "none",
  265. mask: false
  266. })
  267. }
  268. },
  269. fail: (res) => {
  270. wx.showToast({
  271. title: "未识别到商户二维码",
  272. icon: "none",
  273. mask: false
  274. })
  275. }
  276. })
  277. },
  278. createQrCode: function (url, canvasId, cavW, cavH) {
  279. console.log('createQrCode!');
  280. //调用插件中的draw方法,绘制二维码图片
  281. let that = this;
  282. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  283. that.setData({
  284. tempFilePath: res
  285. })
  286. });
  287. },
  288. /**
  289. * 生命周期函数--监听页面加载
  290. */
  291. onLoad(options) {
  292. console.log(options);
  293. if (options.cardId) {
  294. this.cardDetail(options.cardId);
  295. this.setData({
  296. cardId: options.cardId,
  297. showImg: options.showImg
  298. })
  299. }
  300. console.log(this.data.showImg, 'showImg');
  301. },
  302. /**
  303. * 生命周期函数--监听页面初次渲染完成
  304. */
  305. onReady() {
  306. },
  307. /**
  308. * 生命周期函数--监听页面显示
  309. */
  310. onShow() {
  311. this.cardDetail(this.data.cardId);
  312. },
  313. /**
  314. * 生命周期函数--监听页面隐藏
  315. */
  316. onHide() {
  317. },
  318. /**
  319. * 生命周期函数--监听页面卸载
  320. */
  321. onUnload() {
  322. },
  323. /**
  324. * 页面相关事件处理函数--监听用户下拉动作
  325. */
  326. onPullDownRefresh() {
  327. this.cardDetail(this.data.cardId);
  328. },
  329. /**
  330. * 页面上拉触底事件的处理函数
  331. */
  332. onReachBottom() {
  333. },
  334. /**
  335. * 用户点击右上角分享
  336. */
  337. onShareAppMessage() {
  338. }
  339. })