<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>
      <div :class="{'SearchContent_show':toggleSearchStatus}" class="clearfix SearchContent">
        <div class="SearchContent_leftInput fl">
          <el-form
            ref="searchForm"
            :model="searchForm"
            inline
            label-width="100px"
            label-position="left"
          >
            <el-form-item ref="orderNumber" label="流水号" prop="orderNumber">
              <el-input
                v-model.trim="searchForm.orderNumber"
                placeholder="流水号"
                style="width:220px"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <el-form-item label="开票状态" prop="invoiceStatus">
              <el-select v-model="searchForm.invoiceStatus" placeholder="请选择" style="width:228px">
                <el-option
                  v-for="(item,index) in kpztTypeList"
                  :key="index"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </el-form-item>
            <el-form-item ref="agentName" label="代理机构名称" prop="agentName">
              <el-input
                v-model.trim="searchForm.agentName"
                placeholder="代理机构名称"
                style="width:220px"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <el-form-item ref="buyersName" label="采购单位名称" prop="buyersName">
              <el-input
                v-model.trim="searchForm.buyersName"
                placeholder="采购单位名称"
                style="width:220px"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <el-form-item ref="tenderNo" label="项目编号" prop="tenderNo">
              <el-input
                v-model.trim="searchForm.tenderNo"
                placeholder="项目编号"
                style="width:220px"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <el-form-item ref="tenderName" label="项目名称" prop="tenderName">
              <el-input
                v-model.trim="searchForm.tenderName"
                placeholder="项目名称"
                style="width:220px"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <el-form-item ref="supplierName" label="缴费机构" prop="supplierName">
              <el-input
                v-model.trim="searchForm.supplierName"
                placeholder="项目名称"
                style="width:220px"
                @keyup.enter.native="onSearch"
              />
            </el-form-item>
            <!-- 冻结状态 -->
            <el-form-item label="支付方式" prop="payMode">
              <el-select v-model="searchForm.payMode" placeholder="请选择" style="width: 220px">
                <el-option
                  v-for="item in payTypeList"
                  :key="item.typecode"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </el-form-item>
            <!--缴费时间-->
            <el-form-item label="缴费时间" prop="createTimeBegin">
              <el-date-picker
                v-model="searchForm.createTimeBegin"
                :format="elValueSaveFormat"
                :value-format="elValueSaveFormat"
                type="date"
                placeholder="开始日期"
              />
              至
              <el-date-picker
                v-model="searchForm.createTimeEnd"
                :format="elValueSaveFormat"
                :value-format="elValueSaveFormat"
                type="date"
                placeholder="结束日期"
              />
            </el-form-item>
            <!--开票时间-->
            <el-form-item label="开票时间" prop="invoiceTimeBegin">
              <el-date-picker
                v-model="searchForm.invoiceTimeBegin"
                :format="elValueSaveFormat"
                :value-format="elValueSaveFormat"
                type="date"
                placeholder="开始日期"
              />
              至
              <el-date-picker
                v-model="searchForm.invoiceTimeEnd"
                :format="elValueSaveFormat"
                :value-format="elValueSaveFormat"
                type="date"
                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>
      </div>
      <div class="crud_menu_title clearfix">
        <el-button
          type="primary"
          class="mb10 ml10"
          plain
          @click="exportBidServiceFeeInfoList"
        >
          导出列表
        </el-button>
      </div>
      <el-row class="table-alert-info">
        <el-col>
          <el-link :underline="false">
            合计投标服务费:<span class="sum_color"> {{ statistics.totalDocumentPrice }} </span>元
          </el-link>
        </el-col>
      </el-row>
      <div>
        <el-table
          ref="smallTable"
          v-loading="loading"
          :data="tableData"
          class="tableLimit"
        >
          <el-table-column
            type="index"
            label="序号"
            width="60px"
            align="center"
          />
          <el-table-column
            prop="orderNumber"
            align="center"
            label="流水号"
            min-width="170"
          />
          <el-table-column
            align="center"
            prop="agentName"
            label="代理机构名称"
            min-width="200"
          />
          <el-table-column
            align="center"
            prop="buyersName"
            label="采购单位名称"
            min-width="200"
          />
          <el-table-column
            align="center"
            prop="tenderNo"
            label="项目编号"
            min-width="120"
          />
          <el-table-column
            align="center"
            prop="tenderName"
            label="项目名称"
            min-width="200"
          />
          <el-table-column
            header-align="center"
            align="center"
            prop="packNo"
            label="包件编号"
            min-width="120"
          />
          <el-table-column
            header-align="center"
            align="center"
            prop="supplierName"
            label="缴费机构"
            min-width="200"
          />
          <el-table-column
            header-align="center"
            align="center"
            prop="payCount"
            label="缴费数量"
            min-width="200"
          />
          <el-table-column
            header-align="center"
            align="center"
            prop="payPrice"
            label="缴费金额（元）"
            min-width="150"
          >
            <template slot-scope="scope">
              {{ numFilter(scope.row.payPrice) }}
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="payMode"
            label="支付方式"
            min-width="100"
          >
            <template slot-scope="scope">
              {{ filterDictText(payTypeList, scope.row.payMode) }}
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="payTime"
            label="缴费时间"
            min-width="150"
          />
          <el-table-column
            header-align="center"
            align="center"
            prop="invoiceStatus"
            label="开票状态"
            min-width="100"
          >
            <template slot-scope="scope">
              {{ filterDictText(kpztTypeList, scope.row.invoiceStatus?scope.row.invoiceStatus:'00') }}
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            align="center"
            prop="linkerEmail"
            label="电子邮箱"
            min-width="150"
          />
          <el-table-column
            header-align="center"
            align="center"
            prop="invoiceNo"
            label="发票号"
            min-width="200"
          />
          <el-table-column
            header-align="center"
            align="center"
            prop="budgetTotalMoney"
            label="项目预算"
            min-width="200"
          />
          <el-table-column
            header-align="center"
            align="center"
            prop="invoiceTime"
            label="开票时间"
            min-width="200"
          />
          <!-- <el-table-column
            header-align="center"
            align="center"
            prop="isCanRefund"
            label="是否可以退款"
            min-width="100"
          />
          <el-table-column
            header-align="center"
            align="center"
            prop="isRefund"
            label="退款"
            min-width="100"
          />-->

          <el-table-column
            align="center"
            label="操作"
            width="160"
          >
            <template slot-scope="scope">
              <el-link
                v-if="scope.row.invoiceStatus==='00'"
                type="primary"
                @click.stop="inputInvoice(scope.row,'add')"
              >
                [录入开票]
              </el-link>
              <el-link
                v-if="scope.row.invoiceStatus==='02'"
                type="primary"
                @click.stop="inputInvoice(scope.row,'view')"
              >
                [发票信息]
              </el-link>
              <el-link
                type="primary"
                @click.stop="preview(scope.row)"
              >
                [查看]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="loadData" />
      </div>
    </section>
    <bidServiceInvoiceAddDialog
      v-if="dialogData.dialog"
      ref="bidServiceInvoiceAddDialog"
      :dialog-data="dialogData"
      @loadData="loadData"
    />
  </div>
</template>
<script>
/* 接口*/
import { getBidServiceFeeInvoiceList, exportBidServiceFeeInvoiceList, queryBiServiceInvoiceStatistics, queryInvoiceForServiceOrder } from '@/api/bidService/bidServiceStatistics.js'// 专家入库审核表格接口
/* 公用方法*/
import { filterObj, download, filterDictText, restoreInitialValue, numFilter } from '@/assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { commonMxin } from '@/mixins/commonMxin'
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
import bidServiceInvoiceAddDialog from './bidServiceFeeInvoiceAdd-dialog.vue'
export default {
  name: 'BidServiceInvoiceList',
  components: {
    pagination, // 分页
    bidServiceInvoiceAddDialog
  },
  mixins: [ListMixin, commonMxin],
  data() {
    return {
      dialogData: {
        dialog: false, // 展示状态
        id: '', // 编辑时才会有财务状况id
        opType: ''
      },
      loading: true,
      // 搜索
      searchForm: {
        agentName: '', //  代理机构名称
        buyersName: '',
        tenderNo: '', // 项目编号
        tenderName: '', // 项目名称
        supplierName: '', // 缴费机构
        payMode: '', // 支付方式
        createTimeBegin: '', // 缴费开始时间
        createTimeEnd: '', // 缴费结束时间
        invoiceTimeBegin: '', // 开票开始时间
        invoiceTimeEnd: '' // 开票结束时间
      },
      // 开标费用统计数据
      statistics: {
        pageDocumentPrice: 0, // 单页开票金额
        pageNoTaxRatePrice: 0, // 单页开票不含税金额
        pageTaxAmount: 0, // 单页开票税额
        totalDocumentPrice: 0, // 总开票金额
        totalNoTaxRatePrice: 0, // 总开票不含税金额
        totalTaxAmount: 0 // 总页开票税额
      },
      payTypeList: [
        { typename: '支付宝', typecode: '00' },
        { typename: '微信', typecode: '01' },
        { typename: '银联', typecode: '02' },
        { typename: '广发', typecode: '03' },
        { typename: '中金支付', typecode: '04' }
      ], // 支付方式数据字典
      kpztTypeList: [
        { typename: '未开票', typecode: '00' },
        { typename: '开票失败', typecode: '01' },
        { typename: '已开票', typecode: '02' }
      ], // 开票状态数据字典
      tableData: []
    }
  },
  created() {
    // 获取列表信息
    this.loadData()
    // 获得数据字典
    // this.getGroupType()
  },
  methods: {
    numFilter,
    filterDictText, // 字典值替换文本通用方法
    // 获得数据字典
    /* getGroupType() {
      this.$store.dispatch('getGroupType', ['paytype']).then((data) => {
        this.payTypeList = data.bidTypeData.paytypeList
      })
    },*/
    // 获取数据
    loadData() {
      const params = this.getQueryParams()// 查询条件
      getBidServiceFeeInvoiceList(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {
        this.loading = false
      })
      this.queryBiServiceStatistics(params)
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    queryBiServiceStatistics(params) {
      queryBiServiceInvoiceStatistics(params).then(response => {
        this.statistics = response.data
      }).catch(() => {
      })
    },
    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      // 获取列表信息
      this.loadData()
    },
    // 重置
    resetForm(formName) {
      restoreInitialValue(this.searchForm)
      // 获取列表信息
      this.onSearch()
    },
    // 导出
    exportBidServiceFeeInfoList() {
      const params = this.getQueryParams()// 查询条件
      exportBidServiceFeeInvoiceList(params).then(res => {
        download(res, '投标服务费发票管理.xls')
      })
    },
    // 查看
    preview(row) {
      this.$router.push({
        name: 'bidServiceBasicInfo',
        params: {
          bidServiceStatisticsId: row.id
        }
      })
    },
    // 手动录入发票
    inputInvoice(row, opType) {
      this.dialogData.opType = opType
      this.dialogData.id = row.id
      this.dialogData.dialog = true
      const data = {
        id: row.id
      }
      queryInvoiceForServiceOrder(data).then(res => {
        const invoiceData = res.data
        console.log(invoiceData)
        this.$refs.bidServiceInvoiceAddDialog.openInvoiceDialog(this.dialogData.opType, invoiceData)
      }).catch(() => {
      })
    }
  }
}
</script>
<style lang="less" scoped>

.crud_menu_title{
  .el-button{
    margin-top: 8px;
  }
}

</style>
