<template>
  <div>
    <basicDetails
        ref="details"
        :titleText="mainData.rolename"
        :oldFormPath="{edit:'HManagement/roleManage/modules'}"
        :editData="mainData"
        :mainAreaData="mainAreaData"
        turnPageId="20221101131902"
        delApiId="20221101132002"
        idname="roleid"
        ownertable="sys_role"
        tags=""
        :tabs="['授权信息']"
        @pageChange="pageChange"
        @onEditSuccess="queryMainData($route.query.id)">
      <div slot="tags">
      </div>
      <div slot="customOperation" >
      </div>
      <div class="container normal-panel" slot="slot0" >
        <el-row :gutter="20">
          <el-col :span="12">
            <tableLayout :layout="tablecols" :data="roleMainInfo.apps" height="500px" :custom="false" @rowClick="appoptionselect">
            </tableLayout>
          </el-col>
          <el-col :span="11">
            <el-row :gutter="40">
              <el-col :span="12">
                <p class="title">功能</p>
                <div class="flex-align-center flex-between option-item" v-for="item in appoptions" :key="item.index">
                  <p>{{item.optionname}}</p>
                </div>
              </el-col>
              <el-col :span="12">
                <p class="title">隐藏字段</p>
                <div class="flex-align-center flex-between option-item" v-for="item in hiddenfields" :key="item.index">
                  <p>{{item.fieldname}}</p>
                </div>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
      </div>
    </basicDetails>
  </div>
</template>

<script>
export default {
  name: "detail",
  data() {
    return {
      mainData:{},
      mainAreaData:{},
      form:{
        "roleid":0,
        "rolename":"",
        "remarks":""
      },
      roleMainInfo:{},
      tablecols:[],
      appoptions:[],
      hiddenfields:[],
      roleid:0,
      active_systemappid:''
    }
  },
  components:{
  },
  methods:{
    async queryMainData(id) {
      const res = await this.$api.requested({
        "classname": "webmanage.role.role",
        "method": "query_roleMain",
        "content": {
          "roleid":this.$route.query.id
        }
      })
      this.mainData = res.data
      this.form = {
        "roleid":res.data.roleid,
        "rolename":res.data.rolename,
        "remarks":res.data.remarks,
        "usertype":res.data.usertype,
        "usertypename":res.data.usertypename
      }
      this.roleMainInfo = res.data
      
      //显示默认授权信息,一般默认信息为第一条数据
      res.data.apps[0]?this.appoptionselect(res.data.apps[0]):''
      this.changeDataStructure()
    },
    changeDataStructure() {
      this.mainAreaData = [
        {
          label:'角色名称',
          value:this.mainData.rolename
        },
        {
          label:'角色描述',
          value:this.mainData.remarks
        },
        {
          label:'角色类型',
          value:this.mainData.usertypename
        }
      ]
    },
    // 监听切换数据,上一页,下一页
    pageChange (id,rowindex,tabIndex) {
      this.flag = false
      tabIndex = this.$route.query.tabIndex
      this.$router.replace({path:'/roleDetail',query:{id:id,rowindex:rowindex,tabIndex:tabIndex}})
      this.queryMainData(id)
    },
    onSuccess(){
      this.visible = false
      this.queryMainData(this.$route.query.id)
      this.$emit('onSuccess')
    },
    async appoptionselect (row) {
      this.active_systemappid = row.systemappid
      this.appoptions = row.options
      this.hiddenfields = row.hiddenfields
    },
  },
  mounted () {
   // 获取应用表结构
    this.tablecols = this.tool.tabelCol(this.$route.name).detailsAppsTable.tablecols
    this.roleid = this.$route.query.id
    this.roleid !== '0'?this.queryMainData():''
  },
  created() {
  }
}
</script>

<style scoped>
.mb-16{
  margin-bottom:16px
}
.title{
  height: 20px;
  line-height: 20px;
  font-size: 14px;
  text-indent: 7px;
  font-weight: bold;
  color: #333333;
  margin-bottom: 20px;
  border-left: .3rem solid #3874F6;
}
.option-item{
  color:#333333;
  font-size: 14px;
  border-bottom:1px solid #f1f2f3;
  line-height: 35px;
}
</style>