<template>
  <div class="about">
    <content-Header>
      <template v-slot:header>新增操作员</template>
    </content-Header>
    <content-form interval-width="30px" :role="role" ref="contentForm" :user-information="userInformation" @user-form="userForm"  >
      <el-button  class="button-submit" :disabled="submitDisabled" @click='submitForm()' type="primary">提 交</el-button>
    </content-form>
    <template>
      <dialog-box :dialogVisible.sync="dialogVisible" >
        <template v-slot:show-errtitle>{{dialogErrTltle}}</template>
        <template v-slot:show-text>{{dialogVisibleIf}}</template>
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </dialog-box>  
    </template>
  
  </div>

    
</template>
<script>
// @ is an alias to /src
import ContentHeader from '@/common/components/ContentHeader.vue' //公共头部

import ContentForm from '@/components/addOperator/ContentForm.vue'
import DialogBox from '../common/components/DialogBox.vue'
export default {
  name: 'AddOperator',
  components: {
    ContentHeader,
    ContentForm,
    DialogBox
  },
  data(){
    return{
      role: [],         //角色字典
      userInformation: [] , //用户信息的业务类型
      dialogVisible : false,
      dialogErrTltle : '', //错误表头
      dialogVisibleIf : '错误',
      submitDisabled: false
    }
  },
  created () {

    let _this =  this;
    const getUserInfo = this.$store.state.userInfo ;//登录账号信息
    // console.log(this.$store.state.rightDict); 
    // fql.WFW_USER_MANAGE_SERVICE['角色字典查询']({}).then(function(res){
      _this.role = this.$store.state.roleDict //从store里获取（角色字典查询）赋值给 role
    // })
    console.log(getUserInfo);
        
    const userInformation={
      USER_CODE: getUserInfo.USERCODE,
      INST_USER_CODE: getUserInfo.USERCODE,
      CUST_CODE : getUserInfo.USER_CUSTID, //用户登录名
      SYSTEM_ID : '79', //子系统编号
      ACTION_TYPE : '1', //操作类型
      OPERATOR : getUserInfo.USER_CUSTID //操作员

    }
     fql.WFW_USER_MANAGE_SERVICE['用户信息查询'](userInformation)
     .then(res =>{
       if(res.list == undefined){throw new Error(res)}
       if(res.RNUM != 1){throw new Error(res.msg)}
         _this.userInformation = res.list[0].RIGHT_LIST 
    })    
    .catch( err =>{ 
      this.dialogErrTltle = '查询失败！'
      this.dialogVisibleIf =  'W12001003  错误信息'+ err
      this.dialogVisible = true
    })
    // 查询用户信息
  },
  methods:{
    userForm(val){
      console.log(val);
    },
    submitForm(){   //表单提交
    let _this = this
    
    let refContentForm = this.$refs.contentForm
       if(!refContentForm.testGetChildRef()){
         return false
       }
        this.submitDisabled = true
        setTimeout(() => {
          this.submitDisabled = false
        }, 3000);
        const resGetUserInfo =  this.$store.state.userInfo   
        //创建操作员入参对象
        // console.log(refContentForm.userForm);
        // const userFormObj =Object.assign({}, refContentForm.userForm); 
        const userFormObj = refContentForm.userForm; 
        userFormObj.ROLE_ID = userFormObj.ROLE_ID.join(',')   // 将BUSIN_TYPEarr转为逗号间隔（业务类型）
        userFormObj.BUSIN_TYPE = "CWJRY" // 将BUSIN_TYPEarr转为逗号间隔（业务类型）
        fql.WFW_USER_MANAGE_SERVICE['创建操作员'](userFormObj).then(res=>{
          if(res.list == undefined){ throw new Error(res) }
          if(res.RNUM != '1')  {
            _this.dialogErrTltle = '错误'  //提示头
            _this.dialogVisibleIf = "W12001001  错误信息"+ res.msg
            _this.dialogVisible = true
            return
            };
          let res1001 = res.list[0]
          var objData2 = {
            ACCT_CODE :  res1001.CUST_CODE,   //账号代码
            // ACCT_CODE :  'test01',   //账号代码   
            ACCT_TYPE : "795" ,   //账号类型
            PWD_TYPE : "5" ,     //密码类型
            RESET_FLAG : "0" ,   //是否重置标志
            SYSTEM_ID : "79" ,   //子系统编号
            USER_CODE: resGetUserInfo.USERCODE,
            INST_USER_CODE: resGetUserInfo.USERCODE,
            ACTION_TYPE : "1" ,   //操作类型
            OPERATOR : resGetUserInfo.USER_CUSTID ,   //操作员
          }
          fql.WFW_USER_MANAGE_SERVICE['设置操作员初始密码'](objData2).then(res1002=>{
            if(res1002.RNUM != '1')  {
              _this.dialogErrTltle = '错误'  //提示头
              _this.dialogVisibleIf = "W12001001  错误信息"+ res1002.msg
              _this.dialogVisible = true
            return
            };
            console.log(res1002.list[0].USER_CODE);
            // alert("USER_CODE: "+res1002.list[0].USER_CODE)
            _this.dialogVisibleIf = "USER_CODE: "+res1002.list[0].USER_CODE  
            _this.dialogErrTltle = '新增操作员成功！'  //提示头
            _this.dialogVisible = true
            refContentForm.resetForm()   //表单重置
            var objData3={
              ACCT_TYPE: '795',  //账号类型
              ACCT_CODE: res1001.CUST_CODE,  //账号代码
              BUSIN_TYPE: 'CWJRY',  //业务类型
              RIGHT_LIST: JSON.stringify(refContentForm.dataRight[4].getObjTypeValue),  //权限json串
              ACTION_TYPE: '1',  //操作类型
              USER_CODE: resGetUserInfo.USERCODE,
              INST_USER_CODE: resGetUserInfo.USERCODE,
              OPERATOR: resGetUserInfo.USER_CUSTID,  //操作员
            }
            fql.WFW_USER_MANAGE_SERVICE['为账号批量分配权限'](objData3).then(res1007=>{
              if(res1007.RNUM != 0)  {
                  _this.dialogErrTltle = '错误'  //提示头
                  _this.dialogVisibleIf = "W12001007  错误信息"+ res1007.msg
                  _this.dialogVisible = true
                  return
              }
            })
          })
    
    })
    .catch( err =>{
        // alert(err)
        _this.dialogErrTltle = '提交失败！'
        _this.dialogVisibleIf = "W12001001  错误信0息"+err
        _this.dialogVisible = true
    })      
    },

  }
}
</script>
<style scoped>
/* 提交按钮Style */
.button-submit{
  display: block;
  width: 102px;
  height: 30px;
  border-radius: 2px;
  padding: 0;
  text-align: center;
  margin-left: 154px;
  margin-top: 24px;
  margin-bottom: 24px;
  background: #2E5DED;
 
}
.el-input__inner{
  margin-left: 50px;
  padding-left: 30px;
}

</style>