index.vue 14.1 KB
Newer Older
潘琦 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<template>
  <div class="full-page">
    <div class="container">
      <div class="detail-card" v-if="voucherData">
        <div class="head">
          <span class="before-dot"></span>
          <span class="after-dot"></span>
          <div class="picture">
            <div class="round">
              <mt-spinner v-show="voucherData.logoLoading" type="fading-circle" color="#43d1be"></mt-spinner>
              <img v-show="!voucherData.logoLoading" :src="voucherData.merchantsLogo" class="full-width"/>
            </div>
          </div>
          <div class="title">{{voucherData.deptName}}</div>
潘琦 committed
15
          <!-- <div class="tool">
潘琦 committed
16
            <img src="../../assets/images/icon-qr-code.png" class="full-width"/>
潘琦 committed
17
          </div> -->
潘琦 committed
18 19
        </div>
        <div class="body">
20 21
          <div class="big-title" v-if="voucherType === '2'">免费<span class="unit">价值{{voucherData.cost}}</span></div>
          <div class="big-title" v-else>{{voucherData.cost}}<span class="unit"></span></div>
潘琦 committed
22
          <div class="text-center">{{voucherData.voucherName}}</div>
23 24
          <div class="qrcode-block">
            <div class="qrcode-inner">
25 26 27 28
              <div class="qrcode-frame">
                <mt-spinner v-show="qrcodeLoading" type="fading-circle" color="#43d1be"></mt-spinner>
                <div id="qrcode"></div>
              </div>
29 30 31
            </div>
            <h4 class="text-danger text-center">请在使用时将券码出示给医生</h4>
          </div>
潘琦 committed
32
          <div class="table">
33 34 35 36
            <div class="tr">
              <div class="td label">领取人:</div>
              <div class="td text-left">{{voucherData.userName}}</div>
            </div>
潘琦 committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
            <div class="tr">
              <div class="td label">可用时间:</div>
              <div class="td text-left">{{voucherData.useStartTime && voucherData.useStartTime !== "" ? voucherData.useStartTime.split(" ")[0] : ""}} - {{voucherData.useEndTime && voucherData.useEndTime !== "" ? voucherData.useEndTime.split(" ")[0]:""}}</div>
            </div>
            <div class="tr">
              <div class="td label">服务内容:</div>
              <div class="td text-left">{{voucherData.content}} </div>
            </div>
            <div class="tr">
              <div class="td label">使用须知:</div>
              <div class="td text-left">{{voucherData.useNotice}} </div>
            </div>
          </div>
        </div>
        <div class="footer">
          <div class="table">
            <div class="tr">
              <div class="td" v-for="(item, index) in voucherBtnData" :key="index">
                <div class="table-btn" v-if="voucherBtnData.length > 3" :class="voucherBtnData.length > 3?'vertical':'transverse'" @click="handleClick(item.url)"> <!-- transverse:横向 vertical:垂直 -->
                  <div class="cell icon">
                    <mt-spinner v-show="item.iconLoading" type="fading-circle" color="#43d1be"></mt-spinner>
                    <img v-show="!item.iconLoading" :src="item.picture"/>
                  </div>
                  <div class="cell title">{{item.title}}</div>
                </div>
                <div class="table-btn" v-if="voucherBtnData.length == 2" :class="voucherBtnData.length == 2 && index === 0?'transverse pull-right':'pull-left transverse'" @click="handleClick(item.url)"> <!-- transverse:横向 vertical:垂直 -->
                  <div class="cell icon">
                    <mt-spinner v-show="item.iconLoading" type="fading-circle" color="#43d1be"></mt-spinner>
                    <img v-show="!item.iconLoading" :src="item.picture"/>
                  </div>
67 68 69 70 71 72 73
                  <div class="cell title">{{item.title}}</div>
                </div>
                <div class="table-btn transverse" v-if="voucherBtnData.length == 1" @click="handleClick(item.url)"> <!-- transverse:横向 vertical:垂直 -->
                  <div class="cell icon">
                    <mt-spinner v-show="item.iconLoading" type="fading-circle" color="#43d1be"></mt-spinner>
                    <img v-show="!item.iconLoading" :src="item.picture"/>
                  </div>
潘琦 committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
                  <div class="cell title">{{item.title}}</div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="block m-t">
        <div class="spinner" v-show="contentMessageSpinner"><mt-spinner type="fading-circle" color="#43d1be" :size="40"></mt-spinner></div>
        <ul>
          <li v-for="(item, index) in contentData" :key="index" @click="goToContent(item.imprId)">
            <ContentItem :data="item"></ContentItem>
          </li>
        </ul>
        <div v-show="contentMessageVisible" class="message-block"><i class="glyphicon glyphicon-info-sign"></i> 暂无相关健康知识!</div>
      </div>
      <!-- 扫码核销 -->
92
      <!-- <div class="model" v-show="qrCodeVisible">
潘琦 committed
93 94 95 96 97 98 99
        <div class="model-body">
          <div class="title">医生扫描券码即可服务</div>
          <div id="qrcode"></div>
        </div>
        <div class="text-center model-close">
          <i class="glyphicon glyphicon-remove-circle" @click="qrCodeVisible=false"></i>
        </div>
100
      </div> -->
潘琦 committed
101 102 103 104

      <!-- 小贴士 -->
      <div class="popup-model" v-if="tipsPopupVisible">
        <div class="body">
105
          <!-- <p class="label-title">产检时间</p>
潘琦 committed
106 107 108
          <p>{{tipsData.tipsTime}}</p>
          <p class="label-title">产检项目</p>
          <p>{{tipsData.tipsTitle}}</p>
109
          <p class="label-title">产检贴士</p> -->
潘琦 committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
          <p v-html="tipsData.tipsDetailed"></p>
          <div class="footer">
            <div style="padding: 10px;"><button class="btn-default btn-block" @click="tipsPopupVisible=false">确认</button></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getVoucherInfoById, getButtonByVoucherId, getContentListByMakeId, getQrCodeByVoucherId, getTipsByVoucherId } from '@/api/apply/apply'
import { imageBase64 } from '@/api/admin/admin'
import QRCode from 'qrcodejs2'
import ContentItem from '@/components/contentItem'
// import { noscroll, renewscroll } from '@/util/index'

export default {
  name: 'detail',
  data () {
    return {
潘琦 committed
131
      voucherId: this.$route.query.voucherId,
潘琦 committed
132
      makeId: this.$route.query.makeId,
133
      voucherType: this.$route.query.voucherType,
潘琦 committed
134 135 136 137 138
      voucherData: null,
      voucherBtnData: null,
      contentData: [], // 内容流数据
      contentMessageSpinner: true, // 内容流加载状态,默认显示
      contentMessageVisible: false, // 内容流文字提示,默认不显示,接口返回数组为0显示
139 140
      qrCodeVisible: true, // 二维码显示状态
      qrcodeLoading: true,
潘琦 committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
      tipsPopupVisible: false, // “小贴士”弹窗显示状态
      tipsData: { // “小贴士”数据
        tipsTime: '无',
        tipsTitle: '无',
        tipsDetailed: '无'
      }
    }
  },
  created () {
    this.getVoucherInfoByIdFn() // 根据voucherId查询该券详情
    this.getContentListByMakeIdFn() // 根据券makeId查询内容流
  },
  mounted: function () {
  },
  computed: {
  },
  components: {
    ContentItem
  },
  methods: {
    getVoucherInfoByIdFn () { // 根据voucherId获取该券信息
潘琦 committed
162 163
      if (this.voucherId) {
        getVoucherInfoById(this.voucherId).then(res => {
潘琦 committed
164 165 166 167 168 169 170 171 172 173 174
          if (res.code === 0) {
            let data = res.data
            if (data.merchantsLogo && data.merchantsLogo !== '') {
              this.imgBase64(data.merchantsLogo).then(res => { // 社区logo图片转换base64插入图片
                data.merchantsLogo = res
                data.logoLoading = false // 图片加载完成标识
              })
            }
            data.logoLoading = true // 图片加载中标识
            this.voucherData = data
            this.foreachButtons() // 配置按钮图标
175
            this.qrCodePopup() // 获取券的核销二维码
潘琦 committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
            console.log('getVoucherInfoByIdFn' + this.voucherData.merchantsLogo)
          }
        }).catch((error) => {
          this.$toast({
            message: error.message,
            position: 'center',
            duration: 3000
          })
        })
      } else {
        this.$toast({
          message: '券id不能为空',
          position: 'center',
          duration: 3000
        })
      }
    },
    foreachButtons () { // 按钮配置接口,多个按钮图标转换base64,插入对应对应按钮图标
      let that = this
潘琦 committed
195
      getButtonByVoucherId(this.voucherId).then(res => {
潘琦 committed
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
        if (res && res.msg === 'success') {
          that.voucherBtnData = res.data
          that.voucherBtnData.forEach(function (item, index) {
            item.iconLoading = true // 图片加载中标识
            that.imgBase64(item.picture).then(res => {
              let btn = that.voucherBtnData[index]
              btn.iconLoading = false // 图片加载完成标识
              btn.picture = res
            })
          })
        }
      }).catch((error) => {
        console.log(error.message)
        this.$toast({
          message: error.message,
          position: 'center',
          duration: 3000
        })
      })
    },
    handleClick (type) { // 券配置按钮点击
潘琦 committed
217
      console.log(type)
潘琦 committed
218 219 220 221
      switch (type) {
        case 'popup:code':
          this.qrCodePopup() // 核销二维码
          break
潘琦 committed
222 223 224
        case 'jump:report':
          this.reportLink()
          break
潘琦 committed
225 226 227
        case 'popup:tips':
          this.tipsPopup() // 小贴士
          break
潘琦 committed
228 229 230
        case 'jump:appraise':
          this.commentLink()
          break
潘琦 committed
231 232 233
      }
    },
    qrCodePopup () { // 核销二维码弹窗
234 235
      console.log(this.voucherId)
      // document.getElementById('qrcode').innerHTML = ''
潘琦 committed
236
      getQrCodeByVoucherId(this.voucherId).then(res => {
237
        this.qrcodeLoading = false
潘琦 committed
238
        if (res && res.msg === 'success') {
239
          // this.qrCodeVisible = true
潘琦 committed
240 241 242 243 244 245 246 247
          let qrcode = new QRCode('qrcode', {
            width: 200,
            height: 200,
            // text: '', // 二维码地址
            colorDark: '#000',
            colorLight: '#fff'
          })
          qrcode.clear()
248 249 250 251 252
          if (res.data) {
            qrcode.makeCode(JSON.stringify(res.data))
          } else {
            this.qrCodeVisible = false
          }
潘琦 committed
253
        } else {
254
          this.qrCodeVisible = false
潘琦 committed
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
          this.$toast({
            message: '获取服务券二维码失败',
            position: 'center',
            duration: 3000
          })
        }
      }).catch((error) => {
        console.log(error.message)
        this.$toast({
          message: error.message,
          position: 'center',
          duration: 3000
        })
      })
    },
    tipsPopup () { // 小贴士
      this.$Indicator.open()
潘琦 committed
272
      getTipsByVoucherId(this.voucherId).then(res => {
潘琦 committed
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
        this.$Indicator.close()
        if (res && res.msg === 'success') {
          this.tipsPopupVisible = true
          this.tipsData = res.data
          this.tipsData.tipsDetailed = this.tipsData.tipsDetailed.replace(/[\r\n]/g, '<br>')
        } else {
          this.$toast({
            message: '该服务券还没有小贴士噢!',
            position: 'center',
            duration: 3000
          })
        }
      }).catch((error) => {
        console.log(error.message)
        this.$toast({
          message: error.message,
          position: 'center',
          duration: 3000
        })
      })
    },
潘琦 committed
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
    reportLink () {
      this.$toast({
        message: '建设中',
        position: 'center',
        duration: 3000
      })
    },
    commentLink () { // 评价
      console.log(this.voucherId)
      this.$router.push({
        path: '/comment/comment',
        query: {
          voucherId: this.voucherId
        }
      })
    },
潘琦 committed
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
    // showTipsPopup () {
    //   this.tipsPopupVisible = true
    //   noscroll()
    // },
    // hideTipsPopup () {
    //   this.tipsPopupVisible = false
    //   renewscroll()
    // },
    getContentListByMakeIdFn () {
      let params = {
        curPage: 1,
        pageSize: 10
      }
      this.contentMessageSpinner = true
      getContentListByMakeId(this.makeId, params).then(res => {
        this.contentMessageSpinner = false
        if (res.code === 0) {
          this.contentData = res.data.records
328
          if (this.contentData.length <= 0) {
潘琦 committed
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
            this.contentMessageVisible = true
          } else {
            this.contentMessageVisible = false
          }
        }
      }).catch((error) => {
        this.$toast({
          message: error.message,
          position: 'center',
          duration: 3000
        })
      })
    },
    imgBase64 (url) {
      return new Promise((resolve, reject) => {
        imageBase64(url).then(res => {
          if (res.code === 0) {
            resolve(res.data)
          }
        }).catch((error) => {
          reject(error)
          console.log(error)
        })
      })
    },
    goToContent (imprId) { // 跳转至知识详情页
      this.$router.push({
        path: '/content',
        query: {
          imprId: imprId
        }
      })
    }
  }
}
</script>

<style scoped>
  .full-page {
    background-color: #43d1be;
  }
  .detail-card {
    margin-bottom: 1em;
  }
  .detail-card .body{
    font-size: 1em;
  }
  .detail-card .body .table .tr > .td {
    vertical-align: top;
  }
  .detail-card .body .table .tr > .td.label{
380
    width: 5em;
潘琦 committed
381 382
    font-size: 1em;
    font-weight:bold;
383
    text-align: right;
潘琦 committed
384
  }
385 386 387 388 389 390 391 392 393 394
  .detail-card .body .qrcode-block {
    margin: 2em 0;
  }
  .detail-card .body .qrcode-block h4{
    font-size: 1.2em;
  }
  .detail-card .body .qrcode-inner {
    margin-bottom: 1em;
    text-align: center;
  }
395
  .detail-card .body .qrcode-inner .qrcode-frame{
396 397 398 399 400 401 402
    display: inline-block;
    width: 220px;
    height: 220px;
    padding: 10px;
    background-color: #fff;
    box-shadow: 0 0 16px rgb(221, 221, 221, 1);
  }
403 404 405 406 407 408 409 410
  .detail-card .body .qrcode-inner #qrcode {
    display: inline-block;
    width: 200px;
    height: 200px;
  }
  /* .detail-card .body .qrcode-inner #qrcode > img:nth-child(2) {
    display: none;
  } */
411 412 413 414 415 416
</style>

<style>
  .detail-card .mint-spinner-fading-circle{
    width: 5em !important;
    height: 5em !important;
417
    margin: 4em auto 0 auto;
418
  }
潘琦 committed
419
</style>