<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix" v-hasPermi="['platform:finance:merchant:closing:page:list']">
        <div class="container">
          <el-form size="small" inline label-width="100px">
            <el-form-item label="时间选择：">
              <el-date-picker
                v-model="timeVal"
                value-format="yyyy-MM-dd"
                format="yyyy-MM-dd"
                size="small"
                type="daterange"
                placement="bottom-end"
                placeholder="自定义时间"
                style="width: 250px"
                @change="onchangeTime"
              />
            </el-form-item>
            <el-form-item label="关键字：">
              <el-input
                v-model.trim="searchInfo.keyword"
                @keyup.enter.native="searchList"
                placeholder="请输入订单号/申请单号/发票号码"
                class="selWidth"
                size="small"
              >
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  size="small"
                  class="el-button-solt"
                  @click="getList(1)"
                  v-hasPermi="['platform:finance:merchant:closing:page:list']"
                />
              </el-input>
            </el-form-item>
            <el-form-item label="开票状态：" class="width100" style="display: block">
              <el-select v-model="searchInfo.fapiaoStatus" placeholder="请选择" @change="searchList">
                <el-option label="全部" :value="-1"></el-option>
                <el-option label="未开票" :value="0"></el-option>
                <el-option label="已开票" :value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <el-table v-loading="listLoading" tooltip-effect="dark" :data="invoiceList" style="width: 100%" class="table">
        <el-table-column prop="orderNo" label="订单号" min-width="180" />
        <!-- <el-table-column label="商户名称" min-width="150" align="center" >
          <template slot-scope="scope">
            <span>{{ scope.row.orderDetails[0].merName }}</span>
          </template>
        </el-table-column> -->
        <el-table-column prop="userName" label="用户昵称" min-width="120" align="center" />
        <!-- <el-table-column label="订单金额" min-width="120" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.order.payPrice }}</span>
          </template>
        </el-table-column> -->
        <!-- <el-table-column label="订单状态" min-width="80" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.order.status === 0 ? '待支付' : scope.row.order.status === 1 ? '待发货' : scope.row.order.status === 2 ? '部分发货' : scope.row.order.status === 3 ? '待核销' : scope.row.order.status === 4 ? '待收货' : scope.row.order.status === 5 ? '已收货' : scope.row.order.status === 6 ? '已完成' : '已取消' }}</span>
          </template>        
        </el-table-column> -->
        <el-table-column prop="amount" label="发票金额" min-width="120" align="center" />
        <el-table-column prop="fapiaoNo" label="发票单号" min-width="120" align="center" />
        <el-table-column prop="amount" label="发票类型" min-width="80" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.fapiaoType === 0 ? '普通发票' : '专用发票' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="amount" label="发票抬头" min-width="70" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.titleType === 0 ? '个人' : '企业' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="title" label="发票联系人" min-width="120" align="center" />
        <el-table-column prop="email" label="发票联系信息" min-width="170" align="center" />
        <!-- <el-table-column label="下单时间" min-width="150" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.order.createTime }}</span>
          </template>
        </el-table-column> -->
        <el-table-column prop="amount" label="开票状态" min-width="70" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.fapiaoStatus === 0 ? '未开票' : '已开票' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="发票备注" min-width="120" align="center" />
        <el-table-column label="操作" min-width="60" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="openInvoiceDetailDialog(scope.row)"
              v-hasPermi="['platform:finance:merchant:closing:detail']"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[20, 40, 60, 80]"
          :page-size="limit"
          :current-page="page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>
    <invoiceDetailDialog :showInvoiceDetailDialog="showInvoiceDetailDialog" :invoiceDetailInfo="invoiceDetailInfo" @closeInvoiceDetailDialog="closeInvoiceDetailDialog" />
  </div>
</template>
<script>
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
import { getInvoiceListApi } from '@/api/finance';
import { checkPermi } from '@/utils/permission'; // 权限判断函数
import invoiceDetailDialog from './components/invoiceDetailDialog';

export default {
  name: 'FinanceInvoice',
  
  data() {
    return {
      listLoading: true,
      showInvoiceDetailDialog: false,
      timeVal: [],
      page: 1,
      limit: 20,
      total: 0,
      totalPage: null,
      invoiceList: [],
      searchInfo: {
        keyword: '',
        timeFrom: '',
        timeTo: '',
        fapiaoStatus: null
      },
      invoiceDetailInfo: {}
    };
  },
  components: { invoiceDetailDialog },

  mounted() {
    if (checkPermi(['platform:finance:merchant:closing:page:list'])) this.getList();
  },

  methods: {
    checkPermi,

    getList() {
      let params = {
        page: this.page,
        limit: this.limit
      }
      this.listLoading = true;
      this.searchInfo.keyword ? params.keyword = this.searchInfo.keyword : null;
      this.searchInfo.timeFrom ? params.timeFrom = this.searchInfo.timeFrom : null;
      this.searchInfo.timeTo ? params.timeTo = this.searchInfo.timeTo : null;
      this.searchInfo.fapiaoStatus >= 0 ? params.fapiaoStatus = this.searchInfo.fapiaoStatus : null;

      getInvoiceListApi(params)
        .then((res) => {
          let { limit, list, page, total, totalPage } = res;

          this.limit = limit;
          this.invoiceList = list;
          this.page = page;
          this.total = total;
          this.totalPage = totalPage;
          this.listLoading = false;

          console.info('invoice list', res);
        }).catch(() => {
          this.listLoading = false;
        });
    },

    // 具体日期
    onchangeTime(e) {
      this.page = 1;
      this.timeVal = e;
      if (!this.timeVal) {
        this.searchInfo.timeFrom = '';
        this.searchInfo.timeTo = '';
        this.getList();
        return;
      }

      [this.searchInfo.timeFrom, this.searchInfo.timeTo] = this.timeVal;
      this.getList();
    },

    searchList() {
      this.page = 1;
      this.getList();
    },

    openInvoiceDetailDialog(row) {
      this.invoiceDetailInfo = row;
      this.showInvoiceDetailDialog = true;
    },

    closeInvoiceDetailDialog() {
      this.showInvoiceDetailDialog = false;
    },

    pageChange(page) {
      this.page = page;
      this.getList();
    },

    handleSizeChange(val) {
      this.limit = val;
      this.getList();
    }
  },
};
</script>

<style lang="scss" scoped>
.demo-image__preview {
  width: 60px;
  height: 60px;
  .el-image {
    width: 100%;
    height: 100%;
  }
}
.title {
  font-size: 20px;
}
.wid100 {
  width: 100px;
}
.ml100 {
  margin-left: 100px;
}
.transferMinAmount {
  ::v-deep.el-form-item__content {
    line-height: normal;
  }
}
::v-deep .el-dialog__title {
  font-weight: bold;
}
.selWidth {
  width: 300px;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
  font-size: 12px;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.font-red {
  color: #ff4949;
}
.tabBox_tit {
  width: 60%;
  font-size: 12px !important;
  margin: 0 2px 0 10px;
  letter-spacing: 1px;
  padding: 5px 0;
  box-sizing: border-box;
}
.pictrue {
  width: 60px;
  height: 60px;
  border: 1px dotted rgba(0, 0, 0, 0.1);
  margin-right: 10px;
  position: relative;
  cursor: pointer;
  img {
    width: 100%;
    height: 100%;
  }
}
.box-container {
  overflow: hidden;
  padding: 0 30px;
  font-size: 14px;
}

.box-container .list.image {
  margin: 20px 0;
  position: relative;
}
.box-container .list.image img {
  position: absolute;
  top: -20px;
}
.box-container .list {
  float: left;
  line-height: 40px;
}
.box-container .sp100 {
  width: 100%;
}

.acea-row {
  margin-bottom: 25px;
}
.pictures {
  width: 100%;
  height: 100%;
}
</style>
