<template>
  <el-form :model="form" :rules="rules" ref="form">
    <el-form-item :label="label" prop="FSEX">
        <el-radio-group v-model="curtBzId" style="display:flex;flex-wrap: wrap;">
          <el-radio v-for="(item,index) in orgInfo" border :label="item.FBZID">{{ getOrgPathName(item) }}({{item.FBZID}})</el-radio>
        </el-radio-group>
    </el-form-item>
    <el-form-item style="text-align: center;">
      <el-button type="primary" @click="submitForm">{{ $t("hivuiMain_des_save")}}</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { query, update} from '@main/api/user.js'
export default {
  data(){
    return {
      bzList:[],
      label: this.$t("hivuiMain_main_bz", { default: '主岗' }),
      curtBzId: '',
      orgInfo:{}
    }
  },
  created(){
    this.getOrgInfo()
  },
  methods: {
    getOrgInfo(){
      var param = {
        modelFilePath: "/platf/org/entity/SysOrgPsmEntity.xml",
        pageSize: -1,
        __zcQuery: false,
        __returnCount: true,
        __bottomSummary: false,
      }
      let userId = top.Scp.User && top.Scp.User.fuserid
      if(userId){
        let queryCdions = {
          join: 'and',
          items:[
            {
              sign: 'eq',
              name: 'FUSERID',
              dataType: 'dbString',
              value: userId,
              enable: true
            }
          ]
        }
        let __body = JSON.stringify({queryCdions: queryCdions})
        param.__body = __body
        query(param).then((res)=>{
          this.orgInfo = res.dataPack && res.dataPack.rows
          if(this.orgInfo && this.orgInfo.length){

          }
        })
      }
    },
    submitForm() {
      // let bz = this.bzList.filter(res => res.fbzid == this.curtBzId)[0]
      let org = this.orgInfo.filter(res => res.FBZID == this.curtBzId)[0]
      let data = {
          $m:"/platf/org/entity/SysOrgPsmEntity.xml",
          $old:org,
          FDEFAULTBZ:1
      }
      update(data).then(res =>{
        this.$message({
          type: 'success',
          message: this.$t("hivuiMain_personalCenter_editTips") || "修改成功",
        })
      })
    },
    getOrgPathName(obj){
      if(this.bzList && this.bzList.length){
        let bz = this.bzList.filter(item => item.fbzid == obj.FBZID)
        return bz[0]?.forgnamepath || obj.FBZNAME
      }else{
        return obj.FBZNAME
      }
    }
  }
}
</script>

<style lang="less">

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.el-upload-list__item-actions {
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  cursor: default;
  text-align: center;
  color: #fff;
  opacity: 0;
  font-size: 20px;
  background-color: rgba(0, 0, 0, 0.5);
  transition: opacity 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.showImg:hover {
  .el-upload-list__item-actions {
    opacity: 1;
  }
}
.el-upload-list__item-delete {
  display: block;
  position: static;
  font-size: inherit;
  color: inherit;
  .el-icon-delete {
    font-family: element-icons !important;
    speak: none;
    font-style: normal;
    font-weight: 400;
    font-variant: normal;
    text-transform: none;
    line-height: 1;
    vertical-align: baseline;
    display: inline-block;
    -webkit-font-smoothing: antialiased;
  }
}
.el-upload-list__item-actions span + span {
  margin-left: 15px;
}
.el-upload-list__item-name i:hover,.el-upload-list__item-name a:hover{
  color: #409eff;
}
</style>
