<template>
  <div>
    <basicDetails
        ref="details"
        :titleText="mainData.name"
        :oldFormPath="{edit:'HDrpManagement/workBillModule/components'}"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        turnPageId="20221031141102"
        idname="sa_workorder_templateid"
        ownertable="sa_workorder_template"
        :delApiId="20230207140803"
        tags=""
        :tabs="['工作明细','详细信息']"
        @pageChange="pageChange"
        @onEditSuccess="queryMainData($route.query.id)">
      <div slot="tags">
      </div>
      <div slot="customOperation" >
        <customBtn 
          btnName="启用"
          message="确定启用该服务模板吗?"
          idName="20230207140703"
          keyName="sa_workorder_templateid"
          :id="$route.query.id"
          :paramData="[{key:'isused',value:true}]"
          class="inline-16"
          @onSuccess="queryMainData()"
          v-if="!mainData.isused && tool.checkAuth($route.name,'used')"
        />
        <customBtn 
          btnName="关闭"
          message="确定关闭该服务模板吗?"
          idName="20230207140703"
          keyName="sa_workorder_templateid"
          :id="$route.query.id"
          :paramData="[{key:'isused',value:false}]"
          class="inline-16"
          @onSuccess="queryMainData() && tool.checkAuth($route.name,'close')"
          v-else
        />
      </div>
      <div slot="slot0" >
        <taskDetail>
        </taskDetail>
      </div>
      <div slot="slot1" >
        <detailInfo :more="true" :data="detailInfo"></detailInfo>
      </div>
    </basicDetails>
  </div>
</template>

<script>
import detailInfo from '@/components/detailInfo/index'
import taskDetail from './taskDetail/index'
export default {
  name: "detail",
  data() {
    return {
      mainData:{},
      mainAreaData:{},
      detailInfo:''
    }
  },
  components:{
    detailInfo,
    taskDetail
  },
  provide() {
    return {
      isEdit:() => this.mainData.isused == 1
    }
  },
  methods:{
    async queryMainData(id) {
      const res = await this.$api.requested({
        "id":20230207140503,
        "content": {
          "nocahce":true,
          "sa_workorder_templateid": this.$route.query.id
        }
      })
      this.mainData = res.data
      this.changeDataStructure()
      console.log(this.mainData);
      
    },
    changeDataStructure() {
      this.mainAreaData = [
        {
          label:'模板名称',
          value:this.mainData.name
        },
        {
          label:'服务类型',
          value:this.mainData.type
        },
        {
          label:'是否启用',
          value:this.mainData.isused ? '是' : '否'
        },
      ]
      this.detailInfo = [
        {
          title:'基本信息',
          info: [
            {
              label:'模板名称',
              value:this.mainData.name
            },
            {
              label:'服务类型',
              value:this.mainData.type
            },
            {
              label:'是否启用',
              value:this.mainData.isused ? '是' : '否'
            },
          ]
        },
        {
          title:'系统信息',
          info: [
            {label:'创建人',value:this.mainData.createby},
            {label:'创建时间',value:this.mainData.createdate},
            {label:'编辑人',value:this.mainData.changeby},
            {label:'编辑时间',value:this.mainData.changedate},
          ]
        },
      ]
    },
    async handleStatus (status) {
      let res = await this.$api.requested({
        "id": "20230207140703",
        "version":1,
        "content": {
            "sa_workorder_templateid":this.$route.query.id,
            "isused":status == '关闭' ? false : true
        }
      })
      this.tool.showMessage(res,() => {
        this.queryMainData()
      })
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex,tabIndex) {
      this.flag = false
      tabIndex = this.$route.query.tabIndex
      this.$router.replace({path:'/workBillModuleDetail',query:{id:id,rowindex:rowindex,tabIndex:tabIndex}})
      this.queryMainData(id)
    },
    onSuccess(){
      this.visible = false
      this.queryMainData(this.$route.query.id)
      this.$emit('onSuccess')
    }
  },
  mounted () {
    this.queryMainData(this.$route.query.id)
  },
  created() {
  }
}
</script>

<style scoped>

</style>