<template>
    <view class="app_cotainer">
        <view class="content">
            <p>调研题目：{{infoMation.surveyTitle}}</p>
            <view style="margin-top: 20rpx;">调研内容：</view>
            <p style="margin-top: 20rpx; font-size: 32rpx;">{{infoMation.surveyContent}}</p>
        </view>
        <u--form labelPosition="left" :fromData="fromData" :model="fromData" :rules="rules" ref="uForm1">
            <u-form-item label="" prop="replyContent" labelWidth="80" borderBottom>
                <u--textarea v-model="fromData.replyContent" placeholder="回复内容"></u--textarea>
            </u-form-item>
        </u--form>
        <view class="btn_add">
            <u-button type="primary" size="large" text="提交信息" @click="submit"></u-button>
        </view>
    </view>
</template>

<script>
    const rules = {
        'replyContent': {
            type: 'string',
            required: true,
            message: '请填写投诉标题',
            trigger: ['blur', 'change']
        },
    }
    import {
        queryByIdEmploymentSurveyManage,
        replyEmploymentSurveyManage
    } from '@/api/help.js'
    export default {
        data() {
            return {
                infoMation: {},
                fromData: {},
                rules: Object.assign({}, rules),
                isNext: true,
            }
        },
        onLoad({
            id
        }) {
            this.getDetail(id)
        },
        created() {

        },
        methods: {
            async submit() {
                if (this.isNext) {
                    this.isNext = false
                } else {
                    return
                }
                if (!this.fromData.replyContent) {
                    this.isNext = true
                    return this.$api.mag('请输入回复内容')
                }
                console.log('submit', this.fromData)
                let params = {
                    surveyId: this.infoMation.id,
                    ...this.fromData,
                }
                uni.showLoading({
                    title: '请求中'
                })
                let resData = await replyEmploymentSurveyManage(params)
                uni.hideLoading()
                this.isNext = true
                if (resData.data?.code === 200) {
                    uni.$u.toast(resData.data.msg)
                    this.$api.sleep(1000).then(() => {
                        uni.navigateBack(1)
                    })
                }
            },
            getDetail(id) {
                return new Promise(async (resolve, reject) => {
                    let resData = await queryByIdEmploymentSurveyManage({
                        id
                    })
                    if (resData.data.code === 200) {
                        this.infoMation = resData.data.data
                        resolve(resData.data.data)
                    } else {
                        reject()
                    }
                })
            }
        }
    }
</script>

<style scoped>
    .app_cotainer {
        padding: 24rpx;
    }

    .content {
        margin-bottom: 100rpx;
    }
</style>