<template>
    <global-page title="跟踪反馈" navLeftType="text" :showNavRight="true" navRightType="button" navRightText="保存" @handleRightClick="handleSave">
        <view class="mocp-form">
            <up-form labelPosition="left" labelWidth="auto" :model="formData" :rules="rules" ref="formRef">
                <up-form-item label="跟踪反馈" :borderBottom="true" labelPosition="top" prop="gzFeedbackContent" required>
                    <up-textarea
                        v-model="formData.gzFeedbackContent"
                        placeholder="一段很长很长的内容文字，长文本自动换行，该选项的描述是一段很长的内容"
                        :height="40"
                        border="none"
                    ></up-textarea>
                </up-form-item>
            </up-form>
        </view>
    </global-page>
</template>

<script setup>
import { reactive, ref } from 'vue'
import useAssignWorkStore from 'mocp/store/assign-work'
import { storeToRefs } from 'pinia'
import { onLoad } from '@dcloudio/uni-app'
import { savaGzFeedbackApi } from 'mocp/api/assign-work'

const assignWorkStore = useAssignWorkStore()
const { arrangeWorkExtend } = storeToRefs(assignWorkStore)
const formData = reactive({
    gzFeedbackContent: ''
})
const rules = reactive({
    gzFeedbackContent: [
        {
            required: true,
            message: '请输入跟踪反馈',
            trigger: ['blur', 'change']
        }
    ]
})
//页面初始化
onLoad(() => {
    formData.id = arrangeWorkExtend.value.id
    formData.workId = arrangeWorkExtend.value.workId
    formData.company = arrangeWorkExtend.value.company
    formData.gzFeedbackContent = arrangeWorkExtend.value.gzFeedbackContent
})
//保存
const formRef = ref()
const handleSave = async () => {
    await formRef.value?.validate()
    const res = await savaGzFeedbackApi(formData, { loading: true })
    if (res.code == 200) {
        uni.$mocpJump.navigateBack()
        uni.$mocpMessage.success(res.message)
        //更新当前责任单位详情
        assignWorkStore.setState('arrangeWorkExtend', res.data)
    } else {
        uni.$mocpMessage.error(res.message)
    }
}
</script>
<style lang="scss" scoped>
.mocp-form {
    background: #fff;
    padding: 0 32rpx;
}
</style>
