<!--
  @description:开票信息列表
  @Modifier:qk
  @routerPath:/supperManagement/enterpriseManagement-list
  @date:2020/3/24-10:27
-->
<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-position="right"
          >
            <el-form-item ref="invoiceTitle" label="发票抬头" prop="invoiceTitle">
              <el-input v-model="searchForm.invoiceTitle" placeholder="请输入发票抬头" style="width:220px" />
            </el-form-item>
            <el-form-item ref="taxpayerIdentificationNumber" label="税号" prop="taxpayerIdentificationNumber">
              <el-input v-model="searchForm.taxpayerIdentificationNumber" placeholder="请输入税号" style="width:220px" />
            </el-form-item>
            <el-form-item ref="invoiceType" label="发票类型" prop="invoiceType">
              <el-select v-model="searchForm.invoiceType" placeholder="请选择">
                <el-option
                  v-for="item in invoiceTypeGroup"
                  :key="item.typecode"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </el-form-item>
            <el-form-item ref="date" label="创建日期" prop="date">
              <el-date-picker
                v-model="createTimeDate"
                :value-format="elValueSaveFormat"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width:220px"
                @change="dateCheng"
              />
            </el-form-item>
            <el-form-item ref="isInvalid" label="是否作废" prop="isInvalid">
              <el-select v-model="searchForm.isInvalid" placeholder="请选择" style="width:220px">
                <el-option
                  v-for="item in isInvalidGroup"
                  :key="item.typecode"
                  :label="item.typename"
                  :value="item.typecode"
                />
              </el-select>
            </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-button class="mb10" type="primary" @click="add">
        录入开票信息
      </el-button>
      <section>
        <el-table
          ref="smallTable"
          v-loading="loading"
          :data="tableData"
          width="100%"
        >
          <el-table-column
            type="index"
            label="序号"
            width="60px"
            align="center"
          />
          <el-table-column
            prop="invoiceTitle"
            header-align="center"
            label="发票抬头"
            min-width="240px"
          />
          <el-table-column
            header-align="center"
            prop="taxpayerIdentificationNumber"
            label="税号"
            min-width="240px"
            align="center"
          />
          <el-table-column
            header-align="center"
            label="发票类型"
            width="120"
            align="center"
          >
            <template slot-scope="scope">
              <p>{{ scope.row.invoiceType === '00'?'普票':'专票' }}</p>
            </template>
          </el-table-column>
          <el-table-column
            label="创建日期"
            prop="createDate"
            align="center"
            min-width="120"
          >
            <template slot-scope="scope">
              {{ scope.row.createDate && $Moment(scope.row.createDate).format(momentDate) }}
            </template>
          </el-table-column>
          <el-table-column
            label="是否作废"
            align="center"
            min-width="110"
          >
            <template slot-scope="scope">
              <span v-for="(item,index) in isInvalidGroup" v-if="scope.row.isInvalid===item.typecode" :key="index">
                {{ item.typename }}
              </span>
            </template>
          </el-table-column>
          <el-table-column
            header-align="center"
            label="操作"
            align="center"
            width="146"
          >
            <template slot-scope="scope">
              <el-link
                type="primary"
                size="mini"
                @click="intoProject(scope.row)"
              >
                [查看]
              </el-link>
              <el-link
                v-if="scope.row.isInvalid==='0'"
                size="mini"
                type="primary"
                @click="intoSee(scope.row)"
              >
                [作废]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="loadData" />
      </section>
    </section>
  </div>
</template>
<script>
/* 接口*/
import { listInvoicePages, getInvoiceDictionaries, invalidInvoice } from '@/api/supplier/enterpriseManagement'// 发票列表
/* 公用方法*/
import { filterObj } from '@/assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { initGroupMixin } from '@/mixins/initGroupMixin'// 字典信息
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页

export default {
  name: 'ProjectManagerTenderList',
  components: {
    pagination // 分页
  },
  mixins: [ListMixin, initGroupMixin],
  data() {
    return {
      childenData: {
        dialog: false
      },
      loading: true,
      createTimeDate: [], // 创建时间
      invoiceTypeGroup: [], // 发票类型
      isInvalidGroup: [], // 发票是否作废
      // 搜索
      searchForm: {
        invoiceTitle: '', // 发票抬头
        taxpayerIdentificationNumber: '', // 税号
        invoiceType: '', // 发票类型
        createDateBegin: '', // 创建日期-开始
        createDateEnd: '', // 创建日期-结束
        isInvalid: '' // 是否作废
      },
      tableData: []
    }
  },
  created() {
    // 字典信息
    this.initTypeGroup()
    // 获取列表信息
    this.loadData()
  },
  methods: {
    // 创建时间
    dateCheng(val) {
      // 赋值开始时间 与结束数据
      this.searchForm.createDateBegin = val[0]
      this.searchForm.createDateEnd = val[1]
    },
    // 获取字典
    initTypeGroup() {
      getInvoiceDictionaries().then(res => {
        this.invoiceTypeGroup = res.data.invoiceTypeGroup.typeList
        this.isInvalidGroup = res.data.isInvalidGroup.typeList
      })
    },
    // 新增
    add() {
      this.$router.push('/supperManagement/invoiceInFormation')
    },
    // 获取数据
    loadData() {
      const params = this.getQueryParams()// 查询条件
      listInvoicePages(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {

      })
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 查看
    intoProject(row) {
      if (row.invoiceType === '00') {
        this.$router.push({
          path: '/supperManagement/generalVote',
          query: {
            id: row.id // Id
          }
        })
      }
      if (row.invoiceType === '01') {
        this.$router.push({
          path: '/supperManagement/specialTicket',
          query: {
            id: row.id // Id
          }
        })
      }
    },
    // 作废
    intoSee(row) {
      this.$confirm('作废之后将不能使用本条开票信息，确认作废？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        invalidInvoice(row.id).then(res => {
          this.$message({
            type: 'success',
            message: '作废成功!'
          })
          this.onSearch()
        })
      }).catch(() => {
      })
    },
    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      // 获取列表信息
      this.loadData()
    },
    // 重置
    resetForm(formName) {
      this.$refs[formName].resetFields()
      this.searchForm.createDateBegin = ''
      this.searchForm.createDateEnd = ''
      this.createTimeDate = ''
      // 获取列表信息
      this.onSearch()
    }
  }
}
</script>
<style lang="less" scoped>

</style>
