<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--部门数据-->
      <el-col :span="['2'].includes(routeParams.stillFieldType)?4:0" :xs="24" v-if="['2'].includes(routeParams.stillFieldType)">
        <div class="head-container">
          <el-input
            v-model="deptName"
            placeholder="请输入部门名称"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 20px"
          />
        </div>
        <div class="head-container" ref="treeContainer" :style="{ height: treeHeight + 'px' } ">
          <el-tree
            :data="deptOptions"
            :props="defaultProps"
            :expand-on-click-node="false"
            node-key="id"
            :default-expanded-keys="[365]"
            :filter-node-method="filterNode"
            ref="tree"
            @node-click="handleNodeClick"
          />
        </div>
      </el-col>
      <!--用户数据-->
      <el-col :span="['2'].includes(routeParams.stillFieldType)?20:24" :xs="24">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="120px" @submit.native.prevent>
          <el-form-item label="标题" prop="stillName">
            <el-input
              v-model="queryParams.stillName"
              placeholder="请输入标题"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <!--<el-form-item label="还田人" prop="stillUserName" v-if="['3'].includes(routeParams.stillFieldType)">-->
            <!--<el-input-->
              <!--v-model="queryParams.stillUserName"-->
              <!--placeholder="请输入还田人"-->
              <!--clearable-->
              <!--size="small"-->
              <!--@keyup.enter.native="handleQuery"-->
            <!--/>-->
          <!--</el-form-item>-->
          <!--<el-form-item label="所属市" prop="city" v-if="['3'].includes(routeParams.stillFieldType)">-->
            <!--<el-input-->
              <!--v-model="queryParams.city"-->
              <!--placeholder="请输入所属市"-->
              <!--clearable-->
              <!--size="small"-->
              <!--@keyup.enter.native="handleQuery"-->
            <!--/>-->
          <!--</el-form-item>-->
        <!--  <el-form-item label="所属乡(镇、街)" prop="village" v-if="['3'].includes(routeParams.stillFieldType)">
            <el-input
              v-model="queryParams.village"
              placeholder="请输入所属乡(镇、街)"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>-->
          <el-form-item label="联系电话" prop="stillPhone" v-if="['3'].includes(routeParams.stillFieldType)">
            <el-input
              v-model="queryParams.stillPhone"
              placeholder="请输入联系电话"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <!--<el-form-item label="还田面积(单位㎡)" prop="stillArea">-->
            <!--<el-input-->
              <!--v-model="queryParams.leaveArea"-->
              <!--placeholder="请输入还田面积(单位㎡)"-->
              <!--clearable-->
              <!--size="small"-->
              <!--@keyup.enter.native="handleQuery"-->
            <!--/>-->
          <!--</el-form-item>-->
          <!--<el-form-item label="还田量(单位kg)" prop="stillAmount">-->
            <!--<el-input-->
              <!--v-model="queryParams.leaveAmount"-->
              <!--placeholder="请输入还田量(单位kg)"-->
              <!--clearable-->
              <!--size="small"-->
              <!--@keyup.enter.native="handleQuery"-->
            <!--/>-->
          <!--</el-form-item>-->
          <!--<el-form-item label="还田时间" prop="stillTime" v-if="['2','3'].includes(routeParams.stillFieldType)">-->
            <!--<el-date-picker clearable size="small"-->
                            <!--v-model="queryParams.stillTime"-->
                            <!--type="year"-->
                            <!--value-format="yyyy"-->
                            <!--placeholder="选择还田时间">-->
            <!--</el-date-picker>-->
          <!--</el-form-item>-->
          <el-form-item label="所属县(市丶区)" prop="district" v-if="['3'].includes(routeParams.stillFieldType)">
            <el-input
              v-model="queryParams.district"
              placeholder="请输入所属县(市丶区)"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <!--<el-form-item label="地块编号" prop="landInfoId" v-if="['3'].includes(routeParams.stillFieldType)">-->
            <!--<el-input-->
              <!--v-model="queryParams.landInfoId"-->
              <!--placeholder="请输入地块编号"-->
              <!--clearable-->
              <!--size="small"-->
              <!--@keyup.enter.native="handleQuery"-->
            <!--/>-->
          <!--</el-form-item>-->
          <el-form-item label="还田开始时间" prop="startStillTime" v-if="['2','3'].includes(routeParams.stillFieldType)"label-width="120px">
            <el-date-picker clearable
                            @change="startStillTimeChange"
                            v-model="queryParams.startStillTime"
                            type="year"
                            value-format="yyyy"
                            size="small"
                            style="width: 215px;"
                            placeholder="请选择还田开始时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="还田结束时间" prop="endStillTime" v-if="['2','3'].includes(routeParams.stillFieldType)" label-width="120px">
            <el-date-picker clearable
                            @change="endStillTimeChange"
                            v-model="queryParams.endStillTime"
                            type="year"
                            value-format="yyyy"
                            size="small"
                            style="width: 215px;"
                            placeholder="请选择还田结束时间">
            </el-date-picker>
          </el-form-item>
          <!--<el-form-item label="补助金额" prop="subsidyMoney" v-if="['3'].includes(routeParams.stillFieldType)">-->
            <!--<el-input-->
              <!--v-model="queryParams.subsidyMoney"-->
              <!--placeholder="请输入补助金额"-->
              <!--clearable-->
              <!--size="small"-->
              <!--@keyup.enter.native="handleQuery"-->
            <!--/>-->
          <!--</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" v-if="['1'].includes(routeParams.stillFieldType)">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['StillField:StillField:add']"
            >新增</el-button>
          </el-col>
          <el-col :span="1.5" v-if="['1'].includes(routeParams.stillFieldType)">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['StillField:StillField:edit']"
            >修改</el-button>
          </el-col>
          <el-col :span="1.5" v-if="['1'].includes(routeParams.stillFieldType)">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['StillField:StillField:remove']"
            >删除</el-button>
          </el-col>
          <!--<el-col :span="1.5">-->
            <!--<el-button-->
              <!--type="info"-->
              <!--plain-->
              <!--icon="el-icon-upload2"-->
              <!--size="mini"-->
              <!--@click="handleImport"-->
              <!--v-hasPermi="['StillField:StillField:import']"-->
            <!--&gt;导入-->
            <!--</el-button>-->
          <!--</el-col>-->
          <el-col :span="1.5" v-if="['1', '2', '3'].includes(routeParams.stillFieldType)">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['StillField:StillField:export']"
            >导出</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="StillFieldList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <!--<el-table-column label="${comment}" align="center" prop="id" />-->
          <el-table-column label="标题" align="center" prop="stillName" />
          <el-table-column label="还田面积(单位㎡)" align="center" prop="stillArea" />
          <el-table-column label="还田类型" align="center" prop="stillType" >
            <template slot-scope="scope">
              <dict-tag :options="dict.type.farm_returning_type" :value="scope.row.stillType"/>
            </template>
          </el-table-column>
          <el-table-column label="联系电话" align="center" prop="stillPhone" />
          <el-table-column label="还田时间" align="center" prop="stillTime" width="180">
            <template slot-scope="scope">
              <span>{{ scope.row.stillTime }}年</span>
            </template>
          </el-table-column>
          <el-table-column label="所属部门" align="center" prop="deptName" />
          <el-table-column label="创建人" align="center" prop="createName" />
          <el-table-column label="创建时间" align="center" prop="createTime" />
          <el-table-column label="修改人" align="center" prop="updateName" />
          <el-table-column label="修改时间" align="center" prop="updateTime" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button v-if="['2', '3'].includes(routeParams.stillFieldType)"
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="handleDetail(scope.row)"
                v-hasPermi="['StillField:StillField:edit']"
              >详情</el-button>
              <el-button v-if="['1'].includes(routeParams.stillFieldType)"
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['StillField:StillField:edit']"
              >修改</el-button>
              <el-button v-if="['1'].includes(routeParams.stillFieldType)"
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['StillField:StillField: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-col>
    </el-row>

    <!-- 添加或修改农业还田对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" class="form-style">
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-row :gutter="20">
          <el-col :span="12">
        <el-form-item label="标题" prop="stillName">
          <el-input v-model="form.stillName" placeholder="请输入标题" maxlength="20"/>
        </el-form-item>
        <el-form-item label="还田面积(单位㎡)" prop="stillArea">
          <el-input v-model="form.stillArea" placeholder="请输入还田面积(单位㎡)" maxlength="20"/>
        </el-form-item>
        <el-form-item label="还田量(单位kg)" prop="stillAmount">
          <el-input v-model="form.stillAmount" placeholder="请输入还田量(单位kg)" maxlength="20"/>
        </el-form-item>
        <el-form-item label="联系电话" prop="stillPhone">
          <el-input v-model="form.stillPhone" placeholder="请输入联系电话" maxlength="13"/>
        </el-form-item>
            <el-form-item label="还田类型" prop="stillType">
              <el-select v-model="form.stillType" placeholder="请选择还田类型">
                <el-option
                  v-for="dict in dict.type.farm_returning_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
        <el-form-item label="还田时间" prop="stillTime">
          <el-date-picker clearable size="small"
            v-model="form.stillTime"
            type="year"
            value-format="yyyy"
            placeholder="选择还田时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="所属县（市）区" prop="district">
          <el-input v-model="form.district" placeholder="请输入所属县（市）区" maxlength="20"/>
        </el-form-item>
        <el-form-item label="所属乡镇（街）" prop="village">
          <el-input v-model="form.village" placeholder="请输入所属乡镇（街）" maxlength="20"/>
        </el-form-item>
            <el-form-item label="所属部门" prop="deptId" :label-width="labelWidth">
<!--              <treeselect-->
<!--                v-if="!disable"-->
<!--                :flat="false"-->
<!--                :allowSelectingDisabledDescendants="true"-->
<!--                v-model="form.deptId" :options="deptOptions" :show-count="true"-->
<!--                placeholder="请选择所属部门"/>-->
<!--              <el-select v-model="form.deptName" placeholder="请选择所属部门" :style="inputStyle" v-if="disable" :disabled="disable">-->
<!--                <el-option-->
<!--                  v-for="dept in deptOptions"-->
<!--                  :key="dept.deptId"-->
<!--                  :label="dept.deptName"-->
<!--                  :value="dept"-->
<!--                />-->
<!--              </el-select>-->
<!--              <deptselector :setValue=setDataDeptId :dataDeptId="form.deptId"-->
<!--                            v-model="form.deptId"></deptselector>-->
              <treeselect v-model="form.deptId" :options="deptOptions" multiple:false :show-count="true" :noResultsText="'空'" :noOptionsText="'空'"
                          placeholder="请选择部门" @select="hx"/>
            </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注" maxlength="30"/>
        </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-if="submit">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 农业还田详情对话框 -->
    <el-dialog :title="title" :visible.sync="openDetail" width="800px" class="form-style">
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="标题：" prop="stillName">
              <label>{{ form.stillName }}</label>
            </el-form-item>
            <el-form-item label="还田面积(单位㎡)：" prop="stillArea">
              <label>{{ form.stillArea }}</label>
            </el-form-item>
            <el-form-item label="还田量(单位kg)：" prop="stillAmount">
              <label>{{ form.stillAmount }}</label>
            </el-form-item>
            <!--<el-form-item label="还田人：" prop="stillUserName">-->
              <!--<label>{{ form.stillUserName }}</label>-->
            <!--</el-form-item>-->
            <el-form-item label="联系电话：" prop="stillPhone">
              <label>{{ form.stillPhone }}</label>
            </el-form-item>
            <el-form-item label="还田类型：" prop="stillType">
              <label v-for="(dict, index) in dict.type.farm_returning_type" v-if="form.stillType == dict.value" >{{dict.label}}</label>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="还田时间：" prop="stillTime">
              <label>{{ form.stillTime }}年</label>
            </el-form-item>
            <el-form-item label="所属县(市丶区)：" prop="district">
              <label>{{ form.district }}</label>
            </el-form-item>
            <el-form-item label="所属乡(镇、街)：" prop="village">
              <label>{{ form.village }}</label>
            </el-form-item>
            <el-form-item label="所属部门：" prop="deptId" >
              <label>{{ form.deptName }}</label>
            </el-form-item>
            <el-form-item label="备注：" prop="remarks">
              <label>{{ form.remarks }}</label>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-if="submit">确 定</el-button>
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport"/>
            是否更新已经存在的数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
                   @click="importTemplate">下载模板
          </el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStillField, getStillField, delStillField, addStillField, updateStillField } from "@/api/data/digitalagriculture/StillField/StillField";
import {checkPositiveDecimal, checkNonnegativeInteger, validPhoneMobile} from "@/api/rules/rules";
import deptselector from '@/views/components/deptselector'
import { getToken } from '@/utils/auth'
import { treeselect } from '@/api/system/dept'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import {format_date} from "@/views/data/common/dateExport";

export default {
  name: "StillField",
  dicts:['farm_returning_type'],
  components: {
    deptselector,
    Treeselect,
  },
  data() {
    return {
      // 树形容器
      treeContainer: null,
      // 树形高度
      treeHeight: 0,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层宽度
      labelWidth: '150px',
      // 文本框宽度
      inputStyle: 'width: 310px',
      // 农业还田表格数据
      StillFieldList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示详情页弹出层
      openDetail: false,
      // 是否显示提交按钮
      submit: false,
      // 部门名称
      deptName: undefined,
      // 部门树选项
      deptOptions: undefined,
      // 导入参数
      upload: {
        // 是否显示导入弹出层
        open: false,
        // 导入弹出层标题
        title: '',
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: 'Bearer ' + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + '/center-data/StillField/import/importData'
      },
      // 路由参数
      routeParams: {
        stillFieldType: null
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stillName: null,
        stillArea: null,
        stillType: null,
        stillAmount: null,
        stillUserName: null,
        stillPhone: null,
        subsidyMoney: null,
        stillTime: null,
        startStillTime: null,
        endStillTime: null,
        city: null,
        district: null,
        village: null,
        landInfoId: null,
        createDate: null,
        updateDate: null,
        remarks: null,
        deptId: null,
        deptName: null,
        stillFieldType: null,
      },
      // 表单参数
      form: {},
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      // 正小数校验
      checkPositiveDecimal: checkPositiveDecimal,
      // 正整数校验
      checkNonnegativeInteger: checkNonnegativeInteger,
      //手机号,座机号校验
      validPhoneMobile: validPhoneMobile,
      // 表单校验
      rules: {
        deptId: [
          {required: true, message: "所属部门不能为空", trigger: "change"},
        ],
        stillArea: [
          {required: true, message: "面积不能为空", trigger: "blur"},
          {validator: checkPositiveDecimal, trigger: 'blur'}
        ],
        stillTime: [
          {required: true, message: "还田时间不能为空", trigger: "blur"},
        ],
        stillAmount: [
          {required: true, message: "还田量不能为空", trigger: "blur"},
          {validator: checkPositiveDecimal, trigger: 'blur'}
        ],
        subsidyMoney: [
          {required: true, message: "补助金额不能为空", trigger: "blur"},
          {validator: checkPositiveDecimal, trigger: 'blur'}
        ],
        stillType: [
          {required: true, message: "还田类型不能为空", trigger: "change"},
        ],
        stillName: [
          { required: true, message: "标题不能为空", trigger: "blur" },
          { min: 2, max: 20, message: '标题长度必须介于 2 和 20 之间', trigger: 'blur' }
        ],
        stillPhone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" },
          {validator: validPhoneMobile, trigger: 'blur'}
        ],
      }
    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val)
    }
  },
  created() {
    // 路由参数 秸秆还田类型
    this.routeParams.stillFieldType = this.$route.query.stillFieldType;
    this.getList();
    this.getTreeselect();
  },
  mounted() {
    this.treeContainer = this.$refs.treeContainer
    window.addEventListener('resize', this.handleResize)
    this.handleResize()
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.handleResize)
  },
  methods: {
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data
      })
    },
    hx(node) {
      this.form.dataDeptId = node.id
      this.form.deptId = node.id
      this.form.deptName = node.label
      this.$refs.form.validateField('deptId');
    },
    handleResize() {
      this.treeHeight = window.innerHeight - 200// 按需减去其他元素的高度
    },
    setDataDeptId(e) {
      this.form.deptId = e.deptId
      this.form.deptName = e.deptName
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.deptId = data.id
      this.handleQuery()
    },
    /** 查询农业还田列表 */
    getList() {
      this.loading = true;
      this.queryParams.stillFieldType = this.routeParams.stillFieldType;// 查询秸秆还田信息类型
      listStillField(this.queryParams).then(response => {
        this.StillFieldList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openDetail = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        stillName: null,
        stillArea: null,
        stillType: null,
        stillAmount: null,
        stillUserName: null,
        stillPhone: null,
        subsidyMoney: null,
        stillTime: null,
        city: null,
        district: null,
        village: null,
        landInfoId: null,
        createBy: null,
        createDate: null,
        updateBy: null,
        updateDate: null,
        remarks: null,
        delFlag: null,
        deptId: null,
        deptName: 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.submit = true;
      this.title = "添加农业还田";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getStillField(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.submit = true;
        this.title = "修改农业还田";
      });
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      this.reset();
      const id = row.id || this.ids
      getStillField(id).then(response => {
        this.form = response.data;
        this.openDetail = true;
        this.submit = false;
        this.title = "农业还田详情";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // this.form.deptName = this.deptOptions.filter((item) => {
          //   return this.form.deptId == item.id;
          // })[0].label;
          if (this.form.id != null) {
            updateStillField(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStillField(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否删除选中的数据').then(function() {
        return delStillField(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = '导入'
      this.upload.open = true
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('/center-data/StillField/importTemplate', {}, `StillField_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false
      this.upload.isUploading = false
      this.$refs.upload.clearFiles()
      this.$alert('<div style=\'overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;\'>' + response.msg + '</div>', '导入结果', { dangerouslyUseHTMLString: true })
      this.getList()
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit()
    },
    /** 导出按钮操作 */
    handleExport() {
      let str = this.$route.query.stillFieldType=='3' ? '秸秆还田统计':(this.$route.query.stillFieldType=='1'?'秸秆还田上报':'秸秆还田台账');

      this.download('/center-data/StillField/export', {
        ...this.queryParams
      }, str+`_${format_date(new Date())}.xlsx`)
    },
    /** 还田开始时间 */
    startStillTimeChange(value) {
      this.$set(this.queryParams, "startStillTime", value);
      if (
        new Date(this.queryParams.endStillTime).getTime() != 0 &&
        new Date(value).getTime() >
        new Date(this.queryParams.endStillTime).getTime()
      ) {
        this.queryParams.startStillTime = "";
        this.$message.error("请选择的时间小于还田结束时间");
      }
    },
    /** 还田结束时间 */
    endStillTimeChange(value) {
      this.$set(this.queryParams, "endStillTime", value);
      if (
        new Date(this.queryParams.startStillTime).getTime() != 0 &&
        new Date(value).getTime() <
        new Date(this.queryParams.startStillTime).getTime()
      ) {
        this.queryParams.endStillTime = "";
        this.$message.error("请选择时间大于还田开始时间");
      }
    }
  }
};
</script>

<style>
.head-container {
  overflow-y: auto;
}
</style>
