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.

cardUse.js 8.8 KiB

2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
3 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. setTimeout(() => {
  199. wx.navigateBack()
  200. }, 1500);
  201. }).catch(err => {
  202. wx.showToast({
  203. title: err.message,
  204. icon: 'error'
  205. })
  206. })
  207. },
  208. goCheck() {
  209. wx.navigateTo({
  210. url: `/pages/ConsumeDetail/ConsumeDetail?cardId=${this.data.data.id}`,
  211. })
  212. },
  213. // 无法转赠
  214. goGiveNone() {
  215. if (this.data.data.amount !== this.data.data.remainingAmount) {
  216. wx.showToast({
  217. title: '该卡已消费,不支持转增',
  218. icon: 'none'
  219. })
  220. } else {
  221. wx.showToast({
  222. title: '该卡不支持转增',
  223. icon: "error"
  224. })
  225. }
  226. },
  227. // 扫一扫去支付
  228. gotoPay: function () {
  229. app.globalData.previewFlag = true
  230. let that = this;
  231. wx.scanCode({
  232. success: (res) => {
  233. if (util.isJSON(res.result)) {
  234. let value = JSON.parse(res.result);
  235. if (value.END == 'B' && value.TYPE == 'merchant' && value.ID) {
  236. Http.get({
  237. url: config.api.findByCode,
  238. data: {
  239. merchantCode: value.ID,
  240. }
  241. })
  242. .then(res => {
  243. if (res.code == 200) {
  244. let merChantDetail = JSON.stringify(res.data);
  245. if (merChantDetail && that.data.data.id && (that.data.data.remainingAmount)) {
  246. merChantDetail = encodeURIComponent(merChantDetail)
  247. console.log(that.data.data, 'data');
  248. wx.navigateTo({
  249. url: `/pages/scanPay/scanPay?merChant=${merChantDetail}&cardid=${that.data.data.id}&remainingAmount=${that.data.data.remainingAmount / 100}&payCheck=${that.data.data.payCheck}`,
  250. })
  251. }
  252. }
  253. })
  254. .catch(err => {
  255. console.log(err)
  256. })
  257. } else {
  258. wx.showToast({
  259. title: "未识别到商户二维码",
  260. icon: "none",
  261. mask: false
  262. })
  263. }
  264. } else {
  265. wx.showToast({
  266. title: "未识别到商户二维码",
  267. icon: "none",
  268. mask: false
  269. })
  270. }
  271. },
  272. fail: (res) => {
  273. wx.showToast({
  274. title: "未识别到商户二维码",
  275. icon: "none",
  276. mask: false
  277. })
  278. }
  279. })
  280. },
  281. createQrCode: function (url, canvasId, cavW, cavH) {
  282. console.log('createQrCode!');
  283. //调用插件中的draw方法,绘制二维码图片
  284. let that = this;
  285. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  286. that.setData({
  287. tempFilePath: res
  288. })
  289. });
  290. },
  291. /**
  292. * 生命周期函数--监听页面加载
  293. */
  294. onLoad(options) {
  295. console.log(options);
  296. if (options.cardId) {
  297. this.cardDetail(options.cardId);
  298. this.setData({
  299. cardId: options.cardId,
  300. showImg: options.showImg
  301. })
  302. }
  303. console.log(this.data.showImg, 'showImg');
  304. },
  305. /**
  306. * 生命周期函数--监听页面初次渲染完成
  307. */
  308. onReady() {
  309. },
  310. /**
  311. * 生命周期函数--监听页面显示
  312. */
  313. onShow() {
  314. this.cardDetail(this.data.cardId);
  315. },
  316. /**
  317. * 生命周期函数--监听页面隐藏
  318. */
  319. onHide() {
  320. },
  321. /**
  322. * 生命周期函数--监听页面卸载
  323. */
  324. onUnload() {
  325. },
  326. /**
  327. * 页面相关事件处理函数--监听用户下拉动作
  328. */
  329. onPullDownRefresh() {
  330. this.cardDetail(this.data.cardId);
  331. },
  332. /**
  333. * 页面上拉触底事件的处理函数
  334. */
  335. onReachBottom() {
  336. },
  337. /**
  338. * 用户点击右上角分享
  339. */
  340. onShareAppMessage() {
  341. }
  342. })