<template>
    <div class="card" style="margin-bottom: 20px">
        <van-row style="border-bottom: solid 1px #e4e4e4;">
            <van-col span="16">
                <h3><strong>校卡审核</strong></h3>
            </van-col>
            <van-col span="8">
                <p :style="{ color: statusColor }">{{statusString}}</p>
            </van-col>
        </van-row>
        <div v-if="status===30 || status === 500">
            <add-photo :photoURL="imgUrl" @onRead="onRead"/>
            <p>活动仅允许深大学生参与，请上传正面校卡照片审核~</p>
            <van-button
                    type="primary"
                    class="submit_button"
                    @click="schoolPresent"
                    :loading="loading"
            >保存
            </van-button>
        </div>
        <div v-else>
            <img :src="schoolpic" style="max-width: 100%"/>
        </div>


    </div>
</template>

<script>
    import {  Row, Col,  } from 'vant';
    import AddPhoto from "../components/addPhoto";
    import {BasicFunction} from "../connector/basic-service";
    export default {
        name: "schoolCard",
        components: {
            AddPhoto,
            [Row.name]: Row, [Col.name]: Col,
        },
        data() {
            return {
                statusColor: '',
                statusString: '-----',
                photo: null,
                loading: false,
                status: 0,
                imgage: null,
                imgDo: {},
                schoolpic: "",
                IMGPREFIX: "http://gift.fogice.com"

            }
        },
        methods: {
            schoolPresent() {
                // 检验输入
                this.loading = true;
                if (this.photo === null) {
                    Toast.fail('请上传礼物照片');
                    this.loading = false;
                    return;
                }
                this.imgDo.userSchoolCardPic = this.imgUrl;
                let that = this;
                BasicFunction.get_data("smartIdentity/updateBatch", function (response) {
                    console.log("------ Data Rcvd in uploadphotoChange --------");
                    console.log(response);
                    if (response.ret === "10000") {
                        Toast.success("上传成功")
                    } else {
                        Toast.fail("上传失败，请检查网络");
                    }
                }, [this.imgDo]);
            },
            onRead: function (e) {
                this.photo = e;
            }
        },
        created: function () {
            if (!localStorage.getItem('frontend-userid')) {
                this.$router.push('login');
                return;
            }
            let userid = localStorage.getItem('frontend-userid');
            let that = this;
            BasicFunction.get_data('smartIdentity/list?userId=' + userid, function (res) {
                console.log(res);
                if (res.ret === '10000') {
                    var t = res.model.list;
                    that.status = t[0].userReviewStatus;
                    that.imgDo = t[0];
                    console.log(that);
                    if (that.status === 30) {
                        that.statusColor = '#c5c5c5';
                        that.statusString = '未上传校卡';
                        that.$router.push('verify');
                        return;
                    } else if (that.status === 0 || that.status === 1000) {
                        that.schoolpic = that.IMGPREFIX + t[0].userSchoolCardPic;
                        if (that.status === 0) {
                            that.statusColor = '#c5c530';
                            that.statusString = '审核中'
                        }

                        if (that.status === 1000) {
                            that.statusColor = '#00ff00';
                            that.statusString = '审核通过'
                        }
                    } else {
                        that.statusColor = '#ff0000';
                        that.statusString = '审核未通过'
                    }
                }
            }, {});
        }
    }
</script>

<style scoped>
    p, h3 {
        color: #fd6740;
    }

    p, h3 {
        padding: 5px;
    }
    p {
        padding-top:  3px ;
    }
    .card {
        background-color: white;
        margin: 20px 20px;
        border: solid 1px #e4e4e4;
        padding: 15px;
        text-align: left;
    }

    .submit_button {
        margin-bottom: 10px;
        margin-left: auto;
        margin-right: auto;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: #fd6740;
        border-color: #fd6740;
        width: 85%;
    }
</style>