<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="费用名称" prop="feeName">
        <el-input
          v-model="queryParams.feeName"
          placeholder="请输入费用名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </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"
        >新增</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="['system:for: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="['system:for:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="forList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="费用名称" align="center" prop="feeName" />
      <el-table-column label="使用人" align="center" prop="userIdName" />
      <el-table-column label="经办人" align="center" prop="handledByUserIdName" >
        <template slot-scope="scope">
          <span v-if="scope.row.handledByUserIdName == null">-</span>
          <span>{{scope.row.handledByUserIdName}}</span>
        </template>
      </el-table-column>
      <el-table-column label="审批人" align="center" prop="approvedUserIdName" >
        <template slot-scope="scope">
          <span v-if="scope.row.approvedUserIdName == null">-</span>
          <span>{{scope.row.approvedUserIdName}}</span>
        </template>
      </el-table-column>
      <el-table-column label="用途说明" align="center" prop="applicationDescription" >
        <template slot-scope="scope">
        <span v-if="scope.row.applicationDescription == null">-</span>
        <span>{{scope.row.applicationDescription}}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="大写合计" align="center" prop="totalWords" />-->
      <el-table-column label="小写合计" align="center" prop="totalFigures" />
      <el-table-column label="申请时间" align="center" prop="registrationDate" width="180">
        <template slot-scope="scope">
          <span v-if="scope.row.registrationDate == null">-</span>
          <span>{{scope.row.registrationDate}}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" >
        <template slot-scope="scope">
          <span v-if="scope.row.remark == null">-</span>
          <span>{{scope.row.remark}}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="eventLevel">
        <template slot-scope="scope">
          <span v-if="scope.row.approvalStatus == null">-</span>
          <span v-if="scope.row.approvalStatus == 1">待核算部审批</span>
          <span v-if="scope.row.approvalStatus == 2">完成</span>
          <span v-if="scope.row.approvalStatus == 3">驳回</span>
        </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="details(scope.row)"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-if="scope.row.approvalStatus == 1&&roleKey==1"
            @click="handleUpdate(scope.row)"
          >审批</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            v-if="(scope.row.approvalStatus == 1||scope.row.approvalStatus == 3)&&scope.row.handledByUserId==$store.state.user.userId"
            @click="handleDelete(scope.row)"
          >删除</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="inser" width="800px"  :close-on-click-modal="false" destroy-on-close>
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
              <el-row>
                <el-col :span="12">
              <el-form-item label="费用名称" prop="feeName">
                <el-input v-model="form.feeName" placeholder="请输入费用名称" />
              </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="使用人" prop="userId">
                    <el-select v-model="form.userId" placeholder="请选择使用人" style="width: 100%">
                      <el-option v-for="item in transactorList"
                                 :key="item.userId"
                                 :label="item.nickName"
                                 :value="item.userId"/>
                    </el-select>
                  </el-form-item>
                </el-col>
      <!--          <el-col :span="12">-->
      <!--            <el-form-item label="借支部门" prop="borrowingDeptId">-->
      <!--              <treeselect-->
      <!--                v-model="form.borrowingDeptId"-->
      <!--                :options="formDeptOptions"-->
      <!--                :show-count="true"-->
      <!--                placeholder="请选择部门"-->
      <!--              />-->
      <!--            </el-form-item>-->
      <!--          </el-col>-->
              </el-row>

              <el-row>
      <!--          <el-col :span="12">-->
      <!--            <el-form-item label="登记日期" prop="registrationDate" >-->
      <!--              <el-date-picker clearable-->
      <!--                              v-model="form.registrationDate"-->
      <!--                              type="date"-->
      <!--                              value-format="yyyy-MM-dd"-->
      <!--                              placeholder="选择登记日期"-->
      <!--                              style="width: 100%;">-->
      <!--              </el-date-picker>-->
      <!--            </el-form-item>-->
      <!--          </el-col>-->

                <el-col :span="24">
                  <el-form-item label="小写合计" prop="totalFigures">
                    <el-input v-model="form.totalFigures" placeholder="请输入小写合计" />
                  </el-form-item>
                </el-col>
              </el-row>

      <!--        <el-row>-->
      <!--          <el-col :span="12">-->
      <!--        <el-form-item label="大写合计" prop="totalWords">-->
      <!--          <el-input v-model="form.totalWords" placeholder="请输入大写合计" />-->
      <!--        </el-form-item>-->
      <!--          </el-col>-->
      <!--        </el-row>-->



                  <el-form-item label="用途说明" prop="applicationDescription">
                    <el-input v-model="form.applicationDescription" type="textarea" placeholder="请输入用途说明" />
                  </el-form-item>


              <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" type="textarea" placeholder="请输入备注" />
              </el-form-item>


<!--              <el-form-item   v-if="form.attachmentUrl !=null" label="附件" prop="attachmentUrl">-->
<!--              <div style="height: 60px;width: 100px;margin-top: 5px">-->
<!--                <img  @click="godown(form.attachmentUrl)" v-if="ispictrue(form.attachmentUrl)" style="width: 100%;height: 100%"/>-->
<!--                <img  @click="godown(form.attachmentUrl)" v-if="!ispictrue(form.attachmentUrl)" style="width: 100%;height: 100%"/>-->
<!--              </div>-->
<!--              </el-form-item>-->

              <el-form-item v-if="form.borrowing ==null" label="附件" prop="attachmentUrl">
                <FileUpload
                  listType="picture"
                  @resFun="getFileInfo"
                  @remove="listRemove"
                  :fileArr="fileList"
                  :fileSize="500"
                  :fileType="[
                    'png',
                    'jpg',
                    'jpeg',
                    'mp4',
                    'doc',
                    'xls',
                    'ppt',
                    'txt',
                    'pdf',
                  ]"
                />
                <el-input
                  v-show="false"
                  disabled
                  v-model="form.attachmentUrl"
                ></el-input>
              </el-form-item>
            </el-form>

      <div slot="footer" class="dialog-footer"  style="text-align: center" >
        <el-button  v-if="this.form.borrowing ==null" type="primary" style="width: 150px" @click="submitForm"
        >提交申请</el-button
        >
        <el-button style="width: 150px; border-color: #1890ff; color: #1890ff" @click="cancel">取 消</el-button>
      </div>

    </el-dialog>

    <!-- 审批 -->
    <el-dialog  :title="title" :visible.sync="open" width="800px"  :close-on-click-modal="false" destroy-on-close>
<!--      <el-form ref="form" :model="form" :rules="rules" label-width="100px">-->
<!--        <el-row>-->
<!--          <el-col :span="12">-->
<!--        <el-form-item label="费用名称" prop="feeName">-->
<!--          <el-input v-model="form.feeName" placeholder="请输入费用名称" />-->
<!--        </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="使用人" prop="userId">-->
<!--              <el-select v-model="form.userId" placeholder="请选择使用人" style="width: 100%">-->
<!--                <el-option v-for="item in transactorList"-->
<!--                           :key="item.userId"-->
<!--                           :label="item.nickName"-->
<!--                           :value="item.userId"/>-->
<!--              </el-select>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--&lt;!&ndash;          <el-col :span="12">&ndash;&gt;-->
<!--&lt;!&ndash;            <el-form-item label="借支部门" prop="borrowingDeptId">&ndash;&gt;-->
<!--&lt;!&ndash;              <treeselect&ndash;&gt;-->
<!--&lt;!&ndash;                v-model="form.borrowingDeptId"&ndash;&gt;-->
<!--&lt;!&ndash;                :options="formDeptOptions"&ndash;&gt;-->
<!--&lt;!&ndash;                :show-count="true"&ndash;&gt;-->
<!--&lt;!&ndash;                placeholder="请选择部门"&ndash;&gt;-->
<!--&lt;!&ndash;              />&ndash;&gt;-->
<!--&lt;!&ndash;            </el-form-item>&ndash;&gt;-->
<!--&lt;!&ndash;          </el-col>&ndash;&gt;-->
<!--        </el-row>-->

<!--        <el-row>-->
<!--&lt;!&ndash;          <el-col :span="12">&ndash;&gt;-->
<!--&lt;!&ndash;            <el-form-item label="登记日期" prop="registrationDate" >&ndash;&gt;-->
<!--&lt;!&ndash;              <el-date-picker clearable&ndash;&gt;-->
<!--&lt;!&ndash;                              v-model="form.registrationDate"&ndash;&gt;-->
<!--&lt;!&ndash;                              type="date"&ndash;&gt;-->
<!--&lt;!&ndash;                              value-format="yyyy-MM-dd"&ndash;&gt;-->
<!--&lt;!&ndash;                              placeholder="选择登记日期"&ndash;&gt;-->
<!--&lt;!&ndash;                              style="width: 100%;">&ndash;&gt;-->
<!--&lt;!&ndash;              </el-date-picker>&ndash;&gt;-->
<!--&lt;!&ndash;            </el-form-item>&ndash;&gt;-->
<!--&lt;!&ndash;          </el-col>&ndash;&gt;-->

<!--          <el-col :span="24">-->
<!--            <el-form-item label="小写合计" prop="totalFigures">-->
<!--              <el-input v-model="form.totalFigures" placeholder="请输入小写合计" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->

<!--&lt;!&ndash;        <el-row>&ndash;&gt;-->
<!--&lt;!&ndash;          <el-col :span="12">&ndash;&gt;-->
<!--&lt;!&ndash;        <el-form-item label="大写合计" prop="totalWords">&ndash;&gt;-->
<!--&lt;!&ndash;          <el-input v-model="form.totalWords" placeholder="请输入大写合计" />&ndash;&gt;-->
<!--&lt;!&ndash;        </el-form-item>&ndash;&gt;-->
<!--&lt;!&ndash;          </el-col>&ndash;&gt;-->
<!--&lt;!&ndash;        </el-row>&ndash;&gt;-->



<!--            <el-form-item label="用途说明" prop="applicationDescription">-->
<!--              <el-input v-model="form.applicationDescription" type="textarea" placeholder="请输入用途说明" />-->
<!--            </el-form-item>-->


<!--        <el-form-item label="备注" prop="remark">-->
<!--          <el-input v-model="form.remark" type="textarea" placeholder="请输入备注" />-->
<!--        </el-form-item>-->


<!--        <el-form-item   v-if="form.borrowing !=null" label="附件" prop="attachmentUrl">-->
<!--        <div style="height: 60px;width: 100px;margin-top: 5px">-->
<!--          <img  @click="godown(form.attachmentUrl)" v-if="ispictrue(form.attachmentUrl)" style="width: 100%;height: 100%"/>-->
<!--          <img  @click="godown(form.attachmentUrl)" v-if="!ispictrue(form.attachmentUrl)" style="width: 100%;height: 100%"/>-->
<!--        </div>-->
<!--        </el-form-item>-->

<!--        <el-form-item v-if="form.borrowing ==null" label="附件" prop="attachmentUrl">-->
<!--          <FileUpload-->
<!--            listType="picture"-->
<!--            @resFun="getFileInfo"-->
<!--            @remove="listRemove"-->
<!--            :fileArr="fileList"-->
<!--            :fileSize="500"-->
<!--            :fileType="[-->
<!--              'png',-->
<!--              'jpg',-->
<!--              'jpeg',-->
<!--              'mp4',-->
<!--              'doc',-->
<!--              'xls',-->
<!--              'ppt',-->
<!--              'txt',-->
<!--              'pdf',-->
<!--            ]"-->
<!--          />-->
<!--          <el-input-->
<!--            v-show="false"-->
<!--            disabled-->
<!--            v-model="form.attachmentUrl"-->
<!--          ></el-input>-->
<!--        </el-form-item>-->

<!--      </el-form>-->

      <el-form label-width="80px"  ref="form" :model="form">
        <el-row style="height: 15px">
          <el-col :span="7">
            <el-form-item label="费用名称">{{form.feeName}}</el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="使用人">{{form.userIdName}}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="经办人">{{form.handledByUserIdName}}</el-form-item>
          </el-col>
<!--          <el-col :span="5">-->
<!--            <el-form-item label="审批人">{{form.approvedUserIdName}}</el-form-item>-->
<!--          </el-col>-->

        </el-row>
        <el-divider></el-divider>
        <el-row style="height: 15px">
          <el-col :span="7">
            <el-form-item label="借支部门">{{form.deptName}}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="申请时间">{{form.registrationDate}}</el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="小写合计">{{form.totalFigures}}</el-form-item>
          </el-col>
        </el-row>
        <el-divider></el-divider>
        <el-row>
          <el-col :span="24">
            <el-form-item label="用途说明" v-if="form.applicationDescription!=null">{{form.applicationDescription}}</el-form-item>
            <el-form-item label="用途说明">-</el-form-item>
          </el-col>
        </el-row>
        <el-divider></el-divider>
        <el-row >
          <el-col :span="24">
            <el-form-item label="备注" v-if="form.remark!=null">{{form.remark}}</el-form-item>
            <el-form-item label="备注">-</el-form-item>
          </el-col>
        </el-row>
        <el-divider></el-divider>

<!--        <el-row>-->
<!--          <el-col :span="24">-->
<!--            <el-form-item label="审批人">{{form.approvedUserIdName}}</el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->

<!--        <el-divider></el-divider>-->
        <el-row>
          <el-col :span="24">
            <el-form-item   v-if="form.attachmentUrl !=null" label="附件" prop="attachmentUrl">
              <div style="height: 60px;width: 100px;margin-top: 5px">
                <img  @click="godown(form.attachmentUrl)" v-if="ispictrue(form.attachmentUrl)" style="width: 100%;height: 100%" src="@/assets/images/wenjian.png"/>
                <img  @click="godown(form.attachmentUrl)" v-if="!ispictrue(form.attachmentUrl)" style="width: 100%;height: 100%" src="@/assets/images/wenjian.png"/>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider  v-if="form.attachmentUrl !=null"></el-divider>
      </el-form>

      <div slot="footer" class="dialog-footer"  style="text-align: center" >
        <el-button  v-if="this.form.borrowing !=null"  type="primary" style="width: 150px" @click="submitForm(2)"
        >通过</el-button
        >

        <el-button v-if="this.form.borrowing !=null" type="primary" style="width: 150px" @click="submitForm(3)"
        >驳回</el-button
        >
        <el-button style="width: 150px; border-color: #1890ff; color: #1890ff" @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 详情对话框 -->
    <el-dialog :title="title" :visible.sync="detail" width="800px" :close-on-click-modal="false" destroy-on-close>
      <el-form label-width="100px" ref="form" :model="form">
        <el-row style="height: 15px">
          <el-col :span="7">
            <el-form-item label="费用名称">{{form.feeName}}</el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="使用人">{{form.userIdName}}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="经办人">{{form.handledByUserIdName}}</el-form-item>
          </el-col>
        </el-row>
        <el-divider></el-divider>
        <el-row style="height: 15px">
          <el-col :span="7">
            <el-form-item label="借支部门">{{form.deptName}}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="申请时间">{{form.registrationDate}}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="审批时间" v-if="form.approvalTime!=null">{{form.approvalTime}}</el-form-item>
            <el-form-item label="审批时间" v-else>-</el-form-item>
          </el-col>
        </el-row>
        <el-divider></el-divider>


        <el-row style="height: 15px">
          <el-col :span="7">
            <el-form-item label="小写合计" v-if="form.totalFigures!=null">{{form.totalFigures}}</el-form-item>
            <el-form-item label="小写合计" v-else>-</el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="用途说明" v-if="form.applicationDescription!=null">{{form.applicationDescription}}</el-form-item>
            <el-form-item label="用途说明" v-else>-</el-form-item>
          </el-col>

        </el-row>


        <el-divider></el-divider>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" v-if="form.remark!=null">{{form.remark}}</el-form-item>
            <el-form-item label="备注" v-else>-</el-form-item>
          </el-col>
        </el-row>
        <el-divider></el-divider>

        <el-row>
          <el-col :span="24">
            <el-form-item label="审批人" v-if="form.approvedUserIdName!=null">{{form.approvedUserIdName}}</el-form-item>
            <el-form-item label="审批人" v-else>-</el-form-item>
          </el-col>
        </el-row>

        <el-divider></el-divider>
        <el-row>
          <el-col :span="24">
            <el-form-item   v-if="form.attachmentUrl !=null" label="附件" prop="attachmentUrl">
              <div style="height: 60px;width: 100px;margin-top: 5px">
                <img  @click="godown(form.attachmentUrl)" v-if="ispictrue(form.attachmentUrl)" style="width: 100%;height: 100%" src="@/assets/images/wenjian.png"/>
                <img  @click="godown(form.attachmentUrl)" v-if="!ispictrue(form.attachmentUrl)" style="width: 100%;height: 100%" src="@/assets/images/wenjian.png"/>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider  v-if="form.attachmentUrl !=null"></el-divider>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { listFor, getFor, delFor, addFor, updateFor, exportFor ,getDepartmentBalance } from "@/api/system/for";
import { selectTransactorByDeptId,listUser,listpersonnel } from "@/api/system/user";
import Treeselect from "@riophae/vue-treeselect";
import { treeselect } from "@/api/system/dept";
import FileUpload from "@/components/FileUpload";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "For",
  components: {
    Treeselect,
    FileUpload,
  },
  data() {
    return {
      //权限判断
      roleKey:"",
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 借支申请表格数据
      forList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //添加弹出层
      inser:false,
      //详情弹出层
      detail:false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        feeName: null,
        borrowingDeptId: null,
        handledByUserId: null,
        applicationDescription: null,
        userId: null,
        totalWords: null,
        totalFigures: null,
        approvedUserId: null,
        registrationDate: null,
        attachmentUrl: null,
        isDel: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        feeName: [
          { required: true, message: "费用名称名称不能为空", trigger: "blur" },
        ],
        totalFigures: [
          { required: true, message: "小写合计不能为空", trigger: "blur" },
        ],
        userId: [
          { required: true, message: "使用人不能为空", trigger: "blur" },
        ],
      },
      formDeptOptions: [],
      transactorList: [],
      fileList: [],
    };
  },
  listRemove(e) {
    this.fileList = [];
    this.form.attachmentUrl = "";
  },
  created() {
    this.getTreeselect();
    this.getList();
  },
  watch:{
    "form.borrowingDeptId":{
      handler(newValue, oldValue){
        // this.changeDept();
        this.getTransactor();
      },
      deep: true,
    },
  },
  methods: {
    getFileInfo(res) {
      this.form.attachmentUrl = res.url;
      this.fileList = [
        {
          name: res.fileName,
          url: uploadfile,
        },
      ];
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then((response) => {
        this.deptOptions = response.data;
        this.formDeptOptions = response.data;

        // 申请服务时买方不能选自己部门
        // var items = this.formDeptOptions[0].children;
        // var result = [];
        // var j=0;
        // for(var i=0; i<items.length; i++){
        //   if(items[i].id != this.$store.state.user.deptId){
        //     result[j] = items[i];
        //     j++;
        //   }
        // }
        // this.formDeptOptions[0].children = result;
      });
    },
    getTransactor() {
      this.form.tradeTransactor = null;
      // if (this.form.borrowingDeptId && this.form.borrowingDeptId != null) {
        // this.form.deptId=this.form.borrowingDeptId;
      listpersonnel().then(
          (res) => {
            this.transactorList = res.rows;
          }
        );
      // }
    },
    /** 查询借支申请列表 */
    getList() {
      this.loading = true;
      listFor(this.queryParams).then(response => {
        console.log(response.permissionSymbol)
         this.roleKey=response.permissionSymbol;

        this.forList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.inser=false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        borrowing: null,
        feeName: null,
        borrowingDeptId: null,
        handledByUserId: null,
        applicationDescription: null,
        userId: null,
        totalWords: null,
        totalFigures: null,
        approvedUserId: null,
        registrationDate: null,
        remark: null,
        attachmentUrl: null,
        isDel: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
      this.fileList = [];
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.borrowing)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.fileList = [];
      this.transactorList=[];
      this.reset();
      this.inser = true;
      this.title = "借支申请";
    },
    /**详情*/
    details(row){
      this.reset();
      const borrowing = row.borrowing || this.ids
      getFor(borrowing).then(response => {
        this.form = response.data;
        this.detail = true;
        this.title = "详情信息";
      });
      this.form.attachmentUrl = this.form.attachmentUrl;
      this.fileList = [
        {
          name: res.fileName,
          url: uploadfile,
        },
      ];


      treeselect().then((response) => {
        this.formDeptOptions = response.data;

        // 申请服务时买方不能选自己部门
        var items = this.formDeptOptions[0].children;
        var result = [];
        var j=0;
        for(var i=0; i<items.length; i++){
          if(items[i].id != this.$store.state.user.deptId){
            result[j] = items[i];
            j++;
          }
        }
        this.formDeptOptions[0].children = result;
      });

    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const borrowing = row.borrowing || this.ids
      getFor(borrowing).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "审批借支申请";
      });
      this.form.attachmentUrl = this.form.attachmentUrl;
      this.fileList = [
        {
          name: res.fileName,
          url: uploadfile,
        },
      ];


      treeselect().then((response) => {
        this.formDeptOptions = response.data;

        // 申请服务时买方不能选自己部门
        var items = this.formDeptOptions[0].children;
        var result = [];
        var j=0;
        for(var i=0; i<items.length; i++){
          if(items[i].id != this.$store.state.user.deptId){
            result[j] = items[i];
            j++;
          }
        }
        this.formDeptOptions[0].children = result;
      });

    },
    /** 提交按钮 */
    submitForm(row) {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.borrowing != null) {
            this.form.approvalStatus=row;
            updateFor(this.form).then(response => {
              if (response==2){
                this.$message.error('部门余额不足');
              }else{
                // alert("审批成功")
                this.msgSuccess("审批成功");
                this.open = false;
                this.getList();
              }

            });
          } else {
            getDepartmentBalance(this.form).then(response => {
              if (response==2){
                this.$message.error('部门余额不足');

              }else{
                addFor(this.form).then(response => {
                  this.msgSuccess("申请提交");
                  this.inser = false;
                  this.getList();
                });

              }
            })

          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const borrowings = row.borrowing || this.ids;
      this.$confirm('是否确认删除此数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delFor(borrowings);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有借支申请数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportFor(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    },
    godown(src){
      window.open(src);
    },
    ispictrue(src){
      var pattern = /(\.jpg|\.jpeg|\.png|\.gif)$/i;
      //console.log()
      return pattern.test(src);
    },
  }
};
</script>
<style scoped lang="scss">
  .outer-div {
    //padding: 24px;
    margin: 0 auto;
  }
  .header {
    height: 47px;
    width: 100%;
    //border-bottom: 1px solid #ebebeb;
    //margin-bottom: 24px;
  }
  /*ul li {*/
  /*  margin: 0;*/
  /*  padding: 0;*/
  /*  list-style: none;*/
  /*}*/
  .tab-tilte {
    font-family: PingFangSC-Semibold;
    letter-spacing: 0;
    width: 90%;
    padding-left: 0;
  }
  .tab-tilte li {
    float: left;
    font-size: 16px;
    color: #999999;
    // line-height: 53px;
    text-align: center;
    margin-right: 30px;
    cursor: pointer;
  }
  /* 点击对应的标题添加对应的背景颜色 */
  .tab-tilte .active {
    color: #3385ff;
    // border-bottom: 2px solid #3385ff;
  }

  .applyService {
    float: right;
    width: 124px;
    border-radius: 18px;
    color: white;
    background: #1890ff;
  }
</style>

