智慧保安互联网APP
zengh
2022-06-21 4efeb31d5b4921d7e851c256009486ad86bc70e2
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<template>
    <view class="container">
 
        <view class="group-chat-box">
 
            <u-form :model="form" ref="uForm">
 
                <u-form-item label-width='132' prop="content" label="指令内容" :required="true">
                    <u-input type='textarea' v-model="form.content" placeholder="请输入指令内容" />
                </u-form-item>
 
                <u-form-item label-width='158' prop="recipientText" label="指令接收人" :required="true">
 
                    <u-input type='textarea' v-model="form.recipientPeople" placeholder="请选择指令接收人"
                        @click="recipientClick" autoHeight  />
 
                    <!-- <u-button slot="right" type="success" size="mini" @click="recipientClick">选择接收人</u-button> -->
 
                    <u-popup :closeable="true" v-model="recipientShow" mode="bottom" height="50%" border-radius="14">
 
                        <view>
 
                            <u-checkbox-group v-show="recipientList.length > 0" @change="checkboxGroupChange"
                                :wrap='true' :size="40">
 
                                <u-checkbox v-model="item.checked" v-for="(item, index) in recipientList" :key="index"
                                    :name="item.id" shape="circle"
                                    style="padding: 0 40rpx; height: 92rpx; position: relative; box-sizing: border-box;">
 
                                    <view style="margin-left: 22rpx">
                                        {{item.real_name}}
                                    </view>
 
                                </u-checkbox>
 
                            </u-checkbox-group>
 
                            <view style=" height: 92rpx; padding: 0 40rpx;" v-show="recipientList.length == 0">
 
                                暂无数据
 
                            </view>
 
                        </view>
 
                    </u-popup>
 
                </u-form-item>
 
                <u-form-item label-width='184' label="指令相关图片" class='imgissue-upload'>
                    <seeImgs :imgs="imgs" :videos="[]" @del="delImg" :type="'imgs'"></seeImgs>
                    <image style="width: 4rem; height: 4rem; display: block;" @tap="takePhoto"
                        src="../../static/images/upload.png" mode=""></image>
                </u-form-item>
 
            </u-form>
 
        </view>
 
        <view class="establish-box">
 
            <u-button class="submit" type="primary" @click="initiateClick">发送</u-button>
 
        </view>
 
        <view>
            <u-toast ref="uToast" />
        </view>
 
    </view>
</template>
 
<script>
    import seeImgs from '../../components/seeImges/seeImges.vue';
    export default {
        components: {
            seeImgs
        },
        data() {
            return {
                recipientShow: false,
                recipientList: [],
                form: {
                    content: '',
                    recipient: '',
                    recipientData: [],
                    recipientPeople: ''
                },
                rules: {
 
                    content: [{
                        min: 5,
                        required: true,
                        message: '指令内容不能少于5个字',
                        trigger: ['change', 'blur'],
                    }],
 
                },
                imgs: [],
            };
        },
        onLoad() {},
        onReachBottom() {
 
        },
        mounted() {},
        onReady() {
            this.$refs.uForm.setRules(this.rules);
        },
        methods: {
            recipientClick() {
                if (this.recipientList.length > 0) {
                    this.recipientShow = true;
                    return;
                }
 
                uni.request({
                    url: this.$store.state.piAPI + "/blade-user/seleL",
                    method: "get",
                    data: {
                        type: 1,
                        jurisdiction: this.$store.state
                            .UserData.jurisdiction,
                    },
                    success: (res) => {
                        this.recipientList = []
 
                        res.data.data.forEach(item => {
                            var flag = true
 
                            if (this.recipientList.length > 0) {
                                this.recipientList.forEach(it => {
                                    if (item.id == it.id) flag = false
                                })
                            }
 
                            if (flag == true) {
                                if (item.id != this.$store.state
                                    .UserData.user_id
                                ) {
                                    item.checked = false;
                                    this.recipientList.push(item)
                                }
                            }
 
                        })
 
                        this.recipientShow = true;
                    }
                });
 
            },
 
            initiateClick() {
                var imgurl = '';
                this.imgs.forEach((item, index) => {
                    if (index == this.imgs.length - 1) {
                        imgurl += item.src
                    } else {
                        imgurl += item.src + ','
                    }
                })
                this.$refs.uForm.validate(valid => {
                    if (valid) {
 
                        if (this.form.recipientData.length == 0) {
                            this.$refs.uToast.show({
                                title: '请最少选择一个接收人',
                            })
                            return
                        }
 
                        var str = '';
 
                        this.form.recipientData.forEach(item => {
                            str += item + ','
                        })
 
                        str = str.substr(0, str.length - 1);
 
                        uni.request({
                            url: this.$store.state.piAPI + "/directive/saveDirectiveAndFile",
                            method: "post",
                            data: {
                                // 接收
                                receiveDirectiveIds: str,
                                // 发送
                                sendDirectiveId: this.$store.state
                                    .UserData.user_id,
                                content: this.form.content,
                                url: imgurl
 
                            },
                            success: (res) => {
                                if (res.data.msg.indexOf('成功') != -1) {
                                    this.$refs.uToast.show({
                                        title: '指令下发成功',
                                        type: 'success',
                                        url: '/pages/dispatch/dispatch'
                                    })
                                }
                            }
                        });
                    } else {
                        console.log('验证失败');
                    }
                });
            },
            //图片删除
            delImg(index) {
                this.imgs.splice(index, 1);
            },
            //图片上传
            takePhoto() {
                var that = this;
                uni.chooseImage({
                    count: 3, //可选择数量,默认9
                    sizeType: ['compressed', 'original'], //上传压缩图,原图
                    sourceType: ['album', 'camera'], //从相册选择或从使用相机
                    success: async (res) => {
                        for (var i = 0; i < res.tempFiles.length; i++) {
                            if (res.tempFiles[i].size > 10 * 1024 * 1000) { //上传图片大小限制
                                uni.showToast({
                                    title: "照片大小不能超过10MB",
                                    icon: "none"
                                })
                                return
                            }
                        }
                        var tempFilePath = res.tempFilePaths;
                        // try {
                        uni.showLoading({
                            title: "上传中...",
                            mask: true
                        })
                        var that = this;
                        // 循环调用uni.uploadFile ,因微信小程序只支持单文件上传
                        for (var i = 0; i < tempFilePath.length; i++) {
                            uni.uploadFile({
                                // url: 'https://web.byisf.com/api/blade-jfpts/depl/put-depl', //仅为示例,非真实的接口地址
                                url: this.$store.state.piAPI +
                                    '/blade-resource/oss/endpoint/put-file-app',
                                filePath: tempFilePath[i],
                                name: 'file',
                                formData: {
                                    'user': 'test' // 上传附带参数
                                },
                                success: (data) => {
                                    console.log(data, JSON.parse(data.data).data)
                                    uni.showToast({
                                        title: '上传图片成功!',
                                        duration: 1000
                                    });
                                    // 根据接口具体返回格式   赋值具体对应url
                                    that.imgs.push({
                                        id: i,
                                        src: JSON.parse(data.data).data
                                    })
                                }
                            });
                        }
                    }
                });
            },
            checkboxGroupChange(e) {
                var that = this
 
                this.form.recipientData = e
 
                var str = ""
                var num = 0
 
                that.form.recipientData.forEach((item, index) => {
                    that.recipientList.forEach((it, index) => {
                        if (item == it.id) {
                            if (num > 0) {
                                str += '、';
                                str += it.real_name;
                            } else {
                                str += it.real_name
                            }
                            num += 1
                            return
                        }
                    })
                })
 
                this.form.recipientPeople = str
 
            },
 
        }
    };
</script>
 
 
<style lang="scss">
    .submit {
        border: none;
        width: 94%;
        height: 86rpx;
        line-height: 86rpx;
        box-sizing: border-box;
        border-radius: 15rpx;
        color: #ffffff;
        font-size: 38rpx;
 
    }
 
    .container {
        height: 100%;
 
        .group-chat-box {
            height: calc(100% - 116rpx);
            padding: 0 36rpx;
            box-sizing: border-box;
            overflow-y: auto;
        }
 
        .establish-box {
            position: relative;
            height: 116rpx;
            background: #fff;
            text-align: center;
 
            uni-button {
                margin: 0;
                position: absolute;
                top: 0;
                left: 0;
                right: 0;
                bottom: 0;
                margin: auto;
            }
 
        }
 
    }
</style>