<template>
    <view>
        <my_form ref="form" :form="form" @isUncomplete="isUncomplete" @onUploading="onUploading" />
        <view class="footer">
            <view class="but" :class="(uncomplete || onUpload) ? 'forbidden' : ''" hover-class="navigator-hover"
                @click="(uncomplete || onUpload) ? '' : submit()">
                立即提交
            </view>
        </view>
        <view style="height: 75px;" />
    </view>
</template>

<script>
export default {
    data() {
        return {
            form: [],
            uncomplete: true,
            pageType: 4,
            onUpload: false,
            isSubmit: false,
        }
    },
    onUnload() {
        if (!this.isSubmit) this.$refs.form.deleteFiles()
    },
    onLoad(options) {
        this.pageType = options.pageType == '设计' ? 4 : 5
        uni.setNavigationBarTitle({
            title: '意见反馈'
        });
        this.initForm()
    },
    methods: {
        async initForm() {
            this.form = [{
                key: "type",
                type: "customClass",
                label: "选择反馈类型",
                isMust: true,//是否必填
                isMultipleChoice: false,//是否多选
                value: '',
                list: [{remarks:'建议',value:'建议'},{remarks:'投诉',value:'投诉'}],
                marginTop: 10
            }, {
                key: "remarks",
                type: "textarea2",
                label: "反馈描述",
                isMust: true,//是否必填
                value: '',
                unBorBot:true,
                marginTop: 10,

            },{
                key: "attachmentids",
                type: "upload",
                label: "图片/视频",
                placeholder: "上传凭证（图片/视频）",
                accept: "image*/,video*/",
                ownertable: "temporary",
                ownerid: 999,
                usetype: 'default',
                allowUpload: true,
                allowDelete: true,
                value: [],
                marginTop: 10
            }]
        },
        isUncomplete(uncomplete) {
            this.uncomplete = uncomplete;
        },
        submit() {
            this.$refs.form.submit().then(data => {
                this.onUpload = true;
                this.$Http.basic({
                    "id": 20240517102502,
                    "content": {
                        "sa_feedbackid": 0,
                        "type": data.type,
                        "remarks": data.remarks
                    },
                }).then(async res => {
                    this.onUpload = false;
                    console.log("新建", res)
                    if (this.cutoff(res.msg)) return;
                    if (data.files.temporarys.length) {
                        this.onUpload = true;
                        await this.$Http.basic({
                            "classname": "system.attachment.Attachment",
                            "method": "createFileLink",
                            "content": {
                                ownertable: 'sa_feedback',
                                ownerid: res.data.sa_feedbackid,
                                usetype: 'default',
                                attachmentids: data.files.temporarys
                            }
                        }).then(async s => {
                            this.isSubmit = true;
                            this.onUpload = false;
                            console.log("绑定附加", s)
                            if (this.cutoff(s.msg)) return;
                        })
                    };
                    if (this.$Http.updateList) return this.$Http.updateList(res.data);
                    uni.navigateBack()
                })
                console.log("页面", data)
            })
        },
        onUploading(ing) {
            this.onUpload = ing;
        },

    },
}
</script>

<style lang="scss" scoped>
.footer {
    position: fixed;
    bottom: 0;
    width: 375px;
    height: 65px;
    background: #FFFFFF;
    box-shadow: 0px -2px 6px 1px rgba(0, 0, 0, 0.16);
    border-radius: 0px 0px 0px 0px;

    .but {
        width: 355px;
        height: 45px;
        background: #C30D23;
        border-radius: 5px;
        margin: 5px auto;
        text-align: center;
        line-height: 45px;
        font-size: 14px;
        color: #FFFFFF;
    }

    .forbidden {
        opacity: .6;
    }
}
</style>