<template> <el-dialog :visible.sync="dialogFormVisible" title="派发工单" append-to-body width="40%"> <el-form class="form" label-width="auto"> <el-row> <el-col :span="16" :offset="4"> <el-form-item label="请选择组织单位:"> <dept-select v-model="deptId" :need-top="false" :dept-show="true" dept-type="03" placeholder="选择组织单位" @input="selectDept"/> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="16" :offset="4"> <el-form-item v-show="showUser" label="请选择维护人员:"> <el-select v-model="account" class="selcet" placeholder="请选择维护人员"> <el-option v-for="user in userList" :key="user.account" :label="user.name" :value="user.account"/> </el-select> </el-form-item> </el-col> </el-row> <el-row> <el-col :span="2" :offset="4"> <el-form-item> <el-button type="primary" class="sumit-button" @click="distribute()">提交</el-button> </el-form-item> </el-col> </el-row> </el-form> </el-dialog> </template> <script> import { getMaintainer, maintainDistribute } from '@/api/job' import DeptSelect from '@/components/DeptSelect' export default { name: 'Distribute', components: { DeptSelect }, data() { return { dialogFormVisible: false, selections: [], account: '', userList: [], deptId: '' } }, computed: { showUser() { return this.deptId } }, methods: { initDialog(dialogFormVisible, selections) { this.dialogFormVisible = true this.selections = selections // console.log(this.selections) // const res = await getMaintainer() // this.userList = res.data }, async selectDept(deptId) { this.account = '' const res = await getMaintainer(deptId) this.userList = res.data }, distribute() { if (!this.account) { return this.$message.error('请选择巡检人员') } const jobIds = [] this.selections.forEach(function(value, index) { jobIds.push(value.id) }) this.$confirm('确认派发吗?', '提示', { confirmButtonText: '是', cancelButtonText: '否', type: 'info' }).then(() => { maintainDistribute(jobIds, this.account).then(response => { if (response.code === 200) { this.$store.dispatch('GetJobCount') this.$emit('watchData') this.$message.success('派发成功') this.dialogFormVisible = false } else { this.$message.error(response.message) } }) }).catch(() => { }) } } } </script> <style scoped> </style>