田源
2023-08-03 ef23237ddabf5ea44856ff369a7c8973758db3d0
Source/UBCS-WEB/src/components/template/SetPersonnel.vue
@@ -10,7 +10,7 @@
                <el-input placeholder="流程模板" v-model="saveParam.modelName" disabled></el-input>
            </el-form-item>
            <el-form-item label="流程名称" prop="processName">
                <el-input placeholder="流程名称" v-model="saveParam.processName">
                <el-input placeholder="流程名称" v-model="saveParam.template">
                </el-input>
            </el-form-item>
            <el-form-item label="流程描述">
@@ -52,7 +52,9 @@
            typeof: String,
            default: '流程审批'
        },
        // 参数:选择的id,多个以数组方式传递:['id','id'],模板id,模板用途,流程名字,流程模板
        // 参数:选择的id,多个以数组方式传递:['id','id'],模板id,模板用途,流程名字,流程模板,
        // flowTemplate:
        // vars:object格式,名字为vars,里面key键值,自己随意
        parameter: {
            typeof: Object,
            default: () => { }
@@ -64,7 +66,8 @@
                    ids: 'ids',
                    flowTemplate: 'flowTemplate',
                    code: 'code',
                    type: 'type'
                    type: 'type',
                    btmtype:'btmtype'
                }
            }
        }
@@ -73,14 +76,28 @@
    watch: {
        visible(n) {
            this.dialogVisible = n;
            if(n){
              this.apiInit()
              this.apiDict()
            if (n) {
                this.apiInit()
                this.apiDict()
            }
        },
        dialogVisible(n) {
            this.$emit('update:visible', n)
        },
        users:{
            handler(val){
                this.collectParam.flowTaskUsers = val
            },
            deep:true,
            immediate:true
        },
      parameter:{
          handler(newval,oldval){
               this.saveParam=newval;
          },
        deep:true,
          immediate:true
      }
    },
    data() {
        return {
@@ -90,7 +107,7 @@
            tags: [],
            typeName: [],
            collectParam: {},
            saveParam: this.saveParam(),
            saveParam: {},
            users: [],
            rules: {
                processName: [
@@ -102,32 +119,37 @@
    },
    mounted() {
        // this.apiInit()
        // this.apiDict()
    },
    methods: {
        saveParam() {
  created() {
  },
  methods: {
        setSaveParam() {
            return {
                processName: this.parameter[this.parameterKeys.flowTemplate],
                topName: this.title,
                ids: this.parameter[this.parameterKeys.ids],
                oids: this.parameter[this.parameterKeys.ids],
                btmtype:this.parameter[this.parameterKeys.btmtype],
                vars:this.parameter['vars']
            }
        },
        userIndex(arr1) {
            return this.initFrom.findIndex(i => i.taskId === arr1)
        },
        async apiInit() {
            const response = await personnelInit({ type: this.parameter[this.parameterKeys.type], templateId: this.parameter[this.parameterKeys.code] })
            const response = await personnelInit({ type: this.parameter[this.parameterKeys.type], templateId: this.parameter[this.parameterKeys.code]})
            if (response.status === 200) {
                console.log(response)
                this.initFrom = response.data.data.user
                this.tags = response.data.data.collect
                const { modelKey, templateId, modelName } = response.data.data.flow
                let flowTaskUsers = response.data.data.user
                this.collectParam = { modelKey, templateId, flowTaskUsers: flowTaskUsers }
                this.users = response.data.data.user
                console.log(this.collectParam)
            console.log('this.saveParam.before',this.saveParam)
                this.saveParam = { ...this.saveParam, modelKey, templateId, modelName }
                this.handleClickTag(this.tags[0])
            console.log('this.saveParam',this.saveParam)
                if (this.tags.length !== 0) this.handleClickTag(this.tags[0])
            }
        },
        async apiDict() {
@@ -154,12 +176,11 @@
                this.collectParam = { ...this.collectParam, name: value }
                console.log(this.collectParam)
                const response = await personnelCollect(this.collectParam)
                Console.log(response)
                console.log(response)
                if (response.status === 200) {
                    this.$nextTick(() => {
                        this.apiInit()
                    })
                    console.log(response)
                }
            }).catch(() => {
@@ -179,47 +200,65 @@
        },
        async apiSave() {
            try {
                const response = await personnelSave(this.saveParam)
                if (response.status === 200) {
                    console.log(response)
                const len = this.collectParam.flowTaskUsers.length
                if (len == 0 && len != this.initFrom.length) {
                    this.$message({
                        type: 'success',
                        message: response.data.msg
                        type: "error",
                        message: "请选择节点!"
                    });
                    this.done()
                } else {
                    const {modelKey,modelName,processDesc,processName,templateId,topName,vars,ids,btmtype} = this.saveParam
                    let vals= {modelKey,modelName,processDesc,processName,templateId,topName,ids,btmtype,...vars}
                    vals.oids=ids;
                    const response = await personnelSave({ variables:vals, flowTaskUsers: this.collectParam.flowTaskUsers, })
                    if (response.status === 200) {
                        this.$message({
                            type: 'success',
                            message: response.data.msg
                        });
                        this.$emit('onLoad')
                        this.done()
                    }
                }
            } catch {
                console.error('接口调用失败')
              this.$message.error('接口调用失败')
            }
        },
        handleClickTag(event) {
            console.log(event)
            console.log('tasks', this.collectParam)
            const flowTaskUsers = event.flowTaskUsers//collet.flowTaskUsers
            let tasks =  this.collectParam.flowTaskUsers;//user
            for(let i=0;i<tasks.length;i++){
                let thisFlowTaskUsers = tasks[i];
                console.log('thisFlowTaskUsers',thisFlowTaskUsers)
                for(let j=0;j<flowTaskUsers.length;j++){
                    let thisFflowTaskUsers = flowTaskUsers[j];
                    if(thisFlowTaskUsers.taskId==thisFflowTaskUsers.taskId){
                        thisFlowTaskUsers['userName']=thisFflowTaskUsers.userName;
                        thisFlowTaskUsers['userId']=thisFflowTaskUsers.userId;
            let flowTaskUsers = this.collectParam.flowTaskUsers
            this.collectParam.flowTaskUsers = flowTaskUsers.map((item, index) => {
                for (let i = 0; i < event.flowTaskUsers.length; i++) {
                    if (item.taskId == event.flowTaskUsers[i].taskId) {
                        item['userName'] = event.flowTaskUsers[i]['userName']
                        item['userId'] = event.flowTaskUsers[i]['userId']
                    }
                }
            }
            console.log(this.collectParam)
                return item
            })
            this.users =  this.collectParam.flowTaskUsers
            // const flowTaskUsers = event.flowTaskUsers//collet.flowTaskUsers
            // let tasks = this.collectParam.flowTaskUsers;//user
            // for (let i = 0; i < tasks.length; i++) {
            //     let thisFlowTaskUsers = tasks[i];
            //     for (let j = 0; j < flowTaskUsers.length; j++) {
            //         let thisFflowTaskUsers = flowTaskUsers[j];
            //         if (thisFlowTaskUsers.taskId == thisFflowTaskUsers.taskId) {
            //             thisFlowTaskUsers['userName'] = thisFflowTaskUsers.userName;
            //             thisFlowTaskUsers['userId'] = thisFflowTaskUsers.userId;
            //         }
            //     }
            // }
            // this.collectParam.flowTaskUsers = {...this.collectParam.flowTaskUsers,userId,userName}
        },
        handleCloseTag(event) {
            console.log(event)
            this.canCollect(event.name)
        },
        handleSelect(event, index) {
            const res = this.typeName.find(item => item.userId === event)
            const { userName } = res
            let users = { ... this.collectParam.flowTaskUsers[index], userName }
            console.log(users)
            this.users[index] = users
            this.$set(this.users, index, { ... this.collectParam.flowTaskUsers[index], userName })
            // this.users[index] = { ... this.collectParam.flowTaskUsers[index], userName }
        },
        done() {
            this.dialogVisible = false