<template>
  <el-dialog
    title="基础信息"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    @close="handleClose"
    width="1200px"
  >
  <el-row>
    <el-col :span="5">
      <span class="label"><span>IC卡卡号：</span>654155444</span>
    </el-col>
    <el-col :span="5">
      <span class="label"><span>农户姓名：</span>张三</span></el-col>
    <el-col :span="5">
      <span class="label"><span>卡状态：</span>正常</span></el-col>
    <el-col :span="4">
      <span class="label"><span>办卡时间：</span>2022-02-15</span></el-col>
    <el-col :span="5">
      <span class="label"><span>所属区域：</span>2022-02-15 </span></el-col>
  </el-row>
  <el-row style="margin: 20px 0">
    <el-col :span="5">
      <span class="label"><span>总用水量：</span>65444 m³</span>
    </el-col>
    <el-col :span="5">
      <span class="label"><span>总用电量：</span>65444 m³</span></el-col>
  </el-row>
  <div style="text-align:right;position:relative">
    <el-date-picker
      v-model="value1"
      type="daterange"
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期">
    </el-date-picker>
    <el-button type="primary" style="margin-left:10px;">查询</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="loadData"
        :columns="columns"
        isShowIndex
        :showPagination="loadData.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="tableRef"
          :args="{ 'highlight-current-row': true }"
          :data="loadData"
          :columns="columns"
          isShowIndex
          :showPagination="loadData.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-tabs>
  </el-dialog>
</template>

<script>
import BTable from '@/components/Table/index.vue';
import { assign } from 'lodash-es';
import { UPLOAD_TYPE_MAP } from '@/utils/constants';
export default {
  name: 'dataDetail',
  props: {
    data: {
      default() {
        return {};
      }
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  components:{
    BTable
  },
  data() {
    return {
      imageUploadType: UPLOAD_TYPE_MAP.FARMING_RECORD,
      dialogSubmitLoading: false,
      dialogVisible: false,
      baseForm: {
        productValue: '',
        productName: '',
        stockAmount: '',
        goodsUnit: '',
        goodsSpecValue: '',
        imageArr1: [],
        supplierId: '',
        imageArr2: []
      },
      loadData:[],
      productList: [],
      syinfoList: [],
      processList: [],
      hasFetched: false,
      landList: [], //基地列表
      columns: [
        {
          label: 'IC卡号',
          prop: 'person',
          customRender: '',
          align: 'center'
        },
        {
          label: '充值金额（元）',
          prop: 'area',
          customRender: '',
          align: 'center'
        },
        {
          label: '充值后金额（元）',
          prop: 'name',
          customRender: '',
          align: 'center'
        },
        {
          label: '充值时间',
          prop: 'phone',
          customRender: 'status',
          align: 'center'
        }
      ]
    };
  },
  computed: {
    goodsUnitLable: function () {
    }
  },
  watch: {
    visible(val) {
      if (val !== this.dialogVisible) {
        this.dialogVisible = val;
        if (val) {
          assign(this.baseForm, this.data);
          if (!this.hasFetched) {
            this.getProductList();
            this.getSyinfoList();
            this.getProcessList();
            this.hasFetched = true;
          }
        }
      }
    },
    data: {
      deep: true,
      handler(val) {
        // console.log(val)
        assign(this.baseForm, val);
        // console.log(this.baseForm)
      }
    }
  },
  created() {},
  mounted() {},
  methods: {
    getProductList() {
    },
    getSyinfoList() {
    },
    getProcessList() {
    },
    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 = {};
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        console.log(valid)
      })
    },

    handleClose() {
      this.$emit('update:visible', false);
      this.resetForm('baseForm');
    },
    handleSuccess() {
      this.resetForm('baseForm');
      this.$emit('update:visible', false);
      this.$emit('success');
    },
    handleKeyUp(target, key) {
      target[key] = target[key].match(/\d+(\.\d{0,2})?/)
        ? target[key].match(/\d+(\.\d{0,2})?/)[0]
        : '';
    }
  }
};
</script>

<style lang="scss" scoped>
::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>
