App.vue 21.4 KB
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 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
<template>
    <div class="fullPage touchmove">
        <div v-if="picUrl">
            <!-- <img mode="widthFix" style="position:relative;width:100vw;height: 50vwpx;" :src="picUrl"/> -->
            <canvas id="painter" ref="captureCanvas"></canvas>
            <div class="template-name-box">
				<div class="template-name-content">
					<span class="template-name-title">模板名称:</span>
					<van-cell :title="templateNameDefault" @click="show = true" is-link />
					<van-popup v-model:show="show" position="bottom">
					    <van-picker :columns="templateNameList" @confirm="onConfirm" @cancel="onCancel" />
					</van-popup>
				</div>
				<van-button class="template-btn" plain type="primary" size="small" @click="templateClick"> + 问题项</van-button>
			</div>
			<div class="template-select-box" v-if="checkboxRefsShow.length > 0">
				<div class="template-select-list">
					<van-tag class="template-select-one" v-for="(item, index) in checkboxRefsShow" :key="index" closeable size="large" type="primary" @close="deleteTemplate(item,index)">
					  {{item.name}}
					</van-tag>
				</div>
			</div>
			<van-popup v-model:show="templateDialogShow" position="bottom" class="template-list-model" closeable round>
				<div class="template-list-box">
					<div class="template-list-title">添加问题项</div>
					<div class="template-list">
						<van-checkbox-group shape="square" v-model="checked" ref="checkboxGroup">
						  <van-cell-group inset>
						    <van-cell v-for="(item, index) in templateItemList" center clickable :key="index" :title="item.name" @click="toggle(index)" >
						      <template #right-icon>
						        <van-checkbox :name="item.id" :ref="el => checkboxRefs[index] = el" @click.stop />
						      </template>
						    </van-cell>
						  </van-cell-group>
						</van-checkbox-group>
					</div>
					<van-button class="template-list-submit" round block type="primary"  @click="templateSubmit">确认</van-button>
				</div>
			</van-popup>
            <!-- <div class="itemList" id="itemList">
                <van-checkbox-group v-model="checked">
                    <van-cell-group inset>
                        <van-cell v-for="(item, index) in templateItemList" clickable center :key="index" :title="'['+item.score+']'+item.name" :label="item.intro" @click="toggle(index)">
                            <template #right-icon>
                                <van-checkbox :name="item.id" :ref="el => checkboxRefs[index] = el" @click.stop />
                            </template>
                        </van-cell>
                    </van-cell-group>
                </van-checkbox-group>
            </div> -->
            <div class="formBox">
				<van-field v-model="message" rows="2" autosize label="备注" type="textarea" placeholder="请输入备注" />
                <van-field name="radio" label="是否需要整改">
                    <template #input>
                        <van-radio-group v-model="isRectify" direction="horizontal">
                            <van-radio name="1">需要</van-radio>
                            <van-radio name="2">不需要</van-radio>
                        </van-radio-group>
                    </template>
                </van-field>
                <van-field
                    v-show="isRectify==1"
                    v-model="rectificationUserName"
                    is-link
                    readonly
                    name="picker"
                    label="整改人"
                    placeholder="点击选择整改人"
                    @click="showRectification = true"
                />
                <van-popup v-model:show="showRectification" position="bottom">
                  <van-picker
                    :columns="userNameList"
                    @confirm="onUserConfirm"
                    @cancel="showRectification = false"
                  />
                </van-popup>
				<div style="padding:15px;">
					<van-button round block type="primary"  @click="submitContent">提交</van-button>
				</div>
            </div>
        </div>
        <div v-else>
            <livePlayer ref="livePlayerRef" :params="paramObj"></livePlayer>
            <div class="tour-btns" v-if="paramObj.type=='titem'">
                <van-button @click="navBackTour" type="primary">返回上一页</van-button>
                <van-button @click="pictureBtn" type="primary">确认并截图</van-button>
            </div>
            <div class="tour-btns" v-else-if="paramObj.type=='view'">
                <van-button block @click="navBack" type="primary">查看其他监控点</van-button>
            </div>
            <div class="tour-btns1" v-else>
                <div class="box">
                    <span @click="navBack">{{decodeURIComponent(paramObj.name)}}
                        <van-icon class="icon" name="play" />
                    </span>
                </div>
                <div class="box box1">
                    <span v-if="bookmark" @click="delCollectGate">
                        <van-icon class="iconMargin" color="#F7B500" name="star" />收藏
                    </span>
                    <span v-else @click="collectGate">
                        <van-icon class="iconMargin" name="star-o" />收藏
                    </span>
                    <span @click="pictureBtn">
                        <van-icon class="iconMargin" name="photograph" />巡检
                    </span>
                </div>
            </div>
        </div>
    </div>
</template>
<script setup>
    import {
        reactive,
        ref,
        onMounted,
        getCurrentInstance
    } from 'vue';
    import {
        Toast
    } from 'vant';
    import livePlayer from '@/components/livePlayer.vue';
    import shopTour from '@/components/shopTour.vue';
    //import vconsole from 'vconsole';
    if (process.env.NODE_ENV !== 'production') {
        //new vconsole();
    }
    /*获取 Url 参数 S*/
    import parse from 'url-param-parser';
    const paramObj = parse(window.location.href).search || {}
    /********************************/
    document.title = decodeURIComponent(paramObj.name);
    window.localStorage.setItem('atoken', paramObj.atoken);
    window.localStorage.setItem('lang', 'zh_CN');
    /*获取 Url 参数 E*/
    import tourApi from '@/api';
    //var data = reactive(v);
    const dataURLtoFile = (dataurl, filename, filetype)=> {
        var arr = dataurl.split(","),
            bstr = atob(arr[1]),
            n = bstr.length,
            u8arr = new Uint8Array(n);
        while (n--) {
            u8arr[n] = bstr.charCodeAt(n);
        }
        return new File([u8arr], filename, {
            type: filetype
        });
    }
    const navBack = () => {
        wx.miniProgram.redirectTo({
            url: `/pages/tour/gate/index?type=${paramObj.type}&atoken=${paramObj.atoken}&userId=${paramObj.userId}&id=${paramObj.id}&channelid=${paramObj.channelid}&platform=${paramObj.platform}&mallId=${paramObj.mallId}&name=${paramObj.name}`
        });
    };
    const navBackTour = () => {
        wx.miniProgram.navigateBack();
    }
    const bookmark = ref(paramObj.bookmark)
    const collectGate = () => {
        tourApi.setBookmark({
            userId: paramObj.userId,
            patrolGateIds: [paramObj.id]
        }).then(res => {
            if (res.data.code == 200) {
                bookmark.value = true;
                return Toast.success('收藏成功');
            }
        })
    }
    const delCollectGate = () => {
        tourApi.delBookmark({
            userId: paramObj.userId,
            patrolGateIds: [paramObj.id]
        }).then(res => {
            if (res.data.code == 200) {
                bookmark.value = false;
                return Toast.success('取消收藏成功');
            }
        })
    }

    const show = ref(false);
    const showPopup = () => {
        show.value = true;
    };
    const checked = ref([]);
    const onConfirm = (value, index) => {
        templateNameDefault.value = value;
        checkboxRefsShow.value = [];
        checkboxRefs.value = [];
        checked.value = []
        if (index > 0) {
            getPatrolTemplateOne(templateList.value[index].id)
        } else {
            templateItemList.value = []
            associateData.value.forEach(item => {
                templateItemList.value.push(...item.sopProjects)
            })
        }
        show.value = false;
    };
    const onCancel = () => {
        show.value = false;
    }
    const checkboxRefs = ref([]);
    const checkboxRefsShow = ref([]);
	const templateClick = (val) => {
		templateDialogShow.value = true;
    }
    const toggle = (index) => {
        checkboxRefs.value[index].toggle();
    }
	const templateSubmit = (index) => {
		templateDialogShow.value = false;
		if(checked.value && checked.value.length>0){
			checkboxRefsShow.value = []
		    checked.value.forEach(item=>{
		        let sopItem = templateItemList.value.find(childItem => item==childItem.id);
		        checkboxRefsShow.value.push({
		            "id": sopItem.id,
		            "name": sopItem.name,
		        })
		    })
		}
	}
	const deleteTemplate = (item,index) => {
	    checkboxRefsShow.value.splice(index,1)
	}
	
	
    const message = ref();
    const isRectify = ref("1")
    const showRectification = ref(false)
    const rectificationUserName = ref('')
    const onUserConfirm = (value) => {
        showRectification.value = false;
        rectificationUserName.value = value
    };
    const submitContent = () => {
        let base64Str = dataURLtoFile(captureCanvas.value.toDataURL('image/jpeg'), new Date().getTime(), 'image/jpeg')
        let formData = new FormData();
        formData.append('accountId', paramObj.accountId)
        formData.append('mallId', paramObj.mallId)
        formData.append('gateId', paramObj.id)
        formData.append('patrolType', 1)
        let sops = []
        if(checked.value && checked.value.length>0){
            checked.value.forEach(item=>{
                let sopItem = templateItemList.value.find(childItem => item==childItem.id);
                sops.push({
                    "id": sopItem.id,
                    "status": 0,
                    "score": sopItem.score
                })
            })
            formData.append('sops', JSON.stringify(sops))
        }else{
            return Toast.fail('请选择检查项');
        }
        
        if (message.value) {
            formData.append('remark', message.value)
        }
        if(isRectify.value==1){
            if(rectificationUserName.value){
                let user = userList.value.find(item => item.name==rectificationUserName.value);
                formData.append('handler', user.id)
            }else{
                return Toast.fail('请选择整改人');
            }
        } else {
			formData.append('handler', '')
		}
        formData.append('pic', base64Str)
        tourApi.confirmPatrolRecord(formData, {
            headers: {
                'Content-type': 'application/x-www-form-urlencoded;charset=utf-8' //multipart/form-data; charset=utf-8
            }
        }).then(res=>{
            let result = res.data;
            if (result.code == '200'){
                Toast.success('提交成功');
                setTimeout(()=>{
                    message.value = '';
                    rectificationUserName.value = '';
                    checked.value = [];
					checkboxRefsShow.value = [];
					checkboxRefs.value = [];
                    let context = captureCanvas.value.getContext("2d")
                    context.clearRect(0, 0, window.innerWidth, window.innerWidth/1.78)
                    picUrl.value = '';
                    console.log(livePlayerRef.value.playerEz)
                    livePlayerRef.value.playerEz.play();
                },1000)
            }else{
                return Toast.fail(result.msg);
            }
            
        })
    }


    const userList = ref([]);
    const userNameList = ref([]);
    const getUserList = () => {
        userList.value = []
        userNameList.value = []
        tourApi.getUsers({
            mallId: paramObj.mallId
        }).then(data => {
            let result = data.data
            if (result.data && result.data.length) {
                result.data.forEach(item => {
                    item.name = item.realName + '(' + item.loginName + ')';
                    userNameList.value.push(item.realName + '(' + item.loginName + ')')
                })
            }
            userList.value = result.data
        })
    }
    const livePlayerRef = ref()
    const picUrl = ref('')
    const captureCanvas = ref('')
    // 获取检查项
    const templateList = ref([]);
    const templateNameList = ref([]);
    const templateNameDefault = ref();
    const tempalteId = ref()
    // 单个模板检查项
    const templateItemList = ref([]);
	// 检查项弹框显示
	const templateDialogShow = ref(false);
    const getPatrolTemplateList = () => {
        tourApi.getPatrolTemplateListFun({
            accountId: paramObj.accountId,
            pageSize: 999,
        }).then(res => {
            let result = res.data;
            if (result.code == 200) {
                templateList.value = result.data.list;
                if (templateList.value.length) {
                    tempalteId.value = templateList.value[0].id
                    getPatrolTemplateOne(templateList.value[0].id)
                    // templateList.value.unshift({
                    //     name: '全部',
                    //     id: ''
                    // })
                    templateNameList.value = []
                    templateList.value.forEach(item => {
                        templateNameList.value.push(item.name)
                    })
					templateNameDefault.value = templateList.value[0].name;
                }
            }
        })
    }
    // 获取单个模板检查项
    const getPatrolTemplateOne = (val) => {
        tourApi.getPatrolTemplateOne({
            id: val,
        }).then(res => {
            let result = res.data;
            if (result.code == 200) {
                templateItemList.value = result.data.sopProjects || [];
            }
        })
    }
    // 获取关联的SOP
    const associateData = ref([])
    const getAssociateList = (record) => {
        associateData.value = [];
        tourApi.getPatrolSopTypeTree({
            accountId: paramObj.accountId,
            system: 0
        }).then(data => {
            let result = data.data;
            if (result.code == '200') {
                let tableData = result.data
                tableData.forEach((item, index) => {
                    if (item.sopProjects.length > 0) {
                        item.key = 1000 + item.id
                        let sopProjects = JSON.parse(JSON.stringify(item.sopProjects))
                        item.sops = sopProjects
                        item.len = sopProjects.length
                        item.choiceNum = 0
                        associateData.value.push(item)
                    }
                })
            }
        })
    }
    const pictureBtn = () => {
        getPatrolTemplateList()
        getAssociateList()
        getUserList()
        Toast.loading({
            duration: 0,
            message: '视频截图中···',
            forbidClick: true,
        });
        tourApi.getCapture({id:paramObj.channelid}).then(res=>{
            if(res.status!=200){
              return Toast.fail(res.data.msg);
            }
            picUrl.value = res.data.data;
            Toast.clear();
            if(paramObj.type!='titem'){
                // picUrl.value = 'https://store.keliuyun.com/images/patrol/capture/20230825/ecd2a635-84af-4968-bc30-1af130460d12.jpg'
                livePlayerRef.value.playerEz.stop();
                let image = new Image()
                image.src = 'https://store.keliuyun.com/images/'+ picUrl.value;
                image.style.width = window.innerWidth + 'px';
                let heightC = window.innerWidth / 1.78
                image.style.height = heightC + 'px'
                image.crossOrigin = 'Anonymous'
                image.onload = () => {
                    captureCanvas.value.width = window.innerWidth;
                    captureCanvas.value.height = heightC;
                    let ctx = captureCanvas.value.getContext("2d");
                    ctx.drawImage(image, 0, 0, window.innerWidth, heightC);
                    capture()
                }
                // this.$refs.livePlayerRef.value.playerEz.stop();
                // wx.miniProgram.redirectTo({
                //  url: `/pages/tour/index/index?action=capture&picUrl=${picUrl}&id=${paramObj.id}&channelid=${paramObj.channelid}&mallId=${paramObj.mallId}&title=${paramObj.name}&atoken=${paramObj.atoken}&userId=${paramObj.userId}`
                // }); 
            }else{
              /***********巡店详情截图****************/
                wx.miniProgram.navigateTo({
                  url: `/pages/tour/titemDetail/index?action=capture&picUrl=${picUrl}&id=${paramObj.tid}`
                });
            }

        })
    };
    const locHistory = ref([]);
    const lastLoc = ref();
    const isMouseDown = ref(false);
    const windowToCanvas = function(x, y) {
        var bbox = captureCanvas.value.getBoundingClientRect(); //获取canvas的位置信息
        return {
            x: Math.round(x - bbox.left),
            y: Math.round(y - bbox.top)
        } //返回当前鼠标相对于canvas的位置
    }

    const capture = function() {
        // 绘制
        var context = captureCanvas.value.getContext("2d");
        captureCanvas.value.addEventListener('touchstart', function(e) {
            e.preventDefault();
            isMouseDown.value = true;
            lastLoc.value = windowToCanvas(e.touches[0].clientX, e.touches[0].clientY)
            locHistory.value.push({
                x: lastLoc.value.x,
                y: lastLoc.value.y,
            })
            console.log(locHistory.value)
        })
        captureCanvas.value.addEventListener('touchmove', function(e) {
            e.preventDefault();
            if (isMouseDown.value) {
                moveStroke({
                    x: e.touches[0].clientX,
                    y: e.touches[0].clientY
                }, context)
            }
        })
        captureCanvas.value.addEventListener('touchend', function(e) {
            locHistory.value.push({
                x: lastLoc.value.x,
                y: lastLoc.value.y,
            })
            isMouseDown.value = false;
        })
    }
    const calcDistance = function(loc1, loc2) {
        return Math.sqrt((loc1.x - loc2.x) * (loc1.x - loc2.x) + (loc1.y - loc2.y) * (loc1.y - loc2.y)) //通过起始结束坐标x,y值计算路程长度
    }
    const moveStroke = function(point, context) {
        var curLoc = windowToCanvas(point.x, point.y)
        var curTimestamp = new Date().getTime();
        var s = calcDistance(curLoc, lastLoc.value)
        var lineWidth = 3
        //draw
        context.beginPath()
        context.moveTo(lastLoc.value.x, lastLoc.value.y)
        context.lineTo(curLoc.x, curLoc.y)

        locHistory.value.push({
            x: curLoc.x,
            y: curLoc.y,
        })

        context.lineWidth = 3
        context.strokeStyle = '#FF0000';
        context.lineCap = "round"
        context.linJoin = "round"
        context.stroke();

        //每次过程结束时,将结束值赋给初始值,一直延续
        lastLoc.value = curLoc
    }
    onMounted(() => {})
</script>
<style scoped lang="less">
    .tour-btns {
        display: flex;
        justify-content: space-between;
        padding: 20px 2vw 0;
        --van-button-border-radius: 60px;

        :deep(.van-button) {
            margin-bottom: 20px;
            border-radius: 60px;
            width: 47vw;

            &.van-button--block {
                width: 100%;
            }
        }
    }

    .tour-btns1 {
        display: flex;
        background: #E6EDFF;
        height: 15vw;
        line-height: 15vw;
        padding: 0 20px;

        .box {
            display: inline-block;
            flex: 1;
        }

        .box1 {
            text-align: right;

            span {
                margin-left: 20px;
            }

        }

        .icon {
            transform: rotate(90deg);
        }
    }

    .iconMargin {
        margin-right: 10px;
    }

    .itemList {
        overflow: auto;
        height: 50%;
    }

    :deep(.van-cell-group--inset) {
        margin: 0;
    }
	.template-select-box{
		background: #fff;
	}
	.template-select-list{
		padding:30px 0px 10px;
		margin:0 30px;
		border-bottom: 1px solid var(--van-cell-border-color);
		.template-select-one{
			margin: 0 20px 20px 0;
			padding: 1.8vw;
			/deep/.van-tag__close{
				margin-left: 10px;
			}
		}
	}
	.template-name-box{
		display: flex;
		align-items: center;
		justify-content: space-between;
		background:#fff;
		padding: 0 30px;
		border-bottom: 1px solid var(--van-cell-border-color);
	}
	.template-name-content{
		display: flex;
		align-items: center;
	}
	.template-name-title{
		width: 140px;
		min-width: 140px;
		font-size: var(--van-cell-font-size);
		color: var(--van-field-label-color);
	}
	.template-btn{
		width: 130px;
	}
	.template-list-model{
		.template-list-box{
			width: calc(100vw - 0px);
			height: calc(80vh - 0px);
			padding: 30px;
			background: #fff;
			border-top-left-radius: 10px;
			border-top-right-radius: 10px;
			.template-list-title{
				font-size: var(--van-font-size-lg);
				line-height: var(--van-font-size-lg);
				margin-bottom: 30px;
			}
			.template-list{
				height: 62vh;
				overflow: auto;
			}
			.template-list-submit{
				margin-top: 30px;
			}
		}
	}
	
</style>