<!--
 * @Title: 
 * @Description: 巡检填报详情
 * @Author: swp
 * @Date: 2022-08-24 10:49:21
 * @LastEditors: 
 * @LastEditTime: 2022-08-24 10:49:21
-->
<template>
    <el-row>
        <el-col :span="24">
            <basic-container>
                <avue-form :option="option" v-model="dataForm" @submit="submitPhoto"></avue-form>
            </basic-container>
        </el-col>
    </el-row>
</template>

<script>

import {
    getDetail,
} from "@/api/business/inspection/inspectionreport.js";
import { nonetworksignalPhotoUpdate } from "@/api/business/inspection/inspectionreport.js";
let putPhotoAction = "/api/galaxy-business/equipment/inspection/report/nonetworksignal/putPhoto";
export default {
    components: {

    },
    props: {
        id: {
            type: [Number],
            required: true
        },
    },
    name: 'inspectionphotosubmit',
    data() {
        return {
            dataForm: {
                siteCheckPhotos: [],
                rainSiteCheckPhotos: [],
                waterSiteCheckPhotos: [],
                groundSiteCheckPhotos: [],
                othersEquipmentCheckPhotos: [],
                rtuReplacePhotos: [],
                rainSensorReplacePhotos: [],
                waterSensorReplacePhotos: [],
                groundSensorReplacePhotos: [],
                batteryReplacePhotos: [],
                sunPowerReplacePhotos: [],
                batteryControlReplacePhotos: [],
                otherEquipmentReplacePhotos: [],
                inspectionWorkPhotos: [],
            },
            option: {
                column: [
                    {
                        label: '站点状态检查补交照片',
                        prop: 'siteCheckPhotos',
                        listType: 'picture-card',
                        type: 'upload',
                        span: 24,
                        action: putPhotoAction,
                        dataType: 'object',
                        props: {
                            label: 'name',
                            value: 'url'
                        },
                        propsHttp: {
                            url: 'name',
                            name: 'originalName',
                            home: this.website.ossServer,
                            res: 'data',
                        },
                    },
                    {
                        label: '雨量站检查补交照片',
                        prop: 'rainSiteCheckPhotos',
                        listType: 'picture-card',
                        type: 'upload',
                        span: 24,
                        action: putPhotoAction,
                        dataType: 'object',
                        props: {
                            label: 'name',
                            value: 'url'
                        },
                        propsHttp: {
                            url: 'name',
                            name: 'originalName',
                            home: this.website.ossServer,
                            res: 'data',
                        },
                    },
                    {
                        label: '水位站检查补交照片',
                        prop: 'waterSiteCheckPhotos',
                        listType: 'picture-card',
                        type: 'upload',
                        span: 24,
                        action: putPhotoAction,
                        dataType: 'object',
                        props: {
                            label: 'name',
                            value: 'url'
                        },
                        propsHttp: {
                            url: 'name',
                            name: 'originalName',
                            home: this.website.ossServer,
                            res: 'data',
                        },
                    },
                    {
                        label: '墒情站检查补交照片',
                        prop: 'groundSiteCheckPhotos',
                        listType: 'picture-card',
                        type: 'upload',
                        span: 24,
                        action: putPhotoAction,
                        dataType: 'object',
                        props: {
                            label: 'name',
                            value: 'url'
                        },
                        propsHttp: {
                            url: 'name',
                            name: 'originalName',
                            home: this.website.ossServer,
                            res: 'data',
                        },
                    },
                    {
                        label: '其他设备检查补交照片',
                        prop: 'othersEquipmentCheckPhotos',
                        listType: 'picture-card',
                        type: 'upload',
                        span: 24,
                        action: putPhotoAction,
                        dataType: 'object',
                        props: {
                            label: 'name',
                            value: 'url'
                        },
                        propsHttp: {
                            url: 'name',
                            name: 'originalName',
                            home: this.website.ossServer,
                            res: 'data',
                        },
                    },
                    {
                        label: 'RTU更换补交照片',
                        prop: 'rtuReplacePhotos',
                        listType: 'picture-card',
                        type: 'upload',
                        span: 24,
                        action: putPhotoAction,
                        dataType: 'object',
                        props: {
                            label: 'name',
                            value: 'url'
                        },
                        propsHttp: {
                            url: 'name',
                            name: 'originalName',
                            home: this.website.ossServer,
                            res: 'data',
                        },
                    },
                    {
                        label: '雨量计更换补交照片',
                        prop: 'rainSensorReplacePhotos',
                        listType: 'picture-card',
                        type: 'upload',
                        span: 24,
                        action: putPhotoAction,
                        dataType: 'object',
                        props: {
                            label: 'name',
                            value: 'url'
                        },
                        propsHttp: {
                            url: 'name',
                            name: 'originalName',
                            home: this.website.ossServer,
                            res: 'data',
                        },
                    },
                    {
                        label: '水位计更换补交照片',
                        prop: 'waterSensorReplacePhotos',
                        listType: 'picture-card',
                        type: 'upload',
                        span: 24,
                        action: putPhotoAction,
                        dataType: 'object',
                        props: {
                            label: 'name',
                            value: 'url'
                        },
                        propsHttp: {
                            url: 'name',
                            name: 'originalName',
                            home: this.website.ossServer,
                            res: 'data',
                        },
                    },
                    {
                        label: '墒情计更换补交照片',
                        prop: 'groundSensorReplacePhotos',
                        listType: 'picture-card',
                        type: 'upload',
                        span: 24,
                        action: putPhotoAction,
                        dataType: 'object',
                        props: {
                            label: 'name',
                            value: 'url'
                        },
                        propsHttp: {
                            url: 'name',
                            name: 'originalName',
                            home: this.website.ossServer,
                            res: 'data',
                        },
                    },
                    {
                        label: '蓄电池更换补交照片',
                        prop: 'batteryReplacePhotos',
                        listType: 'picture-card',
                        type: 'upload',
                        span: 24,
                        action: putPhotoAction,
                        dataType: 'object',
                        props: {
                            label: 'name',
                            value: 'url'
                        },
                        propsHttp: {
                            url: 'name',
                            name: 'originalName',
                            home: this.website.ossServer,
                            res: 'data',
                        },
                    },
                    {
                        label: '太阳能板更换补交照片',
                        prop: 'sunPowerReplacePhotos',
                        listType: 'picture-card',
                        type: 'upload',
                        span: 24,
                        action: putPhotoAction,
                        dataType: 'object',
                        props: {
                            label: 'name',
                            value: 'url'
                        },
                        propsHttp: {
                            url: 'name',
                            name: 'originalName',
                            home: this.website.ossServer,
                            res: 'data',
                        },
                    },
                    {
                        label: '蓄电池控制器更换补交照片',
                        prop: 'batteryControllerReplacePhotos',
                        listType: 'picture-card',
                        type: 'upload',
                        span: 24,
                        action: putPhotoAction,
                        dataType: 'object',
                        props: {
                            label: 'name',
                            value: 'url'
                        },
                        propsHttp: {
                            url: 'name',
                            name: 'originalName',
                            home: this.website.ossServer,
                            res: 'data',
                        },
                    },
                    {
                        label: '其他设备更换补交照片',
                        prop: 'otherEquipmentReplacePhotos',
                        listType: 'picture-card',
                        type: 'upload',
                        span: 24,
                        action: putPhotoAction,
                        dataType: 'object',
                        props: {
                            label: 'name',
                            value: 'url'
                        },
                        propsHttp: {
                            url: 'name',
                            name: 'originalName',
                            home: this.website.ossServer,
                            res: 'data',
                        },
                    },
                    {
                        label: '工作留存补交照片',
                        prop: 'inspectionWorkPhotos',
                        listType: 'picture-card',
                        type: 'upload',
                        span: 24,
                        action: putPhotoAction,
                        dataType: 'object',
                        props: {
                            label: 'name',
                            value: 'url'
                        },
                        propsHttp: {
                            url: 'name',
                            name: 'originalName',
                            home: this.website.ossServer,
                            res: 'data',
                        },

                    },
                ]
            },
        }
    },
    created() {
        // this.init();
    },
    methods: {
        toOss(path) {
            console.log("oss " + this.website.ossServer + path);
            // return "/oss/galaxy/" + path;
            return this.website.ossServer + path;
        },
        init() {
            getDetail(this.id).then(res => {
                const data = res.data;
                console.log(JSON.stringify(data));
                if (data.success) {



                    let siteCheckPhotos = [];
                    let photos = data.data['siteCheckPhotos'];
                    if (null != photos && photos.length > 0) {
                        let photoList = photos.split(",");
                        for (let i = 0; i < photoList.length; i++) {
                            let p = {};
                            p['url'] = photoList[i];
                            p['name'] = photoList[i];
                            siteCheckPhotos.push(p);
                        }
                        this.dataForm.siteCheckPhotos = siteCheckPhotos;
                    }



                    let rainSiteCheckPhotos = [];
                    photos = data.data['rainSiteCheckPhotos'];
                    if (null != photos && photos.length > 0) {
                        let photoList = photos.split(",");
                        for (let i = 0; i < photoList.length; i++) {
                            let p = {};
                            p['url'] = photoList[i];
                            p['name'] = photoList[i];
                            rainSiteCheckPhotos.push(p);
                        }
                        this.dataForm.rainSiteCheckPhotos = rainSiteCheckPhotos;
                    }

                    let waterSiteCheckPhotos = [];
                    photos = data.data['waterSiteCheckPhotos'];
                    if (null != photos && photos.length > 0) {
                        let photoList = photos.split(",");
                        for (let i = 0; i < photoList.length; i++) {
                            let p = {};
                            p['url'] = photoList[i];
                            p['name'] = photoList[i];
                            waterSiteCheckPhotos.push(p);
                        }
                        this.dataForm.waterSiteCheckPhotos = rainSiteCheckPhotos;
                    }

                    let groundSiteCheckPhotos = [];
                    photos = data.data['groundSiteCheckPhotos'];
                    if (null != photos && photos.length > 0) {
                        let photoList = photos.split(",");
                        for (let i = 0; i < photoList.length; i++) {
                            let p = {};
                            p['url'] = photoList[i];
                            p['name'] = photoList[i];
                            groundSiteCheckPhotos.push(p);
                        }
                        this.dataForm.groundSiteCheckPhotos = groundSiteCheckPhotos;
                    }

                    let othersEquipmentCheckPhotos = [];
                    photos = data.data['otherEquipmentCheckPhotos'];
                    console.log(JSON.stringify(photos))
                    if (null != photos && photos.length > 0) {
                        let photoList = photos.split(",");
                        for (let i = 0; i < photoList.length; i++) {
                            let p = {};
                            p['url'] = photoList[i];
                            p['name'] = photoList[i];
                            othersEquipmentCheckPhotos.push(p);
                        }
                        console.log("ppp" + JSON.stringify(othersEquipmentCheckPhotos))
                        this.dataForm.othersEquipmentCheckPhotos = othersEquipmentCheckPhotos;
                    }
                    let rtuReplacePhotos = [];
                    photos = data.data['rtuReplacePhotos'];
                    if (null != photos && photos.length > 0) {
                        let photoList = photos.split(",");
                        for (let i = 0; i < photoList.length; i++) {
                            let p = {};
                            p['url'] = photoList[i];
                            p['name'] = photoList[i];
                            rtuReplacePhotos.push(p);
                        }
                        this.dataForm.rtuReplacePhotos = rtuReplacePhotos;
                    }
                    let rainSensorReplacePhotos = [];
                    photos = data.data['rainSensorReplacePhotos'];
                    if (null != photos && photos.length > 0) {
                        let photoList = photos.split(",");
                        for (let i = 0; i < photoList.length; i++) {
                            let p = {};
                            p['url'] = photoList[i];
                            p['name'] = photoList[i];
                            rainSensorReplacePhotos.push(p);
                        }
                        this.dataForm.rainSensorReplacePhotos = rainSensorReplacePhotos;
                    }
                    let waterSensorReplacePhotos = [];
                    photos = data.data['waterSensorReplacePhotos'];
                    if (null != photos && photos.length > 0) {
                        let photoList = photos.split(",");
                        for (let i = 0; i < photoList.length; i++) {
                            let p = {};
                            p['url'] = photoList[i];
                            p['name'] = photoList[i];
                            waterSensorReplacePhotos.push(p);
                        }
                        this.dataForm.waterSensorReplacePhotos = waterSensorReplacePhotos;
                    }
                    let groundSensorReplacePhotos = [];
                    photos = data.data['groundSensorReplacePhotos'];
                    if (null != photos && photos.length > 0) {
                        let photoList = photos.split(",");
                        for (let i = 0; i < photoList.length; i++) {
                            let p = {};
                            p['url'] = photoList[i];
                            p['name'] = photoList[i];
                            groundSensorReplacePhotos.push(p);
                        }
                        this.dataForm.groundSensorReplacePhotos = groundSensorReplacePhotos;
                    }
                    let batteryReplacePhotos = [];
                    photos = data.data['batteryReplacePhotos'];
                    if (null != photos && photos.length > 0) {
                        let photoList = photos.split(",");
                        for (let i = 0; i < photoList.length; i++) {
                            let p = {};
                            p['url'] = photoList[i];
                            p['name'] = photoList[i];
                            batteryReplacePhotos.push(p);
                        }
                        this.dataForm.batteryReplacePhotos = batteryReplacePhotos;
                    }
                    let sunPowerReplacePhotos = [];
                    photos = data.data['sunPowerReplacePhotos'];
                    if (null != photos && photos.length > 0) {
                        let photoList = photos.split(",");
                        for (let i = 0; i < photoList.length; i++) {
                            let p = {};
                            p['url'] = photoList[i];
                            p['name'] = photoList[i];
                            sunPowerReplacePhotos.push(p);
                        }
                        this.dataForm.sunPowerReplacePhotos = sunPowerReplacePhotos;
                    }
                    let batteryControllerReplacePhotos = [];
                    photos = data.data['batteryControllerReplacePhotos'];
                    if (null != photos && photos.length > 0) {
                        let photoList = photos.split(",");
                        for (let i = 0; i < photoList.length; i++) {
                            let p = {};
                            p['url'] = photoList[i];
                            p['name'] = photoList[i];
                            batteryControllerReplacePhotos.push(p);
                        }
                        this.dataForm.batteryControllerReplacePhotos = batteryControllerReplacePhotos;
                    }
                    let otherEquipmentReplacePhotos = [];
                    photos = data.data['otherEquipmentReplacePhotos'];
                    if (null != photos && photos.length > 0) {
                        let photoList = photos.split(",");
                        for (let i = 0; i < photoList.length; i++) {
                            let p = {};
                            p['url'] = photoList[i];
                            p['name'] = photoList[i];
                            otherEquipmentReplacePhotos.push(p);
                        }
                        this.dataForm.otherEquipmentReplacePhotos = otherEquipmentReplacePhotos;
                    }
                    let inspectionWorkPhotos = [];
                    photos = data.data['inspectionWorkPhotos'];
                    if (null != photos && photos.length > 0) {
                        let photoList = photos.split(",");
                        for (let i = 0; i < photoList.length; i++) {
                            let p = {};
                            p['url'] = photoList[i];
                            p['name'] = photoList[i];
                            inspectionWorkPhotos.push(p);
                        }
                        this.dataForm.inspectionWorkPhotos = inspectionWorkPhotos;
                    }

                    console.log(JSON.stringify(this.dataForm))

                }
            })
        },
        submitPhoto(form, done) {
            let postformdata = {};
            postformdata['id'] = this.id;

            if (form.siteCheckPhotos.length > 0) {
                let photos = '';
                for (let i = 0; i < form.siteCheckPhotos.length; i++) {
                    if (photos.length > 0) {
                        photos = photos + ',';
                    }
                    photos = photos + form.siteCheckPhotos[i].url;
                }
                postformdata['siteCheckPhotos'] = photos;
            }


            if (form.rainSiteCheckPhotos.length > 0) {
                let photos = '';
                for (let i = 0; i < form.rainSiteCheckPhotos.length; i++) {
                    if (photos.length > 0) {
                        photos = photos + ',';
                    }
                    photos = photos + form.rainSiteCheckPhotos[i].url;
                }
                postformdata['rainSiteCheckPhotos'] = photos;
            }



            if (form.waterSiteCheckPhotos.length > 0) {
                let photos = '';
                for (let i = 0; i < form.waterSiteCheckPhotos.length; i++) {
                    if (photos.length > 0) {
                        photos = photos + ',';
                    }
                    photos = photos + form.waterSiteCheckPhotos[i].url;
                }
                postformdata['waterSiteCheckPhotos'] = photos;
            }


            if (form.groundSiteCheckPhotos.length > 0) {
                let photos = '';
                for (let i = 0; i < form.groundSiteCheckPhotos.length; i++) {
                    if (photos.length > 0) {
                        photos = photos + ',';
                    }
                    photos = photos + form.groundSiteCheckPhotos[i].url;
                }
                postformdata['groundSiteCheckPhotos'] = photos;
            }

            if (form.othersEquipmentCheckPhotos.length > 0) {
                let photos = '';
                for (let i = 0; i < form.othersEquipmentCheckPhotos.length; i++) {
                    if (photos.length > 0) {
                        photos = photos + ',';
                    }
                    photos = photos + form.othersEquipmentCheckPhotos[i].url;
                }
                postformdata['otherEquipmentCheckPhotos'] = photos;
            }

            if (form.rtuReplacePhotos.length > 0) {
                let photos = '';
                for (let i = 0; i < form.rtuReplacePhotos.length; i++) {
                    if (photos.length > 0) {
                        photos = photos + ',';
                    }
                    photos = photos + form.rtuReplacePhotos[i].url;
                }
                postformdata['rtuReplacePhotos'] = photos;
            }


            if (form.rainSensorReplacePhotos.length > 0) {
                let photos = '';
                for (let i = 0; i < form.rainSensorReplacePhotos.length; i++) {
                    if (photos.length > 0) {
                        photos = photos + ',';
                    }
                    photos = photos + form.rainSensorReplacePhotos[i].url;
                }
                postformdata['rainSensorReplacePhotos'] = photos;
            }

            if (form.waterSensorReplacePhotos.length > 0) {
                let photos = '';
                for (let i = 0; i < form.waterSensorReplacePhotos.length; i++) {
                    if (photos.length > 0) {
                        photos = photos + ',';
                    }
                    photos = photos + form.waterSensorReplacePhotos[i].url;
                }
                postformdata['waterSensorReplacePhotos'] = photos;
            }


            if (form.groundSensorReplacePhotos.length > 0) {
                let photos = '';
                for (let i = 0; i < form.groundSensorReplacePhotos.length; i++) {
                    if (photos.length > 0) {
                        photos = photos + ',';
                    }
                    photos = photos + form.groundSensorReplacePhotos[i].url;
                }
                postformdata['groundSensorReplacePhotos'] = photos;
            }



            if (form.batteryReplacePhotos.length > 0) {
                let photos = '';
                for (let i = 0; i < form.batteryReplacePhotos.length; i++) {
                    if (photos.length > 0) {
                        photos = photos + ',';
                    }
                    photos = photos + form.batteryReplacePhotos[i].url;
                }
                postformdata['batteryReplacePhotos'] = photos;
            }

            if (form.sunPowerReplacePhotos.length > 0) {
                let photos = '';
                for (let i = 0; i < form.sunPowerReplacePhotos.length; i++) {
                    if (photos.length > 0) {
                        photos = photos + ',';
                    }
                    photos = photos + form.sunPowerReplacePhotos[i].url;
                }
                postformdata['sunPowerReplacePhotos'] = photos;
            }



            if (form.batteryControlReplacePhotos.length > 0) {
                let photos = '';
                for (let i = 0; i < form.batteryControlReplacePhotos.length; i++) {
                    if (photos.length > 0) {
                        photos = photos + ',';
                    }
                    photos = photos + form.batteryControlReplacePhotos[i].url;
                }
                postformdata['batteryControllerReplacePhotos'] = photos;
            }

            if (form.otherEquipmentReplacePhotos.length > 0) {
                let photos = '';
                for (let i = 0; i < form.otherEquipmentReplacePhotos.length; i++) {
                    if (photos.length > 0) {
                        photos = photos + ',';
                    }
                    photos = photos + form.otherEquipmentReplacePhotos[i].url;
                }
                postformdata['otherEquipmentReplacePhotos'] = photos;
            }


            if (form.inspectionWorkPhotos.length > 0) {
                let photos = '';
                for (let i = 0; i < form.inspectionWorkPhotos.length; i++) {
                    if (photos.length > 0) {
                        photos = photos + ',';
                    }
                    photos = photos + form.inspectionWorkPhotos[i].url;
                }
                postformdata['inspectionWorkPhotos'] = photos;
            }

            nonetworksignalPhotoUpdate(postformdata).then((res) => {
                if (res.data.code == 200) {
                    this.$message({
                        type: "success",
                        message: "操作成功",
                    });

                    done();

                    this.$emit("update:visible", false);
                }
            });
        },
    }
}
</script>


<style lang="scss" scoped>
.item-line-start {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
}

.item-line-end {
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
}

.item-line-center {
    display: flex;
    flex-direction: row;
    justify-content: center;
    width: 100%;
}

.block-line {
    border-bottom: 1px solid lightblue;
}

.item-title {
    display: flex;
    flex-direction: column;
    ;
    justify-content: center;
    font-size: 1rem;
}

.item-content {
    display: flex;
    flex-direction: column;
    ;
    justify-content: center;
    padding-left: 10px;
    color: grey;
    font-size: 1rem;
}
</style>

