<template>
  <el-dialog
    title="选择机构"
    :visible.sync="visible"
    width="1100px"
    :close-on-click-modal="false"
    :show-close="false"
  >
    <div class="filter-container">
      <div class="filter-control">
        <span>机构名称:</span>
        <el-input
          v-model="listQuery.userName"
          placeholder="请输入机构名称"
          clearable
          @input="e => (listQuery.productName= checkedInput(e,2))"
        />
      </div>
      <div class="filter-control">
        <span style="width: auto;">状态:</span>
        <el-select v-model="listQuery.clubStatus" style="width:120px;" clearable @change="getList">
          <el-option value="" label="全部" />
          <el-option label="待审核" :value="1" />
          <el-option label="已上线" :value="90" />
          <el-option label="已上线" :value="91" />
          <el-option label="审核未通过" :value="92" />
        </el-select>
      </div>
      <div class="filter-control">
        <span>手机号:</span>
        <el-input
          v-model="listQuery.bindMobile"
          placeholder="请输入手机号"
          clearable
          style="width:160px;"
        />
      </div>
      <div class="filter-control">
        <el-button type="primary" @click="getList">查询</el-button>
      </div>
    </div>
    <el-table ref="table" v-loading="isLoading" :data="list" height="400px" border @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" />
      <el-table-column prop="userName" label="机构名称" align="center" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="{row}">
          <template v-if="row.clubStatus*1===1">
            <el-tag type="warning" size="small">待审核</el-tag>
          </template>
          <template v-else-if="row.clubStatus*1===92">
            <el-tag type="danger" size="small">审核未通过</el-tag>
          </template>
          <template v-else>
            <el-tag v-if="row.clubStatus*1===91" type="danger" size="small">已下线</el-tag>
            <el-tag v-else type="success" size="small">已上线</el-tag>
          </template>
        </template>
      </el-table-column>
      <el-table-column label="联系人" align="center" prop="linkMan" />
      <el-table-column label="手机号" align="center" prop="bindMobile" />
    </el-table>
    <!-- 页码 -->
    <pagination
      :total="total"
      :page-sizes="[10]"
      :page-size="10"
      :page.sync="listQuery.index"
      :limit.sync="listQuery.pageSize"
      @pagination="getList"
    />
    <div slot="footer">
      <el-button @click="handleCanle">取 消</el-button>
      <el-button type="primary" :disabled="disabled" @click="handleAddProConfirm(clubRadio)">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getClubList } from '@/api/club'

export default {
  name: 'ProDialog',
  filters: {
    NumFormat(value) {
      // 处理金额
      return Number(value).toFixed(2)
    }
  },
  data() {
    return {
      visible: true,
      listQuery: {
        index: 1,
        pageSize: 10,
        userOrganizeId: this.$store.getters.organizeId,
        userName: '',
        linkMan: '',
        bindMobile: '',
        startTime: '',
        endTime: ''
      },
      list: [],
      total: 0,
      clubRadio: null,
      isLoading: true
    }
  },
  computed: {
    disabled() {
      return this.clubRadio === null
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 商品列表
    async getList() {
      this.isLoading = true
      const res = await getClubList(this.listQuery)
      const data = res.data.results
      this.list = data.map(item => { item.sort = 0; return item })
      this.total = res.data.totalRecord
      this.isLoading = false
    },
    // 多选商品
    handleSelectionChange(row) {
      this.clubRadio = row
      console.log('row', row)
    },
    handleAddProConfirm() {
      // 确认选择商品
      this.$emit('confirm', this.clubRadio)
    },
    handleCanle() {
      // 取消弹窗
      this.$emit('cancel')
    },
    checkedInput(event, type) {
      let pattern = ''
      switch (type) {
        case 1:
          pattern = /[^\d]/g
          break
        case 2:
          pattern = /[^u4E00-u9FA5|d|a-zA-Z|rns,.?!，。？！…—&$=()-+/*{}[]]|s/g
          break
      }
      return event.replace(pattern, '')
    }
  }
}
</script>
<style lang="scss" scoped>

</style>
