<template>
    <div class="content-box">
        <div class="container">
            <el-form ref="form" :model="sizeForm" label-width="140px">
                <p>主机</p>
                <el-form-item label="名称：" :label-width="formLabelWidth">
                    <el-input v-model="sizeForm.name" autocomplete="off" style="width:50%" :disabled="disable"></el-input>
                    <el-button type="primary" style="margin-left:10px" @click="saveHostName" size="small" v-if="!disable">保存</el-button>
                </el-form-item>
                <el-form-item label="时间：" :label-width="formLabelWidth">
                    <!-- <el-date-picker type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期"
                        v-model="sizeForm.date1" style="width: 50%;" autocomplete="off"></el-date-picker> -->
                     <el-input v-model="sizeForm.date1" autocomplete="off" style="width:50%" :disabled="true"></el-input>
                    <el-button @click="getSetHost" type="primary" style="margin-left:10px" size="small" v-if="!disable">校时</el-button>
                    <el-switch
                    style="margin-left:10px"
                      v-model="timeSwitch"
                      active-text="自动校时"
                      @change="changetimeSwitch"
                      v-if="!disable"
                     >
                    </el-switch>
                </el-form-item>
                <p>备份&恢复</p>
                <el-form-item label="备份服务器设置：">
                    <el-col :span="12">
                        <el-button type="primary" size="small" @click="backupHandle()" :disabled="disable">备份</el-button>
                    </el-col>
                </el-form-item>
                <el-form-item label="还原服务器设置：">
                    <el-col :span="3">
                        <el-button type="primary" size="small" @click="restoreHandle()" :disabled="disable">还原</el-button>
                    </el-col>
                    <el-col :span="8">
                        <!-- <el-upload class="upload-demo" action="https://jsonplaceholder.typicode.com/posts/"
                            :on-preview="handlePreview" :on-remove="handleRemove" :before-remove="beforeRemove" multiple
                            :limit="3" :on-exceed="handleExceed" :file-list="fileList">
                            <el-button size="small" type="primary">点击上传</el-button>
                        </el-upload> -->
                         <!-- <el-upload class="upload-demo" 
                            :on-preview="handlePreview" :on-remove="handleRemove" :before-remove="beforeRemove" multiple
                            @change="handleFileChange"
                            :limit="3" :on-exceed="handleExceed" :file-list="fileList">
                            <el-button size="small" type="primary" @click="load">点击上传</el-button>
                        </el-upload> -->
                        <!-- <el-upload
                             class="upload-demo"
                             ref="upload"
                             :action="action"
                             :on-preview="handlePreview"
                             :on-remove="handleRemove"
                             :on-progress="load"
                             :file-list="fileList"
                             :auto-upload="false">
                             <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
                             <el-button style="margin-left: 10px;" size="small" type="success" @click="load" >上传</el-button>
                        <div slot="tip" class="el-upload__tip">只能上传zip/png文件</div>
                        </el-upload> -->
                         <input type="file" id="fileExport" @change="handleFileChange($event)" ref="inputer" style="display:none">
                        <el-button size="small" type="primary" @click="load" :disabled="disable">点击上传</el-button>
                    </el-col>
                </el-form-item>
                <p>恢复出厂设置</p>
                <el-form-item label="出厂默认值：">
                    <el-col :span="12">
                        <el-button type="primary" @click="handleReset()" size="small" :disabled="disable">重置默认值</el-button>
                    </el-col>
                </el-form-item>
                <p>重新启动</p>
                <el-form-item label="重新启动系统：">
                    <el-col :span="12">
                        <el-button type="primary" @click="handleagain()" size="small" :disabled="disable">重新启动</el-button>
                    </el-col>
                </el-form-item>
                 <el-form-item label="分别重启：">
                    <el-col :span="3">
                       <el-select v-model="resetServiceData" placeholder="请选择服务"  @change='changeResetService' :disabled="disable">
                       <el-option
                         v-for="item in optionsruan"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
                       </el-option>
                     </el-select>
                    </el-col>
                    <el-col :span="4" style="margin-left:10%">
                        <!-- <el-upload class="upload-demo" action="https://jsonplaceholder.typicode.com/posts/"
                            :on-preview="handlePreview" :on-remove="handleRemove" :before-remove="beforeRemove" multiple
                            :limit="3" :on-exceed="handleExceed" :file-list="fileList">
                            <el-button size="small" type="primary">点击上传</el-button>
                        </el-upload> -->
                         <el-button type="primary" @click="handresetService()" size="small" :disabled="disable">重新启动</el-button>
                    </el-col>
                </el-form-item>
                 <p>更新软件</p>
                <el-form-item label="更新软件版本：">
                     <el-col :span="3">
                        <el-button type="primary" size="small" @click="changeUpdata()" :disabled="disable">更新</el-button>
                    </el-col>
                    <el-col :span="8">
                        <input type="file" id="fileExport" @change="handleFileChangeUpdate($event)" ref="inputerUpdate" style="display:none">
                        <el-button size="small" type="primary" @click="loadUpdate" :disabled="disable">点击上传</el-button>
                    </el-col>
                </el-form-item>
                <p>全局设置</p>
                <el-form-item label="视频接入上限：">
                    <el-input-number v-model="videoNumber" :min="1" size="mini" :max="8" :disabled="disable"></el-input-number>
                    <i class="el-icon-warning" style="color: #409EFF; margin: 0 3px 0 10px;"></i>范围1-8、默认6
                </el-form-item>

                <el-form-item label="跳帧设置：">
                    <el-select v-model="FPS" size="mini" placeholder="请选择" :disabled="disable">
                        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                        </el-option>
                    </el-select>
                    <i class="el-icon-warning" style="color: #409EFF; margin: 0 3px 0 10px;"></i>默认取值：单路视频流 0 ；2-3 路视频流
                    1；4-6 路视频流 4
                </el-form-item>
                <el-button type="primary" size="small" @click="commit()" v-if="!disable">保存</el-button>
            </el-form>
        </div>
    </div>
</template>

<script>
import { getHostInfoApi, initData,  configBackup,configRestore, RestartComputer ,getResetService,getTimeData,getSetHostTime,setAutomatic} from '../../api/aboutMachine';
import { getQuanjszData } from '../../api/index';
import serverUrl from '../../config/apiurl.js';
import { setQuanjsz } from '@/api/index';
import axios from 'axios';
import messageMixin from '@/utils/messageMixin.js';

export default {
    mixins: [messageMixin],
    data() {
        return {
            formLabelWidth: '120px',
            sizeForm: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: ''
            },
            action:'',
            fileList: [],
            file:'',
            fileUpdate:'',
            videoNumber: 6,
            timeSwitch:true,
            FPS: '0',
            id: '',
            options: [
                {
                    value: '0',
                    label: '0'
                },
                {
                    value: '1',
                    label: '1'
                },
                {
                    value: '4',
                    label: '4'
                }
            ],
            //，视频算法：cxx_SP 交通算法：cxx_JT 网络服务：cxx_PY 接口服务：zy_API 计算服务：zy_TrafficData ftp备份服务：zy_FtpData 网站：nginx
              optionsruan: [{
          value: 'cxx_SP',
          label: '视频算法'
        }, {
          value: '交通算法：cxx_JT',
          label: '交通算法'
        }, {
          value: 'cxx_PY',
          label: '网络服务'
        }, {
          value: 'zy_API',
          label: '接口服务'
        }, {
          value: 'zy_TrafficData',
          label: '计算服务'
        }, {
          value: 'zy_FtpData',
          label: 'ftp备份服务'
        }, {
          value: 'nginx',
          label: '网站'
        }, {
          value: 'zy_ThirdParty',
          label: '第三方接口服务'
        }, {
          value: 'zy_Video',
          label: '视频流转换服务'
        }
        ],
        resetServiceData: [],
        newNumber:0,
        figRestoreData:'',
        pathData:'',
        guidid:'',
        loadingR:'',
        loadingNUp:'',
        loadingNUpNEW:'',
        uuid:'',
        disable:false, //权限判断按钮
        };
    },
    mounted() {
        if (localStorage.getItem('roleName') == '系统管理员') {
            this.disable = false
        }else{
            this.disable = true
        }
        this.getTime()
        this.getShipjkDatalist();
        this.getInfo();
    window.setInterval(() => {
      setTimeout( this.getTime(), 0);
    }, 1000);
        // this.action=serverUrl.postConfigRestore
    },
    methods: {
         /** 创建mqtt */
        createMqtt() {
            //创建链接，接收
            this.guidid = this.guidNew()
            var topicSends = ['backup-' + this.guidid];
            console.log("this.guidid", this.guidid)
            window.PubScribe(topicSends,-1, this.realInfo); 
        },
        changeN(data) {
            if (
                data == "1" 
            ) {
                return true
            } else {
                return false
            }
        },
        changetimeSwitch(){
            console.log("cscscscs",this.timeSwitch)
            var timeSwitchNew = "1"
            if(this.timeSwitch==true){
                timeSwitchNew = "1"
            }else if(this.timeSwitch==false){
                 timeSwitchNew = "0"
            }
             const formData = new URLSearchParams();
            formData.append('TimeSwitch', timeSwitchNew);
            formData.append('GlobalSettingId', this.id);
             setAutomatic(formData).then(res=>{
          this.$message({
                  message: res.data.msg,
                  type: 'success'
            });
        })
        },
        //
         /** 实时数据分类 */
        realInfo(topic, message) {
            //  console.log("this.guidid", this.guidid)
            //  console.log("topic", topic)
            switch (topic) {
                // 接收托片
                case 'backup-' + this.guidid:
                    try {
                        const utf8decoder = new TextDecoder();
                        const u8arr = new Uint8Array(message);
                        const temp = utf8decoder.decode(u8arr); // 将二进制数据转为字符串
                        // const msg = JSON.parse(temp); //这一步报错则返回的是二进制流图片，不报错则返回的是JSON的错误提示数据
                        console.log("msg",temp)
                        this.loadingR.close()
                        if(temp.indexOf("成功") != -1 ){
                            this.$message({
                                message: temp,
                                type: 'success'
                            });
                        }else{
                              this.$message({
                                message: temp,
                                type: 'warning'
                            });
                        }
                    } catch (error) {
                     }
                    break;
                 case 'Version-' + this.uuid:
                    try {
                        const utf8decoder = new TextDecoder();
                        const u8arr = new Uint8Array(message);
                        const temp = utf8decoder.decode(u8arr); // 将二进制数据转为字符串
                        // const msg = JSON.parse(temp); //这一步报错则返回的是二进制流图片，不报错则返回的是JSON的错误提示数据
                        console.log("msg更新",temp)
                         console.log("temp.number",temp.number)
                          console.log("temp.total",temp.total)
                        // this.loadingR.close()
                        this.loadingNUp.close()
                        this.loadingNUpNEW = this.$loading({
                      lock: true,
                       text: temp.number +'/'+temp.total,
                      target: '.el-dialog',
                      spinner: 'el-icon-loading',
                      background: 'rgba(0, 0, 0, 0.7)'
                    });
                        if(temp.number== temp.total){
                            this.$message({
                                message: '更新成功',
                                type: 'success'
                            });
                            this.loadingNUpNEW.close()
                        }
                    } catch (error) {
                     }
                    break;
            }
        },
        //获取校时数据
        getTime(){
            //  var loadingN =  this.$loading({
            //                   lock: true,
            //                   text: 'Loading',
            //                   spinner: 'el-icon-loading',
            //                   background: 'rgba(0, 0, 0, 0.7)'
            //                 });
            getTimeData().then(res => {
                 if (res.data.code == 200) {
                    // loadingN.close();
                    // this.$message({
                    //     message: res.data.msg,
                    //     type: 'success'
                    // });
                    this.sizeForm.date1 = res.data.data
                } else {
                    //  loadingN.close();
                    this.$message({
                        message: res.data.msg,
                        type: 'warning'
                    });
                }
            })
        },
        //点击校时获取
           getSetHost(){
             var loadingN =  this.$loading({
                              lock: true,
                              text: 'Loading',
                              spinner: 'el-icon-loading',
                              background: 'rgba(0, 0, 0, 0.7)'
                            });
            getSetHostTime().then(res => {
                 if (res.data.code == 200) {
                    loadingN.close();
                    this.$message({
                        message: res.data.msg,
                        type: 'success'
                    });
                } else {
                     loadingN.close();
                    this.$message({
                        message: res.data.msg,
                        type: 'warning'
                    });
                }
            })
        },
        //保存主机时间
        // saveTime() {
        //     let formData = new FormData();
        //     formData.append('HostTime', this.sizeForm.date1);
        //     axios({
        //         method: 'post',
        //         url: serverUrl.setHostTime,
        //         data: formData
        //     }).then(res => {
        //         if (res.data.code == 200) {
        //             this.$message({
        //                 message: res.data.msg,
        //                 type: 'success'
        //             });
        //         } else {
        //             this.$message({
        //                 message: res.data.msg,
        //                 type: 'warning'
        //             });
        //         }
        //     });
        // },
        handleFileChange(event) {
           
            console.log('ssssswww');
                    let inputDOM = this.$refs.inputer;
                    this.file = inputDOM.files[0];// 通过DOM取文件数据
                     let size = this.file.size;//文件大小
                    let maxZrea = 8;              //设置每个分区大小 MB
                    let bufferSize = maxZrea * (1024 * 1024);
                    let fileStart = 0;
                    let fileEnd = bufferSize;
                    let arrFile = [];
                    
                    while (fileStart < size) {
                        var fileInfo = {
                            File: this.file.slice(fileStart, fileEnd),
                            Start: fileStart,
                            End: fileEnd
                        }
                        arrFile.push(fileInfo);
                        fileStart = fileEnd;
                        fileEnd = fileStart + bufferSize;
                    }
                  
                    console.log("this.file.name",this.file.name)                    
                    var dateLength = this.file.name.length;            
                    var key = this.file.name.substring(dateLength-4,dateLength);
                    console.log(key,'点击上传',this.file.name);
                    // if(this.file.name.indexOf("(") != -1||this.file.name.indexOf(")") != -1 ||this.file.name.indexOf("（") != -1 ||this.file.name.indexOf("）") != -1||key!='.zip' ){
                    //      this.$message({
                    //               message: '文件名不符合规范！',
                    //               type: 'warning'
                    //             });
                    // }else{
                          let newNumber= 0
                    var loadingN = this.$loading({
                      lock: true,
                       text: newNumber +'/'+arrFile.length,
                      target: '.el-dialog',
                      spinner: 'el-icon-loading',
                      background: 'rgba(0, 0, 0, 0.7)'
                    });
                     console.log("loadingN",loadingN.text)
                    let count = arrFile.length;
                        let filename = this.file.name + "~" + this.guid();
                    for (var i = 0; i < count; i++) {
                        let formData = new FormData();//new一个formData事件
                        formData.append("file", arrFile[i].File); //将file属性添加到formData里
                        this.action = serverUrl.getSpareElementOrder+"?Name=" + filename + "&Number=" + i + "&BufferSize=" + bufferSize + "&Count=" + count + "&Start=" + arrFile[i].Start + "&End=" + arrFile[i].End + "&Size=" + size+ "&FolderName=Backfile";
                        axios.post(this.action, formData, {
                            headers: {
                                "Content-Type": "multipart/form-data;",
                            }
                        }).then(r => {
                            if (r.data.code!=200) {
                                loadingN.close();
                                //  this.$message({
                                //   message: r.data.msg,
                                //   type: 'warning'
                                // });
                                this.showUniqueWarning(r.data.msg);
                            }else{    
                                if(r.data.data==null){
                                    this.dis = true 
                                    // var newN = i
                                    this.newNumber = newNumber++
                                    loadingN.text = this.newNumber +'/'+arrFile.length
                                }else{
                                    this.dis = false
                                    loadingN.close();
                                      this.$message({
                                  message: r.data.msg,
                                  type: 'success'
                                });
                                this.figRestoreData = r.data.data
                                
                                // this.form.videoStreamAddress=r.data.data
                                // this.fileList.push(r.data.data)
                                }
                            }
                        }).catch(e => {
                            console.log(e);
                        });
                    }
                    // }
                     event.target.value = ''
                     this.clearShownWarnings();
                },
        handleFileChangeUpdate(event) {
                    let inputDOM = this.$refs.inputerUpdate;
                    this.fileUpdate = inputDOM.files[0];// 通过DOM取文件数据
                      let size = this.fileUpdate.size;//文件大小
                    let maxZrea = 8;              //设置每个分区大小 MB
                    let bufferSize = maxZrea * (1024 * 1024);
                    let fileStart = 0;
                    let fileEnd = bufferSize;
                    let arrFile = [];
                    
                    while (fileStart < size) {
                        var fileInfo = {
                            File: this.fileUpdate.slice(fileStart, fileEnd),
                            Start: fileStart,
                            End: fileEnd
                        }
                        arrFile.push(fileInfo);
                        fileStart = fileEnd;
                        fileEnd = fileStart + bufferSize;
                    }
                      var dateLength = this.fileUpdate.name.length;            
                    var key = this.fileUpdate.name.substring(dateLength-4,dateLength);
                    console.log(key);
                    // if(this.fileUpdate.name.indexOf("(") != -1||this.fileUpdate.name.indexOf(")") != -1 ||this.fileUpdate.name.indexOf("（") != -1 ||this.fileUpdate.name.indexOf("）") != -1||key!='.zip' ){
                    //      this.$message({
                    //               message: '文件名不符合规范！',
                    //               type: 'warning'
                    //             });
                    // }else{
                        let newNumber= 0
                    var loadingN = this.$loading({
                      lock: true,
                       text: newNumber +'/'+arrFile.length,
                      target: '.el-dialog',
                      spinner: 'el-icon-loading',
                      background: 'rgba(0, 0, 0, 0.7)'
                    });
                     console.log("loadingN",loadingN.text)
                    let count = arrFile.length;
                    let filename = this.fileUpdate.name + "~" + this.guid();
                    for (var i = 0; i < count; i++) {
                        let formData = new FormData();//new一个formData事件
                        formData.append("file", arrFile[i].File); //将file属性添加到formData里
                        var url = serverUrl.getSpareElementOrder+"?Name=" + filename + "&Number=" + i + "&BufferSize=" + bufferSize + "&Count=" + count + "&Start=" + arrFile[i].Start + "&End=" + arrFile[i].End + "&Size=" + size+ "&FolderName=VersionFile";
                        axios.post(url, formData, {
                            headers: {
                                "Content-Type": "multipart/form-data;",
                            }
                        }).then(r => {
                            if (r.data.code!=200) {
                                loadingN.close();
                                //  this.$message({
                                //   message: r.data.msg,
                                //   type: 'warning'
                                // });
                                this.showUniqueWarning(r.data.msg);
                            }else{    
                                if(r.data.data==null){
                                    this.dis = true 
                                    // var newN = i
                                    this.newNumber = newNumber++
                                    loadingN.text = this.newNumber +'/'+arrFile.length
                                }else{
                                    this.dis = false
                                    loadingN.close();
                                      this.$message({
                                  message: r.data.msg,
                                  type: 'success'
                                });
                                // this.form.videoStreamAddress=r.data.data
                                // this.fileList.push(r.data.data)
                                this.pathData = r.data.data
                             
                                }
                            }
                        }).catch(e => {
                            console.log(e);
                        });
                    }
                    // }
                    event.target.value = ''
                    this.clearShownWarnings();
                },
        S4() {
                    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
                },
        guidNew() {
                    return (this.S4() + this.S4() + this.S4() + this.S4() + this.S4()  + this.S4() + this.S4() + this.S4());
                },
        guid() {
                    return (this.S4() + this.S4() + "-" + this.S4() + "-" + this.S4() + "-" + this.S4() + "-" + this.S4() + this.S4() + this.S4());
                },
                //还原服务器
        load() {
            this.$refs.inputer.dispatchEvent(new MouseEvent('click'))
                   
                    
                },
                //
                //更新软件版本
        loadUpdate(){
              this.$refs.inputerUpdate.dispatchEvent(new MouseEvent('click'))      
                    
                },
        //保存主机名称
        saveHostName(value) {
            let formData = new FormData();
            formData.append('HostName', this.sizeForm.name);
            axios({
                method: 'post',
                url: serverUrl.setHostName,
                data: formData
            }).then(res => {
                if (res.data.code == 200) {
                    this.$message({
                        message: res.data.msg,
                        type: 'success'
                    });
                } else {
                    this.$message({
                        message: res.data.msg,
                        type: 'warning'
                    });
                }
            });
        },
        // 获取名称和时间
        getInfo() {
            getHostInfoApi()
                .then(res => {
                    this.sizeForm.name = res.data.data.hostname;
                    this.sizeForm.date1 = res.data.data.time;
                })
                .catch(err => {
                    this.$message.error(res.data.msg);
                });
        },
        handleagain() {
            this.$confirm('此操作将重新启动系统, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(() => {
                    RestartComputer()
                        .then(res => {
                            console.log(res,'重启启动的接口');
                            this.$message.success(res.data.msg);
                        })
                        .catch(err => {
                            this.$message.error(res.data.msg);
                        });
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消'
                    });
                });
        },
        changeResetService(val){
             console.log("val",val)
             this.resetServiceData = val
        },
        handresetService(){
            console.log("this.resetServiceData",this.resetServiceData)
               if(this.resetServiceData ==''){
                    this.$message({
                        type: 'info',
                        message: '请选择指定服务'
                    });
               }else{
                this.$confirm('此操作将重新启动指定, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
                })
                .then(() => {          
                        this.changeNew(this.resetServiceData)
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消重启指定服务'
                    });
                });
               }
            
        },
        changeNew(val){
             getResetService({ServiceName:val}).then(res => {
                            this.$message.success(res.data.msg);
                        })
                        .catch(() => {
                            this.$message.error(res.data.msg);
                        });
        },
        // 备份服务器事件
        backupHandle() {
            // var ipUrl = window.location.origin
            var ipUrl = '172.16.1.168'
            this.$confirm('此操作将备份操作, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(() => {
                this.createMqtt()
                this.loadingR = this.$loading({
                              lock: true,
                              text: 'Loading',
                              spinner: 'el-icon-loading',
                              background: 'rgba(0, 0, 0, 0.7)'
                            });
                            var url = ipUrl + '/api/ConfigBackup?'+'uuid='+this.guidid
                     // console.log(url, '地址');
                     const a = document.createElement('a')
                     a.href = url
                     a.download = '_home_nvidia_Desktop_zy_backup.zip' // 下载后文件名
                     a.style.display = 'none'
                     document.body.appendChild(a)
                     a.click() // 点击下载
                     document.body.removeChild(a)
                    //  this.$message({
                    //         type: 'success',
                    //         message: '请等待下载' 
                    //     });
                    //  this.loadingR.close()
                      setTimeout(() => {
                           this.loadingR.close()
                            }, 5000);    
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消备份'
                    });
                });
        },
        // 还原服务器设置
        restoreHandle() {
            this.$confirm('此操作将还原服务器设置, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(() => {
                    // 出厂默认设置
                    // configRestore().then(res => {

                    //     console.log(res.data, '还原服务器设置');
                    //     this.$message({
                    //         type: 'success',
                    //         message: '还原' 
                    //     });


                    // }).catch(() => {
                    //     this.$message.error(res.data.msg);
                    // })
                     let formData = new FormData();//new一个formData事件
                        formData.append("path", this.figRestoreData); 
                    var url = serverUrl.postConfigRestore;
                            axios.post(url,formData,{
                            headers: {
                                "Content-Type": "multipart/form-data;",
                            }
                                }).then(res => {
                                     if (res.data.code!=200) {
                                          this.$message({
                                           message: res.data.msg,
                                           type: 'warning'
                                         });
                                    }else{ 
                                        this.$message({
                                        message: res.data.msg,
                                        type: 'success'
                                        });
                                     }
                                })

                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消备份'
                    });
                });
        },
        //更新软件按钮
        changeUpdata(){
              this.$confirm('此操作将更新软件版本, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(() => {
                      //创建链接，接收
                    this.uuid = this.guidNew()
                    var topicSendNew = ['Version-' + this.uuid];
                    window.PubScribe(topicSendNew,1, this.realInfo); 
                    // this.loadingNUp = this.$loading({
                    //   lock: true,
                    //    text: newNumber +'/'+arrFile.length,
                    //   target: '.el-dialog',
                    //   spinner: 'el-icon-loading',
                    //   background: 'rgba(0, 0, 0, 0.7)'
                    // });
                    this.loadingNUp = this.$loading({
                      lock: true,
                       text: 'loading',
                      target: '.el-dialog',
                      spinner: 'el-icon-loading',
                      background: 'rgba(0, 0, 0, 0.7)'
                    });
                     let formData = new FormData();//new一个formData事件
                        formData.append("path", this.pathData); 
                        formData.append("uuid", this.uuid); 
                        var urlNew = serverUrl.postConfigUpdate;
                                 axios.post(urlNew,formData,{
                            headers: {
                                "Content-Type": "multipart/form-data;",
                            }
                                }).then(res => {
                                     if (res.data.code!=200) {
                                    
                                          this.$message({
                                           message: res.data.msg,
                                           type: 'warning'
                                         });
                                          this.loadingNUp.close()
                                    }else{ 
                                       
                                        this.$message({
                                        message: res.data.msg,
                                        type: 'success'
                                        });
                                        this.loadingNUp.close()
                                     }
                                })

                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消更新'
                    });
                });
        },
        // 重置默认值
        handleReset() {
            this.$confirm('此操作将重置默认值, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                    // 出厂默认设置
                    initData().then(res => {
                        console.log(res.data,'出厂默认设置');
                        this.$message({
                            type: 'success',
                            message: '重置' + res.data.msg
                        });
                    }).catch(()=>{
                        this.$message.error(res.data.msg);
                    })

                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消重置'
                    });
                });
        },
        handleRemove(file, fileList) {
            console.log(file, fileList);
        },
        handlePreview(file) {
            console.log(file);
        },
        handleExceed(files, fileList) {
            this.$message.warning(
                `当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`
            );
        },
        beforeRemove(file, fileList) {
            return this.$confirm(`确定移除 ${file.name}？`);
        },
        handleChangeVideoNumber(value) {
            this.videoNumber = value;
            let formData = new FormData();
            formData.append('F_NB_SHIPJRSX', value);
            formData.append('F_NB_TIAOZSZ', this.FPS);
            formData.append('F_VC_ID', this.id);
            axios({
                method: 'post',
                url: serverUrl.postSetQuanjsz,
                data: formData
            }).then(res => {
                console.log('res', res);
                if (res.data.code == 200) {
                    this.$message({
                        message: res.data.msg,
                        type: 'success'
                    });
                } else {
                    this.$message({
                        message: res.data.msg,
                        type: 'warning'
                    });
                }
            });
        },
        handleChange(value) {
            console.log('FPS', value);
            this.FPS = value;
            const formData = new URLSearchParams();
            // let formData = new FormData();
            
             formData.append('timeSwitch', this.timeSwitch);
            formData.append('VideoAccessLimit', this.videoNumber);
            formData.append('SkipFrame', value);
            formData.append('GlobalSettingId', this.id);
            formData(formData).then(res => {
                this.$message({
                    message: res.data.msg,
                    type: 'success'
                });
            });
        },
        //获取全局设置数据
        getShipjkDatalist() {
            getQuanjszData().then(res => {
                console.log('res11111', res);
                if (res.data.code == 200) {
                   
                    this.timeSwitch = this.changeN(res.data.data.timeSwitch);
                    this.videoNumber = res.data.data.videoAccessLimit;
                    this.FPS = res.data.data.skipFrame;
                    this.id = res.data.data.globalSettingId;
                }
            });
        },
        //点击确认
        commit() {
            const formData = new URLSearchParams();
            // let formData = new FormData();
             formData.append('timeSwitch', this.timeSwitch);
            formData.append('VideoAccessLimit', this.videoNumber);
            formData.append('SkipFrame', this.FPS);
            formData.append('GlobalSettingId', this.id);
            setQuanjsz(formData).then(res => {
                this.$message({
                    message: res.data.msg,
                    type: 'success'
                });
            });
        }
    }
};
</script>

<style>
.test-div i {
    font-size: 25px;
}
</style>
<style lang="scss" scoped>
/deep/ .el-form-item__label {
    text-align: left;
    font-size: 15px;
}

/deep/ .el-form-item {
    margin-bottom: 15px;
}

.container {
    width: 100%;
    height: 100%;
     overflow-y: scroll;
    &::-webkit-scrollbar {
        width: 0;
    }
    p {
        width: 95%;
        font-size: 25px;
        text-align: left;
        border-bottom: 1px solid black;
        margin-bottom: 20px;
    }
}
</style>
