<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="">
              <j-input placeholder="名称" v-model="queryParam.name"></j-input>
            </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
              >
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button @click="batchDel" type="danger" icon="minus">批量删除</a-button>
    </div>

    <!-- 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 != 1" @click="setStatus(record,1)">启用</a>
          <a v-else @click="setStatus(record,0)">禁用</a>
          <a-divider type="vertical" />
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm
                  title="确定删除吗?"
                  @confirm="() => handleDelete(record.id)"
                >
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>

    <bus-meeting-room-modal
      ref="modalForm"
      @ok="modalFormOk"
    ></bus-meeting-room-modal>
  </a-card>
</template>

<script>
import "@/assets/less/TableExpand.less";
import { mixinDevice } from "@/utils/mixin";
import { JeecgListMixin } from "@/mixins/JeecgListMixin";
import BusMeetingRoomModal from "./modules/meetingRoom/BusMeetingRoomModal";
import { httpAction, postAction } from "@/api/manage";
export default {
  name: "BusMeetingRoomList",
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    BusMeetingRoomModal,
  },
  data() {
    return {
      description: "bus_meeting_room管理页面",
      // 表头
      columns: [
        {
          title: "名称",
          align: "center",
          dataIndex: "name",
        },
        {
          title: "规格",
          align: "center",
          dataIndex: "spec",
        },
        {
          title: "面积",
          align: "center",
          dataIndex: "area",
        },
        {
          title: "人数",
          align: "center",
          dataIndex: "number",
        },
        {
          title: "管理员姓名",
          align: "center",
          dataIndex: "adminName",
        },
        {
          title: "地址",
          align: "center",
          dataIndex: "address",
        },
        {
          title: "设备",
          align: "center",
          dataIndex: "facility",
        },
        {
          title: "排序",
          align: "center",
          dataIndex: "sort",
        },
        {
          title: "描述",
          align: "center",
          dataIndex: "remark",
        },
        {
          title: "状态",
          align: "center",
          dataIndex: "status",
          customRender: function (text) {
            return text == 1 ? "启用" : "未启用";
          },
        },
        {
          title: "操作",
          dataIndex: "action",
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: { customRender: "action" },
        },
      ],
      url: {
        list: "/business/busMeetingRoom/list",
        delete: "/business/busMeetingRoom/delete",
        deleteBatch: "/business/busMeetingRoom/deleteBatch",
        exportXlsUrl: "/business/busMeetingRoom/exportXls",
        importExcelUrl: "business/busMeetingRoom/importExcel",
      },
      dictOptions: {},
      superFieldList: [],
    };
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG["domianURL"]}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    setStatus(record, status) {
      record.status = status;
      postAction("/business/busMeetingRoom/edit", record).then((res) => {
        if (res.success) {
          this.$message.success(res.message);
        } else {
          this.$message.warning(res.message);
        }
      });
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: "string", value: "tenantId", text: "关联租户" });
      fieldList.push({ type: "string", value: "hotelId", text: "关联酒店" });
      fieldList.push({ type: "string", value: "name", text: "名称" });
      fieldList.push({ type: "string", value: "spec", text: "规格" });
      fieldList.push({ type: "number", value: "area", text: "金额" });
      fieldList.push({ type: "int", value: "number", text: "人数" });
      fieldList.push({
        type: "string",
        value: "adminName",
        text: "管理员姓名",
      });
      fieldList.push({ type: "string", value: "address", text: "地址" });
      fieldList.push({ type: "string", value: "facility", text: "设备" });
      fieldList.push({ type: "int", value: "sort", text: "排序" });
      fieldList.push({ type: "string", value: "remark", text: "描述" });
      fieldList.push({ type: "int", value: "status", text: "状态" });
      this.superFieldList = fieldList;
    },
  },
};
</script>
<style scoped>
@import "~@assets/less/common.less";
</style>