<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="年份" prop="configName">
        <el-date-picker
          v-model="queryParams.year"
          type="year"
          value-format="yyyy"
          placeholder="选择年"
          size="small"
          @keyup.enter.native="handleQuery"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="部门" prop="sysDeptId">
        <el-cascader :options="typeOptionstwo" :props="{value: 'id'}" @change="changeBtn" :show-all-levels="false"></el-cascader>
      </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="['dept:area: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="['dept:area: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="['dept:area: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="['dept:area:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="areaList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="部门名称" align="center" prop="deptName" />
      <el-table-column label="年份" align="center" prop="year" />
      <el-table-column label="新签约亿元以上项目数(个数)" align="center" prop="projectMillionNum" />
      <el-table-column label="其中" align="center">
      <el-table-column label="工业项目数(个数)" align="center" prop="projectIndustryNum" />
      <el-table-column label="1～5亿元项目" align="center" prop="projectOneNum" />
      <el-table-column label="5～10亿元项目" align="center" prop="projectTwoNum" />
      <el-table-column label="10亿元以上" align="center" prop="projectThrNum" />
      <el-table-column label="15亿元以上" align="center" prop="projectFourNum" />
      <el-table-column label="20亿元以上" align="center" prop="projectFiveNum" />
      </el-table-column >
      <el-table-column label="实际利用市外资金(亿元)" align="center" prop="projectCityMoney" />
      <el-table-column label="入省库项目(个数)" align="center" prop="projectProNum" />
      <el-table-column label="其中" align="center">
      <el-table-column label="十大新兴产业项目数(个数)" align="center" prop="projectRisNum" />
      <el-table-column label="现代服务业项目数(个数)" align="center" prop="projectSerNum" />
      <el-table-column label="15亿元以上项目数(个数)" align="center" prop="projectProFiveNum" />
      </el-table-column >
      <el-table-column label="500强投资新注册公司数(个数)" align="center" prop="projectInvestmentNum" />
      <el-table-column label="入统入规(个)" align="center">
      <el-table-column label="入统(个数)" align="center" prop="projectIntegrationNum" />
      <el-table-column label="小升规(个数)" align="center" prop="projectSmallNum" />
      <el-table-column label="新入规(个数)" align="center" prop="projectNewNum" />
      </el-table-column >
      <el-table-column label="备注" align="center" prop="remark" />
      <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="['dept:area:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['dept:area: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="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="200px">
        <el-form-item label="年份" prop="year">
          <el-date-picker
            v-model="form.year"
            type="year"
            value-format="yyyy"
            placeholder="选择年"
            style="width: 100%;"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="部门" prop="sysDeptId">
          <el-cascader :options="typeOptionstwo" :props="{value: 'id'}"   v-model="form.sysDeptId" @change="changeBtn1" :show-all-levels="false"></el-cascader>
        </el-form-item>
        <el-form-item  label="新签约亿元以上项目数(个数)" prop="projectMillionNum">
          <el-input v-model="form.projectMillionNum" placeholder="请输入新签约亿元以上项目数" />
        </el-form-item>

        <el-form-item label="工业项目数（个数）" prop="projectIndustryNum">
          <el-input v-model="form.projectIndustryNum" placeholder="请输入工业项目数" />
        </el-form-item>
        <el-form-item label="1～5亿元项目（个数）" prop="projectOneNum">
          <el-input v-model="form.projectOneNum" placeholder="请输入1～5亿元项目" />
        </el-form-item>
        <el-form-item label="5～10亿元项目（个数）" prop="projectTwoNum">
          <el-input v-model="form.projectTwoNum" placeholder="请输入5～10亿元项目" />
        </el-form-item>
        <el-form-item label="10亿元以上（个数）" prop="projectThrNum">
          <el-input v-model="form.projectThrNum" placeholder="请输入10亿元以上" />
        </el-form-item>
        <el-form-item label="15亿元以上（个数）" prop="projectFourNum">
          <el-input v-model="form.projectFourNum" placeholder="请输入15亿元以上" />
        </el-form-item>
        <el-form-item label="20亿元以上（个数）" prop="projectFiveNum">
          <el-input v-model="form.projectFiveNum" placeholder="请输入20亿元以上" />
        </el-form-item>

        <el-form-item label="实际利用市外资金（亿元）" prop="projectCityMoney">
          <el-input v-model="form.projectCityMoney" placeholder="请输入实际利用市外资金" />
        </el-form-item>
        <el-form-item label="入省库项目(个)" prop="projectProNum">
          <el-input v-model="form.projectProNum" placeholder="请输入入省库项目(个数)" />
        </el-form-item>
        <el-form-item label="十大新兴产业项目数(个)" prop="projectRisNum">
          <el-input v-model="form.projectRisNum" placeholder="请输入十大新兴产业项目数(个数)" />
        </el-form-item>
        <el-form-item label="现代服务业项目数(个)" prop="projectSerNum">
          <el-input v-model="form.projectSerNum" placeholder="请输入现代服务业项目数(个数)" />
        </el-form-item>
        <el-form-item label="15亿元以上项目数(个)" prop="projectProFiveNum">
          <el-input v-model="form.projectProFiveNum" placeholder="请输入15亿元以上项目数(个数)" />
        </el-form-item>
        <el-form-item label="500强投资新注册公司数(个)" prop="projectInvestmentNum">
          <el-input v-model="form.projectInvestmentNum" placeholder="请输入500强投资新注册公司数(个)" />
        </el-form-item>
        <el-form-item label="入统(个)" prop="projectIntegrationNum">
          <el-input v-model="form.projectIntegrationNum" placeholder="请输入入统(个数)" />
        </el-form-item>
        <el-form-item label="小升规(个)" prop="projectSmallNum">
          <el-input v-model="form.projectSmallNum" placeholder="请输入小升规(个数)" />
        </el-form-item>
        <el-form-item label="新入规(个)" prop="projectNewNum">
          <el-input v-model="form.projectNewNum" placeholder="请输入新入规(个数)" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" 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 { listArea, getArea, delArea, addArea, updateArea, exportArea } from "@/api/area/index";
import { listConfigfieu } from '@/api/system/config'

export default {
  name: "Area",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 两区及乡镇单位部门招商计划表格数据
      areaList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,

      typeOptionstwo:[],

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sysDeptId: null,
        isDel: null,
        year: null,
        projectMillionNum: null,
        projectIndustryNum: null,
        projectOneNum: null,
        projectTwoNum: null,
        projectThrNum: null,
        projectFourNum: null,
        projectFiveNum: null,
        projectCityMoney: null,
        projectProNum: null,
        projectRisNum: null,
        projectSerNum: null,
        projectProFiveNum: null,
        projectInvestmentNum: null,
        projectIntegrationNum: null,
        projectSmallNum: null,
        projectNewNum: null,
        typeOptionstwo:[]
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        projectMillionNum:[
                  { required: true, message: '请输入新签约亿元以上项目', trigger: 'change' }
                ],
        targetArrivalAmount:[
                  { required: true, message: '请输入当年新签约金额目标任务(万元)', trigger: 'change' }
                ],
        year: [
                    { type: 'string', required: true, message: '请选择年份', trigger: 'change' }
                  ],
      }
    };
  },
  created() {
    this.getList();
    this.getListthuy()

  },
  methods: {
    changeBtn(e){
      if(e.length == 1){
        this.queryParams.sysDeptId  = e.join(',')
      }else{
         this.queryParams.sysDeptId = e[e.length-1]
      }

    },
    changeBtn1(e){
      if(e.length == 1){
        this.form.sysDeptId  = e.join(',')
      }else{
        this.form.sysDeptId = e[e.length-1]
      }

    },
    /** 查询两区及乡镇单位部门招商计划列表 */
    getList() {
      this.loading = true;
      listArea(this.queryParams).then(response => {
        this.areaList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    getListthuy() {
      this.loading = true;
      listConfigfieu().then((response) => {
        console.log(response.data)
        this.typeOptionstwo = response.data;
        // this.fileList =  this.queryParams.attachment
        // this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sysDeptId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        isDel: null,
        year: null,
        projectMillionNum: null,
        projectIndustryNum: null,
        projectOneNum: null,
        projectTwoNum: null,
        projectThrNum: null,
        projectFourNum: null,
        projectFiveNum: null,
        projectCityMoney: null,
        projectProNum: null,
        projectRisNum: null,
        projectSerNum: null,
        projectProFiveNum: null,
        projectInvestmentNum: null,
        projectIntegrationNum: null,
        projectSmallNum: null,
        projectNewNum: null,
        remark: 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
      getArea(id).then(response => {
        this.form = response.data;
        this.form.sysDeptId = this.form.sysDeptId - 0
        this.open = true;
        this.title = "修改两区及乡镇单位部门招商计划";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateArea(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addArea(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除两区及乡镇单位部门招商计划?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delArea(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有两区及乡镇单位部门招商计划数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportArea(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
