routeDealing.vue 6.11 KB
Newer Older
wangdanlei's avatar
wangdanlei committed
1 2 3 4 5 6 7
<template>
  <div class="routeDealing-com">
    <setParticipants
      ref="participants"
      :basic-data="basicData"
      :participant-data="newParticipantData"
      :is-check-participant="isCheckParticipant"
wangdanlei's avatar
wangdanlei committed
8 9
      :show-title="showTitle"
      label-width="90px"
wangdanlei's avatar
wangdanlei committed
10 11 12 13 14 15 16
    />
    <dee-form
      ref="form"
      :form="propForm"
      :form-data="propFormData"
      :rules="rules"
    />
wangdanlei's avatar
wangdanlei committed
17
    <variableFormDealing ref="variableFormDealing" :basic-data="basicData" />
wangdanlei's avatar
wangdanlei committed
18 19 20 21 22 23
    <el-button v-if="basicData && basicData.canDeal" class="finish-btn" type="primary" @click="submit">完成任务</el-button>
  </div>
</template>

<script>
import SetParticipants from './setParticipants'
wangdanlei's avatar
wangdanlei committed
24
import variableFormDealing from './variableFormDealing'
wangdanlei's avatar
wangdanlei committed
25 26
export default {
  name: 'RouteDealing',
wangdanlei's avatar
wangdanlei committed
27
  components: { SetParticipants, variableFormDealing },
wangdanlei's avatar
wangdanlei committed
28 29 30 31 32
  provide() {
    return {
      routeFormCache: this.routeFormCache
    }
  },
wangdanlei's avatar
wangdanlei committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  props: {
    item: {
      type: Object,
      default: null
    },
    routes: {
      type: Array,
      default: () => []
    },
    participantData: {
      type: Object,
      default: null
    },
    basicData: {
      type: Object,
      default: null
wangdanlei's avatar
wangdanlei committed
49 50 51 52 53 54 55 56
    },
    showTitle: {
      type: Boolean,
      default: false
    },
    isSaveBeforeSubmit: {
      type: Boolean,
      default: false
wangdanlei's avatar
wangdanlei committed
57 58 59 60 61
    }
  },
  data() {
    return {
      propForm: {
wangdanlei's avatar
wangdanlei committed
62 63
        routerSelect: '',
        description: ''
wangdanlei's avatar
wangdanlei committed
64 65 66 67
      },
      routeOptions: [],
      required: false,
      newParticipantData: {},
wangdanlei's avatar
wangdanlei committed
68 69
      isCheckParticipant: false,
      routeFormCache: {}
wangdanlei's avatar
wangdanlei committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    }
  },
  computed: {
    propFormData: function() {
      const propFormData = [
        {
          width: 3,
          data: [
            {
              key: 'description',
              title: '备注',
              width: 3,
              component: {
                name: !this.basicData.canDeal ? 'readable' : 'el-input',
                type: 'textarea',
                rows: '2'
              }
            }
          ]
        }
      ]
      if (this.routes && this.routes.length) {
        propFormData[0].data.unshift({
          key: 'routerSelect',
          title: '处理结果',
          component: {
            name: 'el-radio',
            options: this.routeOptions,
            disabled: !this.basicData.canDeal
          }
        })
      }
      return propFormData
    },
    rules: function() {
      return {
        routerSelect: [
          { required: true, message: '请输入', trigger: 'change' }
        ],
        description: [
          { required: this.required, message: '请填写备注信息', trigger: 'blur' }
        ]
      }
    }
  },
  watch: {
    routes: {
      immediate: true,
      handler(newV, oldV) {
        if (newV) {
wangdanlei's avatar
wangdanlei committed
120
          // this.routes = newV
wangdanlei's avatar
wangdanlei committed
121 122 123 124 125 126 127 128 129
          this.setOptions(newV)
        }
      },
      deep: true
    },
    participantData: {
      immediate: true,
      handler(newV, oldV) {
        if (newV) {
130
          this.$set(this.propForm, 'description', newV.description)
wangdanlei's avatar
wangdanlei committed
131 132 133 134 135 136 137 138 139 140
          this.newParticipantData = newV
        }
      },
      deep: true
    },
    'propForm.routerSelect': {
      handler(val) {
        if (val) {
          this.$set(this.newParticipantData, 'selectRoute', val)
          const findRouteItem = this.routes.find(m => { return m.name === val })
wangdanlei's avatar
wangdanlei committed
141 142
          this.required = !!(findRouteItem && findRouteItem.isCheckForm)
          this.isCheckParticipant = !!(findRouteItem && findRouteItem.isCheckParticipant)
wangdanlei's avatar
wangdanlei committed
143 144 145 146 147 148 149 150 151 152
          this.$emit('routeSelect', val)
        }
      },
      immediate: true
    }
  },
  mounted() {
  },
  methods: {
    setOptions(routes) {
wangdanlei's avatar
wangdanlei committed
153
      this.routeFormCache = {}
wangdanlei's avatar
wangdanlei committed
154 155 156 157
      this.routeOptions = routes.map(item => {
        if (item.isDefault) {
          this.propForm.routerSelect = item.name
        }
wangdanlei's avatar
wangdanlei committed
158
        this.routeFormCache[item.name] = null
wangdanlei's avatar
wangdanlei committed
159 160 161 162 163 164 165 166 167 168
        return {
          label: item.displayName,
          value: item.name
        }
      })
    },
    submit() {
      if (this.$refs['form'].validate()) {
        const partValidate = this.$refs.participants.$refs.participants.validate()
        const routeValidate = this.$refs.form.validate()
wangdanlei's avatar
wangdanlei committed
169 170 171 172 173 174 175 176 177 178 179 180
        const variables = {}
        const taskVariables = {}
        const variableForm = this.$refs.variableFormDealing.$refs.form.form
        if (this.basicData.basicInfo.variableFormInfo && this.basicData.basicInfo.variableFormInfo.length && variableForm && Object.keys(variableForm).length) {
          this.basicData.basicInfo.variableFormInfo.forEach(item => {
            if (item.variableType === '全局变量') {
              this.$set(variables, item.name, variableForm[item.name])
            } else {
              this.$set(taskVariables, item.name, variableForm[item.name])
            }
          })
        }
wangdanlei's avatar
wangdanlei committed
181
        Promise.all([partValidate, routeValidate]).then((result) => {
wangdanlei's avatar
wangdanlei committed
182 183 184 185
          if (!this.isSaveBeforeSubmit) {
            this.$utils.showMessageError('请保存盘点结果')
            return false
          }
wangdanlei's avatar
wangdanlei committed
186 187 188 189 190 191 192 193 194
          const params = {
            'operationName': 'completeTask',
            'operator': localStorage.getItem('userId'),
            'description': this.propForm.description || '',
            'id': this.basicData.basicInfo.id,
            'processDefinitionId': this.basicData.basicInfo.processDefinitionId,
            'processInstId': this.basicData.basicInfo.processInstanceId,
            'routerSelect': this.propForm.routerSelect,
            'taskDefinitionKey': this.basicData.basicInfo.taskDefinitionKey,
wangdanlei's avatar
wangdanlei committed
195 196 197
            'participants': this.$refs['participants'].$refs.participants.form,
            'variables': variables,
            'taskVariables': taskVariables
wangdanlei's avatar
wangdanlei committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
          }
          this.$emit('finishTask', true, params)
        }).catch((error) => {
          console.log('error', error)
          this.$utils.showMessageError('请检查带*的必填项是否填写')
        })
      }
    }
  }
}
</script>

<style lang="scss">
.bjs-powered-by{
  visibility: hidden;
}
.routeDealing-com{
    display:flex;
    justify-content: flex-start;
    flex-wrap:wrap;
    font-size: 13px;
    padding-left: 20px;
    .dee-form2{
      width:100%;
      box-sizing: border-box;
    }
    .finish-btn{
wangdanlei's avatar
wangdanlei committed
225
      margin: 10px auto 24px;
wangdanlei's avatar
wangdanlei committed
226 227 228
    }
}
</style>