<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-row :gutter="24">
        <a-col :md="6" :sm="8">
          <span
            style="float: left; overflow: hidden"
            class="table-page-search-submitButtons"
          >
            <a-button
              @click="batchConfirm"
              type="danger"
              style="margin-left: 8px"
              >批量确认</a-button
            >
            <a-button type="primary" style="margin-left: 8px" @click="batchDel"
              >批量删除</a-button
            >
          </span>
        </a-col>
      </a-row>
    </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 v-if="record.status == 0" @click="handleEdit(record)">确认</a>
          <a-divider type="vertical" />
          <a @click="handleDelete(record.id)">删除</a>
        </span>
      </a-table>
    </div>

    <!-- <bus-market-coupons-cash-used-generate-form-modal
      ref="modalForm"
      @ok="modalFormOk"
    ></bus-market-coupons-cash-used-generate-form-modal> -->
  </a-card>
</template>

<script>
import "@/assets/less/TableExpand.less";
import { mixinDevice } from "@/utils/mixin";
import { JeecgListMixin } from "@/mixins/JeecgListMixin";
// import BusMarketCouponsCashUsedGenerateFormModal from "./BusMarketCouponsCashUsedGenerateFormModal";
import { httpAction, postAction } from "@/api/manage";

export default {
  name: "meetingRoomScheduleDetailList",
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    // BusMarketCouponsCashUsedGenerateFormModal,
  },
  props: {
    meetingRoomScheduleId: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      description: "免房券领取使用表管理页面",
      // 表头
      columns: [
        {
          title: "会议室",
          align: "center",
          dataIndex: "meetingRoomName",
        },
        {
          title: "会议主题",
          align: "center",
          dataIndex: "theme",
        },

        {
          title: "开会日期",
          align: "center",
          dataIndex: "meetingDate",
        },
        {
          title: "开会时段",
          align: "center",
          dataIndex: "timeSpan",
          customRender: function (text) {
            var msg = "";
            if (text == 1) {
              msg = "上午";
            } else if (text == 2) {
              msg = "下午";
            } else if (text == 3) {
              msg = "晚上";
            }
            return msg;
          },
        },
        {
          title: "状态",
          align: "center",
          dataIndex: "status",
          customRender: function (text) {
            return text == 0 ? "未确认" : "已确认";
          },
        },
        {
          title: "操作",
          dataIndex: "action",
          align: "center",
          fixed: "right",
          width: 80,
          scopedSlots: { customRender: "action" },
        },
      ],
      url: {
        list:
          "/business/busMeetingRoomScheduleDetail/list?meetingRoomScheduleId=" +
          this.meetingRoomScheduleId,
        delete: "/business/busMeetingRoomScheduleDetail/delete",
        deleteBatch: "/business/busMeetingRoomScheduleDetail/deleteBatch",
        exportXlsUrl: "/business/busMeetingRoomScheduleDetail/exportXls",
        importExcelUrl: "business/busMeetingRoomScheduleDetail/importExcel",
        confirmBatch: "/business/busMeetingRoomScheduleDetail/confirmBatch",
      },
      dictOptions: {},
      superFieldList: [],
    };
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG["domianURL"]}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    batchConfirm() {
      if (!this.url.confirmBatch) {
        this.$message.error("请设置url.confirmBatch!");
        return;
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning("请选择一条记录！");
        return;
      } else {
        // var ids = "";
        // for (var a = 0; a < this.selectedRowKeys.length; a++) {
        //   ids += this.selectedRowKeys[a] + ",";
        // }
        var that = this;
        that.loading = true;
        postAction(that.url.confirmBatch, { ids: this.selectedRowKeys })
          .then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.loadData();
              that.onClearSelected();
              that.$emit("ok");
            } else {
              that.$message.warning(res.message);
            }
          })
          .finally(() => {
            that.loading = false;
          });
      }
    },
    handleEdit(item) {
      var that = this;
      postAction("/business/busMeetingRoomScheduleDetail/confirm", {
        id: item.id,
      })
        .then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            item.status = 1;
            that.$emit("ok");
          } else {
            that.$message.warning(res.message);
          }
        })
        .finally(() => {});
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({
        type: "string",
        value: "tenantId",
        text: "关联租户",
        dictCode: "",
      });
      fieldList.push({
        type: "string",
        value: "hotelId",
        text: "关联酒店",
        dictCode: "",
      });
      fieldList.push({
        type: "string",
        value: "couponsId",
        text: "免房券id",
        dictCode: "",
      });
      fieldList.push({
        type: "string",
        value: "code",
        text: "券号",
        dictCode: "",
      });
      fieldList.push({
        type: "int",
        value: "status",
        text: "状态 0未领取 1已领取 2已使用 3已作废",
        dictCode: "",
      });
      fieldList.push({
        type: "string",
        value: "userid",
        text: "会员id",
        dictCode: "",
      });
      fieldList.push({
        type: "string",
        value: "userName",
        text: "姓名",
        dictCode: "",
      });
      fieldList.push({
        type: "string",
        value: "roomNumber",
        text: "房间号",
        dictCode: "",
      });
      fieldList.push({
        type: "string",
        value: "checkedInNo",
        text: "入住单号",
        dictCode: "",
      });
      fieldList.push({
        type: "string",
        value: "mobile",
        text: "手机号",
        dictCode: "",
      });
      fieldList.push({ type: "date", value: "gainTime", text: "领取时间" });
      fieldList.push({ type: "date", value: "usedTime", text: "使用时间" });
      this.superFieldList = fieldList;
    },
    handleAdd() {
      this.$refs.modalForm.add(this.ipagination.total, this.couponsId);
      this.$refs.modalForm.title = "优惠券生成";
      this.$refs.modalForm.disableSubmit = false;
    },
  },
};
</script>
<style scoped>
@import "~@assets/less/common.less";
</style>