<!-- 选品会员入驻 -->
<template>
  <div class="app-container">
    <!-- 查询和其他操作 -->
    <div class="filter-container">
      <el-select
        v-model="listQuery.checkState" clearable size="mini" class="filter-item"
        style="width: 200px;" placeholder="请选择审核状态"
      >
        <el-option label="待处理" :value="0" />
        <el-option label="已通过" :value="1" />
        <el-option label="已拒绝" :value="2" />
      </el-select>
      <el-input
        v-model="listQuery.shopName" clearable size="mini" class="filter-item"
        style="width: 200px;margin-left: 10px;" placeholder="请输入选品会员名称"
      />
      <el-input
        v-model="listQuery.shopPhone" clearable size="mini" class="filter-item"
        style="width: 200px;margin-left: 10px;" placeholder="请输入注册手机号"
      />
      <el-select
        v-model="listQuery.authenType" clearable size="mini" class="filter-item"
        style="width: 200px;margin-left: 10px;" placeholder="请选择店铺类型"
      >
        <el-option label="个人" :value="1" />
        <el-option label="个体工商户" :value="2" />
        <el-option label="企业" :value="3" />
        <el-option label="其他组织" :value="4" />
      </el-select>
      <el-date-picker
        v-model="listQuery.dates" type="datetimerange" range-separator="至"
        start-placeholder="开始时间" end-placeholder="结束时间" size="mini"
        class="filter-item" style="margin-left: 10px;line-height: 1;" value-format="yyyy-MM-dd"
      />
      <el-button
        size="mini" class="filter-item" type="primary" icon="el-icon-search"
        style="margin-left:10px;"
        @click="handleSearch"
      >
        查找
      </el-button>
      <br />
      <el-button
        size="mini" type="primary" icon="el-icon-plus"
        @click="$refs.EditModal && $refs.EditModal.handleOpen({ shopId: '' })"
      >
        添加
      </el-button>
    </div>

    <!-- 查询结果 -->
    <div v-tableHeight>
      <el-table
        v-loading="listLoading" height="100%" element-loading-text="正在查询中。。。" :data="list"
        v-bind="{ stripe: true, size: 'small', border: true, fit: true, highlightCurrentRow: true }"
      >
        <el-table-column align="center" width="100" label="选品会员ID" prop="shopId" fixed="left" />
        <el-table-column align="center" label="选品会员名称" prop="shopName">
          <template slot-scope="{ row }">
            <span>{{ row.shopName || '--' }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="店铺类型" prop="authenType">
          <template slot-scope="{ row }">
            <el-tag v-if="row.authenType === 1" effect="plain">个人</el-tag>
            <el-tag v-else-if="row.authenType === 2" effect="plain">个体工商户</el-tag>
            <el-tag v-else-if="row.authenType === 3" effect="plain">企业</el-tag>
            <el-tag v-else-if="row.authenType === 4" effect="plain">其他组织</el-tag>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column align="center" width="120" label="注册手机号" prop="shopPhone" show-overflow-tooltip />
        <el-table-column align="center" width="150" label="创建时间" prop="createTime" />
        <el-table-column align="center" label="操作" width="220" fixed="right" class-name="small-padding fixed-width">
          <template slot-scope="{ row }">
            <el-button type="warning" size="mini" @click="handleDetail(row)">
              详情
            </el-button>
            <el-button
              v-if="listQuery.checkState === 0" size="mini"
              @click="$refs.ApplicationProcessing && $refs.ApplicationProcessing.handleOpen(row)"
            >
              处理
            </el-button>
            <el-button
              v-if="(listQuery.checkState === 1) || (listQuery.checkState === 2)" type="danger"
              size="mini" @click="handleDelete(row)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div>
      <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>

    <!-- 提现处理 -->
    <ApplicationProcessing ref="ApplicationProcessing" @success="getList" />
    <!-- 查看详情 -->
    <DetailModal ref="DetailModal" />
  </div>
</template>

<script>

import ApplicationProcessing from '../../business/settlement/components/ApplicationProcessing'
import DetailModal from '../../business/settlement/components/DetailModal'
import { settlementGetAll, settlementDelete } from '@/api/business'

export default {
  name: 'SelectionMemberSettlement',
  components: {
    ApplicationProcessing,
    DetailModal
  },
  data() {
    return {
      list: [],
      total: 0,
      listLoading: true,
      listQuery: {
        shopName: '',
        shopPhone: '',
        authenType: '',
        dates: [],
        checkState: 0,
        page: 1,
        pageSize: 20,
        shopType: 4
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    async getList() {
      this.listLoading = true
      try {
        const res = await settlementGetAll(this.listQuery)
        this.list = res.data.list
        this.total = res.data.total
      } finally {
        this.listLoading = false
      }
    },
    handleSearch() {
      this.listQuery.page = 1
      this.getList()
    },
    handleDetail(row) {
      this.$refs.DetailModal && this.$refs.DetailModal.handleOpen(row)
    },
    handleDelete(row) {
      this.$confirm('确定删除此项？')
        .then(async () => {
          await settlementDelete({ checkId: row.checkId })
          this.$message({ message: '删除成功！', type: 'success' })
          this.handleSearch()
        })
        .catch(() => {})
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container {
	padding: 20px;
	display: flex;
	flex-direction: column;

	.filter-container {
		.filter-item {
			display: inline-block;
			vertical-align: middle;
			margin-bottom: 10px;
		}
	}

	.small-padding {
		.cell {
			padding-left: 5px;
			padding-right: 5px;
		}
	}

	.fixed-width {
		.el-button--mini {
			padding: 7px 10px;
		}
	}
}
</style>
