<template>
  <div class="join-shop-list-container">
    <div class="search-container" style="display: flex; align-items: center; margin-bottom: 10px">
      <!-- <el-radio-group v-model="listQuery.state" size="mini" @change="handleSearch">
        <el-radio-button label="-1">全部</el-radio-button>
        <el-radio-button label="1">已报名</el-radio-button>
        <el-radio-button label="2">已通过</el-radio-button>
        <el-radio-button label="3">未通过</el-radio-button>
      </el-radio-group> -->
    </div>
    <!-- 查询结果 -->
    <el-table v-loading="listLoading" element-loading-text="正在查询中..." :data="list" v-bind="{ stripe: true, size: 'small', border: true, highlightCurrentRow: true }">
      <el-table-column prop="allianceCardId" label="联盟卡ID" width="90" align="center" />
      <el-table-column prop="shopId" label="参与商家ID" width="90" align="center" />
      <el-table-column prop="shopName" label="商家名称" width="120" align="center" />
      <el-table-column prop="shopLogo" label="商家Logo" width="120" align="center">
        <template slot-scope="scope">
          <el-image :preview-src-list="[scope.row.shopLogo]" v-if="scope.row.shopLogo" :src="scope.row.shopLogo" fit="fill" style="width: 127px; height: 73px"></el-image>
          <span v-else>--</span>
        </template>
      </el-table-column>

      <el-table-column prop="state" label="参与状态" width="120" align="center">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.state === 1" size="mini" type="info">已报名</el-tag>
          <el-tag v-if="scope.row.state === 2" size="mini" type="success">已通过</el-tag>
          <el-tag v-if="scope.row.state === 3" size="mini" type="danger">不通过</el-tag>
        </template>
      </el-table-column>

      <el-table-column prop="settlementRatio" label="结算比例" width="120" align="center">
        <template slot-scope="scope">
          <el-tag>{{ scope.row.settlementRatio * 100 }}%</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="报名时间" align="center" />
    </el-table>

    <div style="margin-top: 10px">
      <el-pagination
        :current-page="listQuery.page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="listQuery.pageSize"
        layout="total, sizes, prev, pager, next, -> ,jumper"
        :total="total"
        @size-change="(val) => (listQuery.pageSize = val) && getList()"
        @current-change="(val) => (listQuery.page = val) && getList()"
      />
    </div>
  </div>
</template>

<script>
import { getRegistrationShopsByIdApi } from '@/api/business'

export default {
  props: {
    cardId: { type: [Number, String], required: true }
  },

  data() {
    return {
      list: [],
      total: 0,
      listLoading: false,
      listQuery: {
        allianceCardId: undefined,
        page: 1,
        pageSize: 20,
      }
    }
  },

  watch: {
    cardId: {
      handler(value) {
        this.listQuery.allianceCardId = value
        value && this.getList()
      },
      immediate: true
    }
  },

  methods: {
    // 获取商家列表
    async getList() {
      try {
        this.listLoading = true
        const res = await getRegistrationShopsByIdApi({ ...this.listQuery, state: this.listQuery.state == '-1' ? undefined : this.listQuery.state * 1 })
        this.list = res.data.list
        this.total = res.data.total
        this.listLoading = false
      } catch (error) {
        this.listLoading = false
      }
    },

    handleSearch() {
      this.listQuery.page = 1
      this.getList()
    }
  }
}
</script>

<style lang="scss" scoped>
.join-shop-list-container {
}
</style>
