<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>
      </div>
      <div class="list-group list_area table_sy" isedit="true" style="overflow: auto">
        <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>
    <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>
    <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-floppy-disk"></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>
  </div>

</template>

<script>

import { HttpResetClass } from 'vue-client'
import Vue from "vue";

export default {
  title: '配置修改',
  ready() {

  },
  data() {
    return {

      curorgid: [this.$login.f.orgid],
      seaching:false,
      modelshow:false,
      modelshow1:false,
      modelshow2:false,
      upmodel:{},
      f_dir:'',
      model:{},
      modeldata:{},
      rightshow:false,
      rightrow:{},
      rightdata:{},
      safeArray: [],
      updateArray:[],
      safeConfig: {
        "民用配置项": {},
        "非民用配置项": {}
      }
    }
  },
  methods: {
    async getorg(val) {
      let res = await Vue.resetget(`/phone/rs/vue`, {data: {}}, {resolveMsg: null, rejectMsg: null})
      Vue.config = res.data
      this.safeConfig["民用配置项"]=Object.assign({},res.data.safecheck.DevicesConfig)
      this.safeConfig["非民用配置项"]=Object.assign({},res.data.safecheck.DevicesSetConfig)
      this.initArray()
    },
    isdelete(item){

      if (item.safename=='燃气表'&&item.safeindex){
        return false
      }
      if (item.safeindex!='1'){
        return true
      }
    },
    isadd(item){
      if (item.safeindex=='4'){
        return false
      }if (item.safeindex=='3'){
        return item.safetype=='selector'||item.safetype=='radio'
      }
      return true
    },
    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('api/af-safecheck/logic/saveVueConfig', {data:{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
    },
    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('api/af-safecheck/logic/saveVueConfig', {data:{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
      })


    },
    cancel1() {
      this.model={}
      this.modeldata={}
      this.modelshow1 = false
    },
    addsafeConfig(item) {
      ////tag

      this.modeldata = item
      this.modelshow = true
    },
    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('api/af-safecheck/logic/saveVueConfig', {data:{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
    },
    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('api/af-safecheck/logic/saveVueConfig', {data:{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
      })
    },
    cancel2(){
      this.modelshow2=false
    },
    updatesafeConfigName(item){

      this.$set('model.name',item.safename)
       this.modeldata=Object.assign({},item)
      this.modelshow1=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
    },
    closeright() {
      this.rightshow = 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

    },
    getrightdataname(name) {
      ////tag
      ////tag
      if (name == 'checkmust') {
        return '是否必填'
      }
      if (name == 'isdefault') {
        return '是否默认'
      }
      if (name == 'index') {
        return '配置下标'
      }
      if (name == 'items') {
        return '配置数量'
      }
      if (name == 'items') {
        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 '选项名称'
      }
    },
    getrightdatavalue(key, value) {
      if (key == 'items') {
        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>
