<template>
  <Container>
    <div slot="left">
      <el-form inline size="small">
        <el-form-item>
          <el-date-picker
            v-model="value_time"
            clearable
            type="daterange"
            value-format="timestamp"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="changeTime"
          ></el-date-picker>
        </el-form-item>
      </el-form>
    </div>
    <!--    表格-->
    <div class="table">
      <el-table :data="tableData" style="width: 100%" type="index">
        <el-table-column prop="goods" label="奖励对象" width="180">
          <template>
            {{ staffName }}
          </template>
        </el-table-column>
        <el-table-column
          prop="originNo"
          label="关联订单号"
          width="180"
        ></el-table-column>
        <el-table-column prop="title" label="说明"></el-table-column>
        <el-table-column prop="amount" label="奖金">
          <template slot-scope="scope">
            <span
              :class="[
                scope.row.type === 5 ? 'success-status' : 'danger-status',
              ]"
            >
              {{ scope.row.type === 5 ? "+" : "-" }}{{ scope.row.amount }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          prop="changeAmount"
          label="变动后奖金"
        ></el-table-column>
        <el-table-column prop="time" label="创建时间">
          <template slot-scope="scope">
            {{ $_common.formatDate(scope.row.createTime) }}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!--    分页查询-->
    <FooterPage
      :page-size="pageSize"
      :total-page.sync="total"
      :current-page.sync="page"
      @pageChange="pageChange"
      @sizeChange="sizeChange"
    ></FooterPage>
  </Container>
</template>
<script>
  import { getAllStaffRewardDesc } from "@/api/Department";

  export default {
    data() {
      return {
        state: "状态",
        total: 0,
        page: 1,
        pageSize: 10,
        index: "",
        value: "",
        status: [
          { value: "启用", lable: "选项一" },
          { value: "禁用", lable: "选项二" },
        ],
        value_time: [],
        tableData: [],
        search_form: {
          start: "",
          end: "",
          enableStatus: "",
        },
        staffId: "",
        staffName: "",
      };
    },
    created() {
      if (this.$route.query.id) {
        this.staffId = this.$route.query.id - 0;
        this.staffName = this.$route.query.name;
      }
      this.getAllStaffRewardDesc();
    },
    activated() {
      if (this.$_isInit()) return;
      if (this.$route.query.id) {
        this.staffId = this.$route.query.id - 0;
        this.staffName = this.$route.query.name;
      }
      this.getAllStaffRewardDesc();
    },
    methods: {
      //  订单时间
      changeTime(val) {
        if (val && val.length) {
          this.search_form.start = val[0] / 1000;
          this.search_form.end = val[1] / 1000 + 86399;
        } else {
          this.search_form.start = "";
          this.search_form.end = "";
        }
        this.pageChange(1);
      },
      async getAllStaffRewardDesc() {
        const { data, pageTotal } = await getAllStaffRewardDesc({
          staffId: this.staffId,
          source: "",
          star: this.search_form.start,
          end: this.search_form.end,
          page: this.page,
          pageSize: this.pageSize,
        });
        this.tableData = data;
        this.total = pageTotal;
      },
      pageChange(page) {
        this.page = page;
        this.getAllStaffRewardDesc();
      },
      // 每页数据大小改变
      sizeChange(val) {
        this.pageSize = val;
        this.pageChange(1);
      },
    },
  };
</script>
<style></style>
