<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="镇耕地面积(万亩)" prop="cultivatedArea">
        <el-input
          v-model="queryParams.cultivatedArea"
          placeholder="请输入镇耕地面积(万亩)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="粮食总产(万吨)" prop="foodstuffProduction">
        <el-input
          v-model="queryParams.foodstuffProduction"
          placeholder="请输入粮食总产(万吨)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="蔬菜种植面积(亩)" prop="vegetablePlantingArea">
        <el-input
          v-model="queryParams.vegetablePlantingArea"
          placeholder="请输入蔬菜种植面积(亩)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="蔬菜总产(吨)" prop="vegetableProduction">
        <el-input
          v-model="queryParams.vegetableProduction"
          placeholder="请输入蔬菜总产(吨)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="农产品种类" prop="type">
        <el-input
          v-model="queryParams.type"
          placeholder="请输入农产品种类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="农产品种植面积(亩)" prop="agriculturalPlantingArea">
        <el-input
          v-model="queryParams.agriculturalPlantingArea"
          placeholder="请输入农产品种植面积(亩)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="特色农业总产量(吨)" prop="agricultureProduction">
        <el-input
          v-model="queryParams.agricultureProduction"
          placeholder="请输入特色农业总产量(吨)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="特色农业年产值(万元)" prop="agricultureOutputVaule">
        <el-input
          v-model="queryParams.agricultureOutputVaule"
          placeholder="请输入特色农业年产值(万元)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总人口(人)" prop="totalPopulation">
        <el-input
          v-model="queryParams.totalPopulation"
          placeholder="请输入总人口(人)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="占地面积(平方公里)" prop="coverArea">
        <el-input
          v-model="queryParams.coverArea"
          placeholder="请输入占地面积(平方公里)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="示范大棚数量(个)" prop="exampleGreenhouse">
        <el-input
          v-model="queryParams.exampleGreenhouse"
          placeholder="请输入示范大棚数量(个)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="村居数量(个)" prop="rusticate">
        <el-input
          v-model="queryParams.rusticate"
          placeholder="请输入村居数量(个)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联合社耕地面积(万亩)" prop="cultivatedAlly">
        <el-input
          v-model="queryParams.cultivatedAlly"
          placeholder="请输入联合社耕地面积(万亩)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="大棚数量(个)" prop="greenhouse">
        <el-input
          v-model="queryParams.greenhouse"
          placeholder="请输入大棚数量(个)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="农产品产值(万元)" prop="outputValue">
        <el-input
          v-model="queryParams.outputValue"
          placeholder="请输入农产品产值(万元)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="庞家镇矢量边界" prop="vectorBoundary">
        <el-input
          v-model="queryParams.vectorBoundary"
          placeholder="请输入庞家镇矢量边界"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="庞家镇村庄矢量边界" prop="villageVectorBoundary">
        <el-input
          v-model="queryParams.villageVectorBoundary"
          placeholder="请输入庞家镇村庄矢量边界"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人" prop="createdBy">
        <el-input
          v-model="queryParams.createdBy"
          placeholder="请输入创建人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createdTime">
        <el-date-picker clearable
          v-model="queryParams.createdTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['crops:data:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['crops:data:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['crops:data:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['crops:data:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="镇耕地面积(万亩)" align="center" prop="cultivatedArea" />
      <el-table-column label="粮食总产(万吨)" align="center" prop="foodstuffProduction" />
      <el-table-column label="蔬菜种植面积(亩)" align="center" prop="vegetablePlantingArea" />
      <el-table-column label="蔬菜总产(吨)" align="center" prop="vegetableProduction" />
      <el-table-column label="农产品种类" align="center" prop="type" />
      <el-table-column label="农产品种植面积(亩)" align="center" prop="agriculturalPlantingArea" />
      <el-table-column label="特色农业总产量(吨)" align="center" prop="agricultureProduction" />
      <el-table-column label="特色农业年产值(万元)" align="center" prop="agricultureOutputVaule" />
      <el-table-column label="总人口(人)" align="center" prop="totalPopulation" />
      <el-table-column label="占地面积(平方公里)" align="center" prop="coverArea" />
      <el-table-column label="示范大棚数量(个)" align="center" prop="exampleGreenhouse" />
      <el-table-column label="村居数量(个)" align="center" prop="rusticate" />
      <el-table-column label="联合社耕地面积(万亩)" align="center" prop="cultivatedAlly" />
      <el-table-column label="大棚数量(个)" align="center" prop="greenhouse" />
      <el-table-column label="农产品产值(万元)" align="center" prop="outputValue" />
      <el-table-column label="庞家镇矢量边界" align="center" prop="vectorBoundary" />
      <el-table-column label="庞家镇村庄矢量边界" align="center" prop="villageVectorBoundary" />
      <el-table-column label="创建人" align="center" prop="createdBy" />
      <el-table-column label="创建时间" align="center" prop="createdTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['crops:data:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['crops:data:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改作物综合数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="镇耕地面积(万亩)" prop="cultivatedArea">
          <el-input v-model="form.cultivatedArea" placeholder="请输入镇耕地面积(万亩)" />
        </el-form-item>
        <el-form-item label="粮食总产(万吨)" prop="foodstuffProduction">
          <el-input v-model="form.foodstuffProduction" placeholder="请输入粮食总产(万吨)" />
        </el-form-item>
        <el-form-item label="蔬菜种植面积(亩)" prop="vegetablePlantingArea">
          <el-input v-model="form.vegetablePlantingArea" placeholder="请输入蔬菜种植面积(亩)" />
        </el-form-item>
        <el-form-item label="蔬菜总产(吨)" prop="vegetableProduction">
          <el-input v-model="form.vegetableProduction" placeholder="请输入蔬菜总产(吨)" />
        </el-form-item>
        <el-form-item label="农产品种类" prop="type">
          <el-input v-model="form.type" placeholder="请输入农产品种类" />
        </el-form-item>
        <el-form-item label="农产品种植面积(亩)" prop="agriculturalPlantingArea">
          <el-input v-model="form.agriculturalPlantingArea" placeholder="请输入农产品种植面积(亩)" />
        </el-form-item>
        <el-form-item label="特色农业总产量(吨)" prop="agricultureProduction">
          <el-input v-model="form.agricultureProduction" placeholder="请输入特色农业总产量(吨)" />
        </el-form-item>
        <el-form-item label="特色农业年产值(万元)" prop="agricultureOutputVaule">
          <el-input v-model="form.agricultureOutputVaule" placeholder="请输入特色农业年产值(万元)" />
        </el-form-item>
        <el-form-item label="总人口(人)" prop="totalPopulation">
          <el-input v-model="form.totalPopulation" placeholder="请输入总人口(人)" />
        </el-form-item>
        <el-form-item label="占地面积(平方公里)" prop="coverArea">
          <el-input v-model="form.coverArea" placeholder="请输入占地面积(平方公里)" />
        </el-form-item>
        <el-form-item label="示范大棚数量(个)" prop="exampleGreenhouse">
          <el-input v-model="form.exampleGreenhouse" placeholder="请输入示范大棚数量(个)" />
        </el-form-item>
        <el-form-item label="村居数量(个)" prop="rusticate">
          <el-input v-model="form.rusticate" placeholder="请输入村居数量(个)" />
        </el-form-item>
        <el-form-item label="联合社耕地面积(万亩)" prop="cultivatedAlly">
          <el-input v-model="form.cultivatedAlly" placeholder="请输入联合社耕地面积(万亩)" />
        </el-form-item>
        <el-form-item label="大棚数量(个)" prop="greenhouse">
          <el-input v-model="form.greenhouse" placeholder="请输入大棚数量(个)" />
        </el-form-item>
        <el-form-item label="农产品产值(万元)" prop="outputValue">
          <el-input v-model="form.outputValue" placeholder="请输入农产品产值(万元)" />
        </el-form-item>
        <el-form-item label="庞家镇矢量边界" prop="vectorBoundary">
          <el-input v-model="form.vectorBoundary" placeholder="请输入庞家镇矢量边界" />
        </el-form-item>
        <el-form-item label="庞家镇村庄矢量边界" prop="villageVectorBoundary">
          <el-input v-model="form.villageVectorBoundary" placeholder="请输入庞家镇村庄矢量边界" />
        </el-form-item>
<!--        <el-form-item label="创建人" prop="createdBy">-->
<!--          <el-input v-model="form.createdBy" placeholder="请输入创建人" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="创建时间" prop="createdTime">-->
<!--          <el-date-picker clearable-->
<!--            v-model="form.createdTime"-->
<!--            type="date"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            placeholder="请选择创建时间">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listData, getData, delData, addData, updateData } from "@/api/crops/data";

export default {
  name: "Data",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 作物综合数据表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cultivatedArea: null,
        foodstuffProduction: null,
        vegetablePlantingArea: null,
        vegetableProduction: null,
        type: null,
        agriculturalPlantingArea: null,
        agricultureProduction: null,
        agricultureOutputVaule: null,
        totalPopulation: null,
        coverArea: null,
        exampleGreenhouse: null,
        rusticate: null,
        cultivatedAlly: null,
        greenhouse: null,
        outputValue: null,
        vectorBoundary: null,
        villageVectorBoundary: null,
        // createdBy: null,
        // createdTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询作物综合数据列表 */
    getList() {
      this.loading = true;
      listData(this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        cultivatedArea: null,
        foodstuffProduction: null,
        vegetablePlantingArea: null,
        vegetableProduction: null,
        type: null,
        agriculturalPlantingArea: null,
        agricultureProduction: null,
        agricultureOutputVaule: null,
        totalPopulation: null,
        coverArea: null,
        exampleGreenhouse: null,
        rusticate: null,
        cultivatedAlly: null,
        greenhouse: null,
        outputValue: null,
        vectorBoundary: null,
        villageVectorBoundary: null,
        // createdBy: null,
        // createdTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加作物综合数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getData(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改作物综合数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateData(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addData(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除作物综合数据编号为"' + ids + '"的数据项？').then(function() {
        return delData(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('crops/data/export', {
        ...this.queryParams
      }, `data_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
