马宇豪
2023-07-21 fc38d1c92f01a224e8373c4425481bb1d85e2bf3
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<template>
    <view>
        <!-- 自定义导航栏 -->
        <view class="navBarBox fix">
            <!-- 状态栏占位 -->
            <view class="statusBar" :style="{ paddingTop: statusBarHeight + 'px' }"></view>
            <!-- 真正的导航栏内容 -->
            <view class="navBar">
                <view class="barText">响应措施反馈</view>
            </view>
        </view>
        <view style="display: flex;flex-direction: column; padding: 10px 15px;">
            <view class="first">
                <text style="font-size: 16px;margin-bottom: 20px;">基础措施</text>
                 <u-checkbox-group
                            v-model="checkboxValue1"
                            placement="column"
                            @change="checkboxChange"
                        >
                            <u-checkbox
                                :customStyle="{marginBottom: '8px'}"
                                v-for="(item, index) in list"
                                :key="index"
                                :label="item.name"
                                :name="item.name"
                            >
                            </u-checkbox>
                        </u-checkbox-group>
            </view>
            <view class="second">
                <text style="font-size: 16px;margin-bottom: 20px;">响应反馈</text>
                <u--textarea style="margin-top: -5px;" v-model="measures" placeholder="请输入内容" ></u--textarea>
            </view>
            <view class="third">
                <text style="font-size: 16px;margin-bottom: 20px;">图片上传</text>
                <u-upload
                        :fileList="fileList1"
                        @afterRead="afterRead"
                        @delete="deletePic"
                        name="1"
                        multiple
                        :maxCount="10"
                        style="margin-top: -10px;"
                    ></u-upload>
                    <view class="pic" v-for="item in nameList" :key="index">
                        {{item.name}}
                    </view>
            </view>
            <u-button class="btn" type="success">提交</u-button>
        </view>
    </view>
</template>
 
<script>
    export default {
        components:{
            
        },
        data() {
            return {
                statusBarHeight: [],
                fileList1: [],
                nameList: [],
                checkboxValue1: '',
                measures: "",
                type: 'textarea',
                border: true,
                height: 100,
                autoHeight: true,
                list: [
                    {
                        name: '苹果',
                        disabled: false
                    },
                    {
                        name: '香蕉',
                        disabled: false
                    },
                    {
                        name: '橙子',
                        disabled: false
                    }
                ]
            }
        },
        onLoad() {
            //获取手机状态栏高度
            this.statusBarHeight = uni.getSystemInfoSync()['statusBarHeight'];
            uni.hideTabBar();
        },
        methods: {
            checkboxChange(n) {
                console.log('change', n);
            },
            // 删除图片
            deletePic(event) {
                this[`fileList${event.name}`].splice(event.index, 1)
                this.nameList.splice(event.index,1)
                console.log("name",this.nameList)
            },
            // 新增图片
            async afterRead(event) {
                // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
                let lists = [].concat(event.file)
                let fileListLen = this[`fileList${event.name}`].length
                console.log("list",lists)
                lists.map((item) => {
                    this.nameList.push({name: item.name});
                    this[`fileList${event.name}`].push({
                        ...item,
                        status: 'uploading',
                        message: '上传中'
                    })
                })
                console.log("nameList",this.nameList)
                for (let i = 0; i < lists.length; i++) {
                    const result = await this.uploadFilePromise(lists[i].url)
                    let item = this[`fileList${event.name}`][fileListLen]
                    this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
                        status: 'success',
                        message: '',
                        url: result
                    }))
                    fileListLen++
                }
            },
            uploadFilePromise(url) {
                return new Promise((resolve, reject) => {
                    let a = uni.uploadFile({
                        url: 'http://www.example.com', // 仅为示例,非真实的接口地址
                        filePath: url,
                        name: 'file',
                        formData: {
                            user: 'test'
                        },
                        success: (res) => {
                            setTimeout(() => {
                                resolve(res.data.data)
                            }, 1000)
                        }
                    });
                })
            },
        }
    }
 
</script>
 
<style lang='scss' scoped>
.navBarBox .navBar {
    background-color:lightgrey;
    height: 25px;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
}
.fix{
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 1;
}
.statusBar{
    background-color:lightgrey;
}
.first{
    display: flex;
    flex-direction: column;
}
.second{
    display: flex;
    flex-direction: column;
    margin-top: 50px;
}
.third{
    display: flex;
    flex-direction: column;
    margin-top: 30px;
    margin-bottom: 50px;
}
/deep/ .u-upload__button{
    background-color: white;
}
.pic{
    display: flex;
    flex-direction: column;
    background-color: rgb(242,242,242);
    margin-top: 5px;
    font-size: 14px;
}
/* .btn{
    position: fixed;
    bottom: var(--window-bottom, 1);
    z-index: 99;
} */
</style>