suggest.vue 4.4 KB
<template>
    <view style="background-color: #F5F7FC; align-items: auto;">
        <view style="align-items: center; display: flex; 
			justify-content: space-between; background-color:white;  margin-top: 3vh;">
            <image src="../../static/common/black_icon_back.png" 
			style="width: 35rpx; height: 35rpx; padding: 25rpx;"
                v-on:click="onBack()" />
            <text style="color: black;">问题反馈</text>
            <text style="color: #298BF3; font-size: 18; margin-right: 35rpx; " v-on:click="commit()">提交</text>
        </view>

        <input class="uni-input" type="text" focus placeholder="欢迎提交您宝贵的建议" style="background-color:white; margin-top: 20rpx; padding: 35rpx; 
			 height: 20;" v-model="suggest_content" />
        
    </view>
</template>

<script>
import http from "@/utils/http";

export default {
    data() {
        return {
            suggest_content: "",
            imageList: []
        }
    },
    methods: {
        onBack() {
            uni.navigateBack()
        },
        async commit() {
			console.log("commit")
            if (this.suggest_content.length < 5) {
                uni.showToast({
                    icon: "none",
                    title: "最短为 5 个字符",
                });
                return;
            }
            let query_data = `mutation{
				 		user_suggest_info(content:${JSON.stringify(this.suggest_content)})
				 	}`;
            if (this.imageList.length > 0) {
                query_data = `mutation{
					 		user_suggest_info(content:${JSON.stringify(this.suggest_content)}
							,images:${JSON.stringify(this.imageList)})
					 	}`;
            }
			console.log(query_data)
            let result = await http.gql({
                query: query_data
            })

            console.info(result);
            //处理返回请求
            if (result && result.data && result.data.user_suggest_info &&
                !result.data.user_suggest_info.error) {
                uni.showToast({
                    icon: "none",
                    title: "提交成功",
                });
                uni.navigateBack()
            } else {
                uni.showToast({
                    icon: "none",
                    title: "提交失败",
                });
            }
        },
        chooseImg() {
            let _this = this;
            uni.chooseImage({
                count: 1, //最多可以选择的图片张数,默认9
                sourceType: ['album'], //album 从相册选图,camera 使用相机,默认二者都有。如需直接开相机或直接选相册,请只使用一个选项
                sizeType: ['original'], //original 原图,compressed 压缩图,默认二者都有
                success(res) {
                    console.log('选择图片完成', res)
                    // 调用上传图片的接口
                    let path = res.tempFilePaths[0];
                    _this.imgToBase64(path).then((base64) => {
                        let buffer = Buffer.from(base64, "base64");
                        let size = buffer.length / 1024 / 1024;
                        if (size > 5) {
                            uni.showToast({
                                icon: "none",
                                title: "图片文件最大不能超过5MB!",
                            });
                            return;
                        }
                        _this.imageList.push(base64);
                    });
                },
                fail() {
                    console.log('失败', err);
                },
                complete() {
                    console.log('结束');

                },
            })
        },
        previewImage(index) {
            uni.previewImage({
                urls: this.imageList,
                current: this.imageList[index],
            });
        },
        clear(index) {
            this.imageList.splice(index, 1);
        },
        imgToBase64(data) {
            return new Promise((resolve, reject) => {
                pathToBase64(data)
                    .then((base64) => {
                        resolve(base64);
                    })
                    .catch((error) => {
                        console.error(error);
                        reject(error);
                    });
            });
        },
    }
}
</script>

<style>
.head-bg {
    width: 100%;
    height: 20%;
}
</style>