<template>
    <div>
        <div class="card">
            <h3>交换成功！写一封感谢信送给ta吧~
            </h3>
            <van-cell-group>
                <van-field
                        type="textarea"
                        placeholder="请输入你想写给ta的感谢信..."
                        rows="5"
                        autosize
                        v-model="assess"
                        :error="assessError"
                        @click="assessError=false"
                        required
                        maxlength="300"
                />
            </van-cell-group>
            <div>
                <van-rate
                        v-model="value"
                        icon="like"
                        void-icon="like-o"
                />
                <p>
                    请选择感动指数（对方不可见）
                </p>
                <van-button round type="primary" class='assess' @click="Assess">送出感谢信</van-button>
            </div>

        </div>
        <div style="position: relative;">
            <img :src="Assessimage" style="max-width: 100%; position: relative;"/>
        </div>
    </div>
</template>

<script>

    import {
        CellGroup, Field,
        Rate,
        Button
    } from 'vant'

    export default {
        name: "Assess",
        components: {
            [CellGroup.name]: CellGroup, [Field.name]: Field,
            [Rate.name]: Rate, [Button.name]: Button,
        },
        data() {
            return {
                value:4,
                assess: '',
                assessError: false,
                active: 0,
                Assessimage: require('../assets/thanks.png'),
            }
        },
        methods: {
            publishPresent() {
                // 检验输入

                if (this.assess.length <= 15) {
                    this.assessError = true;
                    Toast.fail('请输入至少15个字的礼物评价');
                    return;
                }
                // post_present()
                let present = {
                    assess: this.assess,
                };
                console.log(present);
                BasicFunction.get_data("ajaxpostpresent", function (response) {
                    console.log("------ Data Rcvd in PresentReg --------");
                    console.log(response);
                    if(response.ret === "10000"){
                        // 不需要 设置 SessionID， 已经自动保存在jSessionID中
                        this.$router.push('index');
                    } else {
                        // 注册失败的处理
                        Toast.fail("上传失败，请检查网络");
                    }
                }, [{}]);

                // this.$router.push('index');
            },
            Assess() {
                this.$router.push('index');
            },
        },
        created: function () {
            if(this.$route.query.present) {
                let present = this.$route.query.present;
                console.log(present);
                this.assess = present.presentDesc;
            }
        }
    }
</script>

<style scoped>
    h2 {
        color: #fd6740;
        text-align: left;
        padding: 5px;
        border-bottom: solid 1px #e4e4e4;
    }
    .card {
        background-color: white;
        margin: 20px 20px;
        border: solid 1px #e4e4e4;
        padding: 15px;
    }

    .van-buttom {
        background-color: red;
        border-color: red;
        margin: auto;
        width: 10%;
    }
    .van-rate{
        margin: auto;
    }
    p{
        margin: auto;
        size: 5px;
    }

</style>