You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
271 lines
9.1 KiB
271 lines
9.1 KiB
|
6 years ago
|
import AbstractForm from '@/component/AbstractForm'
|
||
|
|
import AbstractFormItem from "@/component/AbstractForm/AbstractFormItem"
|
||
|
|
import AbstractTable from "@/component/AbstractTable"
|
||
|
|
import DocDetailHeader from "@/component/biz/doc/DocDetailHeader"
|
||
|
|
import DocDetailFooter from "@/component/biz/doc/DocDetailFooter"
|
||
|
|
import DocHistory from '@/component/biz/doc/DocHistory'
|
||
|
|
import DocSteps from '@/component/biz/doc/DocSteps'
|
||
|
|
import FormAnchor from "@/component/AbstractForm/FormAnchor"
|
||
|
|
import FormCard from '@/component/AbstractForm/FormCard'
|
||
|
|
import FormValidateInfo from "@/component/AbstractForm/FormValidateInfo"
|
||
|
|
import UploadFile from '@/component/UploadFile'
|
||
|
|
import {commonMethods} from "@/mixin/docTableMixin"
|
||
|
|
import {isEmpty, mergeObj} from '@/util'
|
||
|
|
import {elAlert, elConfirm, elPrompt, elSuccess} from "@/util/message"
|
||
|
|
import {deleteUpload} from "@/util/file"
|
||
|
|
import {auth} from "@/util/auth"
|
||
|
|
import {closeCurrentPage} from "@/util/route"
|
||
|
6 years ago
|
|
||
|
|
export default {
|
||
|
6 years ago
|
components: {
|
||
|
|
AbstractForm,
|
||
|
|
AbstractFormItem,
|
||
|
|
AbstractTable,
|
||
|
|
DocDetailHeader,
|
||
|
|
DocDetailFooter,
|
||
|
|
DocHistory,
|
||
|
|
DocSteps,
|
||
|
6 years ago
|
FormAnchor,
|
||
|
|
FormCard,
|
||
|
|
FormValidateInfo,
|
||
|
6 years ago
|
UploadFile
|
||
|
|
},
|
||
|
|
|
||
|
6 years ago
|
props: {
|
||
|
|
//单据id
|
||
|
|
id: String,
|
||
|
6 years ago
|
//编辑模式,see,add,edit
|
||
|
|
type: String
|
||
|
6 years ago
|
},
|
||
|
6 years ago
|
|
||
|
6 years ago
|
data() {
|
||
|
|
return {
|
||
|
6 years ago
|
attachmentSortSeed: 0,
|
||
|
6 years ago
|
loading: true,
|
||
|
|
//单据提交历史
|
||
|
|
history: [],
|
||
|
|
form: {
|
||
|
|
id: null,
|
||
|
|
cid: null,
|
||
|
|
cname: null,
|
||
|
|
ctime: null,
|
||
|
|
vid: null,
|
||
|
|
vname: null,
|
||
|
|
vtime: null,
|
||
|
|
status: 0,
|
||
|
|
remark: null,
|
||
|
|
data: [],
|
||
|
|
imageList: [],
|
||
|
|
uploadImageList: [],
|
||
|
|
deleteImageList: []
|
||
|
|
},
|
||
|
|
rules: {}
|
||
|
|
}
|
||
|
|
},
|
||
|
6 years ago
|
|
||
|
6 years ago
|
computed: {
|
||
|
|
title() {
|
||
|
|
if (isEmpty(this.type)) return ''
|
||
|
|
switch (this.type) {
|
||
|
|
case 'see':
|
||
|
6 years ago
|
return `查看${this.docName}:${this.form.id}`
|
||
|
6 years ago
|
case 'add':
|
||
|
6 years ago
|
return `添加${this.docName}`
|
||
|
6 years ago
|
case 'edit':
|
||
|
6 years ago
|
return `编辑${this.docName}:${this.form.id}`
|
||
|
6 years ago
|
}
|
||
|
|
},
|
||
|
|
user() {
|
||
|
|
return this.$store.state.user
|
||
|
|
},
|
||
|
|
|
||
|
6 years ago
|
//权限判断以及根据状态控制是否可编辑
|
||
|
6 years ago
|
canSave() {
|
||
|
|
//add模式有添加权限、edit模式有编辑权限且status=0
|
||
|
6 years ago
|
return this.type === 'add' && auth(`${this.baseUrl}/add`)
|
||
|
|
|| this.form.status === 0 && this.type === 'edit' && auth(`${this.baseUrl}/update`)
|
||
|
6 years ago
|
},
|
||
|
|
canCommit() {
|
||
|
|
//有提交权限、add模式或edit模式且status=0
|
||
|
6 years ago
|
return auth(`${this.baseUrl}/commit`)
|
||
|
|
&& (this.type === 'add' || this.type === 'edit' && this.form.status === 0)
|
||
|
6 years ago
|
},
|
||
|
|
canWithdraw() {
|
||
|
|
//有撤回权限、当前用户是创建人、edit模式且status=1
|
||
|
6 years ago
|
return auth(`${this.baseUrl}/withdraw`)
|
||
|
6 years ago
|
&& this.type === 'edit'
|
||
|
|
&& this.user.id === this.form.cid
|
||
|
|
&& this.form.status === 1
|
||
|
|
},
|
||
|
|
canPass() {
|
||
|
|
//有通过权限、edit模式且status=1
|
||
|
6 years ago
|
return auth(`${this.baseUrl}/pass`) && this.type === 'edit' && this.form.status === 1
|
||
|
6 years ago
|
},
|
||
|
|
canReject() {
|
||
|
|
//有驳回权限、edit模式且status=1
|
||
|
6 years ago
|
return auth(`${this.baseUrl}/reject`) && this.type === 'edit' && this.form.status === 1
|
||
|
6 years ago
|
}
|
||
|
|
},
|
||
|
6 years ago
|
|
||
|
6 years ago
|
methods: {
|
||
|
|
...commonMethods,
|
||
|
|
|
||
|
|
//保存,分为添加或修改
|
||
|
|
save() {
|
||
|
|
if (this.loading) return
|
||
|
|
this.$refs.form.validate(v => {
|
||
|
|
if (!v) return
|
||
|
|
if (this.validate) {
|
||
|
6 years ago
|
const valid = this.validate()
|
||
|
6 years ago
|
if (!isEmpty(valid)) return elAlert(valid)
|
||
|
|
}
|
||
|
|
this.loading = true
|
||
|
6 years ago
|
const promise = this.type === 'add' ? this.api.add(this.form) : this.api.update(this.form)
|
||
|
6 years ago
|
promise
|
||
|
|
.then(({data, msg}) => {
|
||
|
6 years ago
|
this.needSearch()
|
||
|
6 years ago
|
elSuccess(msg)
|
||
|
6 years ago
|
this.afterSaveOrCommit(data)
|
||
|
6 years ago
|
})
|
||
|
|
.catch(() => this.loading = false)
|
||
|
|
})
|
||
|
|
},
|
||
|
|
|
||
|
|
//提交,状态由拟定->待审核
|
||
|
|
commit() {
|
||
|
|
if (this.loading) return
|
||
|
|
this.$refs.form.validate(v => {
|
||
|
|
if (!v) return
|
||
|
|
if (this.validate) {
|
||
|
6 years ago
|
const valid = this.validate()
|
||
|
6 years ago
|
if (!isEmpty(valid)) return elAlert(valid)
|
||
|
|
}
|
||
|
|
elConfirm('确认提交审核?')
|
||
|
|
.then(() => this.loading = true)
|
||
|
|
.then(() => this.api.commit(this.form))
|
||
|
|
.then(({data, msg}) => {
|
||
|
|
elSuccess(msg)
|
||
|
6 years ago
|
this.needSearch()
|
||
|
|
this.afterSaveOrCommit(data)
|
||
|
6 years ago
|
})
|
||
|
|
.catch(() => this.loading = false)
|
||
|
|
})
|
||
|
|
},
|
||
|
|
|
||
|
|
//撤回自己的单据,状态由待审核->拟定
|
||
|
|
withdraw() {
|
||
|
|
if (this.loading) return
|
||
|
|
elConfirm('确认撤回?')
|
||
|
|
.then(() => {
|
||
|
|
this.loading = true
|
||
|
|
return this.api.withdraw({id: this.form.id, pid: this.form.pid})
|
||
|
|
})
|
||
|
|
.then(({msg}) => {
|
||
|
|
elSuccess(msg)
|
||
|
6 years ago
|
this.needSearch()
|
||
|
6 years ago
|
this.init(this.form.id)
|
||
|
|
})
|
||
|
|
.catch(() => this.loading = false)
|
||
|
|
},
|
||
|
|
|
||
|
|
//通过单据,状态由待审核->已审核
|
||
|
|
pass() {
|
||
|
|
if (this.loading) return
|
||
|
|
elConfirm('确认通过审核?')
|
||
|
|
.then(() => {
|
||
|
|
this.loading = true
|
||
|
|
return this.api.pass({id: this.form.id, pid: this.form.pid})
|
||
|
|
})
|
||
|
|
.then(({msg}) => {
|
||
|
|
elSuccess(msg)
|
||
|
6 years ago
|
this.needSearch()
|
||
|
|
return this.close()
|
||
|
6 years ago
|
})
|
||
|
6 years ago
|
.catch(() => this.loading = false)
|
||
|
6 years ago
|
},
|
||
|
|
|
||
|
|
//驳回单据,状态由待审核->拟定
|
||
|
|
reject() {
|
||
|
|
if (this.loading) return
|
||
|
|
elPrompt('请输入驳回理由')
|
||
|
|
.then(info => {
|
||
|
|
this.loading = true
|
||
|
|
return this.api.reject({id: this.form.id, pid: this.form.pid, info})
|
||
|
|
})
|
||
|
|
.then(({msg}) => {
|
||
|
|
elSuccess(msg)
|
||
|
6 years ago
|
this.needSearch()
|
||
|
|
return this.close()
|
||
|
6 years ago
|
})
|
||
|
6 years ago
|
.catch(() => this.loading = false)
|
||
|
6 years ago
|
},
|
||
|
|
|
||
|
|
//初始化单据信息
|
||
|
|
init(id) {
|
||
|
|
this.loading = true
|
||
|
|
if (isEmpty(id)) {
|
||
|
6 years ago
|
return elAlert(`获取${this.docName}数据失败,请传入id`, this.close)
|
||
|
6 years ago
|
}
|
||
|
|
this.api.getById(id)
|
||
|
|
.then(data => {
|
||
|
|
if (!data || id !== data.id) return Promise.reject()
|
||
|
|
return Promise.resolve(mergeObj(this.form, data))
|
||
|
|
})
|
||
|
6 years ago
|
.then(() => this.afterInit ? this.afterInit() : Promise.resolve())
|
||
|
6 years ago
|
.catch(e => {
|
||
|
|
console.log(e)
|
||
|
6 years ago
|
return elAlert(`获取${this.docName}数据失败,请重试`, this.close)
|
||
|
6 years ago
|
})
|
||
|
|
.finally(() => this.loading = false)
|
||
|
|
},
|
||
|
|
|
||
|
6 years ago
|
//保存、提交成功后需要判断后续动作
|
||
|
|
afterSaveOrCommit(data) {
|
||
|
|
if (this.type === 'add') {
|
||
|
|
const editUrl = `${this.baseUrl}/detail/edit/${data}`
|
||
|
|
return closeCurrentPage(editUrl)
|
||
|
|
}
|
||
|
|
else return this.init(this.form.id)
|
||
|
6 years ago
|
},
|
||
|
|
|
||
|
6 years ago
|
//关闭页面
|
||
|
|
close() {
|
||
|
6 years ago
|
//删除未保存的上传附件
|
||
|
6 years ago
|
const deleteArr = []
|
||
|
6 years ago
|
if (this.form.uploadImageList.length > 0) {
|
||
|
|
deleteArr.push(...this.form.uploadImageList.map(i => i.url))
|
||
|
|
}
|
||
|
|
if (deleteArr.length > 0) {
|
||
|
|
deleteUpload(deleteArr).catch(e => ({}))
|
||
|
|
}
|
||
|
6 years ago
|
|
||
|
6 years ago
|
return closeCurrentPage(this.baseUrl)
|
||
|
6 years ago
|
},
|
||
|
|
|
||
|
6 years ago
|
needSearch() {
|
||
|
|
this.$store.commit('needSearch/emit', this.baseUrl)
|
||
|
6 years ago
|
},
|
||
|
|
|
||
|
|
//附件操作
|
||
|
|
uploadSuccess(file, res) {
|
||
|
6 years ago
|
this.form.uploadImageList.push({
|
||
|
|
url: res.key,
|
||
|
|
name: file.name,
|
||
|
|
sort: this.attachmentSortSeed,
|
||
|
|
size: file.size
|
||
|
|
})
|
||
|
|
this.attachmentSortSeed++
|
||
|
6 years ago
|
},
|
||
|
|
removeUpload(file) {
|
||
|
|
this.form.deleteImageList.push(file.url)
|
||
|
6 years ago
|
const index = this.form.uploadImageList.findIndex(i => i.url === file.url)
|
||
|
6 years ago
|
if (index > -1) this.form.uploadImageList.splice(index, 1)
|
||
|
|
}
|
||
|
6 years ago
|
},
|
||
|
|
|
||
|
|
mounted() {
|
||
|
|
this.loading = false
|
||
|
|
if (this.type !== 'add') return this.init(this.id)
|
||
|
6 years ago
|
}
|
||
|
|
}
|