<template>
  <div class="flex-row">
    <div class="basic-main">
      <div :class="showData ? 'top' : 'auto'">
        <guan-xian-supervisory-select v-ref:query :show-data="showData"></guan-xian-supervisory-select>
      </div>
      <div v-if="showtotal" style="height: 89%">
        <div class="col-sm-2" style="margin-top: 20px">
          <guan-xian-supervisoryh-cart :selectdata="selectdata"></guan-xian-supervisoryh-cart>
        </div>
        <tabset v-ref:tabs :close="false" :active.sync="active">
          <tab :header='selectdata.defname'>
            <supervisory-service-control v-ref:service :selectdata="selectdata"></supervisory-service-control>
          </tab>
          <tab header='附件'>
            <apply-upload :blodid="selectdata.f_process_id"
                          :isupload = "true"
                          :isdelete="true"
                          :isusetype="true"
                          :isremark = "true"
                          :takeimg="true"
                          :issearch="true"
                          :defname="selectdata.defname">
            </apply-upload>
          </tab>
        </tabset>
      </div>
    </div>
  </div>
</template>
<script>
import Vue from 'vue'
import {HttpResetClass} from 'vue-client'
export default {
  title: '管线建设流程',
  data () {
    return {
      showData: true,     // 控制列表数据
      showtotal: false, // 详情显示
      selectdata: {},
      xmlname: '',        // 配置文件名
      active: 0        // 配置文件名
    }
  },
  ready () {
    console.log('=============用户信息=================')
    console.log(this.$login.f)
    console.log(this.$login.r)
  },
  methods: {
    // 获取页面配置json文件
    async loadName () {
      let http = new HttpResetClass()
      let data = {
        workname: this.selectdata.processname
      }
      let res=await http.load('POST', 'rs/logic/ApplyGetConfigs', {
        data
      }, {resolveMsg: null, rejectMsg: null})

      Vue.prototype.$workflow_vue = res.data
    }
  },
  events: {
    'onMessage' (data) {
      console.log('接收消息')
      console.log(data)
      if (data.type === 'apply-task') {
        this.$refs.query.$refs.cp.$refs.cri.search()
      }
    },
    // 刷新控制层
    async 'breakControl' (servicedata) {

      if (servicedata.id) {
        let data = {
          condition: `u.id = ${servicedata.id}`,
          data: {
            userid: this.$login.f.id,
            f_filiale: "榆林."+this.$login.f.orgs
          }
        }
        let res = await this.$resetpost(
          'rs/sql/getGuanXianliuCheng',
          {data: data},
          {resolveMsg: null, rejectMsg: '数据更新失败，请手查询更新！！！'}
        )

        this.selectdata = res.data[0]
      } else {
        this.selectdata = servicedata
      }

      this.showtotal = false
      this.$nextTick(() => {
        this.showtotal = true
      })

    },
    // 初始化
    async 'apply' (val) {
      this.showtotal = false
      this.selectdata = val
      // 次方法必须同步执行，否则后续会出问题
      // 获取页面json配置文件
      await this.loadName()
      // 显示详细
      this.showtotal = true
      // 关闭列表数据
      this.showData = false
      // 关闭分页
      this.$refs.query.$refs.cp.pager = false
    },
    'search' () {
      this.selectdata = {}
      // 关闭详细
      this.showtotal = false
      // 显示列表数据
      this.showData = true
      // 显示分页
      this.$refs.query.$refs.cp.pager = true
      // 调用查询
      this.$refs.query.$refs.cp.$refs.cri.search()
    },
    'loadPage' () {
      this.selectdata = {}
      // 关闭详细
      this.showtotal = false
      // 显示列表数据
      this.showData = true
      // 显示分页
      this.$refs.query.$refs.cp.pager = true
      // 调用查询
      this.$refs.query.$refs.cp.loadPage(this.$refs.query.model.pageIndex)
    }
  },
  watch: {
  }
}
</script>
