<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <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
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:GARDENTRADEDATA:add']"
        >新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:GARDENTRADEDATA:edit']"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:GARDENTRADEDATA:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          size="mini"
          @click="importFile"
          v-hasPermi="['business:GARDENTRADEDATA:add']"
        >导入</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:GARDENTRADEDATA:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table :data="GARDENTRADEDATAList" @selection-change="handleSelectionChange" fixed>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="园区名称" align="center" prop="gardenName" width="130">
        <template slot-scope="scope">
          {{scope.row.gardenName}}
        </template>
      </el-table-column>
      <el-table-column label="企业出口退税额" align="center" prop="companyDrawback" width="130">
        <template slot-scope="scope">
          {{scope.row.companyDrawback}}
        </template>
      </el-table-column>
      <el-table-column label="园区出口退税总额" align="center" prop="gardenDrawback" width="140">
        <template slot-scope="scope">
          {{scope.row.gardenDrawback}}
        </template>
      </el-table-column>
      <el-table-column label="园区运营单位缴税总额" align="center" prop="gardenTax" width="170">
        <template slot-scope="scope">
          {{scope.row.gardenTax}}
        </template>
      </el-table-column>
      <el-table-column label="企业承接单量" align="center" prop="companyLists" width="130">
        <template slot-scope="scope">
          {{scope.row.companyLists}}
        </template>
      </el-table-column>
      <el-table-column label="园区承接单总量" align="center" prop="gardenLits" width="130">
        <template slot-scope="scope">
          {{scope.row.gardenLits}}
        </template>
      </el-table-column>
      <el-table-column label="企业创新获奖量" align="center" prop="companyInnovative" width="130">
        <template slot-scope="scope">
          {{scope.row.companyInnovative}}
        </template>
      </el-table-column>
      <el-table-column label="园区内创新获奖总量" align="center" prop="gardenInnovative" width="160">
        <template slot-scope="scope">
          {{scope.row.gardenInnovative}}
        </template>
      </el-table-column>
      <el-table-column label="企业工业用水、用电量" align="center" prop="companyWaterElectric" width="170">
        <template slot-scope="scope">
          {{scope.row.companyWaterElectric}}
        </template>
      </el-table-column>
      <el-table-column label="园区工业用水、用电总量" align="center" prop="gardenWaterElectric" width="190">
        <template slot-scope="scope">
          {{scope.row.gardenWaterElectric}}
        </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="['business:GARDENTRADEDATA:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:GARDENTRADEDATA: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>
      <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 { listGARDENTRADEDATA, getGARDENTRADEDATA, delGARDENTRADEDATA, addGARDENTRADEDATA, updateGARDENTRADEDATA } from "@/api/portal/GARDENTRADEDATA/GARDENTRADEDATA.js";
import importFile from "./importFile.vue";
import edit from "./edit.vue";
export default {
  name: "GARDENTRADEDATA",
  data() {
    return {
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 园区贸易数据表格数据
      GARDENTRADEDATAList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        gardenId: null,
        deptId: null,
        companyDrawback: null,
        gardenDrawback: null,
        gardenTax: null,
        companyLists: null,
        gardenLits: null,
        companyInnovative: null,
        gardenInnovative: null,
        companyWaterElectric: null,
        gardenWaterElectric: null,
        createTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        gardenId: [
          { required: true, message: "园区ID不能为空", trigger: "blur" }
        ],
        deptId: [
          { required: true, message: "保税区ID不能为空", trigger: "blur" }
        ],
        companyDrawback: [
          { required: true, message: "企业出口退税额 不能为空", trigger: "blur" }
        ],
        gardenDrawback: [
          { required: true, message: "园区出口退税总额 不能为空", trigger: "blur" }
        ],
        gardenTax: [
          { required: true, message: "园区运营单位缴税总额 不能为空", trigger: "blur" }
        ],
        companyLists: [
          { required: true, message: "企业承接单量 不能为空", trigger: "blur" }
        ],
        gardenLits: [
          { required: true, message: "园区承接单总量 不能为空", trigger: "blur" }
        ],
        companyInnovative: [
          { required: true, message: "企业创新获奖量 不能为空", trigger: "blur" }
        ],
        gardenInnovative: [
          { required: true, message: "园区内创新获奖总量 不能为空", trigger: "blur" }
        ],
        companyWaterElectric: [
          { required: true, message: "企业工业用水、用电量 不能为空", trigger: "blur" }
        ],
        gardenWaterElectric: [
          { required: true, message: "园区工业用水、用电总量 不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询园区贸易数据列表 */
    getList() {
      this.loading = true;
      listGARDENTRADEDATA(this.queryParams).then(response => {
        this.GARDENTRADEDATAList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    importFile(){
      this.iframe({ obj: importFile, param: {}, title: '导入', width: '500px', height: '50%' });
    },
    // 表单重置
    reset() {
      this.form = {
        gardenId: null,
        deptId: null,
        companyDrawback: null,
        gardenDrawback: null,
        gardenTax: null,
        companyLists: null,
        gardenLits: null,
        companyInnovative: null,
        gardenInnovative: null,
        companyWaterElectric: null,
        gardenWaterElectric: 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.gardenId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.iframe({ obj: edit, param: {}, title: '添加园区贸易数据', width: '750px', height: '70%' });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.gardenId || this.ids;
      this.iframe({ obj: edit, param: {id:id}, title: '修改园区贸易数据', width: '750px', height: '70%' });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.gardenId != null) {
            updateGARDENTRADEDATA(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGARDENTRADEDATA(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const gardenIds = row.gardenId || this.ids;
      this.$modal.confirm('是否确认删除？').then(function() {
        return delGARDENTRADEDATA(gardenIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/GARDENTRADEDATA/export', {
        ...this.queryParams
      }, `GARDENTRADEDATA_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
