<template>
  <el-drawer title="详情" :visible.sync="drawer" size="60%">
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      ref="crud"
      v-model="form"
      @search-change="searchChange"
      @search-reset="searchReset"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot="userNum" slot-scope="{row}">
        <span>{{row.userNum}} 人</span>
      </template>
      <template slot="serviceFee" slot-scope="{row}">
        <span v-if="!row.serviceFee && row.serviceFee!== 0">-</span>
        <span v-else>￥{{moneyFormat(row.serviceFee)}}</span>
      </template>
      <template slot="total" slot-scope="{row}">
        <span v-if="!row.total && row.total!== 0">-</span>
        <span v-else>￥{{moneyFormat(row.total)}}</span>
      </template>
    </avue-crud>
  </el-drawer>
</template>

<script>
import { getDetail } from "@/api/manage/account";
import { moneyFormat } from "@/util/money";

export default {
  data() {
    return {
      id: null,
      form: {},
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      drawer: false,
      option: {
        height: "auto",
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        dialogClickModal: false,
        menu: false,
        addBtn: false,
        column: [
          {
            label: "公司名称",
            prop: "companyName",
            display: false,
            search: true,
          },
          {
            label: "结算人数",
            prop: "userNum",
            display: false,
            slot: true,
          },
          {
            label: "服务费",
            prop: "serviceFee",
            display: false,
            slot: true,
          },
          {
            label: "结算比例",
            prop: "ratio",
            display: false,
          },
          {
            label: "结算期",
            prop: "month",
            display: false,
          },
          {
            label: "结算金额",
            prop: "total",
            display: false,
            slot: true,
          },
        ],
      },
      data: [],
    };
  },
  computed: {},
  methods: {
    initData() {
      this.onLoad(this.page, this.query);
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      getDetail(
        page.currentPage,
        page.pageSize,
        Object.assign(this.query, params),
        this.id
      ).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
      });
    },
    open(id) {
      this.id = id;
      this.drawer = true;
      this.page.currentPage = 1;
      this.query = {};
      this.onLoad(this.page, this.query);
    },
    moneyFormat,
  },
};
</script>

<style>
</style>
