<template>
  <div>
    <div class="search-term">
      <el-form :inline="true" :model="searchInfo" class="demo-form-inline">
			<el-form-item  label="手机号码" prop="phone">
			  <el-input placeholder="请输入手机号码" v-model="searchInfo.phone" type="text" class="user-form-item" clearable></el-input>
			</el-form-item>
			
			<el-form-item  label="身份证号" prop="cardId">
			  <el-input placeholder="请输入身份证" v-model="searchInfo.cardId" type="text" class="user-form-item" clearable></el-input>
			</el-form-item>
			
			
			<el-form-item  label="是否通过" prop="isOk">
			  <el-switch :active-value="1" :inactive-value="0"  v-model="searchInfo.isOk"></el-switch>
			</el-form-item>
		</el-form>
    </div>

    <el-table :data="tableData"  border stripe>
      <el-table-column label="流水号"  prop="id">
      </el-table-column>
	  
      <el-table-column label="手机号码"  prop="phone" min-width="100"> </el-table-column>
	  <el-table-column label="身份证"  prop="cardId" min-width="200"> </el-table-column>
      <el-table-column label="姓名"  prop="nickname"> </el-table-column>
	  
	  <el-table-column label="是否通过"  prop="isOk" >
		 <template slot-scope="{row}">
		   <span> {{row.isOk?'通过':'未通过'}}</span>
		 </template> 
	  </el-table-column>
	  
	  <el-table-column label="信息"  prop="msg" ></el-table-column>
	  
      <el-table-column
        align="center"
        width="160px"
        label="操作"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="{row}">
			<el-button
			  v-if="row.isOk"
			  type="success"
			  size="small"
			  icon="el-icon-circle-check"
			  disabled
			>已经认证</el-button>
			
		  <el-button
			v-else
		    type="primary"
		    size="small"
		    icon="el-icon-circle-check"
		    @click="passIdentify(row)"
		  >通过</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="page"
      :page-size="size"
      :page-sizes="[10, 30, 50, 100]"
      :style="{float:'right',padding:'20px'}"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
  </div>
</template>

<script>
import { getIdentifyList, postData} from "@/api/study.js";
import infoList from "@/mixins/infoList";
import { MessageBox } from "element-ui";

export default {
  name: "Api",
  data() {
    return {
	  listApi: getIdentifyList,
      tableData: [],
    };
  },
  watch:{
	searchInfo:{
		handler(val, oldVal){
		    this.page = 1;
			this.getTableData()
		},
		deep:true
	}
  },
  mixins: [infoList],
  methods: { 
	dosubmit( row, cb ){
		let param = {id: row.id}
		postData("passIdentify", param).then(res=>{
			if( res.code == 200){
				this.$message.successMsg("通过实名认证",1)
				row.isOk = 1
				cb&&cb()
			}
		})
	},
	passIdentify(row){
		let that = this
		let {phone,cardId,nickname} = row
		MessageBox({
		  title: "身份确认",
		  dangerouslyUseHTMLString: true,
		  message: `<span>用户：${nickname}\n</br>电话：${phone}\n</br> 身份证:${cardId}\n</br>一旦提交就不可以修改，你是否继续操作</span>`,
		  showCancelButton: true,
		  confirmButtonText: "确定",
		  cancelButtonText: "取消",
		  beforeClose: (action, instance, done) => {
		    if (action === "confirm") {
		      that.dosubmit( row, done );
		    } else{
		      done();
		    }
		  }
		})
	}
  },
  created() {
    this.getTableData();
  }
};
</script>
<style scoped lang="scss">
.el-tag--mini {
  margin-left: 5px;
}
.warning {
  color: #dc143c;
}
</style>
