<!--
  @description:项目管理-招标文件/资审文件标书获取记录
  @Modifier: 肖文龙
  @routerPath:
  @date: 2020/1/15-11:15
-->
<template>
  <div class="main">
    <dl class="projectInfoDetail">
      <dt v-if="isTenderDoc">
        <p class="projectInfoDetail_icon">
          <i class="iconfont icon-biaoduanbaoxinxi" />
        </p>
        {{ dict.examinationFileName }}文件获取记录列表
      </dt>
      <dd>
        <el-table
          ref="smallTable"
          :data="tableData"
        >
          <el-table-column

            prop="packNo"
            label="标段（包）编号"
            align="center"
          />
          <el-table-column

            prop="packName"
            label="标段（包）名称"
            width="300px"
            header-align="center"
          />
          <el-table-column

            prop="tenderDocumentReceiveEndTime"
            label="标书获取截止时间"
            align="center"
          >
            <template slot-scope="scope">
              {{ scope.row.tenderDocumentReceiveEndTime && $Moment(scope.row.tenderDocumentReceiveEndTime).format(momentDateTime) }}
            </template>
          </el-table-column>
          <el-table-column

            prop="documentPrice"
            label="售价（元）"
            header-align="center"
            align="right"
          >
            <template slot-scope="scope">
              {{ scope.row.documentPrice?Number(scope.row.documentPrice).toFixed(2):scope.row.documentPrice }}
            </template>
          </el-table-column>
          <el-table-column

            prop="totalPay"
            label="本次支付成功人数（人）"
            header-align="center"
            align="right"
          />
          <el-table-column

            prop="totalPrice"
            label="金额总计（元）"
            header-align="center"
            align="right"
          >
            <template slot-scope="scope">
              {{ scope.row.totalPrice?Number(scope.row.totalPrice).toFixed(2):scope.row.totalPrice }}
            </template>
          </el-table-column>
        </el-table>
      </dd>
    </dl>
    <!-- 报名列表
      biddingbulletinIsNeedSingup 是否需要报名 00不需要 01需要
      判断非依法需要显示 其它条件不显示(isLegalTender 00非依法必招)
    -->
    <tenderApplyList v-if="biddingbulletinIsNeedSingup === '01' && legalLimitData.isLegalTender === '00'" :stage-id="$store.getters.groupId.stageId" />
    <dl class="projectInfoDetail">
      <dt>
        <p class="projectInfoDetail_icon">
          <i class="iconfont icon-biaoduanbaoxinxi" />
        </p>
        购买详情信息
        <el-button
          type="primary"
          size="mini"
          @click="exportExel('')"
        >
          导出全部
        </el-button>
        <el-button
          type="primary"
          size="mini"
          @click="exportExel('01')"
        >
          导出支付成功
        </el-button>
      </dt>
      <dd>
        <el-table
          ref="smallTable"
          :data="detailList"
        >
          <el-table-column
            type="index"
            label="序号"
            align="center"
            width="60"
          />
          <el-table-column
            prop="supplierName"
            label="投标人名称"
            min-width="230"
            header-align="center"
          />
          <el-table-column
            prop="linker"
            label="联系人"
            min-width="120px"
            align="center"
          />
          <el-table-column
            prop="linkerTel"
            label="手机号码"
            align="center"
            min-width="120px"
          />
          <!--<el-table-column
            prop="linkerEmail"
            label="邮箱"
            align="center"
            width="150"
          />-->
          <el-table-column
            prop="downloadTime"
            label="下载时间"
            align="center"
            width="140"
          />
          <el-table-column
            prop="payStatus"
            label="订单状态"
            align="center"
            min-width="90"
          >
            <template slot-scope="scope">
              <span
                v-for="(item,index) in payStatusList"
                v-if="scope.row.payStatus===item.typecode"
                :key="index"
                :class="item.class"
              >{{ item.typename }}</span>
            </template>
          </el-table-column>
          <!--<el-table-column
            prop="postLinkerAddress"
            label="邮寄地址"
            align="center"
          />
          <el-table-column
            prop="emailCode"
            label="邮编"
            align="center"
          />-->
          <!--isCanCheck 是否可以查看 00否 01是-->
          <el-table-column
            label="操作"
            width="80"
            align="center"
          >
            <template slot-scope="scope">
              <el-link
                v-if="scope.row.isCanCheck !=='00'"
                type="primary"
                @click="tenderDocSee(scope.row)"
              >
                [查看]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="initDataList" />
      </dd>
    </dl>
    <div v-if="isTenderDoc" class="but_footer">
      <div class="but_footer-h" />
      <div class="but_footer-but">
        <el-button @click="back()">
          返 回
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
/* api*/
import { queryTenderRecordList, queryTenderRecordDetailList, exportDocumentRecordDetailList } from '@api/bidding/biddocfee'
import { getTenderStageBizRuleAndTimeRuleByStageId } from '@api/bidding/bidBulletin'
/* 公共方法*/
import { download, filterObj } from '@/assets/js/utils'
/* 混合开发*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { tenderDoc } from './../mixins/tenderDoc'// 招标文件/资审文件
import { tenderDocGroupMixin } from './../mixins/tenderDocGroupMixin'// 招标文件/标书获取-公用字典
import { tenderStageTimeRule } from '@/views/bidding/bulletin/mixins/tenderStageTimeRule'// 招标公告时间规则（获取依法、非依法）
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
import tenderApplyList from './../../tenderBid/tenderApply/tenderApply-list' // 报名列表
export default {
  name: 'TenderDocTakeRecordsListDetail',
  components: {
    pagination, // 分页
    tenderApplyList
  },
  mixins: [tenderDoc, ListMixin, tenderDocGroupMixin, tenderStageTimeRule],
  props: {
    // 是否从招标文件进来的-布尔值
    isTenderDoc: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      tableData: [], // 标书获取记录列表
      searchFrom: {
        pageNo: 1, // 当前页
        pageSize: 10, // 每页条数
        stageIds: '' // 阶段Id
      },
      //  购买详情信息列表
      detailList: [
        /*        {
          createUser: '', // (投标人)
          linker: '', // 联系人
          linkerTel: '', // 手机号码
          linkerEmail: '', // 邮箱
          downloadTime: '', // 下载时间
          payStatus: '', // 订单状态
          postLinkerAddress: '', // 邮寄地址
          emailCode: ''// 邮编
        }*/
      ],
      biddingbulletinIsNeedSingup: '' // 是否需要报名字段 00不需要 01需要
    }
  },
  created() {
    this.initData()// 初始化
    this.initDataList()// 获取标书获取详情列表
    this.getTenderStageBizRuleAndTimeRule() // 规则信息 是否需要报名
  },
  methods: {
    // 初始化-标书获取记录列表
    initData() {
      const params = this.getInitDataQueryParams()// 查询条件
      queryTenderRecordList(params).then(res => {
        this.tableData = res.data
      })
    },
    // 获取文件购买记录详情列表
    initDataList() {
      const params = this.getQueryParams()// 查询条件
      queryTenderRecordDetailList(params).then(res => {
        this.detailList = res.data.records
        this.paginationData.total = res.data.total
      })
    },
    // 导出文件购买记录详情列表
    exportExel(payStatus) {
      const params = this.getInitDataQueryParams()// 查询条件
      const data = {
        ...params,
        payStatus: payStatus, // 01导出支付成功 为空时导出全部
        pageNo: 1,
        pageSize: 999999999
      }
      exportDocumentRecordDetailList(data).then(res => {
        if (payStatus === '01') { // 导出支付成功
          download(res, this.$route.query.tenderName + '购买详情支付成功信息.xls')
        } else { // 导出全部
          download(res, this.$route.query.tenderName + '购买详情信息.xls')
        }
      })
    },
    // 标书获取记录列表-查询条件
    getInitDataQueryParams() {
      const param = {
        tenderId: this.$store.getters.groupId.tenderId// 项目
      }
      param.stageIds = this.$store.getters.groupId.stageId// 阶段Id-投标标书获取时取的
      return filterObj(param)
    },
    // 获取文件购买记录详情列表-查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchFrom)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      param.stageIds = this.$store.getters.groupId.stageId // 阶段Id-投标标书获取时取的
      return filterObj(param)
    },
    // 根据阶段id获取阶段业务规则是否需要报名字段
    getTenderStageBizRuleAndTimeRule() {
      const stageId = this.$store.getters.groupId.stageId
      getTenderStageBizRuleAndTimeRuleByStageId(stageId).then(res => {
        this.biddingbulletinIsNeedSingup = res.data.isNeedSignup
      }).catch(() => {
      })
    },
    // 查看标书获取记录详情
    tenderDocSee(row) {
      // 路由携带参数
      const query = {
        ...this.$route.query,
        stageId: row.stageId, // 阶段Id
        supplierId: row.supplierId // 供应商Id
      }
      this.$router.push({
        path: '/bidding/projectDrive/tenderDoc/tenderDocTakeRecords-detail',
        query: query
      })
    },
    // 返回
    back() {
      const query = { ...this.$route.query }
      this.$router.push({
        path: '/bidding/projectDrive/tenderDoc/tenderProcfilePack-add',
        query: {
          id: query.id, // 项目id
          tenderName: query.tenderName, // 项目名称
          packId: query.packId// 标段Id
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>

</style>
