<!--
  @description:CA管理-CA发票管理
  @Modifier:肖文龙
  @routerPath:/caManage/invoiceManageList
  @date:2019-12-6 11:50:41
-->
<template>
  <div style="height: 100%">
    <section class="title p0-16">
      CA发票管理
    </section>
    <section :class="{'SearchContent_show':toggleSearchStatus}" class="p0-16 clearfix SearchContent">
      <div class="SearchContent_leftInput fl">
        <el-form
          ref="searchForm"
          :model="searchForm"
          label-width="100px"
          inline
        >
          <el-form-item label="项目名称" label-width="100px" prop="title">
            <el-input v-model="searchForm.title" placeholder="项目名称" style="width:240px" />
          </el-form-item>
          <el-form-item label="审核时间" prop="applyStartDate">
            <el-date-picker
              v-model="toExamineDate"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              style="width:240px"
              @change="chooseTimeRange"
            />
          </el-form-item>
          <el-form-item label="CA类型" label-width="100px" prop="caType">
            <el-select v-model="searchForm.caType" placeholder="请选择" style="width:240px">
              <el-option v-for="item in caTypeOptions" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="支付方式" label-width="100px" prop="paymentMode">
            <el-select v-model="searchForm.paymentMode" placeholder="请选择" style="width:240px">
              <el-option v-for="item in paymentModeOptions" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="缴费时间" label-width="100px" prop="payStartDate">
            <el-date-picker
              v-model="payDate"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              style="width:240px"
              @change="chooseTimeRange"
            />
          </el-form-item>
          <el-form-item label="是否开取专票" label-width="100px" prop="specialTicket">
            <el-select v-model="searchForm.specialTicket" placeholder="请选择" style="width:240px">
              <el-option v-for="item in specialTicketOptions" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="开票状态" label-width="100px" prop="specialTicket">
            <el-select v-model="searchForm.billingStatus" placeholder="请选择" style="width:240px">
              <el-option v-for="item in billingStatusOptions" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <div class="fr">
        <el-button
          v-if="toggleSearchStatus"
          icon="el-icon-arrow-up"
          class="toggleSearchStatus"
          type="gray"
          @click="handleToggleSearch"
        />
        <el-button
          v-else
          icon="el-icon-arrow-down"
          class="toggleSearchStatus"
          type="gray"
          @click="handleToggleSearch"
        />
        <el-button type="primary" icon="iconfont icon-search" @click="onSearch('searchForm')">
          搜索
        </el-button>
        <el-button plain type="info" @click="resetForm('searchForm')">
          重置
        </el-button>
      </div>
    </section>
    <section class="main">
      <el-table
        id="tableData"
        :data="tableData"
        :fit="true"
        style="width: 100%"
        size="small"
      >
        <el-table-column type="index" label="序号" width="60" align="center" />
        <el-table-column prop="serialNumber" min-width="70%" align="center" label="流水号" />
        <el-table-column prop="title" min-width="100%" label="申请单位" />
        <el-table-column prop="createDate" min-width="100%" label="申请时间" />
        <el-table-column prop="createDate" min-width="100%" label="审核时间" />
        <el-table-column prop="caType" min-width="100%" label="CA类型">
          <template slot-scope="scope">
            <span v-if="scope.row.paymentMode==='00'">单位身份证证书</span>
            <span v-if="scope.row.paymentMode==='01'">个人数字证书</span>
          </template>
        </el-table-column>
        <el-table-column prop="serviceType" min-width="100%" label="服务类型">
          <template slot-scope="scope">
            <span v-if="scope.row.paymentMode==='00'">证书办理</span>
            <span v-if="scope.row.paymentMode==='01'">支付宝</span>
          </template>
        </el-table-column>
        <el-table-column prop="paymentMode" min-width="100%" label="支付方式">
          <template slot-scope="scope">
            <span v-if="scope.row.paymentMode==='00'">易支付</span>
            <span v-if="scope.row.paymentMode==='01'">支付宝</span>
            <span v-if="scope.row.paymentMode==='02'">微信</span>
          </template>
        </el-table-column>
        <el-table-column prop="PayData" min-width="200px" label="缴费时间" />
        <el-table-column prop="billingStatus" min-width="200px" label="开票状态">
          <template slot-scope="scope">
            <span v-if="scope.row.paymentMode==='00'">1已开票</span>
            <span v-if="scope.row.paymentMode==='01'">未开票</span>
          </template>
        </el-table-column>
        <el-table-column prop="specialTicket" min-width="200px" label="是否专票">
          <template slot-scope="scope">
            <span v-if="scope.row.paymentMode==='00'">是</span>
            <span v-if="scope.row.paymentMode==='01'">否</span>
          </template>
        </el-table-column>
        <el-table-column prop="mobilePhone" min-width="200px" label="移动电话" />
        <el-table-column prop="refund" min-width="200px" label="退款">
          <template slot-scope="scope">
            <span v-if="scope.row.paymentMode==='00'">是</span>
            <span v-if="scope.row.paymentMode==='01'">否</span>
          </template>
        </el-table-column>
        <el-table-column prop="purchaseNo" min-width="200px" label="发票号码" />
        <el-table-column prop="invoiceCode" min-width="200px" label="发票代码" />
        <el-table-column prop="invoiceVerificationCode" min-width="200px" label="发票验证码" />
        <el-table-column prop="electronicsMail" min-width="200px" label="电子邮箱" />
        <el-table-column prop="province" min-width="100%" label="地址" />
        <el-table-column prop="orderType" min-width="200px" label="开票方式">
          <template slot-scope="scope">
            <span v-if="scope.row.orderType==='00'">电子发票</span>
            <span v-if="scope.row.orderType==='01'">录入发票</span>
          </template>
        </el-table-column>
        <el-table-column prop="relStatus" align="center" width="160px" fixed="right" label="操作">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.relStatus==='00'"
              size="mini"
              type="info"
              plain
              @click="auditBtn(scope.row.id,scope.row.relStatus)"
            >
              发票信息
            </el-button>
            <el-button
              v-else
              size="mini"
              type="primary"
              plain
              @click="auditBtn(scope.row.id,scope.row.relStatus)"
            >
              录入发票
            </el-button>
            <el-button
              size="mini"
              type="info"
              plain
              @click="auditBtn(scope.row.id)"
            >
              查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination :pagination-data="paginationData" @change="getData" />
    </section>
  </div>
</template>

<script>
import { getList } from '@/api/purchase/purchaseMain'
import { ListMixin } from '@/mixins/ListMixin'
import pagination from '@comp/common/pagination/pagination'
export default {
  name: 'InvoiceManageList',
  components: {
    pagination
  },
  mixins: [ListMixin],
  data() {
    return {
      is_hide: false,
      searchForm: {
        applyEndDate: '', // 发布结束日期
        applyStartDate: '', // 发布开始日期
        purchaseNo: '', // 采购项目编号
        purchaseType: '', // 采购方式
        stage: '', // 项目所处阶段
        title: '', // 采购项目名称
        auditStatus: '' // 审核状态
      },
      toExamineDate: '', // 审核时间
      payDate: '', // 缴费时间
      // 发票管列表
      tableData: [{
        serialNumber: '', // 流水号
        applicantUnit: '', // 申请单位
        applicationData: '', // 申请时间
        AuditData: '', // 审核时间
        caType: '', // CA类型
        serviceType: '', // 服务类型
        paymentMode: '', // 支付方式
        PayData: '', // 缴费时间
        billingStatus: '', // 开票状态
        specialTicket: '', // 是否专票
        mobilePhone: '', // 移动电话
        refund: '', // 退款
        invoice: '', // 发票号码
        invoiceCode: '', // 发票代码
        invoiceVerificationCode: '', // 发票验证码
        electronicsMail: '', // 电子邮箱
        region: '', // 地区
        invoiceMethod: '', // 开票方式
        operation: '', // 操作
        id: '', //
        paymenAamount: '', // 缴费金额
        unitMin: '', // 单位名称
        paymentVoucher: '', // 支付凭证
        auditStatus: '00' // 审核状态
      }],
      // 制作状态
      productionStatusOptions: [{
        value: '00',
        label: '未制作'
      }, {
        value: '01',
        label: '已制作'
      }],
      // 是否开取专票
      specialTicketOptions: [{
        value: '00',
        label: '否'
      }, {
        value: '01',
        label: '是'
      }],
      // 开票状态
      billingStatusOptions: [{
        value: '00',
        label: '未开票'
      }, {
        value: '01',
        label: '已开票'
      }],
      // CA类型
      caTypeOptions: [{
        value: '00',
        label: '单位身份证书'
      }, {
        value: '01',
        label: '个人数字证书'
      }],
      // 支付方式
      paymentModeOptions: [{
        value: '00',
        label: '易宝支付'
      }, {
        value: '01',
        label: '支付宝'
      }, {
        value: '02',
        label: '微信'
      }, {
        value: '03',
        label: '其他'
      }]

    }
  },
  mounted() {
  },
  methods: {
    // 路径跳转
    auditBtn(id, operation) { // 项目id)
      if (operation === '00') {
        // 发票信息
        this.$router.push({
          path: '/caManage/invoiceManageList/informationDetail',
          query: {
            id: id
          }
        })
      } else if (operation === '01') {
        // 录入发票
        this.$router.push({
          path: '/caManage/invoiceManageList/entryAdd',
          query: {
            id: id
          }
        })
      } else {
        // 查看单位身份数字证书申请信息
        this.$router.push({
          path: '/caManage/certificateInformationDetail',
          query: {
            id: id
          }
        })
      }
    },
    // excel导出
    exportExcel() {
    },
    // 时间转换
    chooseTimeRange(t) {
      const timeArr = t
      if (timeArr) {
        const moment = require('moment')
        for (const i in timeArr) {
          timeArr[i] = moment(timeArr[i]).format('YYYY-MM-DD')
        }
        this.searchForm.applyEndDate = timeArr[1] // 结束日期
        this.searchForm.applyStartDate = timeArr[0] // 开始日期
      }
    },
    // 初始化分页
    initData(tableData) {
      if (tableData === false) {
        this.tableData = []
      } else {
        const moment = require('moment')
        this.tableData = tableData.data.results
        this.paginationData.total = tableData.data.total
        for (let i = 0; i < this.tableData.length; i++) {
          this.tableData[i].createDate = moment(this.tableData[i].createDate).format('YYYY-MM-DD')
          // 审核状态
          if (this.tableData[i].auditStatus === '00') {
            this.tableData[i].auditStatus = '待审核'
          } else if (this.tableData[i].auditStatus === '01') {
            this.tableData[i].auditStatus = '审核通过'
          } else {
            this.tableData[i].auditStatus = '审核不通过'
          }
        }
      }
    },
    // 获取列表
    getData() {
      const data = {
        pageNo: this.paginationData.pageNo,
        pageSize: this.paginationData.pageSize,
        orgMethod: '00', // 自主采购
        ...this.searchForm
      }
      getList(data).then(response => {
        this.initData(response)
      }).catch(res => {})
    },

    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.getData()
    },
    // 搜索重置
    resetForm(formName) {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.toExamineDate = ''
      this.$refs[formName].resetFields()
      this.getData()
    }
  }
}
</script>

<style lang="less">

</style>
