Blame view

pages/businessCard/printCard.vue 6.58 KB
36884ffd   刘淇   打印
1
2
  <template>
      <view>
9bac797d   刘淇   卡券发放
3
          <uni-section :title="`${cardRuleName}(${cardTypeName})`" type="line">
36884ffd   刘淇   打印
4
5
              <uni-card padding="0" spacing="0">
                  <uni-list>
9bac797d   刘淇   卡券发放
6
                      <uni-list-item title="适应车场" :rightText="plName">
36884ffd   刘淇   打印
7
8
                          <text></text>
                      </uni-list-item>
843fbfe3   刘淇   发放卡券代码格式化
9
10
                      <uni-list-item :title="`价格:¥${(price/100).toFixed(2)}/张`"
                                     :rightText="`商户库存:${cardNum}张`"></uni-list-item>
36884ffd   刘淇   打印
11
12
13
14
                  </uni-list>
              </uni-card>
          </uni-section>
  
9bac797d   刘淇   卡券发放
15
          <view class=" uni-card text-center" style="padding: 10px 0">
843fbfe3   刘淇   发放卡券代码格式化
16
              <image :src="qrUrl" style="width: 300px;height:300px;margin: 0 auto;"
e1beceff   刘淇   二维码保存图片
17
                     show-menu-by-longpress='1'></image>
36884ffd   刘淇   打印
18
19
          </view>
  
c9d45ef5   刘淇   商户券 有效期
20
          <view style="padding: 5px 10px">长按上面二维码可以保存为图片</view>
9bac797d   刘淇   卡券发放
21
22
  
          <view class=" uni-card" style="padding: 10px 15px">
c9d45ef5   刘淇   商户券 有效期
23
24
              <view style="padding-bottom: 10px;">选择二维码有效期</view>
              <!--<uni-number-box @change="changeValue" min="1"/>-->
843fbfe3   刘淇   发放卡券代码格式化
25
              <uni-datetime-picker v-model="single" :start="startTime"/>
fc8d2d1a   刘淇   打印
26
27
          </view>
  
36884ffd   刘淇   打印
28
          <view class="uni-padding-wrap uni-common-mt">
fc8d2d1a   刘淇   打印
29
              <!--<button type="primary" style="margin-bottom: 15px">停止自动发放</button>-->
de23b5ec   刘淇   生成二维码
30
              <button type="warn" @click="changeTime">重新生成二维码</button>
36884ffd   刘淇   打印
31
32
33
34
35
36
37
          </view>
  
  
      </view>
  </template>
  
  <script>
9bac797d   刘淇   卡券发放
38
  import uQRCode from '../../common/uqrcode.js' //引入uqrcode.js
843fbfe3   刘淇   发放卡券代码格式化
39
  import { formatDate } from '../../common/date.js';
36884ffd   刘淇   打印
40
41
  export default {
    data() {
36884ffd   刘淇   打印
42
      return {
9bac797d   刘淇   卡券发放
43
44
45
46
47
48
49
        cardTypeName: '',// 卡类型名称
        cardRuleName: '',// 卡名称
        plName: '', // 停车场
        price: '', // 卡价格
        cardNum: '', // 库存
        cardRelParkNo: '',//商券规则关联车场和商户编码
        numberValue: '1',
c9d45ef5   刘淇   商户券 有效期
50
        deadline: '2099-10-01 00:00:00',
9bac797d   刘淇   卡券发放
51
        qrUrl: '', // 图片地址
c9d45ef5   刘淇   商户券 有效期
52
        single: '',
843fbfe3   刘淇   发放卡券代码格式化
53
54
        startTime: '',
        deadlineInit: ""
36884ffd   刘淇   打印
55
56
57
58
59
60
      }
    },
    onLoad(params) {
      wx.showShareMenu({
        withShareTicket: true
      })
9bac797d   刘淇   卡券发放
61
62
63
64
65
66
67
68
      console.log(params)
      let option = params
      this.cardRelParkNo = option.cardRelParkNo
      this.cardTypeName = option.cardTypeName
      this.cardRuleName = option.cardRuleName
      this.plName = option.plName
      this.price = option.price
      this.cardNum = option.cardNum
b467bab6   刘淇   卡券发放默认时间为一天有效
69
70
      this.deadline = this.dateAdd(1)
      console.log(this.deadline)
9bac797d   刘淇   卡券发放
71
      this.getCouponStaticQR()
36884ffd   刘淇   打印
72
73
74
    },
    onShow() {
      var me = this;
36884ffd   刘淇   打印
75
    },
c9d45ef5   刘淇   商户券 有效期
76
77
    mounted() {
      setTimeout(() => {
843fbfe3   刘淇   发放卡券代码格式化
78
79
80
81
82
        this.startTime = Date.now()
        this.single = formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss')
        this.deadlineInit = formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss');
        console.log(this.single)
      }, 500)
c9d45ef5   刘淇   商户券 有效期
83
    },
9bac797d   刘淇   卡券发放
84
    computed: {},
36884ffd   刘淇   打印
85
    methods: {
b467bab6   刘淇   卡券发放默认时间为一天有效
86
87
88
89
90
91
92
93
94
95
96
97
98
      timeAdd0(str) {
        if (str < 10) {
          str = '0' + str;
        }
        return str
      },
      dateAdd(days) {
        var startDate = new Date();
        startDate = +startDate + days * 1000 * 60 * 60 * 24;
        startDate = new Date(startDate);
        var nextStartDate = startDate.getFullYear() + "-" + this.timeAdd0((startDate.getMonth() + 1)) + "-" + this.timeAdd0(startDate.getDate()) + " " + this.timeAdd0(startDate.getHours()) + ":" + this.timeAdd0(startDate.getMinutes()) + ":" + this.timeAdd0(startDate.getSeconds())
        return nextStartDate;
      },
9bac797d   刘淇   卡券发放
99
      changeValue(value) {
fc8d2d1a   刘淇   打印
100
101
        this.numberValue = value
      },
9bac797d   刘淇   卡券发放
102
103
104
105
106
      getCouponStaticQR() {
        let that = this
        let paramsData = {
          cardRelParkNo: this.cardRelParkNo,
          codeType: '2',
c9d45ef5   刘淇   商户券 有效期
107
          deadline: this.deadline
9bac797d   刘淇   卡券发放
108
109
110
111
112
113
114
115
116
117
        }
        // 首页信息获取 接口
        that.$myRequest({
          url: that.$common.getCouponStaticQR,
          method: 'POST',
          data: that.$common.requestSign(paramsData)
        }).then(res => {
          console.log(res)
          that.qrUrl = res.data.qrUrl
          console.log(that.qrUrl)
36884ffd   刘淇   打印
118
119
        })
      },
9bac797d   刘淇   卡券发放
120
121
122
123
124
125
126
      //**生成二维码**//
      qrFun: function (text) {
        this.qrShow = true
        uQRCode.make({
          canvasId: 'qrcode',
          componentInstance: this,
          text: text,
1fa597c2   刘淇   二维码大小
127
          size: 130,
9bac797d   刘淇   卡券发放
128
129
130
131
132
133
134
135
          margin: 0,
          backgroundColor: '#ffffff',
          foregroundColor: '#000000',
          fileType: 'jpg',
          errorCorrectLevel: uQRCode.errorCorrectLevel.H,
          success: res => {
          }
        })
36884ffd   刘淇   打印
136
      },
9bac797d   刘淇   卡券发放
137
      changeTime: function () {
74df59a8   刘淇   商户券 有效期
138
        console.log(this.single)
1e06c01a   刘淇   二维码有效期必须大于当前时间
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
        console.log(new Date(this.single).getTime())
        console.log(new Date().getTime())
        if(new Date(this.single).getTime()<new Date().getTime()){
          uni.showToast({
            title: '二维码有效期时间必须大于当前时间',
            icon: 'none',
            duration: 2000
          })
        }else{
          uni.showToast({
            title: '2',
  
            duration: 2000
          })
  
          this.deadline = this.single
          this.getCouponStaticQR()
        }
  
1fa597c2   刘淇   二维码大小
158
159
160
      },
      // 小程序保存图片
      savePosterPath(url) {
e357dabe   刘淇   商户券 有效期
161
162
163
164
        console.log(url)
        uni.getSetting({ //获取用户的当前设置
          success: res => {
            console.log('1')
843fbfe3   刘淇   发放卡券代码格式化
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
            if (res.authSetting['scope.writePhotosAlbum']) { //验证用户是否授权可以访问相册
              this.saveImageToPhotosAlbum()
            } else {
              console.log('2')
              uni.authorize({//重新发起获取授权
                scope: 'scope.writePhotosAlbum',
                success: () => {
                  this.saveImageToPhotosAlbum(url)
                },
                fail: () => {
                  uni.showToast({
                    title: '请打开保存相册权限,再点击保存相册分享',
                    icon: 'none',
                    duration: 2000
                  })
                  let timer = setTimeout(() => {
                    clearTimeout(timer)
                    uni.openSetting({ //调起客户端小程序设置界面,让用户开启访问相册
                      success: e => {
                      }
                    })
                  }, 2000)
                }
              })
            }
e357dabe   刘淇   商户券 有效期
190
191
          }
        })
1fa597c2   刘淇   二维码大小
192
      },
843fbfe3   刘淇   发放卡券代码格式化
193
      saveImageToPhotosAlbum() {
e357dabe   刘淇   商户券 有效期
194
195
196
        console.log(this.qrUrl)
        wx.downloadFile({
          url: this.qrUrl,
843fbfe3   刘淇   发放卡券代码格式化
197
198
199
200
201
202
203
204
205
206
207
          success: res => {
            if (res.statusCode === 200) {
              wx.saveImageToPhotosAlbum({
                filePath: res.tempFilePath,
                success(res) {
                  wx.showToast({title: '保存图片成功!',})
                },
                fail(res) {
                  wx.showToast({title: '保存图片失败!',})
                }
              })
e357dabe   刘淇   商户券 有效期
208
            }
843fbfe3   刘淇   发放卡券代码格式化
209
210
211
212
213
          },
          fail: err => {
            console.log(err, 'err')
          }
        })
e357dabe   刘淇   商户券 有效期
214
      },
36884ffd   刘淇   打印
215
216
217
218
219
    }
  }
  </script>
  
  <style lang="scss" scoped>
36884ffd   刘淇   打印
220
  
36884ffd   刘淇   打印
221
222
  
  </style>