<!--
  Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.

  https://www.mall4j.com/

  未经允许，不可做商业用途！

  版权所有，侵权必究！
-->

<template>
  <view class="Mall4j container page-write-offs-records-all">
    <view class="write-offs-records-all">
      <!-- 全部 -->
      <view
        v-if="virtualVerifyLogList && virtualVerifyLogList.length"
        class="write-offs-box"
      >
        <view class="top">
          <view class="certificate-code">
            <view class="write-label">
              券码：
            </view>
            <view class="write-text">
              {{ writeOffCode }}
            </view>
          </view>
        </view>
        <view>
          <view
            v-for="item in virtualVerifyLogList"
            :key="item.id"
            class="pickup"
          >
            <view class="pickup-name">
              <view class="circle" />
              <text class="txt">
                {{ item.stationName }}
              </text>
            </view>
            <view class="write-offs-date">
              {{ dateTimeFormat(item.createTime) }}
            </view>
          </view>
        </view>
      </view>
      <!-- 暂无核销记录 -->
      <view
        v-if="!(virtualVerifyLogList && virtualVerifyLogList.length) && isLoaded"
        class="no-record"
      >
        <view class="no-record-img">
          <img
            src="@/static/empty-img/order-empty.png"
            alt=""
          >
          <view class="no-record-tip">
            {{ $t('noRecordWriteOff') }}~
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import moment from 'moment'

const isLoaded = ref(false)
const writeOffCode = ref('')
const virtualVerifyLogList = ref([])

const dateTimeFormat = computed(() => {
  return (val) => {
    return moment(val).format('YYYY-MM-DD HH:mm:SS')
  }
})

/**
 * 生命周期函数--监听页面加载
 */
onLoad((options) => {
  writeOffCode.value = options.writeOffCode
  getVirtualVerifyLogInfo()
  uni.setNavigationBarTitle({
    title: $t('writeOffRecord')
  })
})

const getVirtualVerifyLogInfo = () => {
  isLoaded.value = false
  const params = {
    url: '/mall4cloud_order/my_order/get_by_write_off_code',
    method: 'GET',
    data: {
      writeOffCode: writeOffCode.value
    }
  }
  http.request(params).then((res) => {
    virtualVerifyLogList.value = res
    isLoaded.value = true
  })
}

</script>
<style lang="scss" scoped>
@use "write-offs-records-all";
</style>
