<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :span="3">
            <a-form-item label="">
              <a-input
                placeholder="房号/姓名/手机号/单号"
                v-model="queryParam.keyw"
              ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="3">
            <a-form-item label="">
              <a-select
                v-model="queryParam.type"
                style="width: 100%"
                placeholder="类型"
              >
                <a-select-option :value="1">入住</a-select-option>
                <a-select-option :value="2">预定</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :span="3" v-if="queryParam.type == 1">
            <a-form-item label="">
              <a-select
                v-model="queryParam.livingStatus"
                style="width: 100%"
                placeholder="类型"
              >
                <a-select-option :value="-1">正常入住</a-select-option>
                <a-select-option :value="1">已结账退房</a-select-option>
                <a-select-option :value="2">先走未结</a-select-option>
                <a-select-option :value="3">联房退房</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :span="3" v-else-if="queryParam.type == 2">
            <a-form-item label="">
              <a-select
                v-model="queryParam.bookingStatus"
                style="width: 100%"
                placeholder="类型"
              >
                <a-select-option :value="1">预定中</a-select-option>
                <a-select-option :value="2">在住</a-select-option>
                <a-select-option :value="3">已取消</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span
              style="float: left; overflow: hidden"
              class="table-page-search-submitButtons"
            >
              <a-button type="primary" @click="searchQuery" icon="search"
                >查询</a-button
              >
              <!-- <a-button
                type="primary"
                @click="searchReset"
                icon="reload"
                style="margin-left: 8px"
                >重置</a-button
              > -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChange,
        }"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px; font-style: italic"
            >无图片</span
          >
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic"
            >无文件</span
          >
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)"
          >
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleInfo(record)">查看</a>
          <a-divider v-if="queryParam.type == 2" type="vertical" />
          <a v-if="queryParam.type == 2" @click="setOrderStatus(record)"
            >取消订单</a
          >

          <a-divider type="vertical" v-if="queryParam.type == 2" />
          <a v-if="queryParam.type == 2" @click="handleInfo(record)">入住</a>
        </span>
      </a-table>
    </div>
    <bill-room-info-modal
      ref="ModalBillRoomInfo"
      @ok="modalLockRoomFormOk"
    ></bill-room-info-modal>
  </a-card>
</template>

<script>
import "@/assets/less/TableExpand.less";
import { mixinDevice } from "@/utils/mixin";
import { JeecgListMixin } from "@/mixins/JeecgListMixin";
import BillRoomInfoModal from "./modules/checkIn/BillRoomInfoModal.vue";
import { httpAction, postAction, getAction } from "@/api/manage";
export default {
  name: "CesOrderMessageList",
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    BillRoomInfoModal,
  },
  data() {
    return {
      description: "客单",
      // 表头
      columns: [
        {
          title: "单号",
          align: "center",
          dataIndex: "orderNo",
        },
        {
          title: "客人/电话",
          align: "center",
          dataIndex: "customerName",
          customRender: function (text, record) {
            return record.customerName + "/" + record.customerPhone;
          },
        },
        {
          title: "客人类型",
          align: "center",
          dataIndex: "customerType",
          customRender: function (text) {
            if (text == 1) {
              return "散客";
            } else if (text == 2) {
              return "会员";
            } else if (text == 3) {
              return "协议单位";
            } else if (text == 4) {
              return "中介";
            }
          },
        },
        {
          title: "入住类型",
          align: "center",
          dataIndex: "isLiving",
          customRender: function (text, record) {
            if (record.livingDayPrices && record.livingDayPrices.length > 0) {
              return record.livingDayPrices[0].livingType == 1
                ? "全天"
                : "钟点";
            }
            if (record.bookingDayPrices && record.bookingDayPrices.length > 0) {
              return record.bookingDayPrices[0].livingType == 1
                ? "全天"
                : "钟点";
            }
            return "--";
          },
        },
        {
          title: "房型",
          align: "center",
          dataIndex: "layoutName",
        },
        {
          title: "房号",
          align: "center",
          dataIndex: "roomName",
          customRender: function (text, record) {
            return !text ? "排房" : text;
          },
        },
        {
          title: "房价",
          align: "center",
          dataIndex: "createDate",
          customRender: function (text, record) {
            if (record.livingDayPrices && record.livingDayPrices.length > 0) {
              return record.livingDayPrices[0].price;
            }
            if (record.bookingDayPrices && record.bookingDayPrices.length > 0) {
              return record.bookingDayPrices[0].price;
            }
            return "--";
          },
        },
        // {
        //   title: "状态",
        //   align: "center",
        //   dataIndex: "createDate",
        // },
        {
          title: "预抵时间",
          align: "center",
          dataIndex: "arrivalTime",
        },
        {
          title: "预离时间",
          align: "center",
          dataIndex: "dueOutTime",
        },
        {
          title: "金额",
          align: "center",
          dataIndex: "yuE",
          customRender: function (text, record) {
            return record.yuE + "（余）/" + record.yushou + "（预）";
          },
        },
        {
          title: "操作",
          dataIndex: "action",
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: { customRender: "action" },
        },
      ],
      url: {
        list: "/business/busRoomBookingOrders/kedan-orders",
        delete: "/order/cesOrderMessage/delete",
        deleteBatch: "/order/cesOrderMessage/deleteBatch",
        exportXlsUrl: "/order/cesOrderMessage/exportXls",
        importExcelUrl: "order/cesOrderMessage/importExcel",
      },
      dictOptions: {},
      superFieldList: [],
      hotelList: [],
      queryParam: { type: 1, livingStatus: -1, bookingStatus: 1 },
    };
  },
  created() {
    getAction("/business/busHotel/list", { pageNo: 1, pageSize: 100 }).then(
      (res) => {
        if (res.success) {
          this.hotelList = res.result.records;
        }
      }
    );
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG["domianURL"]}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    setOrderStatus(record) {
      postAction("/business/busRoomBookingOrders/set-booking-status", {
        id: record.id,
        bookingStatus: 2,
      }).then((res) => {
        if (res.success) {
          this.$message.success(res.message);
          this.loadData();
        } else {
          this.$message.warning(res.message);
        }
      });
    },
    handleInfo(record) {
      if (this.queryParam.type == 2) {
        this.$router.push({
          name: "room-scheduledetail",
          params: {
            id: record.orderNo,
          },
        });
      } else {
        this.$refs.ModalBillRoomInfo.add(record.id, 1);
        this.$refs.ModalBillRoomInfo.title = "账单";
        this.$refs.ModalBillRoomInfo.disableSubmit = true;
      }
    },
  },
};
</script>
<style scoped>
@import "~@assets/less/common.less";
</style>