<!--
  @description:采购立项-供应商-正在参与项目-采购文件-不收取标书费
  @Modifier:gmy
  @routerPath:/procurement/procurementSupplier/procurementCollection
  @date:2020/7/1-13:27
-->
<template>
  <div>
    <div v-show="payStatus === '00'">
      <p class="page-title">
        1.采购文件下载
      </p>
      <table v-loading="loading" class="tableData">
        <tr class="singleRow">
          <td>采购文件</td>
          <td colspan="3">
            <downloadFile v-if="noTenderFeeFilsData.bizId" :down-load="true" :data="noTenderFeeFilsData" :down-load-click="down" />
          </td>
        </tr>
        <tr class="singleRow">
          <td>附件信息</td>
          <td colspan="3">
            <downloadFile :data="openTenderProjectFileType" :down-load="true" />
          </td>
        </tr>
      </table>
    </div>
    <div v-show="payStatus === '01'">
      <section class="p0-16">
        <p class="page-title">
          1.开票信息
        </p>
        <!-- 表格部分 -->
        <table class="tableData">
          <tr>
            <td>发票抬头</td>
            <td>{{ invoiceInfo.invoiceTitle }}</td>
            <td>发票类型</td>
            <td>{{ invoiceInfo.invoiceType }}</td>
          </tr>
          <tr>
            <td>纳税人识别号(统一社会信用代码)</td>
            <td>{{ invoiceInfo.taxpayerIdentificationNumber }}</td>
            <td>地址、电话</td>
            <td>{{ invoiceInfo.taxpayeraddr }}{{ invoiceInfo.taxpayertel }}</td>
          </tr>
          <tr>
            <td>开户行及账号</td>
            <td>{{ invoiceInfo.bankaccount }}</td>
            <td>邮箱</td>
            <td>{{ invoiceInfo.consigneeEmail }}</td>
          </tr>
        </table>
        <p class="page-title">
          2.订单支付
        </p>
        <table v-loading="loading" class="tableData">
          <tr>
            <td>标书费(元)</td>
            <td style="color: #ff0000">
              {{ payMoney }}
            </td>
          </tr>
          <tr>
            <td>支付方式</td>
            <td>工商</td>
          </tr>
        </table>
      </section>
    </div>
    <!--保存按钮-->
    <div v-show="payStatus === '01'" class="but_footer">
      <div class="but_footer-but">
        <el-button type="primary" :loading="confirmLoading" @click="submitPay()">
          提交订单
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
/*
  api接口
  */
import { getSupplierBailFeePayStatus, submitBidFeePay } from '@api/procurement/procurementFee'

import { getByUserIdInvoiceInfo } from '@api/common/user'

import { saveDownloadProcfileRecord, paymentOfTenderFeeMessage } from '@api/procurement/procurementProtdoc'

/* 公共方法*/
import { procurementTenderfeeMixins } from '../mixins/procurementTenderfeeMixins.js'
// vuex
import { mapGetters } from 'vuex'
/* 公共组件 */
import downloadFile from '@comp/common/updownload/downloadFile'// 文件回显组件
export default {
  name: 'ProcurementProjectAdd',
  inject: ['getTenderBase'],
  components: {
    downloadFile
  },
  mixins: [procurementTenderfeeMixins],
  props: {
    procfileId: {
      type: String,
      default: () => {
        return ''
      }
    }
  },
  data() {
    return {
      loading: false,
      status: '01', // 需要审批
      payStatus: '', // 支付状态
      invoiceInfo: '', // 发票信息
      payMoney: '', // 支付金额
      confirmLoading: false, // 按钮loading
      savaData: {
        downloadStatus: '', // 下载状态 00失败 01成功
        downloadTerminal: '00', // 下载终端00:平台端 01:投标管家端 02:招标管家端 03:开标工具端 04:评标工具端 05:安卓端 06:苹果端
        procfileId: '', // 文件id
        tenderId: '', // 项目ID
        packId: '', // 标段ID
        orderMoney: '', // 订单金额
        supplierName: '', // 供应商名称
        payMode: '06', // 支付方式，目前写死了
        supplierId: '', // 供应商ID
        tenderNo: '', // 项目编号
        tenderName: '' // 项目名称
      },
      tenderBase: this.getTenderBase() // 项目基本信息
    }
  },
  computed: {
    /* language 国际化*/
    ...mapGetters(['language'])
  },
  watch: {
  },
  created() {
    this.getBiziddata()
    this.queryProcurementRuleRecord()
  },
  methods: {
    // 获取业务id
    getBiziddata() {
      this.noTenderFeeFilsData.bizId = this.procfileId // 获取采购文件主键id
      this.openTenderProjectFileType.bizId = this.tenderBase.tenderId // 获取公开附件的业务id
    },
    // 下载成功触发的回调
    down(file) {
      this.loading = true
      // 判断文件fileid是否存在，区分是否下载成功
      if (file.fileId) {
        this.savaData.downloadStatus = '01'
        this.savaData.procfileId = this.procfileId
        const data = this.savaData
        this.savaDownLoad(data) // 调用保存下载记录方法
      } else {
        this.savaData.downloadStatus = '00'
      }
    },
    // 封装保存下载记录方法
    savaDownLoad(data) {
      saveDownloadProcfileRecord(data).then(res => {
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    // 查询项目是否收取标书费
    queryProcurementRuleRecord() {
      const userId = this.$store.getters.info.id
      const supplierId = this.$store.getters.info.currentDepart.id
      const packId = this.tenderBase.packId
      const tenderId = this.tenderBase.tenderId
      paymentOfTenderFeeMessage(packId).then(res => {
        // 01 收标书费情况下
        if (res.data.isReceiveTenderDocumentPrice === '01') {
          this.getByUserIdInvoiceInfo(userId)
          this.getPayStatus(supplierId, tenderId)
          this.payMoney = res.data.payAmount
        } else {
          this.payStatus = '00'
        }
      }).catch(() => {
        this.loading = false
      })
    },
    // 获取供应商标书费支付状态
    getPayStatus(userId, tenderId) {
      getSupplierBailFeePayStatus(userId, tenderId).then(res => {
        // 保证金状态：默认00:已支付 01:未支付
        if (res.data === '01') {
          this.payStatus = '01'
        } else if (res.data === '00') {
          this.payStatus = '00'
        }
      })
    },
    // 获取发票信息
    getByUserIdInvoiceInfo(userId) {
      getByUserIdInvoiceInfo(userId).then(res => {
        if (res.data != null) {
          this.invoiceInfo = res.data
        }
      })
    },
    // 提交订单
    submitPay() {
      this.confirmLoading = true
      this.savaData.tenderId = this.tenderBase.tenderId
      this.savaData.packId = this.tenderBase.packId
      this.savaData.tenderNo = this.tenderBase.tenderNo
      this.savaData.tenderName = this.tenderBase.tenderName
      this.savaData.supplierId = this.$store.getters.info.currentDepart.id
      this.savaData.orderMoney = this.payMoney
      this.savaData.supplierName = this.$store.getters.info.currentDepart.departname
      const data = this.savaData
      submitBidFeePay(data).then(res => {
        this.IEVersion(res.data)
        this.confirmLoading = false
      }).catch(() => {
        this.loading = false
        this.confirmLoading = false
      })
    },

    IEVersion(data) {
      var userAgent = navigator.userAgent // 取得浏览器的userAgent字符串
      var isIE = userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1 // 判断是否IE<11浏览器
      var isEdge = userAgent.indexOf('Edge') > -1 && !isIE // 判断是否IE的Edge浏览器
      var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf('rv:11.0') > -1
      if (isIE) {
        var reIE = new RegExp('MSIE (\\d+\\.\\d+);')
        reIE.test(userAgent)
        var fIEVersion = parseFloat(RegExp['$1'])
        if (fIEVersion < 10) {
          this.$message({
            message: 'IE版本过低,请使用IE10或以上!',
            type: 'warning'
          })
        } else {
          window.open(data, '_blank')
        }
      } else if (isEdge) {
        // edge
        // 不是ie浏览器
        this.$alert(data, '支付地址(请复制地址到IE浏览器中打开,支付成功之后请刷新当前页面)', {
          dangerouslyUseHTMLString: true
        })
      } else if (isIE11) {
        window.open(data, '_blank')
      } else {
        // 不是ie浏览器
        this.$alert(data, '支付地址(请复制地址到IE浏览器中打开,支付成功之后请刷新当前页面)', {
          dangerouslyUseHTMLString: true
        })
      }
      this.confirmLoading = false
    }
  }
}
</script>

<style lang="less" scoped>

  /deep/.show-word-limit-padding{
    .el-input__inner{
      padding-right: 70px;
    }
  }
  .title{
    font-weight: 600;
  }
</style>
