<template>
  <div id="unit" class="flex-row">
<!--    <work-busy :is-busy="seaching"></work-busy>-->
    <div class="flex basic-main" style="flex:1">
      <div novalidate="" class="row form-horizontal select-overspread container-fluid auto" partial="">
        <div novalidate="" class="form-inline auto" partial="">
          <div class="form-group col-sm-2">
            <label class="font_normal_body">组织机构</label>
            <res-select
              :initresid='curorgid'
              @res-select="getorg"
              is-mul="false"
              restype='organization'
            >
            </res-select>
          </div>
          <div class="form-group col-sm-2">
            <label class="font_normal_body">配置名称</label>
            <v-select
              v-model="dispositioName"
              :options='disposition'
              @change="dispselect"
               close-on-select
              :value-single="true"
              clear-button>
            ></v-select>
          </div>
        </div>
      </div>
      <div class="list-group list_area table_sy" isedit="true" style="overflow: auto" v-if="firstShow">
        <table class="table table-bordered">
          <thead a-partial="head" class="text-left">
          <tr>
            <th>安检配置项</th>
          </tr>
          </thead>
          <tbody>
          <tr a-partial="body" :id="'vc-datagrid-tree-grid-'+$index" v-for="item in safeArray">
            <td><a herf="#" @click="selectedshow($index)" class="list-group-item expand-transition"
                   style="border: none;background-color: transparent;cursor: pointer" :id="'vc-tree-tree-grid-'+$index">
              <span style="color: black" v-for="n in item.safeindex-1 ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
              <span style="color: black" :id="'vc-tree-tree-grid-'+$index">
                <span style="color: black" v-if="item.safeshow&&(item.safetype=='selector'||item.safetype=='radio'||item.safetype=='')"
                      @click.stop="pushArray(item,$index)" class="glyphicon glyphicon-minus-sign"
                      style="font-size: 18px;">
                   </span>
                <span style="color: black" v-if="!item.safeshow&&(item.safetype=='selector'||item.safetype=='radio'||item.safetype=='')"
                      @click.stop="pushArray(item,$index)" class="glyphicon glyphicon-plus-sign"
                      style="font-size: 18px;">
                   </span>
                <span style="color: black" v-if="item.safetype!='selector'&&item.safetype!='radio'&&item.safetype!=''" style="font-size: 18px;">
                   &nbsp;&nbsp;&nbsp;</span>
              </span> <span style="color: black" partial="">  <span>{{ item.safename }}</span>
                 <span style="color: black" v-if="item.safevalue!=0">【{{ item.safevalue }}】</span>
              <span style="color: black" v-show="item.selectedshow">
                        <button  v-show="isadd(item)" class="button_spacing button_export" @click.stop="addsafeConfig(item)">添加</button><!--v-if-->
                        <button  v-show="isdelete(item)" class="button_spacing button_export" @click.stop="updatesafeConfigName(item)">修改名称</button><!--v-if-->
                        <button  v-show="isdelete(item)" class="button_spacing button_export" @click.stop="updatesafeConfig(item)">修改属性</button><!--v-if-->

                        <button  v-show="isdelete(item)" class="button_spacing button_export" @click.stop="deletesafeConfig(item)">删除</button><!--v-if-->
                      </span>
            </span> </a></td>
          </tr>
          </tbody>
          <tbody>
          <tr a-partial="foot"></tr>
          </tbody>
        </table>
      </div>
      <div class="list-group list_area table_sy" isedit="true" style="overflow: auto" v-if="!firstShow">
        <table class="table table-bordered">
          <thead a-partial="head" class="text-left">
          <tr>
            <th>工单配置项</th>
          </tr>
          </thead>
          <tbody>
          <tr a-partial="body" :id="'vc-datagrid-tree-grid-'+$index" v-for="item in telArray">
            <td>
              <a herf="#" @click="selecttelshow($index)" class="list-group-item expand-transition" style="border: none;background-color: transparent;cursor: pointer" :id="'vc-tree-tree-grid-'+$index">
              <span style="color: black" v-for="n in item.telindex-1 ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
              <span style="color: black" :id="'vc-tree-tree-grid-'+$index">
                <span style="color: black" v-if="item.telshow&&(item.teltype=='selector'||item.teltype=='radio'||item.teltype=='')"
                      @click.stop="tlepushArray(item,$index)" class="glyphicon glyphicon-minus-sign"
                      style="font-size: 18px;">
                   </span>
                <span style="color: black" v-if="!item.telshow&&(item.teltype=='selector'||item.teltype=='radio'||item.teltype=='')"
                      @click.stop="tlepushArray(item,$index)" class="glyphicon glyphicon-plus-sign"
                      style="font-size: 18px;">
                   </span>
                <span style="color: black" v-if="item.telshow!='selector'&&item.teltype!='radio'&&item.teltype!=''" style="font-size: 18px;">
                   &nbsp;&nbsp;&nbsp;</span>
              </span> <span style="color: black" partial=""><span>{{ item.telname }}</span>
                 <span style="color: black" v-if="item.telvalue!=0">【{{ item.telvalue }}】</span>
              <span style="color: black" v-show="item.selectedshow">
                        <button  v-show="isteladd(item)" class="button_spacing button_export" @click.stop="addsafeConfig(item)">添加</button><!--v-if-->
                        <button  v-show="isteldelete(item)" class="button_spacing button_export" @click.stop="updatetelConfigName(item)">修改名称</button><!--v-if-->
                        <button  v-show="isteldelete(item)" class="button_spacing button_export" @click.stop="updatetelConfig(item)">修改属性</button><!--v-if-->
                        <button  v-show="isteldelete(item)" class="button_spacing button_export" @click.stop="deletetelConfig(item)">删除</button><!--v-if-->
                      </span>
            </span> </a></td>
          </tr>
          </tbody>
          <tbody>
          <tr a-partial="foot"></tr>
          </tbody>
        </table>
      </div>
    </div>
    <div class="binary-right" style="width: 40%" v-if="rightshow"> <!--fragment-start-->
      <div class="auto select-overspread" style="overflow-y: hidden"> <!--fragment-start-->
        <ul class="nav nav-tabs"><p class="bg-info text-center" style="padding: 8px">功能信息</p> <!--v-if--> <h3
          class="txtline">上一级【{{ getlastname() }}】</h3><!--v-if--> </ul>
        <div class="form-horizontal" style="margin-top:20px;flex: 1">
          <div class="row">
            <div class="col-sm-6" v-for="(key,value) in rightdata">
              <label class="font_normal_body">{{getrightdataname(key)}}</label>
              <input type="text" style="width:60%" class="input_search full-with"  :placeholder="getrightdatavalue(key,value)"
                                                                                      disabled=""></div>
          </div>

          <button @click="closeright()" class="btn button_clear col-sm-1 col-sm-offset-1" style="width: 70px"><span
            class="glyphicon glyphicon-log-out" style="color: black"></span>返回
          </button>
        </div><!--fragment-end--><!--vue-validator--> </div><!--v-component--><!--fragment-end--><!--v-if--> </div>
    <div class="binary-right" style="width: 40%" v-if="righttelshow">
      <div class="auto select-overspread" style="overflow-y: hidden">
        <ul class="nav nav-tabs"><p class="bg-info text-center" style="padding: 8px">功能信息</p> <h3
          class="txtline">上一级【{{ getlastname() }}】</h3></ul>
        <div class="form-horizontal" style="margin-top:20px;flex: 1">
          <div class="row">
            <div class="col-sm-6" v-for="(key,value) in rightteldata">
              <label class="font_normal_body">{{getrightdataname(key)}}</label>
              <input type="text" style="width:60%" class="input_search full-with"  :placeholder="getrightdatavalue(key,value)"
                     disabled=""></div>
          </div>
          <button @click="closeright()" class="btn button_clear col-sm-1 col-sm-offset-1" style="width: 70px"><span
            class="glyphicon glyphicon-log-out" style="color: black"></span>返回
          </button>
        </div> </div> </div>
    <modal :show.sync="modelshow"  v-ref:modal large backdrop="false">
      <header slot="modal-header" class="modal-header">
        <button type="button" class="close" @click="cancel"><span style="color: black">&times;</span></button>
      </header>
      <article slot="modal-body" class="modal-body">
        <div class="auto select-overspread" style="overflow-y: hidden">
          <validator name='v'>
            <ul class="nav nav-tabs">
              <p class="bg-info text-center" style="padding: 8px;">配置添加</p>
            </ul>
            <div class="form-horizontal" style="margin-top:20px;flex: 1;">
              <div class="row">
                <div class="col-sm-6">
                  <label class="font_normal_body" >配置名称</label>
                  <input type="text"
                         v-model="model.name" style="width:60%"
                         class="input_search full-with"  placeholder="配置名称">
                </div>
              </div>


              <button @click="confirm()"  class="btn button_search col-sm-1 col-sm-offset-5" style="width: 70px" :disabled="!$v.valid">
                <span style="color: black" class="glyphicon glyphicon-floppy-disk"></span>保存
              </button>
              <button @click='cancel()'  class="btn button_clear col-sm-1 col-sm-offset-1" style="width: 70px">
                <span style="color: black" class=" glyphicon glyphicon-log-out"></span>返回
              </button>
            </div>
          </validator>
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
      </footer>
    </modal>
    <modal :show.sync="modelshow1"  v-ref:modal large backdrop="false">
      <header slot="modal-header" class="modal-header">
        <button type="button" class="close" @click="cancel1"><span style="color: black">&times;</span></button>
      </header>
      <article slot="modal-body" class="modal-body">
        <div class="auto select-overspread" style="overflow-y: hidden">
          <validator name='v'>
            <ul class="nav nav-tabs">
              <p class="bg-info text-center" style="padding: 8px;">名称修改</p>
            </ul>
            <div class="form-horizontal" style="margin-top:20px;flex: 1;">
              <div class="row">
                <div class="col-sm-6">
                  <label class="font_normal_body" >配置名称</label>
                  <input type="text"
                         v-model="model.name" style="width:60%"
                         class="input_search full-with"  placeholder="配置名称">
                </div>
              </div>


              <button @click="confirm1()"  class="btn button_search col-sm-1 col-sm-offset-5" style="width: 70px" :disabled="!$v.valid">
                <span style="color: black" class="glyphicon glyphicon-floppy-disk"></span>保存
              </button>
              <button @click='cancel1()'  class="btn button_clear col-sm-1 col-sm-offset-1" style="width: 70px">
                <span style="color: black" class=" glyphicon glyphicon-log-out"></span>返回
              </button>
            </div>
          </validator>
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
      </footer>
    </modal>
    <modal :show.sync="modelshow2"  v-ref:modal large backdrop="false">
      <header slot="modal-header" class="modal-header">
        <button type="button" class="close" @click="cancel2"><span style="color: black">&times;</span></button>
      </header>
      <article slot="modal-body" class="modal-body">
        <div class="auto select-overspread" >
          <validator name='v'>
            <ul class="nav nav-tabs">
              <p class="bg-info text-center" style="padding: 8px;">属性修改</p>
            </ul>
            <div class="form-horizontal" style="margin-top:20px;margin-bottom:20px;flex: 1;">
              <div class="row">
                <div class="col-sm-6" v-for="objs in updateArray">
                  <label class="font_normal_body" >{{objs.label}}</label>
                  <input v-if="objs.type=='input'" type="text"
                         v-model="objs.value" style="width:60%"
                         class="input_search full-with"  :placeholder="objs.label">
                  <v-select v-if="objs.type=='selector'"
                            :value.sync="objs.value"
                            v-model="objs.value" style="width:60%"
                            close-on-select
                            :value-single="true"
                            :options="objs.options"
                            class=" full-with"  :placeholder="objs.label"></v-select>
                </div>
              </div>


              <button @click="confirm2()"  class="btn button_search col-sm-1 col-sm-offset-5" style="width: 70px" :disabled="!$v.valid">
                <span style="color: black" class="glyphicon glyphicon-floppy-disk"></span>保存
              </button>
              <button @click='cancel2()'  class="btn button_clear col-sm-1 col-sm-offset-1" style="width: 70px">
                <span style="color: black" class=" glyphicon glyphicon-log-out"></span>返回
              </button>
            </div>
          </validator>
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
      </footer>
    </modal>
    <modal :show.sync="modeltelshow"  v-ref:modal large backdrop="false">
      <header slot="modal-header" class="modal-header">
        <button type="button" class="close" @click="cancel"><span style="color: black">&times;</span></button>
      </header>
      <article slot="modal-body" class="modal-body">
        <div class="auto select-overspread" style="overflow-y: hidden">
          <validator name='v'>
            <ul class="nav nav-tabs">
              <p class="bg-info text-center" style="padding: 8px;">配置添加</p>
            </ul>
            <div class="form-horizontal" style="margin-top:20px;margin-bottom: 100px;maflex: 1;">
              <div class="row">
                <div class="col-sm-6">
                  <label class="font_normal_body" >配置名称</label>
                  <input type="text"
                         v-model="model.name" style="width:60%"
                         class="input_search full-with"  placeholder="配置名称">
                </div>
                <div class="col-sm-6" v-if="modeldata.telindex===2">
                  <label class="font_normal_body" >配置类型</label>
                  <v-select
                    v-model="model.type"
                    :value.sync="model.type"
                    :options='distype'
                    close-on-select
                    :value-single="true"
                    clear-button>
                    ></v-select>
                </div>
                <div class="col-sm-6" v-if="modeldata.telindex===2">
                  <label class="font_normal_body" >配置数量</label>
                  <input type="text"
                         v-model="model.num" style="width:60%"
                         class="input_search full-with"  placeholder="配置数量">
              </div>
              <div  class="row"></div>
              <button @click="telconfirm()"  class="btn button_search col-sm-1 col-sm-offset-5" style="width: 70px" :disabled="!$v.valid">
                <span style="color: black" class="glyphicon glyphicon-floppy-disk"></span>保存
              </button>
              <button @click='cancel()'  class="btn button_clear col-sm-1 col-sm-offset-1" style="width: 70px">
                <span style="color: black" class=" glyphicon glyphicon-log-out"></span>返回
              </button>
            </div>
            </div>
          </validator>
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
      </footer>
    </modal>
    <modal :show.sync="modeltelshow1"  v-ref:modal large backdrop="false">
      <header slot="modal-header" class="modal-header">
        <button type="button" class="close" @click="cancel1"><span style="color: black">&times;</span></button>
      </header>
      <article slot="modal-body" class="modal-body">
        <div class="auto select-overspread" style="overflow-y: hidden">
          <validator name='v'>
            <ul class="nav nav-tabs">
              <p class="bg-info text-center" style="padding: 8px;">名称修改</p>
            </ul>
            <div class="form-horizontal" style="margin-top:20px;flex: 1;">
              <div class="row">
                <div class="col-sm-6">
                  <label class="font_normal_body" >配置名称</label>
                  <input type="text"
                         v-model="model.name" style="width:60%"
                         class="input_search full-with"  placeholder="配置名称">
                </div>
              </div>
              <button @click="contelfirm1()"  class="btn button_search col-sm-1 col-sm-offset-5" style="width: 70px" :disabled="!$v.valid">
                <span style="color: black" class="glyphicon glyphicon-floppy-disk"></span>保存
              </button>
              <button @click='cancel1()'  class="btn button_clear col-sm-1 col-sm-offset-1" style="width: 70px">
                <span style="color: black" class=" glyphicon glyphicon-log-out"></span>返回
              </button>
            </div>
          </validator>
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
      </footer>
    </modal>
    <modal :show.sync="modeltelshow2"  v-ref:modal large backdrop="false">
      <header slot="modal-header" class="modal-header">
        <button type="button" class="close" @click="cancel2"><span style="color: black">&times;</span></button>
      </header>
      <article slot="modal-body" class="modal-body">
        <div class="auto select-overspread" >
          <validator name='v'>
            <ul class="nav nav-tabs">
              <p class="bg-info text-center" style="padding: 8px;">属性修改</p>
            </ul>
            <div class="form-horizontal" style="margin-top:20px;margin-bottom:20px;flex: 1;">
              <div class="row">
                <div class="col-sm-6" v-for="objs in updateArray">
                  <label class="font_normal_body" >{{objs.label}}</label>
                  <input v-if="objs.type=='input'" type="text"
                         v-model="objs.value" style="width:60%"
                         class="input_search full-with"  :placeholder="objs.label">
                  <v-select v-if="objs.type=='selector'"
                            :value.sync="objs.value"
                            v-model="objs.value" style="width:60%"
                            close-on-select
                            :value-single="true"
                            :options="objs.options"
                            class=" full-with"  :placeholder="objs.label"></v-select>
                </div>
              </div>
              <button @click="telconfirm2()"  class="btn button_search col-sm-1 col-sm-offset-5" style="width: 70px" :disabled="!$v.valid">
                <span style="color: black" class="glyphicon glyphicon-floppy-disk"></span>保存
              </button>
              <button @click='cancel2()'  class="btn button_clear col-sm-1 col-sm-offset-1" style="width: 70px">
                <span style="color: black" class=" glyphicon glyphicon-log-out"></span>返回
              </button>
            </div>
          </validator>
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
      </footer>
    </modal>
  </div>
</template>

<script>
import { HttpResetClass } from 'vue-client'
export default {
  title: '配置修改',
  ready() {

  },
  data() {
    return {
      firstShow: true,
      dispositioName:'',
      curorgid: [this.$login.f.orgid],
      seaching:false,
      modelshow:false,
      modelshow1:false,
      modelshow2:false,
      modeltelshow:false,
      modeltelshow1:false,
      modeltelshow2:false,
      upmodel:{},
      f_dir:'',
      model:{},
      modeldata:{},
      rightshow:false,
      righttelshow:false,
      rightrow:{},
      rightelrow:{},
      rightdata:{},
      rightteldata:{},
      telArray: [],
      safeArray: [],
      updateArray:[],
      distype:[{label:"输入框",value:"string"},{label:"选择框",value:"selector"}],
      disposition:this.$appdata.getParam('配置名称'),
      safeConfig: {
        "民用配置项": {},
        "非民用配置项": {}
      },
      telConfig: {
        "民用配置项": {},
        "非民用配置项": {}
      }
    }
  },
  methods: {
 dispselect(val){
   if(val=='安检配置项' || val==""){
     this.firstShow=true
    }else{
     this.firstShow=false
    }
    },
    getorg(val) {
      this.f_filialeid = val[0]
     if (val[0]){
       new HttpResetClass().load('post','rs/sql/tel_singleTable_OrderBy',{data: {
           items: 'f_dir',
           tablename: 't_organization',
           condition: `id  = '${val[0]}'`,
           orderitem: 'id'
         }}).then(res=>{
         if (!res.data[0].f_dir){
           this.$showMessage("该公司无组织目录，无法获取配置文件，请联系管理员确认")
         }else{
           this.f_dir=res.data[0].f_dir
           try {
             new HttpResetClass().load('GET',`/safecheck/rs/vue/DevicesConfig.json?folderName=phonevues&orgDir=${res.data[0].f_dir}`, {},{resolveMsg: '获取居民配置项成功！', rejectMsg: '获取居民配置项出错！'}).then(res=>{
               //tag
               this.safeConfig["民用配置项"]=Object.assign({},res.data)
             })
             new HttpResetClass().load('GET',`/safecheck/rs/vue/DevicesSetConfig.json?folderName=phonevues&orgDir=${res.data[0].f_dir}`, {},{resolveMsg: '获取非居民配置项成功！', rejectMsg: '获取非居民配置项出错！'}).then(res=>{
               //tag
               this.safeConfig["非民用配置项"]=Object.assign({},res.data)
             }).then(res=> {
               this.safeArray = []
               this.initArray()
               this.model = {}
               this.modeldata = {}
             })
             new HttpResetClass().load('GET',`/telephone/rs/vue/SubstitConfigBusiness.json?folderName=phonevues&orgDir=${res.data[0].f_dir}`, {},{resolveMsg: '获取居民配置项成功！', rejectMsg: '获取居民配置项出错！'}).then(res=>{
               this.telConfig["非民用配置项"]=Object.assign({},res.data)
             })
             new HttpResetClass().load('GET',`/telephone/rs/vue/SubstitConfigCivil.json?folderName=phonevues&orgDir=${res.data[0].f_dir}`, {},{resolveMsg: '获取非居民配置项成功！', rejectMsg: '获取非居民配置项出错！'}).then(res=>{
               this.telConfig["民用配置项"]=Object.assign({},res.data)
             }).then(res=> {
               this.telArray = []
               this.initTelArray()
             })
           }catch (e) {
              this.$showMessage("获取配置文件失败"+e)
           }
         }
       })
     }
    },
    isteldelete(item){

      if (item.telindex!=1){
        return true
      }
    },
    isdelete(item){
      if (item.safename=='燃气表'&&item.safeindex){
        return false
      }
      if (item.safeindex!='1'){
        return true
      }
    },
    isteladd(item){
      if (item.telindex===4){
        return false
      }if (item.telindex===3){
        return item.teltype==='selector'||item.teltype==='radio'
      }
      return true
    },
    isadd(item){
      if (item.safeindex=='4' ){
        return false
      }if (item.safeindex=='3'){
        return item.safetype=='selector'||item.safetype=='radio'
      }
      return true
    },
    telconfirm(){
      if (this.modeldata.telindex==1){
        for(var i=0;i<this.telConfig[this.modeldata.telname].data.length;i++){
          if (this.telConfig[this.modeldata.telname].data[i].f_type===this.model.name){
            this.$showMessage('已有配置名'+this.model.name+',修改失败')
            return
          }
        }
      }
      if (this.modeldata.telindex==2){
        for(var i=0;i<this.telConfig[this.modeldata.last].data.length;i++){
          for (var j = 0; j <this.telConfig[this.modeldata.last].data[i].details.length; j++) {
            if (this.telConfig[this.modeldata.last].data[i].details[j].f_project===this.model.name){
              this.$showMessage('已有配置名'+this.model.name+',修改失败')
              return
            }
          }
        }
      }
      if (this.modeldata.telindex==3){
        for(var i=0;i<this.telConfig[this.modeldata.lastlast].data.length;i++){
          for (var j = 0; j <this.telConfig[this.modeldata.lastlast].data[i].details.length; j++) {
            if(!!this.telConfig[this.modeldata.lastlast].data[i].details[j].options){
              for (var k = 0; k < this.telConfig[this.modeldata.lastlast].data[i].details[j].options.length; k++) {
                if (this.telConfig[this.modeldata.lastlast].data[i].details[j].options[k].data===this.model.name){
                  this.$showMessage('已有配置名'+this.model.name+',修改失败')
                  return
                }
              }
            }
          }
        }
      }
      if (this.modeldata.telindex==1){
        this.telConfig[this.modeldata.telname].data.push({
          f_type:this.model.name,
          details:[]
        })
      }
      if (this.modeldata.telindex==2){
        for(var i=0;i<this.telConfig[this.modeldata.last].data.length;i++){
          if(this.telConfig[this.modeldata.last].data[i].f_type==this.modeldata.telname){
            if(this.model.type==""){
              this.$showMessage("请输入类型")
              return
            }
            if(this.model.type=="string"){
              this.telConfig[this.modeldata.last].data[i].details.push({
                f_project:this.model.name,
                level:"",
                type:this.model.type
              })
            }
            if(this.model.type=="selector"){
              let options=[]
              if(this.model.num>0){
                for (let j = 0; j <this.model.num; j++) {
                  options.push({
                    data:"请修改"+j,
                    isdefect:false,
                    f_status:false,
                    isdefault: false
                  })
                }
              }else{
                this.$showMessage("请输入选项数量")
                return
              }
              this.telConfig[this.modeldata.last].data[i].details.push({
                f_project:this.model.name,
                level:"",
                type:this.model.type,
                options:options
              })
            }
          }
        }
      }
      if (this.modeldata.telindex==3){
        for(var i=0;i<this.telConfig[this.modeldata.lastlast].data.length;i++){
          for (var j = 0; j <this.telConfig[this.modeldata.lastlast].data[i].details.length; j++) {
            if(!!this.telConfig[this.modeldata.lastlast].data[i].details[j].options){
              if(this.telConfig[this.modeldata.lastlast].data[i].details[j].f_project===this.modeldata.telname){
                this.telConfig[this.modeldata.lastlast].data[i].details[j].options.push({
                  data:this.model.name,
                  f_status:false,
                  isdefect:false,
                  isdefault:false
                })
              }

            }
          }
        }
      }
      let path
      let value
      if (this.modeldata.last=='民用配置项'||this.modeldata.lastlast=='民用配置项'||this.modeldata.lastlastlast=='民用配置项'){
        path= this.f_dir + `/phonevues/SubstitConfigCivil.json`
        value=this.telConfig["民用配置项"]
      }else{
        path= this.f_dir + `/phonevues/SubstitConfigBusiness.json`
        value=this.telConfig["非民用配置项"]
      }
      /*发送求情*/
      this.$resetpost('rs/vue/telSaveConfig', {path: path, data: JSON.stringify(value)} ).then(res=>{
        this.$showMessage("修改成功")
        /*刷新页面*/
        this.telArray = []
        this.initTelArray()
        this.cancel1()
      })
    },
    confirm() {
      ////tag
      if (this.modeldata.safeindex==1){
        //tag
        for(let name in this.safeConfig[this.modeldata.safename]){
          if(typeof name=='function'){
            continue
          }
          if (name==this.model.name){
            this.$showMessage('已有配置名'+name+',添加失败')
            return
          }
            }
      }
      if (this.modeldata.safeindex==2){
        for(let name in this.safeConfig[this.modeldata.safelast][this.modeldata.safename].items){
          if(typeof name=='function'){
            continue
          }
          if (name==this.model.name){
            this.$showMessage('已有配置名'+name+',添加失败')
            return
          }
        }
        //tag
      }
      if (this.modeldata.safeindex==3){
        for (let i = 0; i < this.safeConfig[this.modeldata.safelastlast][this.modeldata.safelast].items[this.modeldata.safename].options.length; i++) {
          if (this.safeConfig[this.modeldata.safelastlast][this.modeldata.safelast].items[this.modeldata.safename].options[i].data==this.model.name){
            this.$showMessage('已有配置名'+this.model.name+',添加失败')
            return
          }
        }
        //tag
      }
      ////tag
      ////tag)
      if (this.modeldata.safeindex=='1'){
        let index
        ////tag
        ////tag
        if (Object.keys(this.safeConfig[this.modeldata.safename]).length==0){
          index=0
        }else{
        for (let obj in this.safeConfig[this.modeldata.safename]) {
          if(typeof obj=='function'){
            continue
          }
          ////tag
          ////tag
          ////tag
          index = this.safeConfig[this.modeldata.safename][obj].index
        }
        }
        ////tag
        this.safeConfig[this.modeldata.safename][this.model.name] = {
          checkmust: true,
          index: index + 1,
          items:{}
        }
        ////tag)
      }
      if (this.modeldata.safeindex=='2'){
        let index
        ////tag
        ////tag
        if (Object.keys(this.safeConfig[this.modeldata.safelast][this.modeldata.safename].items).length==0){
          index=0
        }else{
        for (let obj in this.safeConfig[this.modeldata.safelast][this.modeldata.safename].items) {
          if(typeof obj=='function'){
            continue
          }
          ////tag
          ////tag
          ////tag
          index = this.safeConfig[this.modeldata.safelast][this.modeldata.safename].items[obj].index
        }
        }

        ////tag
        this.safeConfig[this.modeldata.safelast][this.modeldata.safename].items[this.model.name] = {
          index: index + 1,
          multiple: false,
          options:[],
          isshow:true,
          checkmust:false,
          type: "selector"
        }
        ////tag)
      }
      if (this.modeldata.safeindex=='3'){
        let index
        ////tag
        ////tag
        ////tag
        this.safeConfig[this.modeldata.safelastlast][this.modeldata.safelast].items[this.modeldata.safename].options.push({
          data:this.model.name,
          isdefect:false,
          level:'A',
          isdefault:false
        })

        ////tag)
      }
      let path
      let value
      if (this.modeldata.safelast=='民用配置项'||this.modeldata.safelastlast=='民用配置项'||this.modeldata.safelastlastlast=='民用配置项'){
        path= this.f_dir + `/phonevues/DevicesConfig.json`
        value=this.safeConfig["民用配置项"]
      }else{
        path= this.f_dir + `/phonevues/DevicesSetConfig.json`
        value=this.safeConfig["非民用配置项"]
      }

      this.$resetpost('rs/vue/safeSaveConfig', {path: path, data: JSON.stringify(value)} ).then(res=> {

        this.$showMessage("保存成功")
        this.safeArray = []
        this.initArray()
        this.model = {}
        this.modeldata = {}
        this.rightshow = false
        this.modelshow = false
      })

    },
    cancel() {
      this.model={}
      this.modeldata={}
      this.modelshow = false
      this.modeltelshow = false
    },
    confirm1() {
      if (this.modeldata.safeindex==2){
        //tag
        for(let name in this.safeConfig[this.modeldata.safelast]){
          if(typeof name=='function'){
            continue
          }
          if (name==this.model.name){
            this.$showMessage('已有配置名'+name+',修改失败')
            return
          }
        }
      }
      if (this.modeldata.safeindex==3){
        for(let name in this.safeConfig[this.modeldata.safelastlast][this.modeldata.safelast].items){
          if(typeof name=='function'){
            continue
          }
          if (name==this.model.name){
            this.$showMessage('已有配置名'+name+',修改失败')
            return
          }
        }
        //tag
      }
      if (this.modeldata.safeindex==4){
        for (let i = 0; i < this.safeConfig[this.modeldata.safelastlastlast][this.modeldata.safelastlast].items[this.modeldata.safelast].options.length; i++) {
          if (this.safeConfig[this.modeldata.safelastlastlast][this.modeldata.safelastlast].items[this.modeldata.safelast].options[i].data==this.model.name){
            this.$showMessage('已有配置名'+this.model.name+',修改失败')
            return
          }
        }
        //tag
      }
      this.seaching=true
      ////tag
      ////tag)

      if (this.modeldata.safeindex=='2'){
        this.safeConfig[this.modeldata.safelast][this.model.name]=Object.assign({},this.safeConfig[this.modeldata.safelast][this.modeldata.safename])
        delete this.safeConfig[this.modeldata.safelast][this.modeldata.safename]
      }
      if (this.modeldata.safeindex=='3'){
        this.safeConfig[this.modeldata.safelastlast][this.modeldata.safelast].items[this.model.name]=Object.assign({},this.safeConfig[this.modeldata.safelastlast][this.modeldata.safelast].items[this.modeldata.safename])
        delete this.safeConfig[this.modeldata.safelastlast][this.modeldata.safelast].items[this.modeldata.safename]
      }
      if (this.modeldata.safeindex=='4'){
        ////tag
        ////tag)
        for (let i = 0; i < this.safeConfig[this.modeldata.safelastlastlast][this.modeldata.safelastlast].items[this.modeldata.safelast].options.length; i++) {
          if(this.safeConfig[this.modeldata.safelastlastlast][this.modeldata.safelastlast].items[this.modeldata.safelast].options[i].data==this.modeldata.safename){
            this.safeConfig[this.modeldata.safelastlastlast][this.modeldata.safelastlast].items[this.modeldata.safelast].options[i].data=this.model.name
          }
        }
      }
      let path
      let value
      if (this.modeldata.safelast=='民用配置项'||this.modeldata.safelastlast=='民用配置项'||this.modeldata.safelastlastlast=='民用配置项'){
        path= this.f_dir + `/phonevues/DevicesConfig.json`
        value=this.safeConfig["民用配置项"]
      }else{
        path= this.f_dir + `/phonevues/DevicesSetConfig.json`
        value=this.safeConfig["非民用配置项"]
      }

      this.$resetpost('rs/vue/safeSaveConfig', {path: path, data: JSON.stringify(value)} ).then(res=>{
        this.$showMessage("修改成功")
        this.safeArray = []
        this.initArray()
        this.model={}
        this.modeldata={}
        this.rightshow=false
        this.modelshow1 = false
        this.seaching=false
      })


    },
    contelfirm1() {
      if (this.modeldata.telindex===2){
        for( var i=0;i<this.telConfig[this.modeldata.last].data.length;i++){
          if (this.telConfig[this.modeldata.last].data[i].f_type===this.model.name){
            this.$showMessage('已有配置名'+this.model.name+',修改失败')
            return
          }
        }
      }
      if (this.modeldata.telindex===3){
        for(var i=0;i<this.telConfig[this.modeldata.lastlast].data.length;i++){
          for (let j = 0; j <this.telConfig[this.modeldata.lastlast].data[i].details.length; j++) {
            if (this.telConfig[this.modeldata.lastlast].data[i].details[j].f_project===this.model.name){
              this.$showMessage('已有配置名'+this.model.name+',修改失败')
              return
            }
          }
        }
      }
      if (this.modeldata.telindex===4){
        for(var i=0;i<this.telConfig[this.modeldata.lastlastlast].data.length;i++){
          for (var j = 0; j <this.telConfig[this.modeldata.lastlastlast].data[i].details.length; j++) {
            if(!!this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options){
              for (var k = 0; k < this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options.length; k++) {
                if (this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options[k].data===this.model.name){
                  this.$showMessage('已有配置名'+this.model.name+',修改失败')
                  return
                }
              }
            }
          }
        }
      }
      this.seaching=true
      if (this.modeldata.telindex==2){
        for( var i=0;i<this.telConfig[this.modeldata.last].data.length;i++){
          if (this.telConfig[this.modeldata.last].data[i].f_type===this.modeldata.telname){
            this.telConfig[this.modeldata.last].data[i].f_type=this.model.name
          }
        }
      }

      if (this.modeldata.telindex==3){
        for(var i=0;i<this.telConfig[this.modeldata.lastlast].data.length;i++){
          for (let j = 0; j <this.telConfig[this.modeldata.lastlast].data[i].details.length; j++) {
            if (this.telConfig[this.modeldata.lastlast].data[i].details[j].f_project===this.modeldata.telname){
              this.telConfig[this.modeldata.lastlast].data[i].details[j].f_project=this.model.name
            }
          }
        }
      }
      if (this.modeldata.telindex==4){
        for(var i=0;i<this.telConfig[this.modeldata.lastlastlast].data.length;i++){
          for (var j = 0; j <this.telConfig[this.modeldata.lastlastlast].data[i].details.length; j++) {
            if(!!this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options){
              for (var k = 0; k < this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options.length; k++) {
                if (this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options[k].data===this.modeldata.telname){
                  this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options[k].data=this.model.name
                }
              }
            }
          }
        }
      }
      let path
      let value
      if (this.modeldata.last=='民用配置项'||this.modeldata.lastlast=='民用配置项'||this.modeldata.lastlastlast=='民用配置项'){
        path= this.f_dir + `/phonevues/SubstitConfigCivil.json`
        value=this.telConfig["民用配置项"]
      }else{
        path= this.f_dir + `/phonevues/SubstitConfigBusiness.json`
        value=this.telConfig["非民用配置项"]
      }
      /*发送求情*/
      this.$resetpost('rs/vue/telSaveConfig', {path: path, data: JSON.stringify(value)} ).then(res=>{
        this.$showMessage("修改成功")
       /*刷新页面*/
        this.telArray = []
        this.initTelArray()
        this.cancel1()
      })
    },
    cancel1() {
      this.model={}
      this.modeldata={}
      this.modelshow1 = false
      this.modeltelshow1 = false
    },
    addsafeConfig(item) {
      this.modeldata = item
      this.modeltelshow= true
    },
    deletetelConfig(item){
      this.$showMessage('删除后无法恢复，确认删除吗？',['confirm','cancel']).then(res=>{
        if (res=='confirm'){
          if (item.telindex==2){
            for(var i=0;i<this.telConfig[item.last].data.length;i++){
              if(this.telConfig[item.last].data[i].f_type===item.telname){
                this.telConfig[item.last].data.splice(i, 1);
                i--;

              }
            }
          }else if (item.telindex==3){
            for(var i=0;i<this.telConfig[item.lastlast].data.length;i++){
              for (var j = 0; j <this.telConfig[item.lastlast].data[i].details.length; j++) {
                console.log(this.telConfig[item.lastlast].data[i].details[j].f_project)
                if (this.telConfig[item.lastlast].data[i].details[j].f_project===item.telname){
                //移除这个对象
                  // 移除这个对象
                  this.telConfig[item.lastlast].data[i].details.splice(j, 1);
                  // 移除后需要调整 j 的值，因为数组长度减少了
                  j--;
                }
              }
            }
          }else if (item.telindex==4){
            for(var i=0;i<this.telConfig[item.lastlastlast].data.length;i++){
              for (var j = 0; j <this.telConfig[item.lastlastlast].data[i].details.length; j++) {
                if(!!this.telConfig[item.lastlastlast].data[i].details[j].options){
                  for(var k = 0; k < this.telConfig[item.lastlastlast].data[i].details[j].options.length; k++){
                    if(this.telConfig[item.lastlastlast].data[i].details[j].options[k].data===item.telname &&this.telConfig[item.lastlastlast].data[i].details[j].f_project===item.last){
                    //除这个对象
                      this.telConfig[item.lastlastlast].data[i].details[j].options.splice(k, 1);
                      // 移除后需要调整 k 的值，因为数组长度减少了
                      k--;

                    }
                  }
                }
              }
            }
          }
          let path
          let value
          if (this.modeldata.last==='民用配置项'||this.modeldata.lastlast==='民用配置项'||this.modeldata.lastlastlast==='民用配置项'){
            path= this.f_dir + `/phonevues/SubstitConfigCivil.json`
            value=this.telConfig["民用配置项"]
          }else{
            path= this.f_dir + `/phonevues/SubstitConfigBusiness.json`
            value=this.telConfig["非民用配置项"]
          }
          /*发送求情*/
          this.$resetpost('rs/vue/telSaveConfig', {path: path, data: JSON.stringify(value)} ).then(res=>{
            this.$showMessage("修改成功")
            this.telArray = []
            this.initTelArray()
            this.cancel2()
          })
        }
      })
    },
    deletesafeConfig(item){
      this.$showMessage('删除后无法恢复，确认删除吗？',['confirm','cancel']).then(res=>{
        if (res=='confirm'){
          this.seaching=true
          if (item.safeindex=='2'){
            ////tag
            if (item.safename=='燃气表'){
              this.$showMessage("燃气表不允许删除！！！")
              return
            }else{
              ////tag
              delete this.safeConfig[item.safelast][item.safename]

              for(let name in this.safeConfig[item.safelast]){
                if(typeof name=='function'){
                  continue
                }
                if (this.safeConfig[item.safelast][name].index>item.safesort){
                  this.safeConfig[item.safelast][name].index=this.safeConfig[item.safelast][name].index-1
                }
              }
            }
          }else if (item.safeindex=='3'){
            delete this.safeConfig[item.safelastlast][item.safelast].items[item.safename]
            for(let name in this.safeConfig[item.safelastlast][item.safelast].items){
              if(typeof name=='function'){
                continue
              }
              if (this.safeConfig[item.safelastlast][item.safelast].items[name].index>item.safesort){
                this.safeConfig[item.safelastlast][item.safelast].items[name].index=this.safeConfig[item.safelastlast][item.safelast].items[name].index-1
              }
            }
          }else if (item.safeindex=='4'){
            for (let i = 0; i < this.safeConfig[item.safelastlastlast][item.safelastlast].items[item.safelast].options.length; i++) {
              if (this.safeConfig[item.safelastlastlast][item.safelastlast].items[item.safelast].options[i].data==item.safename){
                this.safeConfig[item.safelastlastlast][item.safelastlast].items[item.safelast].options.splice(i,1)
              }
            }
          }
          let path
          let value
          if (item.safelast=='民用配置项'||item.safelastlast=='民用配置项'||item.safelastlastlast=='民用配置项'){
            path= this.f_dir + `/phonevues/DevicesConfig.json`
            value=this.safeConfig["民用配置项"]
          }else{
            path= this.f_dir + `/phonevues/DevicesSetConfig.json`
            value=this.safeConfig["非民用配置项"]
          }

          this.$resetpost('rs/vue/safeSaveConfig', {path: path, data: JSON.stringify(value)} ).then(res=> {

            this.$showMessage("删除成功")
            this.safeArray = []
            this.initArray()
            this.model = {}
            this.modeldata = {}
            this.rightshow = false
            this.modelshow2 = false
            // this.sleep(2000);
            this.seaching = false
          })
        }
      })

    },
    updatesafeConfig(item){
      this.modeldata=item
      //tag
      let array=[]
      if (item.safeindex=='2') {
        //tag)
        let aa = {"checkmust": false, "index": 1}
        if (this.safeConfig[item.safelast][item.safename].checkmust) {
          array.push({
            label: '是否必填',
            value: true,
            type: 'selector',
            name:'checkmust',
            options: [{label: '是', value: true}, {label: '否', value: false}]
          })
        } else {
          array.push({
            label: '是否必填',
            value: false,
            type: 'selector',
            name:'checkmust',
            options: [{label: '是', value: true}, {label: '否', value: false}]
          })
        }
      }
      if (item.safeindex=='3'){
        let aa={"index":1,"multiple":false,"isshow":true,"checkmust":false,"type":"selector"}
          for (let key in this.safeConfig[item.safelastlast][item.safelast].items[item.safename]){
            if(typeof key=='function'){
              continue
            }
            if (key=='index'){

            }else if(key=='multiple'){
              array.push({
                label: '是否多选',
                value: this.safeConfig[item.safelastlast][item.safelast].items[item.safename][key],
                name:key,
                type: 'selector',
                options: [{label: '是', value: true}, {label: '否', value: false}]
              })
            }else if(key=='options'){

            }else if(key=='isshow'){
              array.push({
                label: '是否展示',
                value: this.safeConfig[item.safelastlast][item.safelast].items[item.safename][key],
                name:key,
                type: 'selector',
                options: [{label: '是', value: true}, {label: '否', value: false}]
              })
            }else if(key=='checkmust'){
              array.push({
                label: '是否必填',
                value: this.safeConfig[item.safelastlast][item.safelast].items[item.safename][key],
                name:key,
                type: 'selector',
                options: [{label: '是', value: true}, {label: '否', value: false}]
              })
            }else if(key=='type'){
              array.push({
                label: '配置类型',
                value: this.safeConfig[item.safelastlast][item.safelast].items[item.safename][key],
                name:key,
                type: 'selector',
                options: [{label: '输入框', value: 'string'}, {label: '选择框', value: 'selector'}, {label: '勾选框', value: 'radio'},{label: '图片框', value: 'picture'}]
              })
            }
          }
        //tag)
      }
      if (item.safeindex=='4'){
        let aa={"data":"333333333","isdefect":"否","level":"A","isdefault":"否"}
        for (let i = 0; i < this.safeConfig[item.safelastlastlast][item.safelastlast].items[item.safelast].options.length; i++) {
          if (this.safeConfig[item.safelastlastlast][item.safelastlast].items[item.safelast].options[i].data==item.safename){
            //tag)
            for(let key in this.safeConfig[item.safelastlastlast][item.safelastlast].items[item.safelast].options[i]){
              if(typeof key=='function'){
                continue
              }
               if(key=='data'){

              }else if(key=='isdefect'){
               array.push({
                 label: '是否隐患',
                 value:  this.safeConfig[item.safelastlastlast][item.safelastlast].items[item.safelast].options[i][key],
                 name:key,
                 type: 'selector',
                 options: [{label: '是', value: true}, {label: '否', value: false}]
               })
             }else if(key=='isdefault'){
               array.push({
                 label: '是否默认',
                 value:  this.safeConfig[item.safelastlastlast][item.safelastlast].items[item.safelast].options[i][key],
                 name:key,
                 type: 'selector',
                 options: [{label: '是否默认', value: ''},{label: '是', value: true}, {label: '否', value: false}]
               })

             }else if(key=='level'){
               array.push({
                 label: '隐患级别',
                 value:  this.safeConfig[item.safelastlastlast][item.safelastlast].items[item.safelast].options[i][key],
                 name:key,
                 type: 'input',
               })

             }
            }
          }
        }
      }
      //tag
     //tag
      this.updateArray=Object.assign([],array)
      this.modelshow2=true
    },
    updatetelConfig(item){
      this.modeldata=item
      let array=[]
      if (item.telindex==2) {
      }
      if (item.telindex==3){
        for(var i=0;i<this.telConfig[this.modeldata.lastlast].data.length;i++){
          for (var j = 0; j <this.telConfig[this.modeldata.lastlast].data[i].details.length; j++) {
            if (this.telConfig[this.modeldata.lastlast].data[i].details[j].f_project===this.modeldata.telname){
              for(let key in this.telConfig[this.modeldata.lastlast].data[i].details[j]){
                if(typeof key=='function'){
                  continue
                }
                if(key==='level'){
                  array.push({
                    label: '隐患级别',
                    value:  this.telConfig[this.modeldata.lastlast].data[i].details[j].level,
                    name:key,
                    type: 'input',
                  })
                }
              }
            }
          }
        }
       }
      if (item.telindex===4){
        for(var i=0;i<this.telConfig[this.modeldata.lastlastlast].data.length;i++){
          for (var j = 0; j <this.telConfig[this.modeldata.lastlastlast].data[i].details.length; j++) {
            if(!!this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options){
              for(var k = 0; k < this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options.length; k++){
                if(this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options[k].data===this.modeldata.telname &&this.telConfig[this.modeldata.lastlastlast].data[i].details[j].f_project===this.modeldata.last){
                for(var  key in this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options[k]){
                    if(typeof key=='function'){
                      continue
                    }
                    if(key==='isdefect'){
                      array.push({
                        label: '隐患',
                        value:  this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options[k].isdefect,
                        name:key,
                        type: 'input',
                      })
                    }
                    if(key==='isdefault'){
                      array.push({
                        label: '是否默认',
                        value:  this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options[k].isdefault,
                        name:key,
                        type: 'input',
                      })
                    }
                    if(key==='f_status'){
                      array.push({
                        label: '是否异常',
                        value:  this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options[k].f_status,
                        name:key,
                        type: 'input',
                      })
                    }
                  }
                }
              }
            }
          }
        }
      }
      this.updateArray=Object.assign([],array)
      this.modeltelshow2=true
    },
    confirm2(){
      this.seaching=true
      if (this.modeldata.safeindex=='2'){
        for (let i = 0; i < this.updateArray.length; i++) {
         this.safeConfig[this.modeldata.safelast][this.modeldata.safename][this.updateArray[i].name]=this.updateArray[i].value
        }
      }
      if (this.modeldata.safeindex=='3'){
        for (let i = 0; i < this.updateArray.length; i++) {
        this.safeConfig[this.modeldata.safelastlast][this.modeldata.safelast].items[this.modeldata.safename][this.updateArray[i].name]=this.updateArray[i].value
          if (this.updateArray[i].name=='type'&&this.updateArray[i].value!='selector'&&this.updateArray[i].value!='radio'){

            if (this.safeConfig[this.modeldata.safelastlast][this.modeldata.safelast].items[this.modeldata.safename].hasOwnProperty('options')){
              delete this.safeConfig[this.modeldata.safelastlast][this.modeldata.safelast].items[this.modeldata.safename].options
            }
          }
          if (this.updateArray[i].name=='type'&&(this.updateArray[i].value=='selector'||this.updateArray[i].value!='radio')){
         if (!this.safeConfig[this.modeldata.safelastlast][this.modeldata.safelast].items[this.modeldata.safename].hasOwnProperty('options')){
              this.safeConfig[this.modeldata.safelastlast][this.modeldata.safelast].items[this.modeldata.safename].options=[]
            }
          }
        }

      }
      if (this.modeldata.safeindex=='4'){

        for (let i = 0; i < this.safeConfig[this.modeldata.safelastlastlast][this.modeldata.safelastlast].items[this.modeldata.safelast].options.length; i++) {
          if(this.safeConfig[this.modeldata.safelastlastlast][this.modeldata.safelastlast].items[this.modeldata.safelast].options[i].data==this.modeldata.safename){
            for (let j = 0; j < this.updateArray.length; j++) {


              this.safeConfig[this.modeldata.safelastlastlast][this.modeldata.safelastlast].items[this.modeldata.safelast].options[i][this.updateArray[j].name]=this.updateArray[j].value
            }
          }
        }
      }
      let path
      let value
      if (this.modeldata.safelast=='民用配置项'||this.modeldata.safelastlast=='民用配置项'||this.modeldata.safelastlastlast=='民用配置项'){
        path= this.f_dir + `/phonevues/DevicesConfig.json`
        value=this.safeConfig["民用配置项"]
      }else{
        path= this.f_dir + `/phonevues/DevicesSetConfig.json`
        value=this.safeConfig["非民用配置项"]
      }

      this.$resetpost('rs/vue/safeSaveConfig', {path: path, data: JSON.stringify(value)} ).then(res=> {

        this.$showMessage("修改成功")
        this.safeArray = []
        this.initArray()
        this.model = {}
        this.modeldata = {}
        this.rightshow = false
        this.modelshow2 = false
        this.seaching = false
      })
    },
    telconfirm2(){
      this.seaching=true
      if (this.modeldata.telindex==3) {
        for (var i = 0; i< this.telConfig[this.modeldata.lastlast].data.length; i++) {
          for (var j = 0; j < this.telConfig[this.modeldata.lastlast].data[i].details.length; j++) {
            if (this.telConfig[this.modeldata.lastlast].data[i].details[j].f_project === this.modeldata.telname) {
              for (let key in this.telConfig[this.modeldata.lastlast].data[i].details[j]) {
                for (let K = 0;  K< this.updateArray.length; K++) {
                  if(this.updateArray[K].name===key){
                    this.telConfig[this.modeldata.lastlast].data[i].details[j][key]=this.updateArray[K].value
                  }
                }
              }
            }
          }
        }
      }
      if (this.modeldata.telindex==4){
        for(var i=0;i<this.telConfig[this.modeldata.lastlastlast].data.length;i++){
          for (var j = 0; j <this.telConfig[this.modeldata.lastlastlast].data[i].details.length; j++) {
            if(!!this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options){
              for(var k = 0; k < this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options.length; k++){
                if(this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options[k].data===this.modeldata.telname &&this.telConfig[this.modeldata.lastlastlast].data[i].details[j].f_project===this.modeldata.last){
                  for(var  key in this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options[k]){
                    for (var l = 0;  l< this.updateArray.length; l++) {
                      if(this.updateArray[l].name===key){
                        this.telConfig[this.modeldata.lastlastlast].data[i].details[j].options[k][key]=this.updateArray[l].value
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
      let path
      let value
      if (this.modeldata.last==='民用配置项'||this.modeldata.lastlast==='民用配置项'||this.modeldata.lastlastlast==='民用配置项'){
        path= this.f_dir + `/phonevues/SubstitConfigCivil.json`
        value=this.telConfig["民用配置项"]
      }else{
        path= this.f_dir + `/phonevues/SubstitConfigBusiness.json`
        value=this.telConfig["非民用配置项"]
      }
      /*发送求情*/
      this.$resetpost('rs/vue/telSaveConfig', {path: path, data: JSON.stringify(value)} ).then(res=>{
        this.$showMessage("修改成功")
        this.telArray = []
        this.initTelArray()
        this.cancel2()
      })
    },
    cancel2(){
      this.modelshow2=false
      this.modeltelshow2=false
    },
    updatesafeConfigName(item){

      this.$set('model.name',item.safename)
       this.modeldata=Object.assign({},item)
      this.modelshow1=true
    },
    updatetelConfigName(item){
      this.$set('model.name',item.telname)
      this.modeldata=Object.assign({},item)
      this.modeltelshow1=true
    },
    initArray() {
      for (let bigsafe in this.safeConfig) {
        if(typeof bigsafe=='function'){
          continue
        }
        ////tag
        ////tag)
        this.safeArray.push({
          selectedshow: false,
          safetype: '',
          safeshow: false,
          safename: bigsafe,
          safevalue: this.safeConfig[bigsafe] ? Object.keys(this.safeConfig[bigsafe]).length : 0,
          safeindex: 1
        })
      }
      this.seaching=false
    },
    initTelArray(){
     //延时0.5s，后执行
      setTimeout(()=>{
        for (let bigsafe in this.telConfig) {
          if (typeof bigsafe == 'function') {
            continue
          }
          this.telArray.push({
            selectedshow: false,
            teltype:'',
            telshow: false,
            telname: bigsafe,
            telvalue: this.telConfig[bigsafe] ? this.telConfig[bigsafe].data.length : 0,
            telindex: 1,
            type:bigsafe
          })
        }
      },1000)
    },
    tlepushArray(val, arrayindex) {
      let spliceindex = arrayindex + 1
      if(this.telArray[arrayindex].telshow == false){
        this.telArray[arrayindex].telshow = true
        if(val.telindex==1){
          let linshiarray = []
          for (let two in this.telConfig[val.telname].data){
            linshiarray.push({
              selectedshow:false,
              telsort:two+1 ,
              teltype:'',
              type: val.type,
              telshow: false,
              telname: this.telConfig[val.telname].data[two].f_type,
              telvalue: this.telConfig[val.telname].data[two].details.length,
              telindex: 2,
              last:val.telname  //fei
            })
          }
          linshiarray=this.jsonSort(linshiarray, "telsort",true)
          for (let i = 0; i < linshiarray.length; i++) {
            this.telArray.splice(spliceindex, 0,linshiarray[i])
          }
        }
       if(val.telindex==2){
         let linshiarray = [];
         for (var  i = 0; i < this.telConfig[val.type].data.length; i++) {
           if (this.telConfig[val.type].data[i].f_type === val.telname) {
             for (var j = 0; j < this.telConfig[val.type].data[i].details.length; j++) {
               linshiarray.push({
                 type:val.type,
                 selectedshow: false,
                 telsort: j+1,
                 teltype: this.telConfig[val.type].data[i].details[j].type,
                 telshow: false,
                 telname: this.telConfig[val.type].data[i].details[j].f_project,
                 telvalue: this.telConfig[val.type].data[i].details[j].options?this.telConfig[val.type].data[i].details[j].options.length:0,
                 telindex: 3,
                 last: val.telname,
                 lastlast:val.last,
               });
             }
           }
         }
         linshiarray=this.jsonSort(linshiarray, "telsort",true)
         for (let i = 0; i < linshiarray.length; i++) {
           this.telArray.splice(spliceindex, 0,linshiarray[i])
         }
      }
       if(val.telindex==3){
         let linshiarray = [];
         for (var  m = 0; m < this.telConfig[val.type].data.length; m++) {
           for (var n = 0; n < this.telConfig[val.type].data[m].details.length; n++){
           if(this.telConfig[val.type].data[m].details[n].f_project==val.telname){
             for (var p = 0; p < this.telConfig[val.type].data[m].details[n].options.length; p++){
               linshiarray.push({
                 telindex: 4,
                 type:val.type,
                 selectedshow: false,
                 telsort: p+1,
                 teltype: this.telConfig[val.type].data[m].details[n].options[p].type,
                 telshow: false,
                 telname: this.telConfig[val.type].data[m].details[n].options[p].data,
                 telvalue: this.telConfig[val.type].data[m].details[n].options[p].options?this.telConfig[val.type].data[m].details[n].options[p].options.length:0,
                 last:val.telname,
                 lastlast:val.last,
                 lastlastlast:val.lastlast

               })
             }
           }
           }
         }
         linshiarray=this.jsonSort(linshiarray, "telsort",true)
         for (let i = 0; i < linshiarray.length; i++) {
           this.telArray.splice(spliceindex, 0,linshiarray[i])
         }
       }
      }else if(this.telArray[arrayindex].telshow ===true){
        this.telArray[arrayindex].telshow = false
        for (let i = 0; i < this.telArray.length; i++) {
          if (this.telArray[i].last === this.telArray[arrayindex].telname
            || this.telArray[i].lastlast === this.telArray[arrayindex].telname
            || this.telArray[i].lastlastlast === this.telArray[arrayindex].telname)  {
            if(this.telArray[arrayindex].type===this.telArray[i].type){
                //从数组中移除
              this.telArray.splice(i, 1);
              i--; // 由于删除了元素，索引需要减1
            }

          }
        }
      }
    },
    closeright() {
      this.rightshow = false
      this.righttelshow = false
    },
    getlastname() {
      if (this.rightrow.safelast) {
        return this.rightrow.safelast
      }
      return '无'
    },
    pushArray(val, arrayindex) {
      ////tag
      ////tag)
      ////tag)
      if (this.safeArray[arrayindex].safeshow == false) {
        let spliceindex = arrayindex + 1
        this.safeArray[arrayindex].safeshow = true
        if (val.safeindex == '1') {
          let linshiarray = []
          for (let two in this.safeConfig[val.safename]) {
            if(typeof two=='function'){
              continue
            }
            ////tag
            ////tag)

            linshiarray.push({
              selectedshow: false,
              safesort: this.safeConfig[val.safename][two].index,
              safetype: '',
              safeshow: false,
              safename: two,
              safevalue: this.safeConfig[val.safename][two].items ? Object.keys(this.safeConfig[val.safename][two].items).length : 0,
              safeindex: 2,
              safelast: val.safename
            })

          }
          linshiarray=this.jsonSort(linshiarray, "safesort",true)
          ////tag
          ////tag)
          for (let i = 0; i < linshiarray.length; i++) {
            this.safeArray.splice(spliceindex, 0,linshiarray[i])
          }
        }
        if (val.safeindex == '2') {
          let linshiarray = []
          let aa = {"safename": "燃气表", "safevalue": 3, "safeindex": 2, "safelast": "民用配置项"}
          for (let isthree in this.safeConfig[val.safelast][val.safename]) {
            if(typeof isthree=='function'){
              continue
            }
            if (isthree == 'items') {
              for (let three in this.safeConfig[val.safelast][val.safename].items) {
                if(typeof three=='function'){
                  continue
                }
                ////tag
                ////tag
                ////tag
                ////tag)
                ////tag)
                linshiarray.push({
                  safesort:this.safeConfig[val.safelast][val.safename].items[three].index,
                  selectedshow: false,
                  safetype: this.safeConfig[val.safelast][val.safename].items[three].type,
                  safeshow: false,
                  safename: three,
                  safevalue: this.safeConfig[val.safelast][val.safename].items[three].options ? Object.keys(this.safeConfig[val.safelast][val.safename].items[three].options).length : 0,
                  safeindex: 3,
                  safelast: val.safename,
                  safelastlast: val.safelast
                })
              }
              linshiarray=this.jsonSort(linshiarray, "safesort",true)
              ////tag
              ////tag)
              for (let i = 0; i < linshiarray.length; i++) {
                this.safeArray.splice(spliceindex, 0,linshiarray[i])
              }
            }
          }

        }
        if (val.safeindex == '3') {
          let linshiarray = []
          let aa = {
            "safename": "燃气表有无改装在卧室、卫生间、客厅",
            "safevalue": 4,
            "safeindex": 3,
            "safelast": "燃气表",
            "safelastlast": "民用配置项"
          }
          for (let isfour in this.safeConfig[val.safelastlast][val.safelast].items[val.safename]) {
            if(typeof isfour=='function'){
              continue
            }
            if (isfour == 'options') {
              for (let four in this.safeConfig[val.safelastlast][val.safelast].items[val.safename].options) {
                if(typeof four=='function'){
                  continue
                }
                ////tag
                ////tag
                ////tag)
                ////tag)
                ////tag)
                linshiarray.push({
                  safesort:four,
                  selectedshow: false,
                  safetype: 'no',
                  safeshow: false,
                  safename: this.safeConfig[val.safelastlast][val.safelast].items[val.safename].options[four].data,
                  safevalue: 0,
                  safeindex: 4,
                  safelast: val.safename,
                  safelastlast: val.safelast,
                  safelastlastlast: val.safelastlast,
                })
              }
              linshiarray=this.jsonSort(linshiarray, "safesort",true)
              ////tag
              ////tag)
              for (let i = 0; i < linshiarray.length; i++) {
                this.safeArray.splice(spliceindex, 0,linshiarray[i])
              }

            }
          }
        }
      } else {
        let deleteindex = {begin: 999999, end: 99999}
        this.safeArray[arrayindex].safeshow = false
        for (let i = 0; i < this.safeArray.length; i++) {
          if (this.safeArray[i].safelast == this.safeArray[arrayindex].safename
            || this.safeArray[i].safelastlast == this.safeArray[arrayindex].safename
            || this.safeArray[i].safelastlastlast == this.safeArray[arrayindex].safename) {
            if (deleteindex.begin == 999999) {
              deleteindex.begin = i
            } else {
              deleteindex.end = i
            }
          }
        }
        ////tag)
        this.safeArray.splice(deleteindex.begin, deleteindex.end + 1 - deleteindex.begin)

      }
      ////tag)
    },
    selectedshow(index) {
      this.rightdata={}
      ////tag
      for (let i = 0; i < this.safeArray.length; i++) {
        this.safeArray[i].selectedshow = false
      }
      this.safeArray[index].selectedshow = true
      this.rightrow = Object.assign({}, this.safeArray[index])
      //传入参数到右侧
      //开始取对应参数
      ////tag
      ////tag
      this.setRightRow(this.rightrow)

      this.rightshow = true

    },
    selecttelshow(index) {
      this.rightteldata={}
      for (let i = 0; i < this.telArray.length; i++) {
        this.telArray[i].selectedshow = false
      }
      this.telArray[index].selectedshow = true
      this.righttelrow = Object.assign({}, this.telArray[index])
      this.setRighttelRow(this.righttelrow)
      this.righttelshow = true
    },
    setRighttelRow(row) {
      if (row.lastlastlast) {
        for (var i = 0; i < this.telConfig[row.lastlastlast].data.length; i++) {
         if(this.telConfig[row.lastlastlast].data[i].f_type===row.lastlast){
         for (var j = 0; j < this.telConfig[row.lastlastlast].data[i].details.length; j++) {
           if (this.telConfig[row.lastlastlast].data[i].details[j].f_project === row.last) {
             if (this.telConfig[row.lastlastlast].data[i].details[j].options) {
               for (var k = 0; k < this.telConfig[row.lastlastlast].data[i].details[j].options.length; k++) {
                 if (this.telConfig[row.lastlastlast].data[i].details[j].options[k].data === row.telname) {
                   this.rightteldata = Object.assign({}, this.telConfig[row.lastlastlast].data[i].details[j].options[k])
                 }
               }
             }
           }
          }
         }
        }
      } else if (row.lastlast) {
        for (var i = 0; i < this.telConfig[row.lastlast].data.length; i++) {
          if(this.telConfig[row.lastlast].data[i].f_type===row.last){
            for (var j = 0; j < this.telConfig[row.lastlast].data[i].details.length; j++) {
              if (this.telConfig[row.lastlast].data[i].details[j].f_project === row.telname) {
                this.rightteldata = Object.assign({}, this.telConfig[row.lastlast].data[i].details[j])
              }
            }
          }
        }
      } else if (row.last) {
        for (var i = 0; i < this.telConfig[row.last].data.length; i++) {
          if(this.telConfig[row.last].data[i].f_type===row.telname
          ){
            this.rightteldata = Object.assign({}, this.telConfig[row.last].data[i])
          }
        }
      }
    },
    getrightdataname(name) {
      ////tag
      ////tag
      debugger
      if (name == 'checkmust') {
        return '是否必填'
      }
      if (name == 'isdefault') {
        return '是否默认'
      }
      if (name == 'index') {
        return '配置下标'
      }
      if (name == 'items') {
        return '配置数量'
      }
      if (name == 'items' ||name== 'details') {
        return '配置数量'
      }
      if (name == 'options') {
        return '选项数量'
      }
      if (name == 'type') {
        return '配置类型'
      }
      if (name == 'isdefect') {
        return '是否隐患'
      }
      if (name == 'isshow') {
        return '是否展示'
      }
      if (name == 'multiple') {
        return '是否多选'
      }
      if (name == 'level') {
        return '隐患级别'
      }
      if (name == 'data') {
        return '选项名称'
      }
      if (name == 'f_status') {
        return '是否异常'
      }
      if (name == 'f_project') {
        return '名称'
      }
      if (name == 'f_type') {
        return '名称'
      }
    },
    getrightdatavalue(key, value) {
      if (key == 'items' ||key == 'details'){
        return Object.keys(value).length
      }
      if (key == 'options') {
        return value.length
      }
      if (value == 'string') {
        return '文本框'
      }
      if (value == 'selector') {
        return '选择框'
      }
      if (value == 'picture') {
        return '照片框'
      }
      if (value == 'radio') {
        return '勾选框'
      }
      if (value === true) {
        return '是'
      }
      if (value === false) {
        return '否'
      }
      return value
    },
    setRightRow(row) {
      ////tag
      if (row.safelastlastlast) {
        ////tag
        ////tag)
        for (let i = 0; i < this.safeConfig[row.safelastlastlast][row.safelastlast].items[row.safelast].options.length; i++) {
          if (this.safeConfig[row.safelastlastlast][row.safelastlast].items[row.safelast].options[i].data == row.safename) {
            this.rightdata = Object.assign({}, this.safeConfig[row.safelastlastlast][row.safelastlast].items[row.safelast].options[i])
          }
        }
      } else if (row.safelastlast) {

        ////tag)
        this.rightdata = Object.assign(this.safeConfig[row.safelastlast][row.safelast].items[row.safename])
      } else if (row.safelast) {
        ////tag)
        this.rightdata = Object.assign(this.safeConfig[row.safelast][row.safename])
      }
    },
    getJsonLength(val) {
      return Object.keys(val).length
    },
    jsonSort(array, field, reverse) {
      ////tag
      //数组长度小于2 或 没有指定排序字段 或 不是json格式数据
      if (array.length < 2 || !field || typeof array[0] !== "object") return array;
      //数字类型排序
      if (typeof array[0][field] === "number") {
        array.sort(function (x, y) {
          return x[field] - y[field]
        });
      }
      //字符串类型排序
      if (typeof array[0][field] === "string") {
        array.sort(function (x, y) {
          return parseInt(x[field]) - parseInt(y[field])
        });
      }
      //倒序
      if (reverse) {
        array.reverse();
      }
      return array;
    },
    sleep(n) {
    var start = new Date().getTime();
  //  //tag;
    while (true) {
    if (new Date().getTime() - start > n) {
      break;
    }
  }
  // //tag.getTime());
}


  },
  events: {}
}
</script>
<style>
/*span {*/
/*  color: black;*/
/*}*/
</style>
