<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="行政区">
        <el-input
          v-model="queryParams.xzqdm"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="活动时间">
        <el-col :span="11">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="form.filetime"
            style="width: 100%"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
        </el-col>
        <el-col class="line" :span="2">-</el-col>
        <el-col :span="11">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="form.readtime"
            style="width: 100%"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
        </el-col>
      </el-form-item>
      <el-form-item label="文件名称">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入文件名称"
          clearable
          @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">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['supervise:pcsj: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="['supervise:pcsj: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="['supervise:pcsj: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="['supervise:pcsj:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row> -->

    <el-table
      v-loading="loading"
      :data="pcsjList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="文件名称" align="center" prop="name" />
      <el-table-column label="区县名称" align="center" prop="xzqmc" />
      <el-table-column
        label="图斑个数"
        align="center"
        prop="spotsnumber"
        width="180"
      >
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.uploadtime, "{y}-{m}-{d}") }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="监测面积（亩）" align="center" prop="spotsarea" />
      <el-table-column label="文件大小" align="center" prop="spotssize" />
      <el-table-column label="录入时间" align="center" prop="filetime" />
      <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="handleBrowse(scope.row)"
            :disabled="scope.row.readstatus != 0"
            >浏览</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDownload(scope.row)"
            >下载</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="name">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="上传用户" prop="uploaduser">
          <el-input v-model="form.uploaduser" placeholder="请输入上传用户" />
        </el-form-item>
        <el-form-item label="上传时间" prop="uploadtime">
          <el-date-picker
            clearable
            v-model="form.uploadtime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择上传时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="文件位置" prop="filepath">
          <el-input v-model="form.filepath" placeholder="请输入文件位置" />
        </el-form-item>
        <el-form-item label="shp位置" prop="shppath">
          <el-input v-model="form.shppath" placeholder="请输入shp位置" />
        </el-form-item>
        <el-form-item label="文件服务发布地址" prop="proxypath">
          <el-input
            v-model="form.proxypath"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="解压文件地址" prop="unzippath">
          <el-input
            v-model="form.unzippath"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="是否入库" prop="storage">
          <el-input v-model="form.storage" placeholder="请输入是否入库" />
        </el-form-item>
        <el-form-item label="行政区划代码" prop="xzqhdm">
          <el-input v-model="form.xzqhdm" placeholder="请输入行政区划代码" />
        </el-form-item>
        <el-form-item label="图斑数量" prop="spotsnumber">
          <el-input v-model="form.spotsnumber" placeholder="请输入图斑数量" />
        </el-form-item>
        <el-form-item label="图斑面积" prop="spotsarea">
          <el-input v-model="form.spotsarea" placeholder="请输入图斑面积" />
        </el-form-item>
        <el-form-item label="图斑大小" prop="spotssize">
          <el-input v-model="form.spotssize" placeholder="请输入图斑大小" />
        </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 {
  listPcsj,
  getPcsj,
  delPcsj,
  addPcsj,
  updatePcsj,
} from "@/api/supervise/pcsj";

export default {
  name: "Pcsj",
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 监管批次数据表格数据
      pcsjList: [
        {
          name: "", //文件名称
          xzqdm: "", //区县名称
          spotsnumber: "", //图斑个数
          spotsarea: "", //监测面积（亩）
          spotssize: "", //文件大小
          filetime: "", //录入时间
        },
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: "", //文件名称
        xzqdm: "", //区县名称
        filetime: "", //录入时间
        readtime: "", //处理时间
      },
      // 表单参数
      form: {
        name: "1",
        uploaduser: "1",
        uploadtime: "1",
        filepath: "1",
        shppath: "1",
        proxypath: "1",
        unzippath: "1",
        filetype: "1",
        storage: "1",
        status: "1",
        xzqhdm: "1",
        spotsnumber: "1",
        spotsarea: "1",
        spotssize: "1",
      },
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleDownload(row) {
      const zipfile =  row.proxypath+".zip";
      window.open(`${zipfile}`);
    },
    /** 查询监管批次数据列表 */
    getList() {
      this.loading = true;
      listPcsj(this.queryParams).then((response) => {
        this.pcsjList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        uploaduser: null,
        uploadtime: null,
        filepath: null,
        shppath: null,
        proxypath: null,
        unzippath: null,
        filetype: null,
        storage: null,
        status: null,
        xzqhdm: null,
        xzqmc: null,
        spotsnumber: null,
        spotsarea: null,
        spotssize: 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 = "添加监管批次数据";
    },
    // 浏览按钮
    handleBrowse(row) {
      this.$router.push({ path: "/remote/gdjc" ,query: { id: row.id}});
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getPcsj(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) {
            updatePcsj(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPcsj(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 delPcsj(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "supervise/pcsj/export",
        {
          ...this.queryParams,
        },
        `pcsj_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
