<!--
  @description: 保证金退回审批
  @Modifier: 肖文龙
  @routerPath: /fee/bailfeeRefundAudit-list
  @date: 2020/03/30-17:40
-->
<template>
  <div>
    <div class="title title_border p0-16">
      <i class="el-icon-s-home" />保证金退回审批
    </div>
    <section class="p0-16">
      <!--查询条件-->
      <div class="crud_menu_title clearfix">
        <span class="icon-line fl">查询条件</span>
        <span class="fr pointer" @click="handleToggleSearch">
          <el-link :underline="false" :class="toggleSearchStatus?'arrow-is-active':''" type="primary" class="toggleSearchStatus icon el-icon-arrow-down" />
          {{ toggleSearchStatus?'收起高级查询' :'展开高级查询' }}
        </span>
      </div>
      <section :class="{'SearchContent_show':toggleSearchStatus}" class="clearfix SearchContent">
        <div class="SearchContent_leftInput fl">
          <el-form
            ref="searchForm"
            :model="searchForm"
            inline
            label-width="120px"
            label-position="left"
          >
            <!-- 项目名称 -->
            <el-form-item
              label="项目名称"
            >
              <el-input
                v-model.trim="searchForm.tenderName"
                style="width:220px"
                placeholder="项目名称"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!-- 项目编号 -->
            <el-form-item
              label="项目编号"
              prop="refundStatus"
            >
              <el-input
                v-model.trim="searchForm.tenderNo"
                style="width:220px"
                placeholder="项目编号"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!-- 标段（包）名称 -->
            <el-form-item
              label="标段（包）名称"
              prop="packName"
            >
              <el-input
                v-model.trim="searchForm.packName"
                style="width:220px"
                placeholder="标段（包）名称"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!-- 标段（包）编号 -->
            <el-form-item
              label="标段（包）编号"
              prop="packNo"
            >
              <el-input
                v-model.trim="searchForm.packNo"
                style="width:220px"
                placeholder="标段（包）编号"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!-- 提交时间 -->
            <el-form-item v-if="bailShowShielding" label="提交时间">
              <el-date-picker
                v-model="createTime"
                :default-time="defaultTimerange"
                value-format="momentSaveFormat"
                style="width:220px"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              />
            </el-form-item>
          </el-form>
        </div>
        <div class="fr">
          <el-button type="primary" @click="onSearch">
            搜 索
          </el-button>
          <el-button plain type="info" @click="resetForm('searchForm')">
            重 置
          </el-button>
        </div>
      </section>
      <el-tabs v-model="activeName">
        <el-tab-pane :label="isShieldingActiveName" name="00" />
        <el-tab-pane v-if="bailShowShielding" label="错误来源" name="01" />
      </el-tabs>
      <div class="mb10">
        <el-button type="primary" @click="allAudit">
          批量审批通过
        </el-button>
      </div>
      <section>
        <el-table
          ref="multipleTable"
          :data="tableData"
          :row-key="getRowKeys"
          @selection-change="onSelect"
        >
          <el-table-column
            type="selection"
            width="55"
            align="center"
          />
          <el-table-column
            type="index"
            label="序号"
            width="60px"
            align="center"
          />
          <!-- 项目名称  -->
          <el-table-column

            header-align="center"
            prop="tenderName"
            label="项目名称"
            min-width="300"
          />
          <!-- 项目名称 -->
          <el-table-column
            header-align="center"
            prop="tenderNo"
            label="项目编号"
            align="center"
            width="160"
          />
          <!-- 标段（包）名称 -->
          <el-table-column
            header-align="center"
            prop="packName"
            label="标段（包）名称"
            min-width="300"
          />
          <!-- 标段（包）编号 -->
          <el-table-column
            header-align="center"
            label="标段（包）编号"
            prop="packNo"
            width="160px"
          />
          <!-- 提交时间 -->
          <el-table-column
            label="提交时间"
            prop="createTime"
            align="center"
            width="130"
          />
          <!-- 操作 -->
          <el-table-column
            header-align="center"
            label="操作"
            width="60"
          >
            <template slot-scope="scope">
              <el-link
                v-if="scope.row.auditStatus === '00'"
                type="primary"
                @click.stop="audit(scope.row)"
              >
                [审批]
              </el-link>
              <el-link
                v-else
                type="primary"
                @click.stop="audit(scope.row)"
              >
                [查看]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="loadData" />
      </section>
    </section>
  </div>
</template>
<script>
/* 接口*/
import { queryWaiteAuditDetailList, auditPassOrReject } from '@api/fee/bailfee'
/* 公用方法*/
import { restoreInitialValue, filterObj } from '@/assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { cashDepositGroupMixin } from '../mixins/cashDepositGroupMixin'
import { depositSystemConfig } from '../mixins/depositSystemConfig'
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页

export default {
  name: 'BailfeeRefundAuditList',
  components: {
    pagination// 分页
  },
  mixins: [ListMixin, cashDepositGroupMixin, depositSystemConfig],
  data() {
    return {
      confirmLoading: true,
      activeName: '00', // 是否非错误来源 00 非错误来原 01错误来源
      // 搜索
      createTime: [], // 提交时间
      searchForm: {
        errorStatus: '', // 是否错误来账 00正常 01错误
        packName: '', // 标段名称
        packNo: '', // 标段编号
        tenderName: '', // 项目名称
        tenderNo: '', // 项目编号
        submitEndTime: '', // 提交结束时间
        submitStartTime: '' // 提交开始时间
      },
      tableData: [], // 列表
      tableDataSelect: [], // 选择的信息
      isShieldingActiveName: '' // 根据是否简单功能tab页文案显示不同
    }
  },
  watch: {
    // 提交时间
    createTime(val) {
      this.searchForm.submitStartTime = val && val[0]
      this.searchForm.submitEndTime = val && val[1]
    },
    // 是否非错误来源
    activeName() {
      this.onSearch()
    }
  },
  created() {
    // 根据是否简单功能tab页文案显示不同
    this.bailShowShielding ? this.isShieldingActiveName = '非错误来款' : this.isShieldingActiveName = '保证金退款审批'
    // 获取列表信息
    this.loadData()
  },
  methods: {
    // 选择退款记录
    onSelect(val) {
      this.tableDataSelect = val
    },
    // table记住分页多选框选中的数据
    getRowKeys(row) {
      return row.refundDetailId
    },
    // 获取数据
    loadData() {
      const params = this.getQueryParams()// 查询条件
      params.packId = this.$route.params.packId // 包组id
      queryWaiteAuditDetailList(params).then(response => {
        this.confirmLoading = false
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {
        this.confirmLoading = false
      })
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.errorStatus = this.activeName// 是否为错误来源
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 搜索
    onSearch() {
      // 清除选项
      this.tableDataSelect = []
      this.$refs.multipleTable.clearSelection()
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      // 获取列表信息
      this.loadData()
    },
    // 重置
    resetForm() {
      restoreInitialValue(this.searchForm)
      // 获取列表信息
      this.onSearch()
    },
    // 批量审批
    allAudit() {
      const refundIds = []
      if (this.tableDataSelect.length > 0) {
        // 获取id
        this.tableDataSelect.forEach(item => {
          refundIds.push(item.refundId)
        })
        this.$confirm('确认审批通过?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          type: 'warning'
        }).then(() => {
          this.confirmLoading = true
          const data = {
            auditStatus: '', //
            refundIds: refundIds.join(',')
          }
          auditPassOrReject(data).then(() => {
            this.$message({
              type: 'success',
              message: '审批成功'
            })
            this.onSearch()// 获取数据
          }).catch(() => {
            this.confirmLoading = false
          })
        }).catch(() => {
        })
      } else {
        this.$message({
          message: '请选择审批信息',
          type: 'warning'
        })
      }
    },
    // 审批
    audit(row) {
      this.$router.push({
        path: '/fee/bailfeeRefundAudit-detail',
        name: 'BailfeeRefundAuditDetail',
        params: {
          packId: row.packId,
          refundId: row.refundId,
          auditStatus: row.auditStatus
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>

</style>
