<template>
  <el-row class="el-row-container">
    <el-card style="margin:16px;min-height: calc(100% - 32px); overflow-y: auto">
      <el-row style="margin-bottom: 10px">
        <el-col :span="12" class="header-label">
          基础信息
        </el-col>
        <el-col :span="12" style="text-align:right">
          <el-button type="primary" @click="backPage">返回</el-button>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="5">
          <span class="label"><span>IC卡卡号：</span>{{baseForm.cardNo}}</span>
        </el-col>
        <el-col :span="5">
          <span class="label"><span>农户姓名：</span>{{baseForm.farmerName}}</span></el-col>
        <el-col :span="5">
          <span class="label"><span>卡状态：</span>{{baseForm.cardStatusContent}}</span></el-col>
        <el-col :span="4">
          <span class="label"><span>办卡时间：</span>{{baseForm.cardCreateddate}}</span></el-col>
        <el-col :span="5">
          <span class="label"><span>所属区域：</span>{{baseForm.areaFullName}}</span></el-col>
      </el-row>
      <el-row style="margin: 20px 0">
        <el-col :span="5">
          <span class="label"><span>总用水量：</span>{{baseForm.waterNumTotal || 0}} m³</span>
        </el-col>
        <el-col :span="5">
          <span class="label"><span>总用电量：</span>{{baseForm.electricNumTotal || 0}} m³</span></el-col>
      </el-row>
      <div style="text-align:right;position:relative;z-index:1000">
        <el-date-picker
          v-model="time"
          clearable
          value-format="yyyy-MM-dd HH:MM:SS"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
        <el-button type="primary" style="margin-left:10px;" @click="handleSearch">查询</el-button>
      </div>
      <el-tabs @tab-click="handleClick" style="margin-top:-30px;">
        <el-tab-pane label="灌溉记录">
          <b-table
            ref="tableRef"
            :args="{ 'highlight-current-row': true }"
            :data="rechargercdList"
            :columns="columns"
            isShowIndex
            :showPagination="!rechargercdList.length"
          >
            <template #styleImg="scope">
              <el-image
                :src="scope.row.imgPreview"
                :preview-src-list="[scope.row.imgPreview]"
                slot="error"
                class="image-slot"
                style="width: 100px; height: 50px"
              >
                <div slot="error" class="image-slot"></div>
              </el-image>
            </template>
            <template #codeNo="scope">
              <el-link
                type="primary"
                :underline="false"
                @click="goDetail(scope.row)"
                >{{ scope.row.traceCodeApplyConcat }}</el-link
              >
            </template>
            <template #status="scope">
              <span style="display:flex;align-items:center;justify-content:center">
                {{ scope.row.name }}
              </span>
            </template>
            <template #useNumber="scope">
              {{ scope.row.useNumber + '/' + scope.row.totalNumber }}
            </template>
            <template #finishGoodName="scope">
              {{ scope.row.finishGoodName&&scope.row.finishgoodNo?scope.row.finishGoodName + '-' + scope.row.finishgoodNo:'' }}
            </template>
          </b-table>
        </el-tab-pane>
        <el-tab-pane label="充值记录">
          <b-table
            ref="tableRechargercd"
            :args="{ 'highlight-current-row': true }"
            :data="rechargercdList"
            :columns="columns"
            isShowIndex
          >
            <template #styleImg="scope">
              <el-image
                :src="scope.row.imgPreview"
                :preview-src-list="[scope.row.imgPreview]"
                slot="error"
                class="image-slot"
                style="width: 100px; height: 50px"
              >
                <div slot="error" class="image-slot"></div>
              </el-image>
            </template>
            <template #ICCard="scope">
              {{ scope }}
              <b-table
                ref="tableRef"
                :args="{ 'highlight-current-row': true }"
                :data="loadData"
                :columns="scope.columns"
                isShowIndex
              >
              </b-table>
            </template>
            <template #codeNo="scope">
              <el-link
                type="primary"
                :underline="false"
                @click="goDetail(scope.row)"
                >{{ scope.row.traceCodeApplyConcat }}</el-link
              >
            </template>
            <template #rechargercdRechargeamount="scope">
              <el-link
                type="primary"
                :underline="false"
                >+{{ Number(scope.row.rechargercdRechargeamount).toFixed(2) }}</el-link
              >
            </template>
            <template #cardAmount="scope">
              {{ Number(scope.row.cardAmount).toFixed(2) }}
            </template>
            <template #status="scope">
              <span style="display:flex;align-items:center;justify-content:center">
                {{ scope.row.name }}
              </span>
            </template>
            <template #useNumber="scope">
              {{ scope.row.useNumber + '/' + scope.row.totalNumber }}
            </template>
            <template #finishGoodName="scope">
              {{ scope.row.finishGoodName&&scope.row.finishgoodNo?scope.row.finishGoodName + '-' + scope.row.finishgoodNo:'' }}
            </template>
          </b-table>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </el-row>
</template>

<script>
import { getCardDetail,getRechargercdList } from '@/api/card/index.js'
import BTable from '@/components/Table/index.vue';
export default {
  name: 'dataDetail',
  props: {
    detailCardId:{ 
      type:String,
    }
  },
  components:{
    BTable
  },
  data() {
    return {
      baseForm: {},
      time:'',
      columns: [
        {
          label: 'IC卡号',
          prop: 'cardNo',
          customRender: '',
          align: 'center',
        },
        {
          label: '充值金额（元）',
          prop: 'rechargercdRechargeamount',
          customRender: 'rechargercdRechargeamount',
          align: 'center'
        },
        {
          label: '充值后金额（元）',
          prop: 'cardAmount',
          customRender: 'cardAmount',
          align: 'center'
        },
        {
          label: '充值时间',
          prop: 'rechargercdRechargetime',
          customRender: '',
          align: 'center'
        }
      ]
    };
  },
  methods: {
    handleClick(){},
    async rechargercdList() {
      const res = await getCardDetail({
        cardId:this.detailCardId
      })
      this.baseForm = res.data
      return this.getRechargercdData(res.data);
    },
    getRechargercdData(payload) {
      const {farmerId,cardNo,cardId} = payload
      const startTime = this.time[0] || ''
      const endTime = this.time[1] || ''
      return getRechargercdList({
        farmerId,
        cardNo,
        cardId,
        startTime,
        endTime
      })
    },
    backPage() {
      this.$emit("backPage")
    },
    goProductsPage() {
      this.handleClose();
      this.$router.push({
        path: '/Products',
        query: {}
      });
    },
    goSourceInfoPage() {
      this.handleClose();
      this.$router.push({
        path: '/sourceInfo',
        query: {
          type: 'add'
        }
      });
    },
    goProcessPage() {
      this.handleClose();
      this.$router.push({
        path: '/basicsettings/process',
        query: {}
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.resetFormData();
      this.dialogVisible = false;
    },
    resetFormData() {
      this.baseForm = {};
    },
    
    handleSearch() {
      this.$refs.tableRechargercd.refresh(true);
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        console.log(valid)
      })
    },

    handleClose() {
      this.$emit('update:visible', false);
      this.resetForm('baseForm');
    },
  }
};
</script>

<style lang="scss" scoped>
.el-row-container{
  height: calc(100% - 32px);
  .header-label{
    color: #333333;
    font-size: 16px;
    font-weight: 700;
    font-family: "Source Han Sans CN VF";
    text-align: left;
  }
}
::v-deep.el-dialog__title{
  color: #333333;
  font-size: 16px;
  font-weight: 700;
}
.input-number {
  width: 100%;
}
.base-form {
  max-height: 70vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 20px;
}
.label{
  color: #333;
  span{
    color: #999;
    font-size: 14px;
    font-style: normal;
  }
}
</style>
<style lang="css" scoped>
::v-deep .el-dialog__header {
  border-bottom: 1px solid #ebeef5;
}
</style>
