<template>
  <el-dialog
    title="灌溉记录"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    @close="handleClose"
    width="1200px"
  >
  <div style="margin-bottom: 20px">
    <span>农户姓名：</span>
    <el-input
      v-model="form.tarcecodeapplyno"
      style="width: 250px;margin:0 15px;"
      placeholder="请i输入农户编号/姓名/电话"
      @keyup.enter.native="handleSearch"
      clearable
    />
    <span>时间：</span>
    <el-input
      v-model="form.tarcecodeapplyno"
      style="width: 250px;margin:0 15px;"
      placeholder="请i输入农户编号/姓名/电话"
      @keyup.enter.native="handleSearch"
      clearable
    />
    <el-button
      type="primary"
      size="small"
      @click="handleSearch"
      >查询</el-button
    >
  </div>
  <b-table
    ref="tableRef"
    :args="{ 'highlight-current-row': true }"
    :data="loadData"
    :columns="columns"
  >
    <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 #number="scope">
      <div>1</div>
      <div>2</div>
      {{ scope.row.finishGoodName&&scope.row.finishgoodNo?scope.row.finishGoodName + '-' + scope.row.finishgoodNo:'' }}
    </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">
        <span class="status"></span>
        {{ 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-dialog>
</template>

<script>
import { assign, omit } from 'lodash-es';
import { UPLOAD_TYPE_MAP } from '@/utils/constants';
import LeftImg from '../assets/img.svg'
import BTable from '@/components/Table'
export default {
  name: 'IrrigationRecord',
  props: {
    data: {
      default() {
        return {};
      }
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      LeftImg: LeftImg,
      imageUploadType: UPLOAD_TYPE_MAP.FARMING_RECORD,
      columns: [
        {
          label: '行政区',
          prop: 'person',
          customRender: '',
          align: 'center'
        },
        {
          label: '农户',
          prop: 'area',
          customRender: '',
          align: 'center'
        },
        {
          label: '手机号',
          prop: 'name',
          customRender: '',
          align: 'center'
        },
        {
          label: '计量模式',
          prop: 'phone',
          customRender: 'number',
          align: 'center'
        },{
          label: '总金额',
          prop: 'phone',
          customRender: '',
          align: 'center'
        },{
          label: '用水量',
          prop: 'phone',
          customRender: '',
          align: 'center'
        },{
          label: '用水金额',
          prop: 'phone',
          customRender: '',
          align: 'center'
        },{
          label: '用电量',
          prop: 'phone',
          customRender: '',
          align: 'center'
        },{
          label: '用电金额',
          prop: 'phone',
          customRender: '',
          align: 'center'
        },{
          label: '开泵时间',
          prop: 'phone',
          customRender: '',
          align: 'center'
        },{
          label: '关泵时间',
          prop: 'phone',
          customRender: '',
          align: 'center'
        },{
          label: '灌溉时长',
          prop: 'phone',
          customRender: '',
          align: 'center'
        }
      ],
      form: {
        productName: ''
      },
      dialogSubmitLoading: false,
      dialogVisible: false,
      baseForm: {
        productValue: '',
        productName: '',
        stockAmount: '',
        goodsUnit: '',
        goodsSpecValue: '',
        imageArr1: [],
        supplierId: '',
        imageArr2: []
      },
      productList: [],
      syinfoList: [],
      processList: [],
      hasFetched: false,
      landList: [], //基地列表
      rules: {
        stockAmount: [
          { required: true, message: '请选择负责人', trigger: 'blur' }
        ],
        sourceinfoId: [
          { required: true, message: '请选择管辖范围', trigger: 'blur' }
        ],
        productName: [
          { required: true, message: '请输入协会名称', trigger: 'blur' }
        ],
        supplierId: [
          { required: false, message: '请输入协会介绍', trigger: 'blur' }
        ],
        goodsSpecValue: [
          { required: true, message: '请选择规格', trigger: 'blur' }
        ]
      }
    };
  },
  components:{
    BTable
  },
  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: {
    loadData(parameter) {
      const queryform = this.form;
      const payload = omit(assign({}, parameter, queryform, {orderByColumn:'tarcecodeapplyCreateddate',isAsc:'desc'}), []);
      return this.getTableData(payload);
    },
    getTableData(payload) {
      return Promise.resolve({
        data: [{
            person:"王大虎",
            area: '2016-05-02',
            name: '王小虎',
            phone: 1588888888,
            address: '上海市普陀区金沙<br>江路 1518 弄'
          }, {
            person:"王大虎",
            area: '2016-05-04',
            name: '王小虎',
            phone: 1588888888,
            address: '上海市普陀区金沙江路 1517 弄'
          }, {
            person:"王大虎",
            area: '2016-05-01',
            name: '王小虎',
            phone: 1588888888,
            address: '上海市普陀区金沙江路 1519 弄'
          }, {
            person:"王大虎",
            area: '2016-05-03',
            name: '王小虎',
            phone: 1588888888,
            address: '上海市普陀区金沙江路 1516 弄'
          }]
      })
    },
    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.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>
.input-number {
  width: 100%;
}
h3{
  height: 14px;
  color: #333333;
  font-size: 14px;
  font-weight: 700;
  margin:0 0 20px 0;
}
.right_content{
  margin-bottom: 10px;
  label{
    color: #999;
    font-size: 14px;
    font-weight: 400;
  }
  span{
    color: #333333;
    font-size: 14px;
  }
}
.base-form {
  max-height: 70vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 20px;
}
</style>
<style lang="css" scoped>
::v-deep .el-dialog__header {
  border-bottom: 1px solid #ebeef5;
}
</style>
