<template>
    <div class="edit-view">
        <el-form :model="formData" :rules="rules" ref="form" label-width="108px" label-position="right" size="small"
                 style="max-width: 500px;">
            <!--<el-form-item prop="orderInfoId" label="订单号">
                <el-input v-model="formData.orderInfoId"></el-input>
            </el-form-item>-->
            <el-form-item prop="nickname" label="用户昵称">
                <!--                <el-input v-model="formData.nickname"></el-input>-->
                <el-card shadow="hover" class="rt-card">
                        {{formData.nickname}}
                </el-card>
            </el-form-item>
            <el-form-item prop="img" label="图片">
                <el-image v-for="item in picList(formData.img)" style="width: 80px; height: 80px; padding-right: 10px"
                          :key="item" :src="item" fit="cover" :preview-src-list="[item]"
                >

                </el-image>
            </el-form-item>
            <el-form-item prop="merShowName" label="商家名称">
<!--                <el-input v-model="formData.nickname"></el-input>-->
                <el-card shadow="hover" class="rt-card">
                    {{formData.merShowName}}
                </el-card>
            </el-form-item>
            <el-form-item prop="goodsLike" label="商品评分">
                <!--<el-input v-model="formData.goodsLike?'好评':'差评'" disabled></el-input>-->
                <el-card shadow="hover">
                    <div>
                        <i v-if="formData.goodsLike===true" class="fas fa-grin" style="font-size: 20px; color: #ff9900"></i>
                        <i v-if="formData.goodsLike===false" class="fas fa-meh" style="font-size: 20px; color: #ff9900"></i>
                        {{formData.goodsLike?'好评':'差评'}}
                    </div>
                    <div>{{formData.goodsAppraise}}</div>
                </el-card>

            </el-form-item>
            <!--<el-form-item prop="goodsAppraise" label="商品评价">
                <el-input type="textarea" v-model="formData.goodsAppraise"></el-input>
            </el-form-item>-->
            <!--<el-form-item prop="riderLike" label="骑手评分">
                <el-input v-model="like"></el-input>
            </el-form-item>-->
            <el-form-item prop="riderName" label="骑手名称">
                <!--                <el-input v-model="formData.nickname"></el-input>-->
                <el-card shadow="hover" class="rt-card">
                    {{formData.riderName}}
                </el-card>
            </el-form-item>
            <el-form-item prop="riderAppraise" label="骑手评价">
                <el-card shadow="hover">
                    <el-rate
                            v-model="formData.riderLike"
                            disabled
                            :max='3'
                            style="padding-bottom: 8px"
                    >
                    </el-rate>
                    <div><span v-for="item in formData.content" :key="item">
                        {{item}}
                    </span></div>
                    <div>{{formData.riderAppraise}}</div>
                </el-card>
                <!--<el-input type="textarea" v-model="formData.riderAppraise"></el-input>-->
            </el-form-item>
            <!--<el-form-item prop="content" label="快捷评价">
                <el-tag v-for="item in formData.content" :key="item"
                        effect="plain" type="info" size="medium">{{item}}</el-tag>
               &lt;!&ndash; <el-input v-for="item in formData.content" :key="item" :value="item"
                style="width: 90px">
                </el-input>&ndash;&gt;
            </el-form-item>-->
            <el-form-item prop="merchantReply" label="商家回复评价">
<!--                <el-input type="textarea" v-model="formData.merchantReply"></el-input>-->
                <el-card shadow="hover" body-style=" padding: '10px' ">
                    {{formData.merchantReply}}
                </el-card>
            </el-form-item>
            <el-form-item prop="appraiseTime" label="评价日期">
                <el-date-picker
                        v-model="formData.appraiseTime"
                        type="datetime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        readonly
                        placeholder="选择日期时间">
                </el-date-picker>

            </el-form-item>
            <el-form-item>
                <!-- <el-button @click="onSave" :loading="saving"
                            type="primary">保存
                 </el-button>
                 <el-button @click="onDelete" :loading="saving"
                            type="danger" v-if="formData.id">删除
                 </el-button>-->
                <el-button @click="$router.go(-1)">返回</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
    export default {
        name: 'AppraisalEdit',
        created() {
            if (this.$route.query.id) {
                this.$http
                    .get('appraisal/getDto/' + this.$route.query.id)
                    .then(res => {
                        this.formData = res;
                        this.riderLike()
                    })
                    .catch(e => {
                        console.log(e);
                        this.$message.error(e.error);
                    });
            }
        },
        data() {
            return {
                saving: false,
                formData: {},
                rules: {},
                like: '',
            }
        },
        methods: {
            picList(row) {
                if (row) {
                    return row.split(",");
                } else {
                    return "";
                }
            },
            onSave() {
                this.$refs.form.validate((valid) => {
                    if (valid) {
                        this.submit();
                    } else {
                        return false;
                    }
                });
            },
            submit() {
                let data = {...this.formData};

                this.saving = true;
                this.$http
                    .post('/appraisal/save', data, {body: 'json'})
                    .then(res => {
                        this.saving = false;
                        this.$message.success('成功');
                        this.$router.go(-1);
                    })
                    .catch(e => {
                        console.log(e);
                        this.saving = false;
                        this.$message.error(e.error);
                    });
            },
            onDelete() {
                this.$alert('删除将无法恢复，确认要删除么？', '警告', {type: 'error'}).then(() => {
                    return this.$http.post(`/appraisal/del/${this.formData.id}`)
                }).then(() => {
                    this.$message.success('删除成功');
                    this.$router.go(-1);
                }).catch(e => {
                    if (e !== 'cancel') {
                        console.log(e);
                        this.$message.error(e.error);
                    }
                })
            },
            riderLike() {
                if (this.formData.riderLike === 1)
                    this.like = '非常差';
                else if (this.formData.riderLike === 2)
                    this.like = '一般';
                else this.like = '超赞'
            }
        }
    }
</script>
<style lang="less" scoped>
    .rt-card /deep/ .el-card__body {
        padding: 3px 15px !important;
    }
</style>
