<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.atvName"
          placeholder="请输入项目名称"
        ></el-input>
      </el-form-item>

      <el-form-item label="项目名称">
        <el-select v-model="queryParams.scale" placeholder="请选择建设规模">
          <el-option
            v-for="item in scaleList"
            :key="item.value + 'typeList'"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="年度计划投资" label-width="120px">
        <el-input
          style="width: 130px"
          v-model="queryParams.least"
          type="number"
          placeholder="最小查询范围"
        ></el-input>
        <div class="ec-input-range-divider"></div>
        <el-input
          style="width: 130px"
          type="number"
          v-model="queryParams.most"
          placeholder="最大查询范围"
        ></el-input>
      </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="['business:ARTICLE:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          size="mini"
          icon="el-icon-delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:ARTICLE:remove']"
          >删除</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table :data="ARTICLEList" @selection-change="handleSelectionChange">
      <el-table-column type="selection"></el-table-column>
      <el-table-column label="保税区名称" align="center" prop="deptName">
        <template slot-scope="scope">
          {{ scope.row.deptName }}
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="atvName">
        <template slot-scope="scope">
          {{ scope.row.atvName }}
        </template>
      </el-table-column>
      <el-table-column label="建设规模" align="center" prop="scale">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.scale == 1" type="success">小型</el-tag>
          <el-tag v-else-if="scope.row.scale == 2" type="success">中型</el-tag>
          <el-tag v-else-if="scope.row.scale == 3" type="success">大型</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="年度投资计划(万)" align="center" prop="plan">
        <template slot-scope="scope">
          {{ scope.row.plan }}
        </template>
      </el-table-column>
      <el-table-column
        label="实际完成投资额(万)"
        align="center"
        prop="reality"
        width="130px"
      >
        <template slot-scope="scope">
          {{ scope.row.reality }}
        </template>
      </el-table-column>
      <el-table-column label="年度投资完成百分比" align="center" prop="retio">
        <template slot-scope="scope">
          {{
            scope.row.retio
              ? scope.row.retio.toFixed(2) * 100 + "%"
              : scope.row.retio
          }}
        </template>
      </el-table-column>
      <el-table-column label="形象进度" align="center" prop="schedule">
        <template slot-scope="scope">
          {{ scope.row.schedule }}
        </template>
      </el-table-column>
      <el-table-column label="项目审核状态" align="center" prop="status">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 0">草稿</el-tag>
          <el-tag v-else-if="scope.row.status == 1" type="info">审核中</el-tag>
          <el-tag v-else-if="scope.row.status == 2" type="danger"
            >审核拒绝</el-tag
          >
          <el-tag v-else-if="scope.row.status == 3" type="success"
            >已审核</el-tag
          >
        </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"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:ARTICLE:edit']"
            v-if="scope.row.status == 0 || scope.row.status == 2"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="handleTask(scope.row)"
            v-hasPermi="['business:ARTICLE:edit']"
            v-if="scope.row.status == 0 || scope.row.status == 2"
            >提交审核</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="showDetail(scope.row)"
            v-hasPermi="['business:ARTICLE:edit']"
            >详情</el-button
          >
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.status == 3"
            @click="showEnterData(scope.row)"
            v-hasPermi="['business:ARTICLE:edit']"
            >数据填报</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"
    />
  </div>
</template>

<script>
import {
  listARTICLE,
  getARTICLE,
  delARTICLE,
  addARTICLE,
  updateARTICLE,
  getUserInfo,
} from "@/api/portal/ARTICLE/ARTICLE.js";
import edit from "./edit.vue";
import enterData from "./enterData.vue";
import detail from "./detail.vue";
export default {
  name: "ARTICLE",
  data() {
    return {
      scaleList: [
        { label: "小型", value: 1 },
        { label: "中型", value: 2 },
        { label: "大型", value: 3 },
      ],
      statusList: [
        { label: "已保存", value: 0 },
        { label: "审核中", value: 1 },
        { label: "审核驳回", value: 2 },
        { label: "已审核", value: 3 },
      ],
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 重点项目管理表格数据
      ARTICLEList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        delFlag: null,
        deptId: null,
        preview: null,
        atvName: null,
        scale: null,
        unit: null,
        content: null,
        plan: null,
        reality: null,
        retio: null,
        schedule: null,
        least:null,
        most:null
      },
      deptId: "",
    };
  },
  created() {
    this.getList();
    this.getDeptId();
  },
  methods: {
    getDeptId() {
      getUserInfo().then((res) => {
        this.deptId = res.user.deptId;
      });
    },
    showDetail(row) {
      const id = row.id || this.ids;
      this.iframe({
        obj: detail,
        param: { id: id },
        title: "详情",
        width: "1050px",
        height: "80%",
      });
    },
    showEnterData(param) {
      this.iframe({
        obj: enterData,
        param: { param: param, deptId: this.deptId },
        title: "数据填报",
        width: "500px",
        height: "350px",
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 查询重点项目管理列表 */
    getList() {
      this.loading = true;
      listARTICLE(this.queryParams).then((response) => {
        this.ARTICLEList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.least = null
      this.queryParams.most = null
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.iframe({
        obj: edit,
        param: {},
        title: "添加重点项目",
        width: "1050px",
        height: "80%",
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id || this.ids;
      this.iframe({
        obj: edit,
        param: { id: id },
        title: "修改重点项目",
        width: "1050px",
        height: "80%",
      });
    },
    handleTask(row) {
      row.status = 1;
      addARTICLE(row).then((response) => {
        if (response.code == 200) {
          this.$modal.msgSuccess("提交审核成功");
          this.getList();
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          return delARTICLE(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>

<style scoped>
.ec-input-range-divider {
  display: inline-block;
  width: 7px;
  height: 1px;
  background: #c0c4cc;
  margin-bottom: 4px;
  margin: 0 5px;
}
</style>
