<template>  
 | 
    <view class="content p30">  
 | 
        <view class="c2 f30 count-title">正在进行第{{upServerCount + 1}}次服务</view>  
 | 
        <view class="bg_w p30 mt20 rd8">  
 | 
            <view class="">  
 | 
                <view class="c2 f28 mb10 must">进场合影</view>  
 | 
                <view class="c9 f26 mb30">拍摄一张照片,须体现企业logo和服务机构人员、专家等全体进场人员</view> 
 | 
                <u-upload 
 | 
                    :fileList="fileList1" 
 | 
                    @afterRead="afterRead" 
 | 
                    @delete="deletePic" 
 | 
                    :sizeType="['compressed']" 
 | 
                    :previewFullImage="true" 
 | 
                    :capture="['camera']" 
 | 
                    width="196rpx" height="152rpx" name="1" :multiple="false" maxCount="1"> 
 | 
                    <image src="../../static/ic_uploadimg@2x.png" mode="widthFix" class="uploadImage"></image> 
 | 
                </u-upload>  
 | 
            </view>  
 | 
            <view class="mt30 mb30"> 
 | 
                <view class="c2 f28 mb10 must">过程照片</view> 
 | 
                <view class="c9 f26 mb30">拍摄2张以上照片,须体现服务机构人员、专家和服务场所,可以是车间或会议室</view> 
 | 
                <u-upload 
 | 
                    :fileList="fileList2" 
 | 
                    @afterRead="afterRead" 
 | 
                    @delete="deletePic" 
 | 
                    :sizeType="['compressed']" 
 | 
                    :previewFullImage="true" 
 | 
                    :capture="['camera']" 
 | 
                    width="196rpx" 
 | 
                    height="152rpx" 
 | 
                    name="2" 
 | 
                > 
 | 
                    <image src="../../static/ic_uploadimg@2x.png" mode="widthFix" class="uploadImage"></image> 
 | 
                </u-upload> 
 | 
            </view> 
 | 
            <u-line color="#e5e5e5"></u-line> 
 | 
            <view class="mt30 mb30"> 
 | 
                <view class="c2 f28 mb10 must">出场合影</view> 
 | 
                <view class="c9 f26 mb30">拍摄一张照片,须体现企业logo和服务机构人员、专家等全体进场人员</view> 
 | 
                <u-upload 
 | 
                    :fileList="fileList3" 
 | 
                    @afterRead="afterRead" 
 | 
                    @delete="deletePic" 
 | 
                    :sizeType="['compressed']" 
 | 
                    :previewFullImage="true" 
 | 
                    width="196rpx" 
 | 
                    height="152rpx" 
 | 
                    name="3" 
 | 
                    :multiple="false" 
 | 
                    maxCount="1" 
 | 
                    :capture="['camera']" 
 | 
                > 
 | 
                    <image src="../../static/ic_uploadimg@2x.png" mode="widthFix" class="uploadImage"></image> 
 | 
                </u-upload> 
 | 
            </view> 
 | 
            <u-line color="#e5e5e5"></u-line> 
 | 
            <view class="mt30 mb30"> 
 | 
                <view class="c2 f28 mb10 must">服务资料</view> 
 | 
                <view class="c9 f26 mb30">服务过程证明资料包括签到表、会议纪要</view> 
 | 
                <view class="upload-btn "> 
 | 
                    <u-button color="#216EEE" text="点击上传" plain @click="uploadFileList"></u-button> 
 | 
                </view> 
 | 
                <view class="mt30 bX f28" v-for="(item, index) in fileList"> 
 | 
                    <view class="mc fx1 file-style">{{item.name}}</view> 
 | 
                    <view class="wc delet-btn ml15" @click="fileList.splice(index, 1)">删除</view> 
 | 
                </view> 
 | 
            </view> 
 | 
            <u-line color="#e5e5e5"></u-line> 
 | 
            <view class="mt30 mb30" v-if="upServerCount!=0"> 
 | 
                <view class="c2 f28 mb10">补充资料</view> 
 | 
                <view class="c9 f26 mb30">服务过程证明资料包括签到表、会议纪要</view> 
 | 
                <view class="upload-btn "> 
 | 
                    <u-button color="#216EEE" text="点击上传" plain @click="uploadFileExtraList"></u-button> 
 | 
                </view> 
 | 
                <view class="mt30 bX f28" v-for="(item, index) in fileExtraList"> 
 | 
                    <view class="fx1 file-style">{{item.name}}</view> 
 | 
                    <view class="wc delet-btn ml15" @click="fileExtraList.splice(index, 1)">删除</view> 
 | 
                </view> 
 | 
            </view> 
 | 
            <u-line color="#e5e5e5"></u-line> 
 | 
            <view class="mt30 mb30"> 
 | 
                <view class="c2 f28 mb10">服务时间</view> 
 | 
                <view class="bX"> 
 | 
                    <view class="fx1 c3 f30">{{ serviceDate || '上传入场照片后会自动更新' }}</view> 
 | 
                    <!-- <u-icon name="arrow-right" color="#666" size="18"></u-icon> --> 
 | 
                </view> 
 | 
                <!-- <u-datetime-picker 
 | 
                    ref="datetimePicker" 
 | 
                    :show="show" 
 | 
                    :formatter="formatter" 
 | 
                    v-model="date" 
 | 
                    mode="date" 
 | 
                    @confirm="confirmDate" 
 | 
                    @cancel="show=false" 
 | 
                ></u-datetime-picker> --> 
 | 
            </view> 
 | 
            <u-line color="#e5e5e5"></u-line> 
 | 
            <view class="mt30 mb30"> 
 | 
                <view class="c2 f28 mb10">服务说明</view> 
 | 
                <u--textarea v-model="content" border="none" placeholder="请输入服务说明" ></u--textarea> 
 | 
            </view>  
 | 
        </view>  
 | 
  
 | 
        <!-- 底部处理 -->  
 | 
        <view class="pt30">  
 | 
            <view class="ptb15">  
 | 
                <u-button color="#216EEE00"></u-button>  
 | 
            </view>  
 | 
            <u-safe-bottom></u-safe-bottom>  
 | 
        </view>  
 | 
        <view class="fixedBottom bg_w" style="z-index: 9999;">  
 | 
            <view class="plr30 ptb15 bX">  
 | 
                <view class="save-btn">  
 | 
                    <u-button color="#216EEE" text="保存" plain @click="submit(0)"></u-button>  
 | 
                </view>  
 | 
                <view class="submit-btn">  
 | 
                    <u-button color="#216EEE" text="提交" type="primary" @click="submit(1)"></u-button>  
 | 
                </view>  
 | 
            </view>  
 | 
            <u-safe-bottom></u-safe-bottom>  
 | 
        </view> 
 | 
        <canvas :style="{ 
 | 
                position: 'fixed', 
 | 
                width: canvasWidth + 'px', 
 | 
                height: canvasHeight + 'px', 
 | 
                bottom: -canvasHeight - 150 + 'px', 
 | 
                right: -canvasWidth - 300 + 'px' 
 | 
            }" canvas-id="imgId"></canvas> 
 | 
            <!--  
 | 
              
 | 
             -->  
 | 
    </view>  
 | 
</template>  
 | 
  
 | 
<script> 
 | 
    import { baseUrl } from '@/common/config' 
 | 
    import { getAddrByLatAndLng, declareService, uploadHCData } from '@/util/api/index.js'  
 | 
    export default {  
 | 
        data() {  
 | 
            return { 
 | 
                date: '', 
 | 
                declareId: '',  
 | 
                fileList1: [], 
 | 
                fileList2: [], 
 | 
                fileList3: [], 
 | 
                fileList: [], 
 | 
                fileExtraList: [], 
 | 
                serviceDate: '', 
 | 
                content: '', 
 | 
                id: '', 
 | 
                show: false, 
 | 
                upServerCount: 1, 
 | 
                canvasWidth: '', 
 | 
                canvasHeight: '', 
 | 
                address:{}  
 | 
            };  
 | 
        }, 
 | 
        onLoad({declareId, upServerCount}) { 
 | 
             
 | 
            // let timestamp = new Date().getTime() 
 | 
            // console.log(uni.$u.timeFormat(timestamp, 'yyyy-mm-dd hh:MM:ss')); 
 | 
            this.declareId = declareId 
 | 
            this.upServerCount = +upServerCount 
 | 
            declareService({ id:declareId, type:0 }) 
 | 
                .then(res => { 
 | 
                    if (res && res.status==0) { 
 | 
                        this.fileList = res.fileList || [] 
 | 
                        this.fileExtraList = res.fileExtraList 
 | 
                        if (res.upEnterFile) { 
 | 
                            this.fileList1 = [{ 
 | 
                                ...res.upEnterFile, 
 | 
                                url: res.upEnterFile.fileurlfull 
 | 
                            }] 
 | 
                        } 
 | 
                        res.upProcessFileList.forEach(item => { 
 | 
                            this.fileList2.push({ 
 | 
                                ...item, 
 | 
                                url: item.fileurlfull 
 | 
                            }) 
 | 
                        }) 
 | 
                        if (res.upOutFile) { 
 | 
                            this.fileList3 = [{ 
 | 
                                ...res.upOutFile, 
 | 
                                url: res.upOutFile.fileurlfull 
 | 
                            }] 
 | 
                        } 
 | 
                        this.serviceDate = res.serviceDate ? res.serviceDate.substring(0, res.serviceDate.length - 9) : '' 
 | 
                        this.content = res.content 
 | 
                        this.id = res.id 
 | 
                    } 
 | 
                }) 
 | 
                .catch(err => { 
 | 
                     
 | 
                }) 
 | 
            uni.getLocation({ 
 | 
                geocode: true, 
 | 
                success: ({latitude, longitude}) => { 
 | 
                    getAddrByLatAndLng({latitude, longitude}) 
 | 
                        .then(res => { 
 | 
                            this.address = res 
 | 
                        }) 
 | 
                        .then(err => {}) 
 | 
                }, 
 | 
                fail: (err) => { 
 | 
                    console.log(err); 
 | 
                } 
 | 
            }) 
 | 
        }, 
 | 
        // onReady() { 
 | 
        //     this.$refs.datetimePicker.setFormatter(this.formatter) 
 | 
        // },  
 | 
        methods: { 
 | 
            formatter(type, value) { 
 | 
                if (type === 'year') { 
 | 
                    return `${value}年` 
 | 
                } 
 | 
                if (type === 'month') { 
 | 
                    return `${value}月` 
 | 
                } 
 | 
                if (type === 'day') { 
 | 
                    return `${value}日` 
 | 
                } 
 | 
                return value 
 | 
            }, 
 | 
            getInfoImage(url, callback) { 
 | 
                // 小程序没有document,只能在页面中建一个canvas,然后在成功时给他隐藏。 
 | 
                // this.flag = false 
 | 
                // 这个函数是可以拿到图片的一些信息,宽高等 
 | 
                uni.getImageInfo({ 
 | 
                     // 初始化photoIndex=0,拿到第一张图片,并添加水印 
 | 
                    src: url, 
 | 
                    success: res => { 
 | 
                        // // 设置画布高度和宽度 
 | 
                        this.canvasWidth = res.width 
 | 
                        this.canvasHeight = res.height 
 | 
                        //获取当前时间 
 | 
                        // let roleNameInfo = date(new Date(), 'long') + '\n' + this.from.data.address 
 | 
                        let timestamp = new Date().getTime() 
 | 
                        // uni.$u.timeFormat(timestamp, 'yyyy-mm-dd hh:MM:ss') 
 | 
                        let timeInfo = uni.$u.timeFormat(timestamp, 'yyyy-mm-dd hh:MM:ss')  
 | 
                        let address =`${this.address.province} ${this.address.city} ${this.address.district} ${this.address.street_number || this.address.street}` 
 | 
                        var ctx = uni.createCanvasContext('imgId', this) 
 | 
                        ctx.drawImage(url, 0, 0, res.width, res.height) 
 | 
                        // 为图片添加水印 
 | 
                        ctx.setFontSize(30) //水印字体大小 
 | 
                        ctx.setFillStyle('white') //水印颜色 
 | 
                        // 水印位置 
 | 
                        ctx.fillText(timeInfo, 30, res.height - 100) 
 | 
                        ctx.fillText(address, 30, res.height - 60) 
 | 
                        // 开始绘制添加水印的图片并显示在页面中 
 | 
                        ctx.draw(false, () => { 
 | 
                            setTimeout(() => { 
 | 
                                //把当前画布指定区域的内容导出生成指定大小的图片,并返回文件路径。在自定义组件下,第二个参数传入自定义组件实例,以操作组件内 <canvas> 组件。 
 | 
                                // 这里主要为了拿到路径 
 | 
                                uni.canvasToTempFilePath({ 
 | 
                                    canvasId: 'imgId', 
 | 
                                    // 设置输出的图片的宽度高度,会加快输出图片时间 
 | 
                                    destWidth: res.width, 
 | 
                                    destHeight: res.height, 
 | 
                                    fileType: 'jpg', //jpg为了压缩 
 | 
                                    quality: 0.8, //图片的质量 
 | 
                                    success: result => { 
 | 
                                        // 返回有水印的图片 
 | 
                                        callback(result.tempFilePath) 
 | 
                                    }, 
 | 
                                    fail: err => { 
 | 
                                        console.log('绘制报错', err); 
 | 
                                    } 
 | 
                                }) 
 | 
                            }, 500) 
 | 
                        }) 
 | 
                    } 
 | 
                }) 
 | 
            },  
 | 
            // 删除图片  
 | 
            deletePic(event) {  
 | 
                this[`fileList${event.name}`].splice(event.index, 1)  
 | 
            },  
 | 
            // 新增图片   
 | 
            async afterRead(event) { 
 | 
                // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式 
 | 
                 
 | 
                setTimeout(()=> { 
 | 
                    let lists = [].concat(event.file) 
 | 
                    let fileListLen = this[`fileList${event.name}`].length 
 | 
                    lists.map((item) => { 
 | 
                        this[`fileList${event.name}`].push({ 
 | 
                            ...item, 
 | 
                            status: 'uploading', 
 | 
                            message: '上传中' 
 | 
                        }) 
 | 
                    }) 
 | 
                     
 | 
                    for (let i = 0; i < lists.length; i++) { 
 | 
                        this.getInfoImage(lists[i].url, async res => { 
 | 
                            const result = await this.uploadFilePromise(res) 
 | 
                            let item = this[`fileList${event.name}`][fileListLen] 
 | 
                            this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, { 
 | 
                                status: 'success', 
 | 
                                message: '', 
 | 
                                ...result.data, 
 | 
                                type: '', 
 | 
                                fileurlfull: result.data.url, 
 | 
                                fileurl: result.data.imgaddr 
 | 
                            })) 
 | 
                            if (event.name==1) { 
 | 
                                this.submit(0, false) 
 | 
                            } 
 | 
                            fileListLen++ 
 | 
                        }) 
 | 
                    } 
 | 
                }, 1500)  
 | 
            },  
 | 
            uploadFilePromise(path) { 
 | 
                return new Promise((resolve, reject) => {  
 | 
                    let a = uni.uploadFile({  
 | 
                        url: `${baseUrl}/public/uploadWechat`,   
 | 
                        filePath: path, 
 | 
                        header: { 
 | 
                            token: this.$store.state.token, 
 | 
                            'content-type': 'application/x-www-form-urlencoded;charset=utf-8', 
 | 
                        },  
 | 
                        name: 'file',  
 | 
                        formData: {  
 | 
                            folder: 'znzz/project_file'  
 | 
                        }, 
 | 
                        success: (res) => { 
 | 
                            resolve(JSON.parse(res.data)) 
 | 
                            uni.$u.toast('上传成功') 
 | 
                        }, 
 | 
                        fail: (err) => { 
 | 
                            uni.$u.toast(err) 
 | 
                        }, 
 | 
                        complete: () => { 
 | 
                             
 | 
                        }  
 | 
                    });  
 | 
                })  
 | 
            }, 
 | 
            confirmDate(val) { 
 | 
                this.show=false 
 | 
                 
 | 
                const timeFormat = uni.$u.timeFormat 
 | 
                this.serviceDate = timeFormat(val.value, 'yyyy-mm-dd') 
 | 
            }, 
 | 
            uploadFileList() { 
 | 
                // console.log('uploadFileList'); 
 | 
                uni.chooseImage({ 
 | 
                    count: 1, 
 | 
                    success: res => { 
 | 
                        // console.log(res); 
 | 
                        this.uploadFilePromise(res.tempFiles[0].path) 
 | 
                            .then(result => { 
 | 
                                this.fileList.push({ 
 | 
                                    ...result.data, 
 | 
                                    name: result.data.imgname, 
 | 
                                    type: '', 
 | 
                                    fileurlfull: result.data.url, 
 | 
                                    fileurl: result.data.imgaddr 
 | 
                                }) 
 | 
                            }) 
 | 
                    } 
 | 
                }) 
 | 
            }, 
 | 
            uploadFileExtraList() { 
 | 
                // console.log('uploadFileExtraList'); 
 | 
                uni.chooseImage({ 
 | 
                    count: 1, 
 | 
                    success: res => { 
 | 
                        this.uploadFilePromise(res.tempFiles[0].path) 
 | 
                            .then(result => { 
 | 
                                this.fileExtraList.push({ 
 | 
                                    ...result.data, 
 | 
                                    name: result.data.imgname, 
 | 
                                    type: '', 
 | 
                                    fileurlfull: result.data.url, 
 | 
                                    fileurl: result.data.imgaddr 
 | 
                                }) 
 | 
                            }) 
 | 
                    } 
 | 
                }) 
 | 
            }, 
 | 
            submit(status, isBtnAction=true) { 
 | 
                if (status) { 
 | 
                    if (!this.fileList1.length) { 
 | 
                        uni.$u.toast('请上传进场照片') 
 | 
                        return 
 | 
                    } 
 | 
                    if (this.fileList2.length<2) { 
 | 
                        uni.$u.toast('至少上传2张服务过程照片') 
 | 
                        return 
 | 
                    } 
 | 
                    if (!this.fileList3.length) { 
 | 
                        uni.$u.toast('请上传出场照片') 
 | 
                        return 
 | 
                    } 
 | 
                    if (!this.fileList.length) { 
 | 
                        uni.$u.toast('请上服务资料') 
 | 
                        return 
 | 
                    } 
 | 
                    // if (!this.serviceDate) { 
 | 
                    //     uni.$u.toast('请上选择服务时间') 
 | 
                    //     return 
 | 
                    // } 
 | 
                } 
 | 
                let data ={ 
 | 
                    status, 
 | 
                    type: 0, 
 | 
                    declareId: this.declareId, 
 | 
                    upOutFile: this.fileList3.length ? this.fileList3[0] : {}, 
 | 
                    upProcessFileList: this.fileList2, 
 | 
                    content: this.content, 
 | 
                    fileList: this.fileList, 
 | 
                    fileExtraList: this.fileExtraList 
 | 
                } 
 | 
                if (!isBtnAction) { 
 | 
                    data.upEnterFile = this.fileList1.length ? this.fileList1[0] : {} 
 | 
                } 
 | 
                uploadHCData(data) 
 | 
                    .then(() => { 
 | 
                        uni.$u.toast(status?'提交成功':'保存成功') 
 | 
                        uni.$emit("success") 
 | 
                        if (isBtnAction) { 
 | 
                            uni.navigateBack() 
 | 
                        } 
 | 
                    }) 
 | 
                    .catch(err => { 
 | 
                         
 | 
                    }) 
 | 
            }  
 | 
        }  
 | 
    }  
 | 
</script>  
 | 
  
 | 
<style lang="scss">  
 | 
    .content {  
 | 
        font-weight: 400;  
 | 
  
 | 
        .count-title {  
 | 
            height: 42rpx;  
 | 
            line-height: 42rpx;  
 | 
        }  
 | 
        .file-style { 
 | 
            color: #216EEE; 
 | 
            min-width: 0; 
 | 
            min-height: 0; 
 | 
            word-wrap: break-word; 
 | 
        } 
 | 
        .delet-btn { 
 | 
            width: 60rpx; 
 | 
            flex-shrink: 0; 
 | 
        }  
 | 
        .uploadImage {  
 | 
            width: 196rpx;  
 | 
            height: 152rpx; 
 | 
        } 
 | 
        .upload-btn { 
 | 
            width: 184rpx; 
 | 
        } 
 | 
        .must::after { 
 | 
            content: ' *'; 
 | 
            color: #F98107; 
 | 
            font-size: 28rpx; 
 | 
            font-weight: 400; 
 | 
            height: 40rpx; 
 | 
            line-height: 40rpx; 
 | 
        } 
 | 
    }  
 | 
  
 | 
    .save-btn {  
 | 
        width: 224rpx;  
 | 
    }  
 | 
  
 | 
    .submit-btn {  
 | 
        width: 446rpx;  
 | 
    }  
 | 
</style> 
 |