|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px';
- const util = require("../../../utils/util.js");
- const config = require("../../../config/config.js");
- const Http = require("../../../utils/HttpBasics");
- let app = getApp();
- const imgurl = require("../../../utils/imgurl");
- const QR = require("../../../utils/memberqrcode.js");
- Page({
- // https://formall.oss-accelerate.aliyuncs.com/cimg/wm01.jpg
- /**
- * 页面的初始数据
- */
- data: {
- navigationBarHeight,
- topLine: imgurl.topLine.url,
- btomLine: imgurl.btomLine.url,
- upDataRqUrlF: imgurl.upDataRqF.url,
- data: {},
- showIdFalg: false,
- code: '',
- codeS: '',
- tempFilePath: '',
- QRdata: {},
- isShowQR: true,
- showhieRq: false,
- cardId: '',
- showImg: ''
- },
-
- cardDetail(couponOrderId) {
- let that = this;
- Http.get({
- url: config.api.cardDetail,
- data: {
- couponOrderId: couponOrderId,
- }
- })
- .then(res => {
- console.log(res)
- if (res.code == 200) {
- res.data.expiredTime = util.formatTime(res.data.expiredTime, "yyyy-MM-dd hh:mm:ss")
- that.setData({
- showPage: true,
- data: res.data,
- supportTransfer: res.data.supportTransfer,
- code: res.data.id,
- codeS: res.data.id.slice(0, 4) + `******` + res.data.id.slice(14),
- })
-
- if (res.data.wxCardInfo.status) {
- this.setData({
- isShowQR: false
- })
- } else {
- that.getQR(res.data.id, res.data.tenantId, res.data.wxCardInfo.ownerUserId)
- const tempObj = {
- id: res.data.id,
- tenantId: res.data.tenantId,
- ownerUserId: res.data.wxCardInfo.ownerUserId
- }
- this.setData({
- QRdata: tempObj
- })
- }
-
- /**
- * 若可转赠获取用户头像信息
- */
- if (that.data.merchantVoList && that.data.merchantVoList.length <= 4) {
- that.setData({
- height: that.data.merchantVoList.length * 140 + 'rpx',
- showMore: false
- })
- } else if (that.data.merchantVoList && that.data.cardDetail.length > 4) {
- that.setData({
- height: 4 * 140 + 'rpx'
- })
- }
- }
- })
- .catch(err => {
- console.log(err)
- })
- },
-
- showId() {
- let this_ = this;
- if (!this_.data.showIdFalg) {
- wx.showModal({
- content: '是否查看完整券码',
- success(res) {
- if (res.confirm) {
- this_.setData({
- showIdFalg: true
- })
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- })
- } else {
- this.setData({
- showIdFalg: false
- })
- }
- },
-
- reQR() {
- this.setData({
- showhieRq: false
- })
- const QRdata = this.data.QRdata
- this.getQR(QRdata.id, QRdata.tenantId, QRdata.ownerUserId)
- },
-
- // 获取动态二维码
- getQR(cardId, cardTenantId, cUserId) {
- Http.get({
- url: `/couponOrder/cardDynamicId?cardId=${cardId}&cardTenantId=${cardTenantId}&cUserId=${cUserId}`,
- }).then(res => {
- console.log(res.data);
- let timer
- let expiredSeconds = res.data.expiredSeconds
- if (expiredSeconds) {
- this.setData({
- expiredSeconds: expiredSeconds
- })
- timer = setInterval(() => {
- if (expiredSeconds != 0) {
- this.setData({
- expiredSeconds: expiredSeconds
- })
- expiredSeconds--
- } else {
- clearInterval(timer)
- this.setData({
- showhieRq: true
- })
- }
- }, 1000);
- }
-
- let url = JSON.stringify({
- END: "C",
- TYPE: "Ecard",
- ID: res.data.dynamicId,
- TENANTID: res.data.cardTenantId,
- })
- this.createQrCode(url, "qrcode", 350, 350);
-
- }).catch(err => {
- console.log(err, 'err');
- wx.showToast({
- title: err.message,
- icon: 'none'
- })
- })
- },
-
- goGive() {
- wx.navigateTo({
- url: `/pages/ConsumeDetail/ConsumeDetail?cardId=${this.data.data.id}`,
- })
- },
-
- goSetSecurity() {
- wx.showModal({
- title: '设置支付密码',
- placeholderText: '请设置密码,不设则默认为无密码',
- editable: true,
- complete: (res) => {
- if (res.cancel) {
- console.log(res);
- }
-
- if (res.confirm) {
- const numReg = /^\d+$/
- const isNum = numReg.test(res.content)
- if (res.content) {
- if (!isNum || (res.content.length != 6)) {
- wx.showToast({
- title: '密码只能为6位数字',
- icon: 'none'
- })
- return
- } else {
- this.setPassword(1, res.content)
- }
- } else {
- this.setPassword(0, '')
- }
- }
- }
- })
- },
-
- setPassword(payCheck, pwd) {
- Http.post({
- url: config.api.updatePayPassword,
- data: {
- id: this.data.data.id,
- payCheck: payCheck,
- payPassword: pwd
- }
- }).then(res => {
- wx.showToast({
- title: '设置成功!',
- icon: 'success'
- })
- setTimeout(() => {
- wx.navigateBack()
- }, 1500);
- }).catch(err => {
- wx.showToast({
- title: err.message,
- icon: 'error'
- })
- })
- },
-
- goCheck() {
- wx.navigateTo({
- url: `/pages/ConsumeDetail/ConsumeDetail?cardId=${this.data.data.id}`,
- })
- },
-
- // 无法转赠
- goGiveNone() {
- if (this.data.data.amount !== this.data.data.remainingAmount) {
- wx.showToast({
- title: '该卡已消费,不支持转增',
- icon: 'none'
- })
- } else {
- wx.showToast({
- title: '该卡不支持转增',
- icon: "error"
- })
- }
-
- },
-
- // 扫一扫去支付
- gotoPay: function () {
- app.globalData.previewFlag = true
- let that = this;
- wx.scanCode({
- success: (res) => {
- if (util.isJSON(res.result)) {
- let value = JSON.parse(res.result);
- if (value.END == 'B' && value.TYPE == 'merchant' && value.ID) {
- Http.get({
- url: config.api.findByCode,
- data: {
- merchantCode: value.ID,
- }
- })
- .then(res => {
- if (res.code == 200) {
- let merChantDetail = JSON.stringify(res.data);
- if (merChantDetail && that.data.data.id && (that.data.data.remainingAmount)) {
- merChantDetail = encodeURIComponent(merChantDetail)
- console.log(that.data.data, 'data');
- wx.navigateTo({
- url: `/pages/scanPay/scanPay?merChant=${merChantDetail}&cardid=${that.data.data.id}&remainingAmount=${that.data.data.remainingAmount / 100}&payCheck=${that.data.data.payCheck}`,
- })
- }
- }
- })
- .catch(err => {
- console.log(err)
- })
- } else {
- wx.showToast({
- title: "未识别到商户二维码",
- icon: "none",
- mask: false
- })
- }
- } else {
- wx.showToast({
- title: "未识别到商户二维码",
- icon: "none",
- mask: false
- })
- }
- },
- fail: (res) => {
- wx.showToast({
- title: "未识别到商户二维码",
- icon: "none",
- mask: false
- })
- }
- })
- },
-
- createQrCode: function (url, canvasId, cavW, cavH) {
- console.log('createQrCode!');
- //调用插件中的draw方法,绘制二维码图片
- let that = this;
- QR.api.draw(url, canvasId, cavW, cavH, function (res) {
- that.setData({
- tempFilePath: res
- })
- });
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- console.log(options);
- if (options.cardId) {
- this.cardDetail(options.cardId);
- this.setData({
- cardId: options.cardId,
- showImg: options.showImg
- })
- }
- console.log(this.data.showImg, 'showImg');
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- this.cardDetail(this.data.cardId);
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- this.cardDetail(this.data.cardId);
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
-
- }
- })
|