cshenfu
2024-05-21 09d8c671d5e6e6045677bfb5218a5fb78c26aa0f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<template>
    <view>
        <u-toast ref="uToast" />
        <view class="make-question">
            <view class="box">
                <view class="selection">
                    撰写标题
                </view>
                <u-input v-model="title" placeholder="请输入问题标题" type="text" :border="true" />
                <view class="selection">
                    撰写问题
                </view>
                <vk-data-input-editor ref="vk_editor" v-model="content" placeholder="请输入问题内容"></vk-data-input-editor>
 
                <view class="selection">
                    选择分类
                </view>
                <u-input v-model="value.label" type="select" :border="true" @click="show = true" />
                <u-select v-model="show" :list="categories" @confirm="actionSheetCallback" value-name="_id"
                    label-name='name'></u-select>
            </view>
 
            <view class="button-box">
                <u-button type="primary" :custom-style="btnCustomStyle" @click="submit">发布问答</u-button>
            </view>
        </view>
 
    </view>
</template>
 
<script>
    var that
    export default {
        data() {
            return {
                btnCustomStyle: {
                    width: "710rpx",
                    height: "80rpx",
                    background: "#1663ff",
                    borderRadius: "8rpx",
                    letterSpacing: "2rpx"
                },
                title: "",
                content: "",
                value: {
                    label: ""
                },
                show: false,
                categories: [],
            };
        },
        onLoad() {
            that = this
            this.getCategories()
        },
        methods: {
            submit() {
                if (this.title.length < 2) {
                    uni.showToast({
                        icon: "none",
                        title: "标题长度太短啦~"
                    })
                    return
                }
 
                if (this.content.length < 10) {
                    uni.showToast({
                        icon: "none",
                        title: "内容长度太短啦~"
                    })
                    return
                }
                if (!this.value.value) {
                    uni.showToast({
                        icon: "none",
                        title: "请选择分类"
                    })
                    return
                }
                uni.showModal({
                    title: "提示",
                    content: "确认提交?",
                    success(res) {
                        if (res.confirm) {
                            uni.vk.callFunction({
                                url: 'client/bbs/kh/add',
                                data: {
                                    title: that.title,
                                    content: that.content,
                                    category_id: that.value.value
                                },
                                success(data) {
                                    that.content = ""
                                    that.title = ""
                                    that.$refs.vk_editor.clear()
                                    that.$refs.uToast.show({
                                        title: '提交成功',
                                        back: true
                                    })
                                },
                                fail(e) {
                                    uni.vk.alert(e.msg)
                                }
                            });
                        }
                    }
                })
            },
            // 点击actionSheet回调
            actionSheetCallback(e) {
                this.value = e[0]
                console.log(e)
            },
            getCategories() {
                uni.vk.callFunction({
                    url: 'client/bbs/pub/categories',
                    success(data) {
                        let categories = [];
                        categories.push(...data.rows);
                        console.log(categories)
                        that.categories.push(...categories);
                    }
                });
            },
        }
    }
</script>
 
<style lang="scss" scoped>
    .make-question {
        padding: 20rpx;
 
        .box {
            background: #FFFFFF;
 
            .selection {
                font-weight: bold;
                color: #333333;
                font-size: 38rpx;
                padding: 20rpx;
            }
        }
 
        .button-box {
            margin-top: 40rpx;
        }
 
    }
</style>