<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="86px"
    >
      <!-- <el-form-item label="指标名称" prop="quotaName">
        <el-input v-model="queryParams.quotaName"></el-input>
      </el-form-item> -->
      <el-form-item label="保税区名称" prop="bondedName">
        <el-select
          v-model="queryParams.bondedName"
          placeholder="请选择保税区"
          clearable
          filterable
          @change="selectBondedChange"
          style="width: 100%"
        >
          <el-option
            v-for="item in deptList"
            :key="item.deptId"
            :label="item.deptName"
            :value="item.deptName"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="年份" prop="year">
        <el-date-picker
          v-model="queryParams.year"
          type="year"
          placeholder="请选择年份"
          size="mini"
          class="year-picker"
          format="yyyy 年"
          value-format="yyyy"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          @click="handleAdd"
          v-if="checkPermi(['business:QUOTABONDED:add'])"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          :disabled="single"
          @click="handleUpdate"
          v-if="checkPermi(['business:QUOTABONDED:edit'])"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          :disabled="multiple"
          @click="handleDelete"
          v-if="checkPermi(['business:QUOTABONDED:remove'])"
          >删除</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table :data="QUOTABONDEDList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="年份"
        align="center"
        prop="year"
      ></el-table-column>
      <el-table-column
        label="保税区名称"
        align="center"
        prop="bondedName"
      ></el-table-column>
      <el-table-column label="审核状态" align="center" prop="approvalStatus">
        <template slot-scope="scope">
          <span>{{
            scope.row.approvalStatus == 0 || scope.row.approvalStatus == null
              ? "未审核"
              : scope.row.approvalStatus == 1
              ? "审核中"
              : scope.row.approvalStatus == 2
              ? "审核通过"
              : "审核拒绝"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="审核时间"
        align="center"
        prop="approvalTime"
      ></el-table-column>
      <el-table-column
        label="审核人"
        align="center"
        prop="approvalName"
      ></el-table-column>
      <el-table-column label="上报状态" align="center" prop="reportStatus">
        <template slot-scope="scope">
          <span
            v-if="scope.row.reportStatus == 0 || scope.row.reportStatus == null"
            >未上报</span
          >
          <span v-if="scope.row.reportStatus == 1">已上报</span>
        </template>
      </el-table-column>
      <el-table-column
        label="上报人"
        align="center"
        prop="reportName"
      ></el-table-column>
      <el-table-column
        label="上报时间"
        align="center"
        prop="reportTime"
      ></el-table-column>
      <el-table-column label="操作" align="center" fixed="right" width="200">
        <template slot-scope="scope">
          <el-button
            v-if="
              (scope.row.auditStatus == 0 || scope.row.auditStatus == null) &&
              (scope.row.approvalStatus == 0 ||
                scope.row.approvalStatus == null ||
                scope.row.approvalStatus == 3) &&
              checkPermi(['gather:QUOTABONDED:audit'])
            "
            icon="el-icon-top"
            size="mini"
            type="text"
            @click="handleApprove(scope.row)"
            >提交审核</el-button
          >
          <!-- <el-button
            v-if="
              scope.row.auditStatus == 1 &&
              (scope.row.approvalStatus == 0 ||
                scope.row.approvalStatus == null) &&
              checkPermi(['business:QUOTABONDED:edit'])
            "
            size="mini"
            type="text"
            @click="handleAdminApprove(scope.row)"
            >审核</el-button
          > -->
          <el-button
            v-if="
              scope.row.approvalStatus == 2 &&
              (scope.row.reportStatus == 0 || scope.row.reportStatus == null) &&
              checkPermi(['gather:QUOTABONDED:report'])
            "
            size="mini"
            type="text"
            icon="el-icon-check"
            @click="handleReport(scope.row)"
            >上报</el-button
          >
          <el-button
            v-if="
              (scope.row.auditStatus == 0 || scope.row.auditStatus == null) &&
              (scope.row.approvalStatus == 0 ||
                scope.row.approvalStatus == null ||
                scope.row.approvalStatus == 3) &&
              checkPermi(['business:QUOTABONDED:edit'])
            "
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
            v-if="
              (scope.row.auditStatus == 0 || scope.row.auditStatus == null) &&
              (scope.row.approvalStatus == 0 ||
                scope.row.approvalStatus == null ||
                scope.row.approvalStatus == 3) &&
              checkPermi(['business:QUOTABONDED:remove'])
            "
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >

          <el-button
            v-if="checkPermi(['business:QUOTABONDED:query'])"
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleSelect(scope.row)"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-if="checkPermi(['business:QUOTABONDED:list'])"
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改辅助指标-综保区对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      :close-on-click-modal="false"
      width="900px"
      append-to-body
    >
      <!-- v-if="this.form.type == 0" -->
      <el-tabs v-model="activeName" type="border-card">
        <!-- @tab-click="handleClick" -->
        <el-tab-pane label="基本信息" name="基本信息">
          <el-form ref="forms" :model="form" :rules="rules">
            <el-form-item label-width="100px" label="年份" prop="year">
              <el-date-picker
                :disabled="isAppoval"
                v-model="form.year"
                type="year"
                placeholder="请选择年份"
                size="mini"
                class="year-picker"
                format="yyyy 年"
                value-format="yyyy"
                style="width: 60%"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label-width="100px" label="保税区" prop="bondedName">
              <el-select
                :disabled="isAppoval"
                v-model="form.bondedName"
                placeholder="请选择保税区"
                clearable
                filterable
                @change="selectBondedChange"
                style="width: 60%"
              >
                <el-option
                  v-for="item in deptList"
                  :key="item.deptId"
                  :label="item.deptName"
                  :value="item.deptName"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-tab-pane>



        <el-tab-pane
          label="指标项"
          name="指标项"
          v-if="QUOTAFEEList.length != 0"
        >
          <el-form ref="form" :model="form" :rules="rules">
            <!-- v-if="dict.remark == item.normId" -->
            <el-card
              class="box-card"
              v-for="(dict, index) in QUOTAFEEList"
              :key="dict.id"
              :value="dict"
              style="margin-bottom: 24px; font-weight: bold"
            >
              <div slot="header" style="margin-left: 30px; font-size: 15px">
                <el-row>
                  <el-col :span="12">
                    <el-form-item
                      label-width="90px"
                      prop="score"
                      label="指标："
                    >
                      <span>{{ dict.quotaName }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item
                      label-width="90px"
                      prop="score"
                      label="分数："
                    >
                      <el-input
                        :disabled="isAppoval"
                        v-model="dict.score"
                      ></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
              <!--          目前详情还没有返回，先在新增显示-->
              <div
                slot="header"
                style="margin-left: 30px; font-size: 15px"
                v-show="title == '辅助指标录入新增'"
              >
                <el-form-item
                  label-width="90px"
                  prop="score"
                  label="指标内容："
                >
                  <span>{{ dict.content }}</span>
                </el-form-item>
              </div>
              <el-form-item
                v-if="dict.confirmWay == '附件'"
                label-width="70px"
                prop="linkUrls"
                label="上传附件"
              >
                <el-upload
                  :on-exceed="exceedHandle"
                  :limit="1"
                  :disabled="isAppoval"
                  class="upload-demo"
                  ref="upload"
                  :headers="upload.headers"
                  :action="upload.url"
                  :on-success="handleFileSuccess.bind(null, index)"
                  :auto-upload="true"
                  :file-list="dict.fileList"
                  :on-remove="handleRemove"
                  :on-change="handleChange"
                >
                  <el-button
                    :disabled="isAppoval"
                    slot="trigger"
                    size="small"
                    type="primary"
                    >选取文件</el-button
                  >
                </el-upload>
              </el-form-item>
              <el-form-item
                v-if="dict.confirmWay == '文字说明'"
                label-width="70px"
                prop="remark"
                label="说明"
              >
                <el-input
                  type="textarea"
                  :disabled="isAppoval"
                  v-model="dict.remark"
                  rows="3"
                ></el-input>
              </el-form-item>
              <el-form-item
                v-if="dict.confirmWay == '数值'"
                label-width="70px"
                prop="numValue"
                label="数值"
              >
                <el-input
                  type="number"
                  :disabled="isAppoval"
                  v-model="dict.numValue"
                ></el-input>
              </el-form-item>
            </el-card>

            <!-- <el-form-item  label-width="100px" label="驳回理由">
          <el-input type="textarea" width="100%" v-model="form.test"></el-input>
        </el-form-item> -->
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="审核记录" name="审核记录" v-if="form.taskVoList">
          <div
            style="
              display: flex;
              align-items: center;
              justify-content: space-between;
            "
          >
            <p
              style="
                padding-right: 12px;
                margin: 0px;
                font-weight: 600;
                font-size: 14px;
                color: #606266;
                width: 100px;
                text-align: right;
              "
            >
              审核记录
            </p>
            <p
              style="
                color: #8cc8ff;
                border: 1px solid #3794eb;
                padding: 4px;
                border-radius: 4px;
              "
            >
              {{
                form.approvalStatus == 0 || form.approvalStatus == null
                  ? "未审核"
                  : form.approvalStatus == 1
                  ? "审核中"
                  : form.approvalStatus == 2
                  ? "审核通过"
                  : "审核拒绝"
              }}
            </p>
          </div>
          <el-timeline>
            <el-timeline-item
              v-for="(item, index) in form.taskVoList"
              :timestamp="item.createTime"
              placement="top"
              :key="index + 'taskHisAction'"
            >
              <el-card>
                <p>{{ item.execName }}{{ item.createTime }}</p>
                <p v-if="item.comments != null">{{ item.comments }}</p>
              </el-card>
            </el-timeline-item>
          </el-timeline>
        </el-tab-pane>

        <!-- <el-tab-pane v-for="it in tabList" :label="it.normName" :name="it.normName">
          <el-form v-model="QUOTAFEEList" v-for="(items,index) in QUOTAFEEList" v-if="it.normId == items.normId" >
            <el-form-item label="指标：">
              <span>{{ items.content }}</span>
            </el-form-item>

            <el-form-item  label="指标内容：">
              <span>{{ items.content }}</span>
            </el-form-item>

            <el-form-item
                v-if="items.confirmWay == '附件'"
                label-width="70px"
                prop="linkUrls"
                label="上传附件"
              >
                <el-upload
                  :disabled="isAppoval"
                  class="upload-demo"
                  ref="upload"
                  :headers="upload.headers"
                  :action="upload.url"
                  :on-success="handleFileSuccess.bind(null, index)"
                  :auto-upload="true"
                  :file-list="items.fileList"
                  :on-remove="handleRemove"
                  :on-change="handleChange"
                  :multiple="true"
                >
                  <el-button
                    :disabled="isAppoval"
                    slot="trigger"
                    size="small"
                    type="primary"
                    >选取文件</el-button
                  >
                </el-upload>
              </el-form-item>
              <el-form-item
                v-if="items.confirmWay == '文字说明'"
                label-width="70px"
                prop="remark"
                label="说明"
              >
                <el-input
                  type="textarea"
                  :disabled="isAppoval"
                  v-model="items.remark"
                  rows="5"
                ></el-input>
              </el-form-item>
              <el-form-item
                v-if="items.confirmWay == '数值'"
                label-width="70px"
                prop="numValue"
                label="数值"
              >
                <el-input
                  type="number"
                  :disabled="isAppoval"
                  v-model="items.numValue"
                ></el-input>
              </el-form-item>

          </el-form>
        </el-tab-pane> -->

      </el-tabs>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="!isAppoval" @click="submitForm"
          >确 定</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listQUOTABONDED,
  getQUOTABONDED,
  delQUOTABONDED,
  addQUOTABONDED,
  updateQUOTABONDED,
  setApprove,
  setAdminApprove,
  setAdminReport,
} from "@/api/norm/QUOTABONDED";
import { listQUOTAFEERole } from "@/api/norm/QUOTAFEE";
import { listAllBONDED } from "@/api/portal/BONDED/BONDED.js";
import { uploadFiles, downloadFiles } from "@/api/common";
import { listDept } from "@/api/system/dept";
import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
import { getToken } from "@/utils/auth";

import { getInfo } from "@/api/login.js";

export default {
  name: "QUOTABONDED",
  data() {
    return {
      // 标签数据
      tabList: [],
      activeName: "",

      user: null,
      // 查看修改
      check: false,

      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/common/upload",
      },
      uploadUrl: process.env.VUE_APP_BASE_API + "/common/uploads",
      isAppoval: false,
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 辅助指标-综保区表格数据
      QUOTABONDEDList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      QUOTAFEEList: [],
      BONDEDList: [],
      fileList: [],
      // 保税区列表
      deptList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bondedName: null,
        quotaName: null,
        year: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        year: [{ required: true, message: "年份不能为空", trigger: "blur" }],
        bondedName: [
          { required: true, message: "综保区名称不能为空", trigger: "blur" },
        ],
        quotaName: [
          { required: true, message: "指标名称不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.listQUOTAFEERole();
    // listAllBONDED().then((response) => {
    //   this.BONDEDList = response.rows;
    // });
    this.getList();
    this.getDeptList();
  },
  methods: {
    checkPermi,
    checkRole,


    listQUOTAFEERole() {
      listQUOTAFEERole().then((response) => {
        response.data.forEach((item, index) => {
          response.data[index].status = item.status == 0 ? false : true;
        });
        this.QUOTAFEEList = response.data;

        this.QUOTAFEEList.forEach((item) => {
          item.fileList = [];
          item.linkUrls = "";
          item.fileNames = "";
        });
        this.tabList = JSON.parse(JSON.stringify(response.data));

        for (var i = 0; i < this.tabList.length - 1; i++) {
          //设置激活的tab
          for (var j = i + 1; j < this.tabList.length; j++) {
            if (this.tabList[i].normId == this.tabList[j].normId) {
              this.tabList.splice(j, 1);
              //因为数组长度减小1，所以直接 j++ 会漏掉一个元素，所以要 j--
              j--;
            }
          }
        }
        this.activeName = "基本信息";
      });
    },
    // 获取保税区列表
    getDeptList() {
      this.loading = true;
      listDept({ parentId: "100" }).then((response) => {
        getInfo().then((res) => {
          this.user = res.user.roles[0];
          if (res.user.dept.type == 2) {
            response.data.forEach((item) => {
              if (item.deptId == res.user.dept.deptId) {
                this.deptList = [item];
                return;
              }
            });
            this.loading = false;
            return;
          } else if (res.user.dept.type == 1) {
            this.deptList = response.data;
          }
          this.loading = false;
        });
      });
    },
    selectBondedChange(val) {
      const selectedDept = this.deptList.find(
        (item) => item.deptName === this.form.bondedName
      );
      if (selectedDept) {
        this.form.bondedId = selectedDept.deptId;
      }
      // this.form.bondedId = val.id;
      // this.form.bondedName = val.bondedName;
    },
    selectQuotaChange(val) {
      this.form.quotaId = val.id;
      this.form.quotaName = val.quotaName;
    },
    /** 查询辅助指标-综保区列表 */
    getList() {
      this.loading = true;
      listQUOTABONDED(this.queryParams).then((response) => {
        this.QUOTABONDEDList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        delFlag: null,
        deptId: null,
        bondedId: null,
        bondedName: null,
        quotaId: null,
        quotaName: null,
        score: null,
        status: "1",
        startTime: null,
        stopTime: null,
        linkUrls: null,
        remark: null,
        fileNames: null,
        enterType: null,
        numValue: null,
      };
      this.fileList = [];
      this.resetForm("forms");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.multiple = !selection.length;

      if (selection.length == 0) {
        return;
      } else {
        if (
          selection.length < 2 &&
          (selection[0].auditStatus == 0 || selection[0].auditStatus == null) &&
          (selection[0].approvalStatus == 0 ||
            selection[0].approvalStatus == null ||
            selection[0].approvalStatus == 3)
        ) {
          this.single = false;
        } else {
          this.single = true;
        }
      }
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.listQUOTAFEERole();
      this.isAppoval = false;
      this.reset();
      this.open = true;
      this.title = "辅助指标录入新增";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getQUOTABONDED(id).then((response) => {
        this.form = response.data;
        this.isAppoval = false;
        this.QUOTAFEEList = response.data.bondedFeeList;
        this.QUOTAFEEList.forEach((item) => (item.fileList = []));
        this.QUOTAFEEList.forEach((item) => {
          item.fileList.push({ name: item.fileNames, url: item.linkUrls });
        });
        this.open = true;
        this.$forceUpdate();
        this.title = "辅助指标录入修改";
      });
    },

    handleSelect(row) {
      this.reset();
      const id = row.id || this.ids;
      getQUOTABONDED(id).then((response) => {
        this.isAppoval = true;
        this.form = response.data;
        this.QUOTAFEEList = response.data.bondedFeeList;
        this.QUOTAFEEList.forEach((item) => (item.fileList = []));
        this.QUOTAFEEList.forEach((item) => {
          item.fileList.push({ name: item.fileNames, url: item.linkUrls });
        });

        this.tabList = JSON.parse(JSON.stringify(response.data.bondedFeeList));

        for (var i = 0; i < this.tabList.length - 1; i++) {
          //设置激活的tab
          for (var j = i + 1; j < this.tabList.length; j++) {
            if (this.tabList[i].remark == this.tabList[j].remark) {
              this.tabList.splice(j, 1);
              //因为数组长度减小1，所以直接 j++ 会漏掉一个元素，所以要 j--
              j--;
            }
          }
        }

        this.activeName = "基本信息";

        this.open = true;
        this.$forceUpdate();
        this.title = "辅助指标录入详情";
      });
    },

    // 文件上传成功处理
    handleFileSuccess(index, response, file, fileList) {
      let linkUrls = "";
      let fileNames = "";
      fileList.forEach((item) => {
        linkUrls += item.response.fileName + ",";
        fileNames += item.response.newFileName + ",";
      });
      this.QUOTAFEEList.forEach((item, key) => {
        if (key == index) {
          item.linkUrls = linkUrls;
          item.fileNames = fileNames;
        }
      });
    },
    /** 提交按钮 */
    async submitForm() {
      this.form.bondedFeeList = this.QUOTAFEEList;
      this.$refs["form"].validate((valid) => {
        if (valid) {
          /*if (!(parseInt(this.form.score) == this.form.score)) {
            this.$message.error("得分必须为整数");
            return;
          }
          if (this.form.enterType == "文字说明" && this.form.remark == null) {
            this.$message.error("请录入文字说明");
            return;
          }
          if (this.form.enterType == "数值" && this.form.numValue == null) {
            this.$message.error("请录入数值");
            return;
          }
          if (
            this.form.numValue != null &&
            !(
              parseInt(this.form.numValue) == this.form.numValue ||
              parseFloat(this.form.numValue) == this.form.numValue
            )
          ) {
            this.$message.error("数值必须为整数或小数");
            return;
          }*/
          if (this.form.id != null) {
            if (this.form.enterType == "附件") {
              if (this.fileList.length < 1) {
                this.$message.error("请选择文件传输！");
                return;
              } else {
                if (this.fileList[0].url == undefined) {
                  let formData = new FormData();
                  this.fileList.forEach((item) => {
                    formData.append("file", item.raw);
                  });
                  uploadFiles(formData).then((res) => {
                    if (res.code == 200) {
                      this.form.bondedFeeList.forEach((item) => {
                        if (item.confirmWay == "附件") {
                          item.linkUrls = res.fileNames;
                          item.fileNames = res.newFileNames;
                        }
                      });
                      //this.form.linkUrls = res.fileNames;
                      //this.form.fileNames = res.newFileNames;
                      updateQUOTABONDED(this.form).then((response) => {
                        this.$modal.msgSuccess("修改成功");
                        this.open = false;
                        this.getList();
                      });
                    }
                  });
                } else {
                  updateQUOTABONDED(this.form).then((response) => {
                    this.$modal.msgSuccess("修改成功");
                    this.open = false;
                    this.getList();
                  });
                }
              }
            } else {
              updateQUOTABONDED(this.form).then((response) => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            }
          } else {
            if (this.form.enterType == "附件") {
              if (this.fileList.length < 1) {
                this.$message.error("请选择文件传输！");
                return;
              } else {
                let formData = new FormData();
                this.fileList.forEach((item) => {
                  formData.append("file", item.raw);
                });
                uploadFiles(formData).then((res) => {
                  if (res.code == 200) {
                    this.form.bondedFeeList.forEach((item) => {
                      if (item.confirmWay == "附件") {
                        item.linkUrls = res.fileNames;
                        item.fileNames = res.newFileNames;
                      }
                    });
                    //this.form.linkUrls = res.fileNames;
                    //this.form.fileNames = res.newFileNames;
                    addQUOTABONDED(this.form).then((response) => {
                      this.$modal.msgSuccess("新增成功");
                      this.open = false;
                      this.getList();
                    });
                  }
                });
              }
            } else {
              addQUOTABONDED(this.form).then((response) => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        }
      });
    },
    // 管理员驳回审核
    setRejectAndResolve(type) {
      let val;
      if (type == "resolve") {
        val = 1;
      } else {
        val = 2;
      }
      setAdminApprove({ quotoBondedId: this.form.id, type: val }).then(
        (res) => {
          if (res.code == 200) {
            this.$message.success(val == 1 ? "审核成功" : "驳回成功");
            this.getList();
            this.open = false;
          }
        }
      );
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除辅助指标-综保区编号为"' + ids + '"的数据项？')
        .then(function () {
          return delQUOTABONDED(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },

    // 用户提交审核
    handleApprove(data) {
      setApprove({ quotoBondedId: data.id }).then((res) => {
        if (res.code == 200) {
          this.$message.success("提交成功");
          this.getList();
        }
      });
    },
    // 管理审核审核
    handleAdminApprove(row) {
      this.reset();
      const id = row.id || this.ids;
      this.isAppoval = true;
      getQUOTABONDED(id).then((response) => {
        this.form = response.data;
        this.form.linkUrls = this.baseURL + response.data.linkUrls;
        this.fileList = [];
        this.fileList.push({
          name: response.data.fileNames,
          url: response.data.linkUrls,
        });
        this.open = true;
        this.title = "辅助指标录入修改";
      });
    },
    // 管理上报
    handleReport(data) {
      setAdminReport({ quotoBondedId: data.id, type: 1 }).then((res) => {
        if (res.code == 200) {
          this.$message.success("上报成功");
          this.getList();
        }
      });
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "business/QUOTABONDED/export",
        {
          ...this.queryParams,
        },
        `QUOTABONDED_${new Date().getTime()}.xlsx`
      );
    },

    handleChange(file, fileList) {},
    handleRemove(file, fileList) {
      this.fileList = fileList;
    },
    exceedHandle(files, fileList){
      this.$message.warning("只能上传一个附件");
    },
    download(resource) {
      let fileNames = resource.split(",");
      fileNames.forEach((item) => {
        downloadFiles("/profile/upload/" + item);
      });
    },
  },
};
</script>
