<template>
  <div class="app-container">
    <div v-if="showDetail">
      <!-- 筛选条件 -->
      <div>
        <el-form
          ref="searchForm"
          :model="searchForm"
          label-width="100px"
          size="small"
          label-position="left"
        >
          <el-row :gutter="20">
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="单据类型" prop="billType">
                <el-input
                  v-model="searchForm.billType"
                  placeholder="请输入"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="单据编号" prop="billNo">
                <el-input
                  v-model="searchForm.billNo"
                  placeholder="请输入"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="往来单位" prop="wlCompanyType">
                <el-input
                  v-model="searchForm.wlCompanyType"
                  placeholder="请输入"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="付款单位" prop="customerName">
                <el-input
                  v-model="searchForm.customerName"
                  placeholder="请输入"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="结算方式" prop="settleType">
                <el-input
                  v-model="searchForm.settleType"
                  placeholder="请输入"
                ></el-input>
              </el-form-item>
            </el-col>
            <!-- <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="收款用途" prop="">
                <el-input v-model="searchForm." placeholder="请输入"></el-input>
              </el-form-item>
            </el-col> -->
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="开始时间" prop="startTime">
                <el-date-picker
                  class="selectStyle"
                  v-model="searchForm.startTime"
                  type="datetime"
                  placeholder="选择日期时间"
                  default-time="00:00:00"
                  value-format="yyyy-MM-dd HH:mm:ss"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="结束时间" prop="endTime">
                <el-date-picker
                  class="selectStyle"
                  v-model="searchForm.endTime"
                  type="datetime"
                  placeholder="选择日期时间"
                  default-time="00:00:00"
                  value-format="yyyy-MM-dd HH:mm:ss"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>

            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="" class="fr">
                <el-button size="small" @click="cancelFn">清空</el-button>
                <el-button size="small" type="primary" @click="searchFn"
                  >搜索</el-button
                >
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <!-- 按钮 -->
      <div class="btn-group clearfix">
        <div class="fr">
          <el-button type="primary" size="small">导出</el-button>
        </div>
      </div>
      <!-- 列表 -->
      <div class="mymain-container">
        <div class="table">
          <el-table
            v-loading="listLoading"
            :data="dataList"
            element-loading-text="Loading"
            border
            fit
            highlight-current-row
            stripe
          >
            <el-table-column
              align="center"
              label="单据类型"
              prop="billType"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="单据编码"
              prop="billNo"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="业务日期"
              prop="theTime"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="币别"
              prop="bibie"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="表头·应收金额"
              prop=""
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="往来单位"
              prop="wlCompanyType"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="表头·实收金额"
              prop="amount"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="收款金额"
              prop=""
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="结算方式"
              prop="settleType"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <!-- <el-table-column
              align="center"
              label="收款用途"
              prop=""
              min-width="160"
              show-overflow-tooltip
            ></el-table-column> -->
            <el-table-column
              align="center"
              label="付款单位"
              prop="customerType"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="表体·实收金额"
              prop="amount"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="勾对"
              prop=""
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="单据状态"
              prop="status"
              min-width="160"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <el-tag v-show="scope.row.status == 'A'">保存</el-tag>
                <el-tag v-show="scope.row.status == 'B'" type="info"
                  >审核中</el-tag
                >
                <el-tag v-show="scope.row.status == 'C'" type="success"
                  >已审核</el-tag
                >
                <el-tag v-show="scope.row.status == 'D'" type="warning"
                  >重新审核</el-tag
                >
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              label="备注"
              prop="remark"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="操作"
              min-width="160"
              show-overflow-tooltip
              fixed="right"
            >
              <template slot-scope="scope">
                <el-button
                  type="text"
                  class="textColor"
                  @click="seeFn(scope.row.id)"
                  >查看</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- 分页 -->
        <div class="fr">
          <el-pagination
            :current-page="currentPage"
            :page-sizes="[10, 20, 30, 50]"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="listTotal"
          >
          </el-pagination>
        </div>
      </div>
    </div>
    <ReceiptListDetail :detailId="detailId" v-else />
  </div>
</template>

<script>
import { getK3ReceiptList } from "@/api/finance/receipt_list";
import ReceiptListDetail from "./components/receipt_list-detail";
export default {
  components: {
    ReceiptListDetail,
  },
  data() {
    return {
      currentPage: 1, // 当前页码
      pageSize: 10, // 每页数量
      listTotal: 0, // 列表总数
      dataList: [], // 列表数据
      searchForm: {
        billType: "",
        billNo: "",
        wlCompanyType: "",
        customerName: "",
        settleType: "",
        startTime: "",
        endTime: "",
      }, //搜索表单
      listLoading: false, // 列表加载loading
      showDetail: true,
      detailId: null,
    };
  },
  created() {
    this.getDataList({ pageSize: this.pageSize, pageNum: this.currentPage });
  },
  methods: {
    //清空
    cancelFn() {
      this.$refs.searchForm.resetFields();
    },
    //搜索
    searchFn() {
      this.getDataList({
        ...this.searchForm,
        pageSize: this.pageSize,
        pageNum: this.currentPage,
      });
    },
    async getDataList(data) {
      const res = await getK3ReceiptList(data);
      console.log(res);
      this.dataList = res.data.records;
    },
    seeFn(id) {
      this.detailId = id;
      this.showDetail = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.selectStyle {
  width: 100%;
}
</style>