<template>
  <div class='auto' id="adjustTree">
    <h3 class="txtline">&nbsp;&nbsp;需要移动的资源【{{data.name}}】</h3>
    <h3 class="txtline">&nbsp;&nbsp;移动到某个资源下面【{{$refs.tree.selected.data.name}}】</h3>
    <tree :model="model" v-ref:tree id='defaultTreeOpen'>
      <span partial>{{row.data.name}}
      </span>
    </tree>
    <button @click="save()" class="btn btn-success">
      <span class="glyphicon glyphicon-floppy-disk"></span>保存
    </button>
    <button @click='$back()' class="btn btn-default">
      <span class=" glyphicon glyphicon-log-out"></span>返回
    </button>
  </div>
</template>

<script>
import * as Util from "../Util"
import co from 'co'
let gen = function * (self) {
  //self.model = yield self.$post('rs/search', {source: `tool.getChildren($${self.data.id}$)`, userid: self.userid},{resolveMsg: null, rejectMsg: null})
  if(self.data.resourcetype == 'user'){
    self.model = yield self.$http.post('rs/search',
      {source: `tool.getFullTree(this.getRights().where(row.getType() != $user$))`,
        userid: self.$login.f.id}
    ).data
  }else{
    self.model = yield self.$http.post('rs/search',
      {source: `tool.getFullTree(this.getRights())`,
        userid: self.$login.f.id}
    ).data
  }
}
export default {
  title: "调整资源位置",
  props: [
    'data' // 要调整的资源
  ],
  data () {
    return {
      model: Util.f,  // 资源树的内容
    }
  },
  ready() {
    let g = gen(this)
    co(g)
  },
  methods: {
    refersh(){
      this.$parent.$parent.$parent.$parent.flush(1)
    },
    // 保存调整结果
    save () {
      console.log("进入保存函数")
      this.$showMessage('确定要将【'+this.data.name+'】移动到'+this.$refs.tree.selected.data.name+'的子', ['confirm', 'cancel']).then((res) => {
        if (res === 'confirm') {
          this.$http.post(`rs/data/move/${this.$refs.tree.selected.id}/${this.data.id}`,{}).then((msg)=>{
            this.refersh()
            this.$back('refresh')
          })
        }
      })
    }
  }
}
</script>
<style>
  .all-checked {
    vertical-align: text-top;
    margin-left: 10px !important;
  }
  td > .glyphicon {
    cursor: pointer;
  }
  th > input[type="checkbox"], td > input[type="checkbox"] {
    cursor: pointer;
  }
  #adjustTree div{
    margin-left: 0px;
    color: #000;
  }
  #adjustTree span {
    color: #000;
  }
  #adjustTree .list-group-item {
    background-color: #fff;
    border: none;
  }
  #adjustTree .list-group-item.active,
  #adjustTree  .list-group-item.active:hover,
  #adjustTree  .list-group-item.active:focus {
    background-color: #fff;
  }

  #adjustTree .active {
    background-color: #5cb85c !important;
  }
</style>
