<!--
  @description: 评审费记账
  @Modifier: haofengxian
  @routerPath: /fee/evalfeeKeeping-list
  @date: 2020-9-23-16:13
-->
<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="98px"
            label-position="left"
          >
            <!-- 表单编号 -->
            <el-form-item label="表单编号">
              <el-input
                v-model="searchForm.formNumber"
                placeholder="请输入表单编号"
                style="width: 228px"
              />
            </el-form-item>
            <!-- 表单名称 -->
            <el-form-item label="表单名称">
              <el-input
                v-model="searchForm.name"
                placeholder="请输入表单编号"
                style="width: 228px"
              />
            </el-form-item>
            <!--记账状态-->
            <el-form-item ref="bookkeepingState" label="记账状态" prop="bookkeepingState">
              <el-select v-model="searchForm.bookkeepingState" placeholder="请选择" style="width:228px">
                <el-option
                  v-for="(item,index) in bookkeepingStatusList"
                  :key="index"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </el-form-item>
            <!-- 到账日期 -->
            <el-form-item ref="accountingTime" label="到账日期" prop="accountingTime">
              <el-date-picker
                v-model="accountingTime"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width:228px"
                @change="changeAccountingTime"
              />
            </el-form-item>
            <!-- 记账日期 -->
            <el-form-item ref="bookkeepingTime" label="记账日期" prop="bookkeepingTime">
              <el-date-picker
                v-model="bookkeepingTime"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width:228px"
                @change="changeBookkeepingTime"
              />
            </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>
      <!--查询结果-->
      <div class="crud_menu_title">
        <span class="icon-line">查询结果</span>
      </div>
      <el-row class="mb10 table-alert-info">
        <el-col>
          <el-button type="primary" @click="surePatch">
            批量记账
          </el-button>
          <!--       <el-button type="primary" plain @click="exportExcel">
            导出评审费记账记录
          </el-button>-->
        </el-col>
      </el-row>
      <section>
        <el-table
          ref="keepingAccountsTable"
          v-loading="loading"
          :data="tableData"
          :row-key="getRowKeys"
          @selection-change="selectionChange"
        >
          <el-table-column
            :reserve-selection="true"
            :selectable="isDisabled"
            disabled="true"
            type="selection"
            fixed="left"
            align="center"
            width="55"
          />
          <el-table-column
            type="index"
            label="序号"
            fixed="left"
            width="60px"
            align="center"
          />
          <!-- 表单编号 -->
          <el-table-column

            prop="formNumber"
            align="center"
            label="表单编号"
            width="220"
          />
          <!-- 表单名称 -->
          <el-table-column

            header-align="center"
            label="表单名称"
            prop="name"
            min-width="200"
          />
          <!-- 评审费总额（元） -->
          <el-table-column
            header-align="center"
            prop="auditTotalMoney"
            label="评审费总额（元）"
            align="right"
            min-width="150"
          />
          <!-- 记账状态 -->
          <el-table-column
            :formatter="bookkeepingStatus"
            header-align="center"
            label="记账状态"
            prop="bookkeepingState"
            align="left"
            min-width="100"
          />
          <!-- 到账时间 -->
          <el-table-column
            header-align="center"
            label="到账时间"
            prop="receivedDate"
            align="center"
            width="140"
          />
          <!-- 记账时间 -->
          <el-table-column
            header-align="center"
            label="记账时间"
            prop="bookkeepingDate"
            align="center"
            width="140"
          />
          <!-- 操作 -->
          <!--未记账00 已记账01 记账失败02 记账申请中03-->
          <el-table-column
            header-align="center"
            label="操作"
            width="110"
          >
            <template slot-scope="scope">
              <el-link
                v-if="scope.row.bookkeepingState==='00' || scope.row.bookkeepingState==='02'"
                type="primary"
                @click.stop="synchronization(scope.row)"
              >
                [记账]
              </el-link>
              <el-link
                type="primary"
                @click.stop="view(scope.row)"
              >
                [查看]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="getTallyList" />
      </section>
    </section>
  </div>
</template>
<script>
/* 接口*/
import { getPageEvalFeeBookkeepingListInfos, batchBookkeeping } from '@api/fee/evalfee'
/* 公用方法*/
import { filterObj, moneyFormat } from '@assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { evalFeeGroupMixin } from '../mixins/evalFeeGroupMixin'
import { evalFeeMixin } from '../mixins/evalFeeMixin'
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页

export default {
  name: 'TenderFeeIncoiceManageList',
  components: {
    pagination// 分页
  },
  mixins: [ListMixin, evalFeeGroupMixin, evalFeeMixin],
  data() {
    return {
      // 获取row的key值
      getRowKeys(row) {
        return row.id
      },
      moneyFormat: moneyFormat, // 金额添加千分位
      loading: true,
      accountingTime: '', // 到账时间
      bookkeepingTime: '', // 记账时间
      // 搜索
      searchForm: {
        auditTotalMoney: 0, // 金额
        bookkeepingDateFrom: '', // 记账日期从
        bookkeepingDateTo: '', // 记账日期到
        bookkeepingState: '', // 记账状态(00 未记账 01已经记账 02 记账失败 03 记账申请中
        formNumber: '', // 表单编号
        name: '', // 表单名称
        receivedDateFrom: '', // 到账日期从
        receivedDateTo: '' // 到账日期到
      },
      tableData: [],
      checkedTr: []// 确认记账批量记账存放数据
    }
  },
  created() {
    // 财预部-评审费记账列表
    this.getTallyList()
  },
  methods: {
    // 财预部-评审费记账列表
    getTallyList() {
      const params = this.getQueryParams()// 查询条件
      getPageEvalFeeBookkeepingListInfos(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {
        this.loading = false
      })
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 导出退款记录
    exportExcel() {
      // 导出评审费记账列表
      this.exportTally()
    },
    // 财预部-导出评审费记账列表
    exportTally() {
      const params = this.getQueryParams()// 查询条件
      delete params.pageNo
      delete params.pageSize
      /*     exportTallyList(params).then(res => {
        download(res, '评审费记账列表.xls')
      }).catch(() => {
      })*/
    },
    // 记账
    chargeAccount(ids) {
      batchBookkeeping(ids).then(res => {
        this.$message({
          message: res.header.msg,
          type: 'success'
        })
        // 获取列表信息
        this.getTallyList()
        this.$refs.keepingAccountsTable.clearSelection()
      }).catch(() => {
      })
    },
    // 记账
    synchronization(row) {
      this.$confirm('确认推送NC记账吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        this.chargeAccount(row.id)
      })
    },
    // 确认 批量记账记账
    surePatch() {
      if (this.checkedTr.length) {
        this.$confirm('确认批量记账吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          type: 'warning'
        }).then(() => {
          const ids = this.checkedTr.map(row => row.id).join(',')
          this.chargeAccount(ids)
        })
      } else {
        this.$message({ message: '请选择一条记录!', type: 'warning' })
      }
    },
    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      // 获取列表信息
      this.getTallyList()
    },
    // 重置
    resetForm(formName) {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.$refs[formName].resetFields()
      this.accountingTime = '' // 到账时间
      this.bookkeepingTime = '' // 记账时间
      Object.keys(this.searchForm).map((val) => {
        this.searchForm[val] = ''
      })
      // 获取列表信息
      this.getTallyList()
    },
    // 查看
    view(row) {
      this.$router.push({
        name: 'EvalfeeKeepingContent',
        params: {
          evalFeeId: row.id
        }
      })
    },
    // 到账时间
    changeAccountingTime(val) {
      if (val) {
        this.searchForm.receivedDateFrom = this.$Moment(val[0]).format(this.momentSaveFormat)// 到账开始时间
        this.searchForm.receivedDateTo = this.$Moment(val[1]).format(this.momentSaveFormat)// 到账结束时间
      }
    },
    // 记账时间
    changeBookkeepingTime(val) {
      if (val) {
        this.searchForm.bookkeepingDateFrom = this.$Moment(val[0]).format(this.momentSaveFormat)//  记账开始时间
        this.searchForm.bookkeepingDateTo = this.$Moment(val[1]).format(this.momentSaveFormat)// 记账结束时间
      }
    },
    // 选择 批量记账记账
    selectionChange(val) {
      this.checkedTr = val
    },
    // 返回
    back() {
      this.$router.push({
        path: '/fee/tenderFeeManage'
      })
    },
    // 复选框部分禁用
    isDisabled(row) {
      return row.bookkeepingState === '00' || row.bookkeepingState === '02'
    }
  }
}
</script>
<style lang="less" scoped>
</style>
