<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" prop="gzApprovalComments" required>
                    <global-picker pickAlign="right" v-model="formData.gzApprovalComments" clearable dictkey="aw_leaderState"></global-picker>
                </up-form-item>
                <up-form-item label="批示要点" :borderBottom="true" labelPosition="top" prop="gzApprovalContent" required>
                    <up-textarea
                        v-model.trim="formData.gzApprovalContent"
                        placeholder="一段很长很长的内容文字，长文本自动换行，该选项的描述是一段很长的内容"
                        :height="40"
                        border="none"
                    ></up-textarea>
                </up-form-item>
            </up-form>
        </view>
    </global-page>
</template>

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

const assignWorkStore = useAssignWorkStore()
const { arrangeWorkExtend } = storeToRefs(assignWorkStore)
const formData = reactive({
    gzApprovalComments: '',
    gzApprovalContent: ''
})
const rules = reactive({
    gzApprovalComments: [
        {
            type: 'number',
            required: true,
            message: '请选择领导批示意见',
            trigger: ['blur', 'change']
        }
    ],
    gzApprovalContent: [
        {
            required: true,
            message: '请输入批示要点',
            trigger: ['blur', 'change']
        }
    ]
})
//页面初始化
onLoad(() => {
    formData.id = arrangeWorkExtend.value.id
    formData.workId = arrangeWorkExtend.value.workId
    formData.company = arrangeWorkExtend.value.company
    formData.gzApprovalComments = arrangeWorkExtend.value.gzApprovalComments
    formData.gzApprovalContent = arrangeWorkExtend.value.gzApprovalContent
})
//保存
const formRef = ref()
const handleSave = async () => {
    await formRef.value?.validate()
    const res = await savaGzApprovalApi(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;
    margin-bottom: 24rpx;
    padding: 0 32rpx;
}
</style>
