<template>
  <div>
    <el-card :bordered="false" shadow="never" class="ivu-mt" :body-style="{padding:0}">
      <div class="padding-add">
        <el-form
            ref="levelFrom"
            :model="levelFrom"
            :label-width="labelWidth"
            :label-position="labelPosition"
            inline
            @submit.native.prevent
        >
          <el-form-item label="等级状态：" label-for="status1">
            <el-select
                v-model="levelFrom.status"
                placeholder="请选择"
                clearable
                element-id="status1"
                @change="userSearchs"
                class="form_content_width"
            >
              <el-option value="" label="全部"></el-option>
              <el-option value="1" label="通过"></el-option>
              <el-option value="0" label="待审核"></el-option>
              <el-option value="-1" label="拒绝"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="关键词：" label-for="title">
            <el-input
                clearable
                v-model="levelFrom.nireid"
                placeholder="请输入真名，身份证号码，用户昵称等"
                class="form_content_width"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="userSearchs">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <el-card :bordered="false" shadow="never" class="ivu-mt mt16">
      <el-table
        :data="levelLists"
        ref="table"
        class="mt14"
        v-loading="loading"
        highlight-current-row
        no-userFrom-text="暂无数据"
        no-filtered-userFrom-text="暂无筛选结果"
      >
        <el-table-column label="ID" width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.id }}</span>
          </template>
        </el-table-column>
        <el-table-column label="身份证" min-width="100">
          <template slot-scope="scope">
            <div class="tabBox_img" v-viewer>
              <img v-lazy="scope.row.image" />
            </div>
          </template>
        </el-table-column>
		<el-table-column label="用户" min-width="120">
		  <template slot-scope="scope">
		    <span>{{ scope.row.nickname }}</span>
		  </template>
		</el-table-column>
        <el-table-column label="名字" min-width="120">
          <template slot-scope="scope">
            <span>{{ scope.row.real_name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="身份证号码" min-width="120">
          <template slot-scope="scope">
            <span>{{ scope.row.id_card }}</span>
          </template>
        </el-table-column>
		<el-table-column label="状态" min-width="100">
		  <template slot-scope="scope">
		    <span v-if="scope.row.status==0">待审核</span>
		    <span v-if="scope.row.status==1">已通过</span>
		    <span v-if="scope.row.status==-1">未通过</span>
		  </template>
		</el-table-column>
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope" v-if="scope.row.status==0">
              <span class="el-dropdown-link" @click="userCheckAdopt(scope.row,'审核通过')">通过</span>
			  <el-divider direction="vertical"></el-divider>
              <span class="el-dropdown-link" @click="userCheckRefuse(scope.row,'审核拒绝')">拒绝</span>
          </template>
        </el-table-column>
      </el-table>
      <div class="acea-row row-right page">
        <pagination
          v-if="total"
          :total="total"
          :page.sync="levelFrom.page"
          :limit.sync="levelFrom.limit"
          @pagination="getList"
        />
      </div>
    </el-card>
  </div>
</template>
<script>
import { mapState, mapMutations } from 'vuex';
import { usercheck, userCheckAdopt, userCheckRefuse,getUserCheckRefuse } from '@/api/newApi';
export default {
  name: 'user_level',
  data() {
    return {
      grid: {
        xl: 7,
        lg: 7,
        md: 12,
        sm: 24,
        xs: 24,
      },
      loading: false,
      levelFrom: {
        status: '',
        title: '',
        page: 1,
        limit: 15,
      },
      levelLists: [],
      total: 0,
      FromData: null,
      imgName: '',
      visible: false,
      levelId: 0,
      modalTitleSs: '',
      titleType: 'level',
      modelTask: false,
      num: 0,
    };
  },
  created() {
    this.getList();
  },
  computed: {
    ...mapState('media', ['isMobile']),
    labelWidth() {
      return this.isMobile ? undefined : '80px';
    },
    labelPosition() {
      return this.isMobile ? 'top' : 'right';
    },
  },
  methods: {
    ...mapMutations('userLevel', ['getlevelId']),
    // 操作
    changeMenu(row, name, num) {
      this.levelId = row.id;
      switch (name) {
        case '1':
          this.getlevelId(this.levelId);
          this.$refs.tasks.modals = true;
          this.$refs.tasks.getList();
          break;
        case '3':
          this.edit(row);
          break;
        default:
          this.del(row, '删除等级', num);
      }
    },
    // 审核通过
    userCheckAdopt(row, tit, num) {
      let delfromData = {
        title: tit,
        url: `user/check/adopt/${row.id}`,
        method: 'put',
        ids: '',
      };
      this.$modalSure(delfromData)
        .then((res) => {
			this.submitFail();
          this.$message.success(res.msg);
        })
        .catch((res) => {
          this.$message.error(res.msg);
        });
    },
	// 审核不通过
	userCheckRefuse(row, tit, num) {
	  this.$modalForm(getUserCheckRefuse({ id: row.id })).then((res) =>{
		  this.submitFail()
	  } );
	},
    // 等级列表
    getList() {
      this.loading = true;
      this.levelFrom.is_show = this.levelFrom.is_show || '';
      usercheck(this.levelFrom)
        .then(async (res) => {
          let data = res.data;
          this.levelLists = data.list.list;
          this.total = res.data.count;
          this.loading = false;
        })
        .catch((res) => {
          this.loading = false;
          this.$message.error(res.msg);
        });
    },
    // 表格搜索
    userSearchs() {
      this.levelFrom.page = 1;
      this.getList();
    },
    // 修改成功
    submitFail() {
      this.getList();
    },
  },
};
</script>

<style scoped lang="stylus">
.tabBox_img{
    width:36px;
    height:36px;
    border-radius:4px;
    cursor:pointer;
    img{
        width:100%;
        height:100%;
	}
}
</style>
