<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="积分类型" prop="type">
        <el-select
          v-model="queryParams.type"
          placeholder="请选择积分类型"
          clearable
          filterable
        >
          <el-option
            v-for="dict in typeList"
            :key="dict.value + 'typeList'"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="数据类型" prop="dataType">
        <el-select
          v-model="queryParams.dataType"
          placeholder="请选择数据类型"
          clearable
          filterable
        >
          <el-option
            v-for="dict in dataTypeList"
            :key="dict.value + 'dataTypeList'"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </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:INTEGRAL: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="['business:INTEGRAL: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="['business:INTEGRAL: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="['business:INTEGRAL:export']"
          >导出</el-button
        >
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      
      :data="INTEGRALList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="积分类型" align="center" prop="type">
        <template slot-scope="scope">
          <span v-if="scope.row.type == 0">绩效积分</span>
          <span v-if="scope.row.type == 1">采集积分</span>
        </template>
      </el-table-column>
      <el-table-column label="保税区名称" align="center" prop="cbName">
        <template slot-scope="scope">
          {{ scope.row.cbName }}
        </template>
      </el-table-column>
      <el-table-column label="数据类型" align="center" prop="dataType">
        <template slot-scope="scope">
          <span v-if="scope.row.dataType == 0">量化指标数据</span>
          <span v-if="scope.row.dataType == 1">月报表数据</span>
        </template>
      </el-table-column>
      <el-table-column label="年份" align="center" prop="year">
        <template slot-scope="scope">
          {{ scope.row.year }}
        </template>
      </el-table-column>
      <el-table-column label="月份" align="center" prop="month">
        <template slot-scope="scope">
          {{ scope.row.month }}
        </template>
      </el-table-column>
      <el-table-column label="季度" align="center" prop="quarter">
        <template slot-scope="scope">
          {{ scope.row.quarter }}
        </template>
      </el-table-column>
      <el-table-column label="总积分" align="center" prop="sumScore">
        <template slot-scope="scope">
          {{ scope.row.sumScore }}
        </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="handleInfo(scope.row)"
            >查看
          </el-button>
          <!-- v-hasPermi="['business:INTEGRAL:edit']" -->
        </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="50%" append-to-body>
      <el-table  :data="form.feeVoList">
        <el-table-column label="采集指标名称" align="center" prop="normfeeName">
          <template slot-scope="scope">
            {{ scope.row.normfeeName }}
          </template>
        </el-table-column>
        <el-table-column label="采集值" align="center" prop="collValue">
          <template slot-scope="scope">
            {{ scope.row.collValue }}
          </template>
        </el-table-column>
        <el-table-column label="积分" align="center" prop="score">
          <template slot-scope="scope">
            {{ scope.row.score }}
          </template>
        </el-table-column>
        <!-- <el-table-column label="是否产生预警" align="center" prop="warningFlag">
          <template slot-scope="scope">
            <span v-if="scope.row.warningFlag == 0">否</span>
            <span v-if="scope.row.warningFlag == 1">是</span>
          </template>
        </el-table-column> -->
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">返回</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listINTEGRAL,
  getINTEGRAL,
  delINTEGRAL,
  addINTEGRAL,
  updateINTEGRAL,
} from "@/api/portal/INTEGRAL/INTEGRAL.js";

export default {
  name: "INTEGRAL",
  data() {
    return {
      typeList: [
        { label: "绩效积分", value: "0" },
        { label: "采集积分", value: "1" },
      ],
      dataTypeList: [
        { label: "量化指标数据", value: "0" },
        { label: "月报表数据", value: "1" },
      ],
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 保税区积分表格数据
      INTEGRALList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        delFlag: null,
        deptId: null,
        type: null,
        gatherId: null,
        cbId: null,
        cbName: null,
        dataType: null,
        year: null,
        month: null,
        quarter: null,
        remark: null,
        sumScore: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [{ required: true, message: "$comment不能为空", trigger: "blur" }],
        delFlag: [
          { required: true, message: "删除标识不能为空", trigger: "blur" },
        ],
        deptId: [
          { required: true, message: "部门标识不能为空", trigger: "blur" },
        ],
        type: [
          { required: true, message: "积分类型不能为空", trigger: "change" },
        ],
        gatherId: [
          { required: true, message: "采集单id不能为空", trigger: "blur" },
        ],
        cbId: [
          { required: true, message: "保税区id不能为空", trigger: "blur" },
        ],
        cbName: [
          { required: true, message: "保税区名称不能为空", trigger: "blur" },
        ],
        dataType: [
          { required: true, message: "数据类型不能为空", trigger: "change" },
        ],
        year: [{ required: true, message: "年份不能为空", trigger: "blur" }],
        month: [{ required: true, message: "月份不能为空", trigger: "blur" }],
        quarter: [{ required: true, message: "季度不能为空", trigger: "blur" }],
        remark: [{ required: true, message: "备注不能为空", trigger: "blur" }],
        sumScore: [
          { required: true, message: "总积分不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询保税区积分列表 */
    getList() {
      this.loading = true;
      listINTEGRAL(this.queryParams).then((response) => {
        this.INTEGRALList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        delFlag: null,
        deptId: null,
        type: null,
        gatherId: null,
        cbId: null,
        cbName: null,
        dataType: null,
        year: null,
        month: null,
        quarter: null,
        remark: null,
        sumScore: 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;
      getINTEGRAL(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改保税区积分";
      });
    },
    //查看详情
    handleInfo(row) {
      this.reset();
      const id = row.id || this.ids;
      this.loading = true;
      getINTEGRAL(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "详情";
        this.loading = false;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateINTEGRAL(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addINTEGRAL(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 delINTEGRAL(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "business/INTEGRAL/export",
        {
          ...this.queryParams,
        },
        `INTEGRAL_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
