<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="6">
            <a-form-item label="">
              <j-input
                placeholder="会员名称"
                v-model="queryParam.name"
              ></j-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item label="">
              <j-input
                placeholder="会员手机号"
                v-model="queryParam.mobile"
              ></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
              >

              <!-- <a-input-number
                style="margin-left: 8px"
                v-model="num"
                :min="1"
                :max="10"
              />
              <a-button
                @click="handleAdd"
                type="danger"
                :disabled="selectedRowKeys.length <= 0"
                >发放</a-button
              > -->
              <a-input-search
                style="width: 200px; margin-left: 8px"
                placeholder="请输入每人发放张数"
                enter-button="发放"
                v-model="num"
                type="danger"
                :disabled="selectedRowKeys.length <= 0"
                @search="handleAdd"
              />
            </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="avatar" slot-scope="text">
          <a-avatar v-if="text" :src="text" />
          <a-avatar v-else icon="user" />
        </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="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>
  </a-card>
</template>

<script>
import "@/assets/less/TableExpand.less";
import { mixinDevice } from "@/utils/mixin";
import { JeecgListMixin } from "@/mixins/JeecgListMixin";
import { httpAction } from "@/api/manage";
export default {
  name: "BusMemberCardList",
  mixins: [JeecgListMixin, mixinDevice],
  props: {
    couponsId: {
      type: String,
      default: "",
    },
    couponsType: {
      type: Number,
      default: 1,
    },
  },
  data() {
    const hotelInfo = JSON.parse(localStorage.getItem("storeInfo"));
    return {
      hotelId: "",
      num: 1,
      description: "bus_member_card管理页面",
      // 表头
      columns: [
        {
          title: "商家",
          align: "center",
          dataIndex: "hotelName",
        },
        {
          title: "头像",
          align: "center",
          dataIndex: "avatar",
          scopedSlots: { customRender: "avatar" },
        },
        {
          title: "会员姓名",
          align: "center",
          dataIndex: "name",
        },
        {
          title: "手机号",
          align: "center",
          dataIndex: "mobile",
        },
        {
          title: "性别",
          align: "center",
          dataIndex: "sex",
          customRender: function (text) {
            return text === 1 ? "男" : "女";
          },
        },
        {
          title: "会员卡号",
          align: "center",
          dataIndex: "cardNo",
        },
        {
          title: "等级类型",
          align: "center",
          dataIndex: "gradeName",
        },
        {
          title: "证件号",
          align: "center",
          dataIndex: "certificateNo",
        },
        {
          title: "推荐员工",
          align: "center",
          dataIndex: "staffId",
        },
        {
          title: "可用积分",
          align: "center",
          dataIndex: "integral",
        },
        {
          title: "可用余额",
          align: "center",
          dataIndex: "balance",
        },
        // {
        //   title: '操作',
        //   dataIndex: 'action',
        //   align:"center",
        //   fixed:"right",
        //   width:147,
        //   scopedSlots: { customRender: 'action' }
        // }
      ],
      url: {
        list:
          hotelInfo && hotelInfo.id
            ? "/business/busMemberCard/list?hotelId=" + hotelInfo.id
            : "/business/busMemberCard/list",
        delete: "/business/busMemberCard/delete",
        deleteBatch: "/business/busMemberCard/deleteBatch",
        exportXlsUrl: "/business/busMemberCard/exportXls",
        importExcelUrl: "business/busMemberCard/importExcel",
      },
      dictOptions: {},
      superFieldList: [],
    };
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG["domianURL"]}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    handleAdd() {
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning("请选择一条记录！");
        return;
      }
      if (this.num <= 0) {
        this.$message.warning("发放数量不能小于0！");
        return;
      }
      var that = this;
      that.confirmLoading = true;
      var url = "/business/busMarketCouponsUsed/gainCouponsUsedToMember";
      if (this.couponsType === 2) {
        url = "/business/busMarketCouponsCashUsed/gainCouponsCashUsedToMember";
      }
      httpAction(
        url,
        {
          couponsId: this.couponsId,
          num: this.num,
          memberIds: this.selectedRowKeys,
        },
        "post"
      )
        .then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.$emit("ok");
          } else {
            that.$message.warning(res.message);
          }
        })
        .finally(() => {
          that.confirmLoading = false;
        });
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: "string", value: "tenantId", text: "关联租户" });
      fieldList.push({ type: "string", value: "hotelId", text: "关联酒店" });
      fieldList.push({ type: "string", value: "mobile", text: "手机号" });
      fieldList.push({ type: "string", value: "cardNo", text: "会员卡号" });
      fieldList.push({ type: "string", value: "cardInnerNo", text: "卡内码" });
      fieldList.push({ type: "string", value: "gradeId", text: "等级类型" });
      fieldList.push({ type: "number", value: "memberFee", text: "会员费" });
      fieldList.push({ type: "int", value: "payType", text: "付款类型" });
      fieldList.push({ type: "int", value: "paymentMethod", text: "付款方式" });
      fieldList.push({ type: "string", value: "name", text: "会员姓名" });
      fieldList.push({ type: "string", value: "avatar", text: "头像" });
      fieldList.push({ type: "int", value: "sex", text: "性别" });
      fieldList.push({
        type: "int",
        value: "certificateType",
        text: "证件类型",
      });
      fieldList.push({
        type: "string",
        value: "certificateNo",
        text: "证件号",
      });
      fieldList.push({ type: "string", value: "address", text: "地址" });
      fieldList.push({
        type: "string",
        value: "consumePassword",
        text: "消费密码",
      });
      fieldList.push({ type: "int", value: "validity", text: "有效期" });
      fieldList.push({
        type: "date",
        value: "validityEndTime",
        text: "有效期截止日期",
      });
      fieldList.push({ type: "string", value: "remark", text: "备注" });
      fieldList.push({ type: "string", value: "staffId", text: "推荐员工" });
      fieldList.push({ type: "int", value: "integral", text: "可用积分" });
      fieldList.push({ type: "number", value: "balance", text: "可用余额" });
      this.superFieldList = fieldList;
    },
  },
};
</script>
<style scoped>
@import "~@assets/less/common.less";
/deep/ .ant-input-search-button {
  background-color: #ff4d4f;
  border-color: #ff4d4f;
}
/deep/ .ant-input-search-button[disabled]:hover {
  opacity: 0.7;
  background-color: #ff4d4f;
  border-color: #ff4d4f;
}
/deep/ .ant-input-search-button[disabled] {
  opacity: 0.7;
  color: #ffffff;
}
</style>