<template>
  <view class="container">
    <view class="content" v-if="!showNoData">
      <view :class="['displayFlexCol', isSuccess ? 'backgroundCustom' : 'back_fail']">
        <view class="back">
          <view class="state">
            <!-- 状态,0初始1退费中2全成功3部分失败4全部失败 -->
            <text>{{queryBean.State=='2'||queryBean.State=='3'?'退款到账':'退款失败'}}</text>
            <text class="ml20">{{queryBean.State=='2'?'全额到账':queryBean.State=='3'?'部分到账':''}}</text> </view>
          <view class="state">
            <text>到账金额</text>
            <text class="ml20"> ￥{{queryBean.RefundAmount/100}} 共{{queryBean.RefundCount}}笔</text> </view>
        </view>
      </view>
      <view class="record_box" v-for="(item, ind) in list" :key="ind">
        <view class="header_time border_bottom">
          <text>交易单号：{{item.OrderNum}}</text>
        </view>
        <view class="main_centent">
          <view class="record_info">
            <text>退款方式</text>
            <text >{{item.ChannelType}}</text>
          </view>
          <view class="record_info" v-if="item.RefundRemark">
            <text>退款原因</text>
            <text>{{item.RefundRemark}}</text>
          </view>
          <view class="record_info" v-if="item.BeginDate">
            <text>发起时间</text>
            <text>{{item.BeginDate}}</text>
          </view>
          <view class="record_info" v-if="item.EndDate">
            <text>到账时间</text>
            <text>{{item.EndDate}}</text>
          </view>
        </view>
        <view class="public_info_foot border_top displayFlexBetween">
          <view :class="['info_foot_name', item.PayState=='7'?'colorRed':'colorCustom']">￥{{item.RefundPrice/100}}</view>
          <view :class="['info_foot_item', item.PayState=='7'?'colorRed':'colorCustom']">{{item.FailReason||'退款成功'}}</view>
        </view>
      </view>
    </view>
    <view v-else class="noData">
      <noData :value="noDataValue"></noData>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import common from '@/utils/common';
import noData from '@/pages/st1/components/noData/noData.vue';
import { querySelfRefundRecordInfo } from '@/pagesPatient/service/outpatient/index';

const queryBean = ref<any>({});
const isSuccess = ref(true);
const list = ref<any[]>([]);
const showNoData = ref(false); // Added showNoData ref, though original JS didn't explicitly set it, but template uses !showNoData. I should set it based on list length or response.
const noDataValue = ref('暂无数据');

onLoad((options) => {
  let bean = options.queryBean ? JSON.parse(options.queryBean) : {};
  queryBean.value = bean;
  isSuccess.value = bean.State != 4;
  main();
});

const main = async () => {
  let bean = queryBean.value;
  let queryData = {
    SelfRefundRecordId: bean.Id,
  };
  let resp = await querySelfRefundRecordInfo(queryData);
  list.value = resp || [];
  showNoData.value = common.isEmpty(list.value);
};
</script>

<style lang="scss" scoped>
.back {
  padding: 40upx 0 120upx;
  font-size: 36upx;
  font-family: Source Han Sans CN;
  font-weight: 500;
}
.back_fail {
  background-color: #ee5753;
  color: #fff;
}
.img {
  width: 154upx;
  height: 150upx;
  margin-right: 22upx;
}

.back .state {
  font-size: 32upx;
  font-weight: 500;
  color: rgba(255, 255, 255, 1);
  margin-bottom: 26upx;
  font-family: Source Han Sans CN;
}

.public_info_foot {
  height: 112upx;
  padding: 0 34upx;
  font-size: 30upx;
  justify-content: space-between;
}

.info_foot_name {
  font-weight: 400;
}

.info_foot_item {
  font-weight: 400;
}

.ml20 {
  margin-left: 20upx;
}


.record_box {
  background: white;
  margin: 30upx;
  border-radius: 24upx;
  margin-top: -94upx;
}
.header_time {
  height: 106upx;
  padding: 30upx;
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}
.header_time text{
  font-size: 32upx;
}
.header_time text:nth-child(1){
  color: #333;
  font-weight: bold;
}
.main_centent {
  padding: 30upx;
  box-sizing: border-box;
}
.record_info {
  margin-bottom: 30upx;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}
.record_info:last-child{
  margin-bottom: 0 !important;
}
.record_info text:nth-child(1){
  width: 26%;
  display: inline-block;
  font-size: 30upx;
  color: #666;
}
.record_info text:nth-child(2){
  width: 74%;
  display: inline-block;
  font-size: 30upx;
  color: #666;
}
</style>
