<template>
  <BasePage :title="title">
    <div class="verif">
      <div class="search_box">
        <img src="/img/search.png" alt="">
        <input type="text" placeholder="输入用户账号/礼品券码搜索" v-model="keyword1" v-if="type === 'verif'">
        <input type="text" placeholder="输入用户账号/会员卡号搜索" v-model="keyword1" v-else>
      </div>

      <BaseList ref="listRef"
        :url="type === 'verif' ? '/v1/client/DUserlipinquansClient/writeoff' : '/v1/client/DUserxiaofeiquansClient/transferdata'"
        class="list" :params="{ keyword1 }">
        <template #default="{ item }">
          <div class="item">
            <div class="t">
              <img class="icon" :src="$file(item.userimg)" alt="">
              <div>
                <span>{{ item.nickname || item.username || '未知用户' }}</span>
                <p>账号：{{ item.cellphone || item.username }}</p>
              </div>
              <span class="r tt" v-if="type === 'verif'">
                已核销
              </span>
              <span class="r pre" v-else>
                赠送金额 ：<b style="color: f00;">500.00</b>
              </span>
            </div>
            <div class="info_box">
              <div>
                <span class="left">订单编号：</span>
                <span class="r rg">{{ item.ordernum }} <img @click="$copyText(item.ordernum); $showSuccessToast('复制成功')"
                    src="/img/copy_b.png" alt=""></span>
              </div>

              <div v-if="type === 'verif'">
                <span class="left">礼品券码：</span>
                <span class="r rg">{{ item.sysid }}<img @click="$copyText(item.sysid); $showSuccessToast('复制成功')"
                    src="/img/copy_b.png" alt=""></span>
              </div>

              <div v-else>
                <span class="left">会员卡号：</span>
                <span class="r rg">{{ item.huiyuankaid }}<img
                    @click="$copyText(item.huiyuankaid); $showSuccessToast('复制成功')" src="/img/copy_b.png" alt=""></span>
              </div>

              <div v-if="type === 'verif'">
                <span class="left">核销时间：</span>
                <span class="r rg">{{ formatTime(item.writeofftime) }}</span>
              </div>

              <div v-else>
                <span class="left">赠送时间：</span>
                <span class="r rg">{{ formatTime(item.addtime) }}</span>
              </div>
            </div>
          </div>
        </template>
      </BaseList>
    </div>
  </BasePage>
</template>

<script>
export default {
  data() {
    return {
      keyword1: '',
      type: this.$route.query.type,
    }
  },
  methods: {
    formatTime(time) {
      if (!time) return '-'
      const date = new Date(time)
      return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}:${String(date.getSeconds()).padStart(2, '0')}`
    },
  },
  computed: {
    title() {
      if (this.$route.query.type === 'verif') {
        return '核销记录'
      } else {
        return '赠卡记录'
      }
    }
  }
}
</script>