<template>
  <view class="container page-business-code">
    <view class="delivery-certificate">
      <view class="address-box item">
        <view class="btn">
          商家码
        </view>
      </view>
      <view class="code-det item">
        <view class="bar-code">
          <w-barcode :options="barOpations" />
        </view>
        <view class="code">
          <image :src="stationQrCode" />
        </view>
      </view>
      <view class="btn-box">
        扫码一键核销
      </view>
    </view>
  </view>
</template>

<script setup>
import Qr from '@/utils/wxqrcode.js'
import http from '@/utils/http.js'
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
const stationId = ref('') // 自提点id
const stationQrCode = ref('')
const barOpations = ref({
  height: 150,
  width: 350,
  code: 'null', // 码值
  orient: 'horizontal'
})
/**
 * 生命周期函数--监听页面加载
 */
onLoad(() => {
  onGetBusCodeInf()
})
/* 请求自提点码信息 */
const onGetBusCodeInf = () => {
  uni.showLoading()
  http.request({
    url: '/mall4cloud_order/station/get_code',
    method: 'GET',
    data: {}
  }).then(({ data }) => {
    stationId.value = data.split('#station#')[1]
    barOpations.value.code = stationId.value + '' // 条形码码值
    // 请求到自提点码信息，执行生成二维码函数
    setTimeout(() => {
      onGetQrcode()
    }, 50)
    uni.hideLoading()
  })
}
/* 生成二维码 */
const onGetQrcode = () => {
  stationQrCode.value = Qr.createQrCodeImg(stationId.value)
}
</script>

<style lang="scss" scoped>
@use "./business-code.scss";
</style>
