<!--
 * @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, nonetworksignalPhotoUpdate
} from "@/api/business/order/process.js";

let putPhotoAction = "/api/galaxy-business/rtu/check/order/process/nonetworksignal/putPhoto";
export default {
    components: {

    },
    props: {
        id: {
            type: [Number],
            required: true
        },
    },
    name: 'checkorderphotosubmit',
    data() {
        return {
            dataForm: {
                baseBeforePhotos: [],
                baseAfterPhotos: [],
                rtuPhotoUrl: [],
                rainSensorPhotoUrl: [],
                waterSensorPhotoUrl: [],
                groundSensorPhotoUrl: [],
                batteryPhotoUrl: [],
                sunPhotoUrl: [],
                // baseBeforePhoto1Take: 0,
                // baseBeforePhoto1Url: [],
                // baseBeforePhoto2Take: 0,
                // baseBeforePhoto2Url: [],
                // baseAfterPhoto1Take: 0,
                // baseAfterPhoto1Url: [],
                // baseAfterPhoto2Take: 0,
                // baseAfterPhoto2Url: [],
                // rtuPhotoTake: 0,
                // rtuPhotoUrl: [],
                // rainSensorPhotoTake: 0,
                // rainSensorPhotoUrl: [],
                // waterSensorPhotoTake: 0,
                // waterSensorPhotoUrl: [],
                // groundSensorPhotoTake: 0,
                // groundSensorPhotoUrl: [],
                // batteryPhotoTake: 0,
                // batteryPhotoUrl: [],
                // sunPhotoTake: 0,
                // sunPhotoUrl: [],
            },
            option: {
                column: [
                    {
                        label: '维修前补交照片',
                        prop: 'baseBeforePhotos',
                        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: 'baseAfterPhotos',
                        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: 'rtuPhotoUrl',
                        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: 'rainSensorPhotoUrl',
                        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: 'waterSensorPhotoUrl',
                        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: 'groundSensorPhotoUrl',
                        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: 'batteryPhotoUrl',
                        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: 'sunPhotoUrl',
                        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) {

                    if (data.data.rtuPhotoTake == 1) {
                        let rtuPhotoUrl = [];
                        let p = {};
                        p['url'] = data.data.rtuPhotoUrl;
                        p['name'] = data.data.rtuPhotoUrl;
                        rtuPhotoUrl.push(p);
                        this.dataForm.rtuPhotoUrl = rtuPhotoUrl;
                    }


                    if (data.data.rainSensorPhotoTake == 1) {
                        let rainSensorPhotoUrl = [];
                        let p = {};
                        p['url'] = data.data.rainSensorPhotoUrl;
                        p['name'] = data.data.rainSensorPhotoUrl;
                        rainSensorPhotoUrl.push(p);
                        this.dataForm.rainSensorPhotoUrl = rainSensorPhotoUrl;
                    }



                    if (data.data.waterSensorPhotoTake == 1) {
                        let waterSensorPhotoUrl = [];
                        let p = {};
                        p['url'] = data.data.waterSensorPhotoUrl;
                        p['name'] = data.data.waterSensorPhotoUrl;
                        waterSensorPhotoUrl.push(p);
                        this.dataForm.waterSensorPhotoUrl = waterSensorPhotoUrl;
                    }

                    if (data.data.groundSensorPhotoTake == 1) {
                        let groundSensorPhotoUrl = [];
                        let p = {};
                        p['url'] = data.data.groundSensorPhotoUrl;
                        p['name'] = data.data.groundSensorPhotoUrl;
                        groundSensorPhotoUrl.push(p);
                        this.dataForm.groundSensorPhotoUrl = groundSensorPhotoUrl;
                    }


                    if (data.data.batteryPhotoTake == 1) {
                        let batteryPhotoUrl = [];
                        let p = {};
                        p['url'] = data.data.batteryPhotoUrl;
                        p['name'] = data.data.batteryPhotoUrl;
                        batteryPhotoUrl.push(p);
                        this.dataForm.batteryPhotoUrl = batteryPhotoUrl;
                    }

                    if (data.data.sunPhotoTake == 1) {
                        let sunPhotoUrl = [];
                        let p = {};
                        p['url'] = data.data.sunPhotoUrl;
                        p['name'] = data.data.sunPhotoUrl;
                        sunPhotoUrl.push(p);
                        this.dataForm.sunPhotoUrl = sunPhotoUrl;
                    }
                    let baseBeforePhotos = [];
                    if (data.data.baseBeforePhoto1Take == 1) {

                        let p = {};
                        p['url'] = data.data.baseBeforePhoto1Url;
                        p['name'] = data.data.baseBeforePhoto1Url;
                        baseBeforePhotos.push(p);

                    }


                    if (data.data.baseBeforePhoto2Take == 1) {

                        let p = {};
                        p['url'] = data.data.baseBeforePhoto2Url;
                        p['name'] = data.data.baseBeforePhoto2Url;
                        baseBeforePhotos.push(p);

                    }
                    this.dataForm.baseBeforePhotos = baseBeforePhotos;

                    let baseAfterPhotos = [];
                    if (data.data.baseAfterPhoto1Take == 1) {

                        let p = {};
                        p['url'] = data.data.baseAfterPhoto1Url;
                        p['name'] = data.data.baseAfterPhoto1Url;
                        baseAfterPhotos.push(p);

                    }


                    if (data.data.baseAfterPhoto2Take == 1) {

                        let p = {};
                        p['url'] = data.data.baseAfterPhoto2Url;
                        p['name'] = data.data.baseAfterPhoto2Url;
                        baseAfterPhotos.push(p);

                    }
                    this.dataForm.baseAfterPhotos = baseAfterPhotos;



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

                }
            })
        },
        submitPhoto(form, done) {

            console.log(JSON.stringify(form))
            let postformdata = {};
            postformdata['id'] = this.id;

            if (form.baseBeforePhotos.length > 0) {
                postformdata['baseBeforePhoto1Take'] = 1;
                postformdata['baseBeforePhoto1Url'] = form.baseBeforePhotos[0].url;
            } else {
                postformdata['baseBeforePhoto1Take'] = 0;
            }

            if (form.baseBeforePhotos.length > 1) {
                postformdata['baseBeforePhoto2Take'] = 1;
                postformdata['baseBeforePhoto2Url'] = form.baseBeforePhotos[1].url;
            } else {
                postformdata['baseBeforePhoto2Take'] = 0;
            }

            if (form.baseAfterPhotos.length > 0) {
                postformdata['baseAfterPhoto1Take'] = 1;
                postformdata['baseAfterPhoto1Url'] = form.baseAfterPhotos[0].url;
            } else {
                postformdata['baseAfterPhoto1Take'] = 0;
            }

            if (form.baseAfterPhotos.length > 1) {
                postformdata['baseAfterPhoto2Take'] = 1;
                postformdata['baseAfterPhoto2Url'] = form.baseAfterPhotos[1].url;
            } else {
                postformdata['baseAfterPhoto2Take'] = 0;
            }

            if (form.rtuPhotoUrl.length > 0) {
                postformdata['rtuPhotoTake'] = 1;
                postformdata['rtuPhotoUrl'] = form.rtuPhotoUrl[0].url;
            } else {
                postformdata['rtuPhotoTake'] = 0;
            }
            if (form.rainSensorPhotoUrl.length > 0) {
                postformdata['rainSensorPhotoTake'] = 1;
                postformdata['rainSensorPhotoUrl'] = form.rainSensorPhotoUrl[0].url;
            } else {
                postformdata['rainSensorPhotoTake'] = 0;
            }
            if (form.waterSensorPhotoUrl.length > 0) {
                postformdata['waterSensorPhotoTake'] = 1;
                postformdata['waterSensorPhotoUrl'] = form.waterSensorPhotoUrl[0].url;
            } else {
                postformdata['waterSensorPhotoTake'] = 0;
            }
            if (form.groundSensorPhotoUrl.length > 0) {
                postformdata['groundSensorPhotoTake'] = 1;
                postformdata['groundSensorPhotoUrl'] = form.groundSensorPhotoUrl[0].url;
            } else {
                postformdata['groundSensorPhotoTake'] = 0;
            }
            if (form.batteryPhotoUrl.length > 0) {
                postformdata['batteryPhotoTake'] = 1;
                postformdata['batteryPhotoUrl'] = form.batteryPhotoUrl[0].url;
            } else {
                postformdata['batteryPhotoTake'] = 0;
            }
            if (form.sunPhotoUrl.length > 0) {
                postformdata['sunPhotoTake'] = 1;
                postformdata['batteryPhotoUrl'] = form.sunPhotoUrl[0].url;
            } else {
                postformdata['sunPhotoTake'] = 0;
            }

            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>

