<template>
  <div class="mod-config">
    <el-form
      :inline="true"
      :model="dataForm"
      @keyup.enter.native="getDataList()"
    >
      <el-form-item>
        <el-input
          v-model="dataForm.groupName"
          placeholder="店铺"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="dataForm.hotelName"
          placeholder="酒店名称"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="dataForm.orderCode"
          placeholder="订单号"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="dataForm.city"
          placeholder="城市"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          value-format="yyyy-MM-dd HH:mm:ss"
          v-model="dataForm.orderDate"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"
          :clearable="false"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-select
          v-model="dataForm.buyStatus"
          placeholder="采购状态"
          multiple
          clearable
        >
          <el-option
            v-for="item in buyStatusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-select
          v-model="dataForm.orderStatus"
          placeholder="订单状态"
          multiple
          clearable
        >
          <el-option
            v-for="item in orderStatusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button @click="reFresh()">重置</el-button>
      </el-form-item>
      <el-form-item>
        <el-button @click="getExcel()">导出</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%"
    >
      <el-table-column
        prop="groupName"
        header-align="center"
        align="center"
        label="店铺"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="orderDate"
        header-align="center"
        align="center"
        label="订购日期"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="orderCode"
        header-align="center"
        align="center"
        label="飞猪订单号"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="orderTime"
        header-align="center"
        align="center"
        label="订单创建时间"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="payPrice"
        header-align="center"
        align="center"
        label="付款金额"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="buyOrderPrice"
        header-align="center"
        align="center"
        label="采购价"
        :show-overflow-tooltip="true"
      >
      </el-table-column>

      <el-table-column
        prop="grossProfit"
        header-align="center"
        align="center"
        label="毛利"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="grossProfitMargin"
        header-align="center"
        align="center"
        label="毛利率(%)"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="hotelName"
        header-align="center"
        align="center"
        label="酒店名称"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="roomNum"
        header-align="center"
        align="center"
        label="间夜数"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        :formatter="dateStr"
        header-align="center"
        align="center"
        label="入离时间"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="name"
        header-align="center"
        align="center"
        label="订单入住人信息"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="city"
        header-align="center"
        align="center"
        label="城市"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="orderStatus"
        header-align="center"
        align="center"
        label="订单状态"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="buyStatus"
        header-align="center"
        align="center"
        label="采购状态"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
    <!-- 入住人详情 -->
    <!-- <peo-info v-if="infoVisible" ref="peoInfo"></peo-info> -->
    <!--弹窗，处理订单-->
    <deal-with v-if="dealWithVisible" ref="dealWith"> </deal-with>
    <!-- 发票详情 -->
    <!-- <invo v-if="invoVisible" ref="invo"> </invo> -->
    <!-- 备注 -->
    <!-- <note v-if="noteVisible" ref="note"></note> -->
  </div>
</template>

<script>
// import PeoInfo from "./ordorder-peo-info"
import DealWith from "./ordorder-dealwith";
import axios from "axios";
// import Invo from "./ordorder-invo"
// import Note from "./ordorder-note"
export default {
  data() {
    return {
      dataForm: {
        orderCode: "",
        orderDate: null,
        groupName: "",
        hotelName: "",
        city: "",
        buyStatus: [],
        orderStatus: []
      },
      me: 0,
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      peoInfoVisible: false,
      dealWithVisible: false,
      infoVisible: false,
      invoVisible: false,
      noteVisible: false,
      buyStatusOptions: [
        {
          value: "0",
          label: "未采购"
        },
        {
          value: "1",
          label: "已受理"
        },
        {
          value: "2",
          label: "采购中"
        },
        {
          value: "3",
          label: "已采购"
        },
        {
          value: "-1",
          label: "采购失败"
        },
        {
          value: "-2",
          label: "退款中"
        },
        {
          value: "-3",
          label: "已退款"
        },
        {
          value: "-4",
          label: "退款失败"
        },
        {
          value: "-5",
          label: "订单取消中"
        },
        {
          value: "-6",
          label: "已取消"
        },
        {
          value: "-7",
          label: "取消失败"
        },
        {
          value: "-8",
          label: "已入住"
        }
      ],
      orderStatusOptions: [
        {
          value: "1",
          label: "未支付"
        },
        {
          value: "2",
          label: "已支付"
        },
        {
          value: "3",
          label: "已发货"
        },
        {
          value: "4",
          label: "已入住"
        },
        {
          value: "-1",
          label: "申请退款"
        },
        {
          value: "-2",
          label: "已退款"
        },
        {
          value: "-3",
          label: "关单"
        },
        {
          value: "-4",
          label: "已入住"
        },
        {
          value: "-5",
          label: "申请取消订单"
        }
      ]
    };
  },
  components: {
    // "peo-info": PeoInfo,
    "deal-with": DealWith
    // invo: Invo,
    // note: Note
  },
  activated() {
    this.reFresh();
  },
  methods: {
    // 导出订单excel
    getExcel() {
      this.$http({
        responseType: "blob",
        method: "get",
        url: this.$http.adornUrl("/ord/orderReport/excel"),
        // 请求参数，可以为空
        params: this.$http.adornParams({
          orderCode: this.dataForm.orderCode,
          orderDateStart: this.dataForm.orderDate[0] || "",
          orderDateEnd: this.dataForm.orderDate[1] || "",
          groupName: this.dataForm.groupName,
          hotelName: this.dataForm.hotelName,
          city: this.dataForm.city,
          buyStatus: this.dataForm.buyStatus.join(","),
          orderStatus: this.dataForm.orderStatus.join(",")
        })
      }).then(({ data }) => {
        let objectUrl = data;
        const blob = new Blob([data], ["application/vnd.ms-excel"]);
        objectUrl = URL.createObjectURL(blob);
        const a = document.createElement("a");
        a.href = objectUrl;
        //这里可以重新定义文件名，以前端为准
        a.download = "orderReportForm.xlsx";
        a.click();
        a.remove();
        URL.revokeObjectURL(objectUrl);
      });
    },
    reFresh() {
      this.dataForm = {
        orderCode: "",
        orderDate: null,
        groupName: "",
        hotelName: "",
        city: "",
        buyStatus: [],
        orderStatus: []
      };
      let date = new Date();
      this.dataForm.orderDate = [
        date.getFullYear() +
          "-" +
          (date.getMonth() + 1) +
          "-" +
          date.getDate() +
          " 00:00:00",
        date.getFullYear() +
          "-" +
          (date.getMonth() + 1) +
          "-" +
          date.getDate() +
          " 23:59:59"
      ];
      this.getDataList();
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/ord/orderReport/list"),
        method: "get",
        params: this.$http.adornParams({
          page: this.pageIndex,
          limit: this.pageSize,
          orderCode: this.dataForm.orderCode,
          orderDateStart: this.dataForm.orderDate[0] || "",
          orderDateEnd: this.dataForm.orderDate[1] || "",
          groupName: this.dataForm.groupName,
          hotelName: this.dataForm.hotelName,
          city: this.dataForm.city,
          buyStatus: this.dataForm.buyStatus.join(","),
          orderStatus: this.dataForm.orderStatus.join(",")
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
          this.me = data.me;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 采购渠道 1,携程 2，美团 3，人工线下采购 4，其他
    buySource(data) {
      let status = data.buySource;
      return status === 1
        ? "携程"
        : status === 2
        ? "美团"
        : status === 3
        ? "人工线下采购"
        : status === 4
        ? "其他"
        : "";
    },
    // 入住时间段
    dateStr(data) {
      return data.checkInDate + "~" + data.checkOutDate;
    },
    // 订单类型
    orderType(data) {
      let status = data.orderType;
      return status === 0 ? "人工订单" : status === 1 ? "直连订单" : "其他";
    },
    statusSources(data) {
      let status = data.buySource;
      return status === 2
        ? "美团"
        : status === 1
        ? "携程"
        : status === 3
        ? "线下"
        : "";
    },
    // 订单状态判断
    statusOrder(data) {
      let status = data.orderStatus;
      return status === 1
        ? "未支付"
        : status === 2
        ? "已支付"
        : status === 3
        ? "已发货"
        : status === 4
        ? "已入住"
        : status === -1
        ? "申请退款"
        : status === -2
        ? "已退款"
        : status === -3
        ? "关单"
        : status === -4
        ? "已入住"
        : status === -5
        ? "申请取消订单"
        : "其他";
    },
    // 采购状态判断
    // 0未采购，1已受理（已提交）2已采购 -1 采购失败 -2 已退单
    statusBuy(data) {
      let status = data.buyStatus;
      return status === 0
        ? "未采购"
        : status === 1
        ? "已受理"
        : status === 2
        ? "采购中"
        : status === 3
        ? "已采购"
        : status === -1
        ? "采购失败"
        : status === -2
        ? "退款中"
        : status === -3
        ? "已退款"
        : status === -4
        ? "退款失败"
        : status === -5
        ? "订单取消中"
        : status === -6
        ? "已取消"
        : status === -7
        ? "取消失败"
        : status === -8
        ? "已入住"
        : "其他";
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.reFresh();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    }
  }
};
</script>
<style>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
