作者:管理员  历史版本:1  最后编辑:Eddy  更新时间:2024-10-24 16:08

客户使用的脚本

Object.assign(JForm,{
  //加载事件
  onLoad:function(form){
        console.log(form,'2222')
            console.log(form.$parent.$parent.$parent.$parent,'333')
        if(form.$parent.$parent.$parent.$parent){
            form.setData('zxmid',form.$parent.$parent.$parent.$parent.dynamicParams.ZXMID_)
        }
  },
 //表单按钮前置事件
  beforeSubmit:function(form,action,postValue,callback){
    const bd = form.getFormData()
        if(action === 'save'){
          if(bd.xmmc !== '' && bd.xmfzr !== ''){
                    //主要成员重复提醒
                    const cy = form.getData('hb_zyqrcpyjckbz_zycy')
                    var ryfind = false
                    var rymsg = ''
                    for (var i = 0; i < cy.length; i++) {
                      for (var j = i + 1; j < cy.length; j++) {
                        if (cy[i].jg0101Id !== '' && cy[j].jg0101Id !== '' && cy[i].jg0101Id === cy[j].jg0101Id) {
                          rymsg = '项目团队成员[校内教职工-' + cy[i].xm + ']数据重复,不能保存!'
                          ryfind = true;
                          break;
                        }
                      }
                      if (ryfind) {
                        break;
                      }
                    }
                    if (ryfind) {
                      this.$form.$message({
                        type: 'warning',
                        message: rymsg
                      })
                      return
                    }else{
                        callback(true)
                    }
              }else{
                   callback(true)
              } 
          }else{
            callback(true)
          }
  }
});
Object.assign(JForm,{
  //加载事件
  onLoad:function(form){
    console.log('form',form)
    let defautData = {}
    try{
      defautData = form.$parent.$parent.$parent.$parent.defaultFormData
      console.log('defaultFormData',defautData)
    }catch (e) {
    }
    if(form.$utils.isEmpty(defautData) || form.$utils.isEmpty(defautData.BUSID_)  || form.$utils.isEmpty(defautData.BUS_TABLE_)  || form.$utils.isEmpty(defautData.TZPYXM_D_) ){
      this.$form.$message({
        message: '数据不完整',
        type: 'error'
      })
      form.closeDialog();
    }
    form.setData('busid',defautData.BUSID_)
    form.setData('tzpyxmD',defautData.TZPYXM_D_)
    form.setData('busTable',defautData.BUS_TABLE_)
  },

  //表单按钮前置事件
  beforeSubmit:function(form,action,postValue,callback){
    if(action==='save'){
      console.log(form)
      const busid = form.getData('busid') //业务主键
      const tzpyxmD = form.getData('tzpyxmD') //
      const busTable = form.getData('busTable') //
      if(form.$utils.isEmpty(busid) || form.$utils.isEmpty(tzpyxmD)  || form.$utils.isEmpty(busTable) ) {
        this.$form.$message({
          message: '数据不完整',
          type: 'error'
        })
        form.closeDialog();
      }else {
        const zzuserId = form.getData('sfzz')//此处借用了是否组长字段存储组长的userid
        const qtzjuserId = form.getData('userId')
        let flag = false
        let msg = ''
        if (form.$utils.isNotEmpty(zzuserId) && form.$utils.isNotEmpty(qtzjuserId)) {
          const cfxz = (','+qtzjuserId+',').indexOf(','+zzuserId+',')>0 //组长是否重复选择,如果组长还在其他专家内,则不能保存
          if(cfxz){
            flag = true
            msg = '组长不能在其他专家内'
          }
        }else{
          if (form.$utils.isEmpty(zzuserId)) {
            flag = true
            msg = '组长不能在其他专家内'
          }
        }
        if (flag) {
          this.$form.$message({
            message: msg,
            type: 'warning'
          })
        } else {
          this.$form.$confirm('该操作将会先删除选择数据的原指定专家,确定要继续吗?').then(()=>{
            form.actions.forEach(res=>{
              if(res.key==="save"){
                res.disabled=true
              }
            })
            const accountUserid = form.$store.getters.userId
            this.$request({
              //调用后端脚本类请求
              url:'/business/v3/form/def/getScriptValue',
              method: 'post',
              data:  {
                'script': `
      import org.apache.commons.lang3.StringUtils;
      import java.text.SimpleDateFormat;
      import java.util.Date;
      import java.util.HashMap;
      import java.util.Map;
      import java.util.UUID;
      String tzpyxmD = "${tzpyxmD}";
        String busTable = "${busTable}";
        String accountUserid = "${accountUserid}";
        String busid = "${busid}";
        String[] pkIds = busid.split(",");
        String zzuserId = "${zzuserId}";/*专家userid*/
        String qtzjuserId = "${qtzjuserId}";/*其他专家userid*/
        String[][] userIdArr = null;
        if(StringUtils.isNotBlank(qtzjuserId)){
            String[] temp = qtzjuserId.split(",");
            if(temp != null && temp.length>0){
                boolean iszz = false;
                for(int kkk=0;kkk<temp.length;kkk++){
                    if(StringUtils.isNotBlank(zzuserId) && zzuserId.equals(temp[kkk])){
                        iszz = true;
                    }
                }
                if(iszz){
                    userIdArr = new String[temp.length][2];
                }else{
                    userIdArr = new String[temp.length+1][2];
                }
                for(int kkk=0;kkk<temp.length;kkk++){
                    userIdArr[kkk][0] = temp[kkk];
                    if(StringUtils.isNotBlank(zzuserId) && zzuserId.equals(temp[kkk])){
                        userIdArr[kkk][1] = "1";
                    }else{
                        userIdArr[kkk][1] = "0";
                    }
                }
            }
        }
        if(userIdArr == null){
            userIdArr = new String[1][2];
        }
        userIdArr[userIdArr.length-1][0] = zzuserId;
        userIdArr[userIdArr.length-1][1] = "1";

        Map<String, Object> valMaps = new HashMap<String, Object>();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String nowTime = formatter.format(new Date());
        for (int ind = 0; ind < pkIds.length; ind++) {
            valMaps.clear();
            valMaps.put("busid_", pkIds[ind]);
            valMaps.put("tzpyxm_d_", tzpyxmD);
            valMaps.put("bus_table_", busTable);
            scriptImpl.deleteDataBySql("t_hb_xmzdzj",valMaps,"=");
            for(int zjIndex = 0;zjIndex<userIdArr.length;zjIndex++){
                String[] zjxx = userIdArr[zjIndex];//第一个值是专家userid,第二个值是是否组长。
                valMaps.clear();
                String id = String.valueOf(UUID.randomUUID()).replaceAll("-","");
                valMaps.put("id_", id);
                valMaps.put("tzpyxm_d_", tzpyxmD);
                valMaps.put("busid_", pkIds[ind]);
                valMaps.put("bus_table_", busTable);
                valMaps.put("user_id_", zjxx[0]);
                valMaps.put("sfzz_", zjxx[1]);
                valMaps.put("create_by_", accountUserid);
                scriptImpl.addDataByBusKey("t_hb_xmzdzj",valMaps);
            }
        }
      `
              }
            }).then(response => {
              this.$form.$message({
                message: '修改成功',
                type: 'success'
              })
              form.callback()
            }).catch(error => {
              console.log(error)
              this.$form.$message({
                message: '修改失败',
                type: 'waring'
              })
              form.actions.forEach(res=>{
                if(res.key==="save"){
                  res.disabled=false
                }
              })
            })

          })

        }
      }
    }else{
      callback(true)
    }
  }
});

Object.assign(JForm,{
  //加载事件
  onLoad:function(form){
    this.$form.$nextTick(() => {
      setTimeout(()=>{
        console.log(1,form.$refs)
        console.log(2,form.$refs.dynamicForm)
        console.log(3,form.$refs.dynamicForm.$refs['formItemsteps_0in7igr'][0])
        console.log(5,form.$refs.dynamicForm.$refs['formItemsteps_0in7igr'][0].$refs['formItemfjsc'][0].$children[0])
        console.log(6,form.$refs.dynamicForm.$refs['formItemsteps_0in7igr'][0].$refs['formItemfjsc'][0].$children[0].$children[1])
        console.log(7,form.$refs.dynamicForm.$refs['formItemsteps_0in7igr'][0].$refs['formItemfjsc'][0].$children[0].$children[1].$children[0])
        //form.formData 获取数据模板传过来的默认数据
        let that = this
        const scmxData =  form.formData
        console.log(12121454545,form.formData)
        // 传值到手开页面
        form.$refs.dynamicForm.$refs['formItemsteps_0in7igr'][0].$refs['formItemfjsc'][0].$children[0].$children[1].$children[0].setRow(scmxData)
        // 监听附件
        let fj = ''
        setTimeout(()=>{
          form.$refs.dynamicForm.$refs['formItemsteps_0in7igr'][0].$refs['formItemfjsc'][0].$children[0].$children[1].$children[0].$watch('files',function(data){
            fj = data
          })
        },1000)
        // 监听步骤条按钮
        form.$watch('curActiveStep',function(data){
          console.log(888888888,fj)
          if(!fj){
            that.$form.$message({
              message: "请先上传附件",
              type: 'warning'
            })
            form.curActiveStep=0
            let loading = that.$form.$loading({
              lock: true,
              text: '加载中',
            })
            setTimeout(()=>{
              form.$refs.dynamicForm.$refs['formItemsteps_0in7igr'][0].$refs['formItemfjsc'][0].$children[0].$children[1].$children[0].setRow(scmxData)
              form.$refs.dynamicForm.$refs['formItemsteps_0in7igr'][0].$refs['formItemfjsc'][0].$children[0].$children[1].$children[0].files = fj
              loading.close()
            },500)
            return
          }
          if(data === 0){
            let loading = that.$form.$loading({
              lock: true,
              text: '加载中',
            })
            setTimeout(()=>{
              form.$refs.dynamicForm.$refs['formItemsteps_0in7igr'][0].$refs['formItemfjsc'][0].$children[0].$children[1].$children[0].setRow(scmxData)
              form.$refs.dynamicForm.$refs['formItemsteps_0in7igr'][0].$refs['formItemfjsc'][0].$children[0].$children[1].$children[0].files = fj
              loading.close()
            },500)
          }
          if(data === 1){
            let FjData = {
              sfid: scmxData.ZSSF_D_,
              pcid:scmxData.ID_,
              fjid: fj
            }
            let loading = that.$form.$loading({
              lock: true,
              text: '加载中',
            })
            setTimeout(()=>{
              form.$refs.dynamicForm.$refs['formItemsteps_0in7igr'][0].$refs['formItemcomponent_166zz9c'][0].$children[0].$children[1].$children[0].getfjdata(FjData)
              loading.close()
            },500)
          }
        })
      }, 1000)
    })
  },

 //表单按钮前置事件
  beforeSubmit:function(form,action,postValue,callback){
    if(action ==='close'){
      this.$form.$parent.$parent.$parent.$parent.$parent.$parent.$parent.$children[11].loadDataTemplate()
      callback(true)
    }else{
      callback(true)
    }
  }

});
Object.assign(JForm,{
  //加载事件
  onLoad:function(form){



    this.$request({
      url:'/jczy/v3/xgJczyXnxq01/query',
      method: 'post',
      data: {  "parameters": [   {      "key": "Q^ISDQXQ_D_^S",  "value": "1"    }  ]}
    }).then(response => {
      const { state } = response
      if (state === 200) {
          form.setData('jwXnxq01Id',response.data.dataResult[0].id);
          form.setData('label_10rjaw1',response.data.dataResult[0].xqmc);
      }
    })

    if(form.getData('bmfs') == 'tdbm'){

      form.setFormRights('tdrs','s');

      //document.getElementsByClassName('el-button-group')[0].display = 'none'
      form.setFormRights('tdrs','r');
    }else{
      form.setFormRights('xg_szjy_kchdmx','h');
      form.setFormRights('tdrs','h');
    }

    this.$request({
      url:'/jczy/v3/xgJczyXs0101/queryStudentInfo',
      method: 'post',
      data: form.getData('jwXs0101Id')
    }).then(response => {
      const { state } = response
      if (state === 200) {
          form.setData('label_1jsv260',response.data.xm)
          form.setData('jwXs0101Id',response.data.xsid)
          form.setData('label_1xyakdo',response.data.xh)
          form.setData('label_0wrkvrz',response.data.nj)
          form.setData('label_1bi18ev',response.data.yxmc)
          form.setData('label_1o07xfb',response.data.bjmc)
        form.setData('ylzd',response.data.nj)
      } else {
        const err = new Error(response.message)
        err.state = state
        err.cause = response.cause
      }
    }).catch(error => {
      console.log(error)
    })

    if(form.getData('id')){
      form.setFormRights('jwXnxq01Id','h');
      form.setFormRights('jwXs0101Id','r');
      form.setFormRights('xgSzjyKckId','r');
      form.setFormRights('xgSzjyKckZxId','r');
      form.setFormRights('hdmc','r');
      form.setFormRights('ksrq','r');
      form.setFormRights('jsrq','r');
      form.setFormRights('kzdd','r');
      form.setFormRights('kznr','r');
      form.setFormRights('bmfs','r');
       form.setFormRights('xgSzjyKkId','r');

      var kchdmx =  form.getData('xg_szjy_kchdmx');
      var sjkchdmx = [];
      for(var i = 0 ; i < kchdmx.length;i++ ){
        if(kchdmx[i].reviewState == '1'){
          sjkchdmx.push(kchdmx[i])
        }
      }
      form.setData('xg_szjy_kchdmx',sjkchdmx);
    }

    //


  },
 //表单按钮前置事件
  beforeSubmit:function(form,action,postValue,callback){




    if(action == 'save'){

      var tdcy = postValue.xg_szjy_kchdmx;
      if(postValue.bmfs == 'tdbm' && tdcy.length > Number(postValue.tdrs)){
        form.$toast({
          message: "团队成员已超过团队人数",
          type: 'warning'
        })
        callback(false);
      }else{
        form.validate(res=>{
          if(res){
            postValue.xg_szjy_kchdmx.push(
              {
                "id": "",
                "jwXs0101Id": form.getData('jwXs0101Id'),
                "ylzd": form.$store.getters.userName,
                "xgSzjyKchdId": "",
                "reviewState": "1",
                "sftjzyD": 'wtj'
              }
            )
            form.setData('reviewState','0');
            callback(true) 
          }else{
            let that = this
            that.$form.$message({
              message: "请填写完整",
              type: 'warning'
            })
          }
        })
      }
    }else{
      callback(true) 
    }

  }

});