<template>
  <ContainerQuery>
    <el-form slot="more" style="margin-bottom: 0" :inline="true" size="small">
      <el-form-item>
        <el-select
          v-model="status"
          placeholder="订单状态"
          clearable
          @change="pageChange(1)"
        >
          <el-option
            v-for="(item, index) in type_options"
            :key="index"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <div class="block">
          <el-date-picker
            v-model="time"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="timestamp"
            @change="timeChange"
          ></el-date-picker>
        </div>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column type="index" label=" "></el-table-column>
      <el-table-column prop="salesManName" label="业务员"></el-table-column>
      <el-table-column prop="dealCustomerNum" label="客户数"></el-table-column>
      <el-table-column prop="num" label="订单数"></el-table-column>
      <el-table-column prop="amount" label="订单金额">
        <template slot-scope="scope">
          {{ $_common.formattedNumber(scope.row.amount) }}
        </template>
      </el-table-column>
    </el-table>
    <FooterPage
      :page-size="pageSize"
      :total-page.sync="pageTotal"
      :current-page.sync="page"
      @pageChange="pageChange"
      @sizeChange="sizeChange"
    ></FooterPage>
  </ContainerQuery>
</template>
<script>
  import { salesManOrder } from "@/api/Commission";
  export default {
    data() {
      return {
        status: "",
        type: "",
        time: "",
        type_options: [
          {
            label: "全部",
            value: "",
          },
          {
            label: "待审核",
            value: 2,
          },
          {
            label: "待发货",
            value: 3,
          },
          {
            label: "待收货",
            value: 4,
          },
          {
            label: "已完成",
            value: 5,
          },
          {
            label: "已关闭",
            value: 6,
          },
        ],
        tableData: [],
        pageTotal: 10,
        page: 1,
        pageSize: 10,
        start: "",
        end: "",
      };
    },
    created() {
      this.salesManOrder();
    },
    methods: {
      async salesManOrder() {
        const res = await salesManOrder({
          page: this.page,
          pageSize: this.pageSize,
          startTime: this.start,
          endTime: this.end,
          orderStatus: this.status,
        });
        this.tableData = res.data;
        this.pageTotal = res.pageTotal;
      },
      // 时间筛选
      timeChange(val) {
        if (val && val.length) {
          this.start = val[0] / 1000;
          this.end = val[1] / 1000 + 86399;
        } else {
          this.start = "";
          this.end = "";
        }
        this.pageChange(1);
      },
      pageChange(val) {
        this.page = val;
        this.salesManOrder();
      },
      sizeChange(val) {
        this.pageSize = val;
        this.salesManOrder();
      },
    },
  };
</script>
<style></style>
