<template>
    <div class="flex-container">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <!-- 搜索区域 -->
            <a-form layout="inline">
                <a-row :gutter="24">
                  <span class="table-page-search-submitButtons" style="float: right; overflow: hidden;height: 35px;">
                    <a-col :md="4" :sm="24">
                      <a-button @click="search()" type="primary">查询</a-button>
                    </a-col>
                  </span>
                    <a-col :md="6" :sm="12"  style="float: right; height: 35px;">
                        <a-form-item label="手机号：">
                          <a-input placeholder="手机号" v-model="queryParam.id"></a-input>
                        </a-form-item>
                    </a-col>

                </a-row>
            </a-form>
        </div>

        <!--列表-->
        <s-table
                :columns="columns"
                :data="rowdata"
                bordered
                ref="table"
                size="small"
                class="flex-filling"
                :locale="emptyText"
        ></s-table>
    </div>
</template>

<script>
    import STable from "@/components/table";
    import {queryAuthCode} from "../../../api/school-center/authCodeAPI";
    import {cloneObject} from "@/utils/util";
    import moment from "moment";

    export default {
        name: "hhrAuthCode",
        components: {
            STable
        },
        data() {
            return {
                emptyText: {emptyText: '暂无数据'},
                callback: false,
                Formtable: this.$form.createForm(this),
                queryParam: {
                    id: "",
                },
                columns: [
                  {dataIndex: "id", width: 80, title: "手机号"},
                  {dataIndex: "userAuthCode", width: 80, title: "验证码"},
                ],
                rowdata: parameter => {
                    let params = {
                        pageNo: parameter.pageNo,
                        pageSize: parameter.pageSize
                    };
                    let obj = cloneObject(this.queryParam);
                    //表示
                    return queryAuthCode(Object.assign(params, obj)).then(res => {
                        console.log(res);
                        let data = {};
                        if (res.state !== "success") {
                            this.$message.error("查询失败！", 5);
                            this.emptyText.emptyText = '查询失败！'
                            data = {
                                data: []
                            };
                        } else {
                            data = {
                                data: res.data
                            };
                        }
                        return data;
                    });
                }
            };
        },
        methods: {
            moment,
            search() {
              let reg = (/^1[0-9]{10}$/);
              if (this.queryParam.id == '') {
                this.$message.error("请输入联系号码！", 5);
                this.emptyText.emptyText = '请输入联系号码！'
                return
              }
              if (reg.test(this.queryParam.id) == false) {
                this.$message.error("请输入正确的联系号码！", 5);
                this.emptyText.emptyText = '请输入正确的联系号码！'
                return
              }
                this.$refs.table.refresh({search: true});
            },
        }
    };
</script>

<style scoped>
</style>