<template>
  <el-dialog
    title="农户管理"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    @close="handleClose"
    width="700px"
  >
    <el-form
      ref="baseForm"
      class="base-form"
      label-position="right"
      label-width="95px"
      :model="baseForm"
      :rules="rules"
      size="small"
    >
      <el-row>
        <el-col :span="24" style="background:#F5F7FA;padding-top:20px;margin-bottom:20px;">
          <el-form-item label="所属区域" prop="productName">
            <el-row>
              <el-col :span="24" style="padding-right:5%">
                <el-select placeholder="请选择区域" style="width:100%">
                </el-select>
              </el-col>
            </el-row>
          </el-form-item>
          <el-col>
            <el-row class="area">
              <el-col :span="5">
                <label>总面积：</label>65446亩
              </el-col>
              <el-col :span="5">
                <label>总水权：</label>65446m³
              </el-col>
              <el-col :span="7" style="width:27%">
                <label>亩产水权：</label>65446亩/m³
              </el-col>
              <el-col :span="6">
                <label>剩余水权：</label>65446m³
              </el-col>
            </el-row>
          </el-col>
        </el-col>
        <el-col :span="24">
          <el-row>
            <el-col :span="12">
            <el-form-item label="农户编号" prop="sourceinfoId">
              <el-row>
                <el-col>
                  <el-input
                    v-model="baseForm.sourceinfoId"
                    filterable
                    style="width: 100%"
                    placeholder="8位数字（不能重复）自动生成"
                  >
                  </el-input>
                </el-col>
              </el-row>
            </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="农户姓名" prop="sourceinfoId">
                <el-row>
                  <el-col>
                    <el-input
                      v-model="baseForm.sourceinfoId"
                      filterable
                      style="width: 100%"
                      placeholder="8位数字（不能重复）自动生成"
                    >
                    </el-input>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="24">
          <el-row>
            <el-col :span="12">
            <el-form-item label="身份证号" prop="sourceinfoId">
              <el-row>
                <el-col>
                  <el-input
                    v-model="baseForm.sourceinfoId"
                    filterable
                    style="width: 100%"
                    placeholder="8位数字（不能重复）自动生成"
                  >
                  </el-input>
                </el-col>
              </el-row>
            </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="联系电话" prop="sourceinfoId">
                <el-row>
                  <el-col>
                    <el-input
                      v-model="baseForm.sourceinfoId"
                      filterable
                      style="width: 100%"
                      placeholder="8位数字（不能重复）自动生成"
                    >
                    </el-input>
                  </el-col>
                </el-row>
              </el-form-item>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="24">
          <el-row>
            <el-col :span="12">
            <el-form-item label="土地面积" prop="sourceinfoId">
              <el-row>
                <el-col style="position:relative">
                  <el-input
                    v-model="baseForm.sourceinfoId"
                    filterable
                    style="width: 90%"
                    placeholder="8位数字（不能重复）自动生成"
                  >
                  </el-input>
                  <span style="position:absolute;margin-left:10px">亩</span>
                </el-col>
              </el-row>
            </el-form-item>
          </el-col>
            <el-col :span="12">
            <el-form-item label="水权" prop="sourceinfoId">
              <el-row>
                <el-col>
                  <el-input
                    v-model="baseForm.sourceinfoId"
                    filterable
                    style="width: 100%"
                    placeholder="请输入水权"
                  >
                  </el-input>
                </el-col>
              </el-row>
            </el-form-item>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
    </el-form>

    <div style="text-align: right">
      <el-button type="info" plain @click="resetForm('baseForm')"
        >取消</el-button
      >
      <el-button
        type="primary"
        style="margin-left:16px;"
        @click="submitForm('baseForm')"
        :disabled="dialogSubmitLoading"
        :loading="dialogSubmitLoading"
        >确定</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
import { assign } from 'lodash-es';
import { UPLOAD_TYPE_MAP } from '@/utils/constants';
export default {
  name: 'addedFarmers',
  props: {
    data: {
      default() {
        return {};
      }
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      imageUploadType: UPLOAD_TYPE_MAP.FARMING_RECORD,
      dialogSubmitLoading: false,
      dialogVisible: false,
      textarea: '',
      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' }
        ]
      }
    };
  },
  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>
.input-number {
  width: 100%;
}
.area{
  margin:0 0 20px 20px;
  label{
    color:#999;
    font-weight: 400;
    font-size: 14px;
  }
}
.base-form {
  max-height: 70vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 20px;
}
.history{
  text-align: right;
  line-height: 32px;
  span{
    color:rgb(20, 164, 120);
    cursor: pointer;
  }
}
</style>
<style lang="css" scoped>
::v-deep .el-dialog__header {
  border-bottom: 1px solid #ebeef5;
}
</style>
