Files
laws_weilai/jero-web/src/views/businessSupport/problemKnowledgeBase/components/problemKnowledgeBaseAdd.vue
T

769 lines
25 KiB
Java

<template>
<div class="doc-detail">
<div class="doc-detail-wrap">
<div class="doc-detail-header" style="position: fixed;top: 0">
<div class="doc-detail-title">
<span style="line-height: 66px;display: inline-block;float: left;cursor: pointer" @click="backClick">
<a-icon type="arrow-left" style="margin-right: 6px;"/>
</span>
{{this.$route.query.id ? $t('edit') :$t('newlyAdded')}}
</div>
</div>
<div style="padding-top: 68px;background: #fff">
<div class="detail-content" style="padding: 24px">
<a-form-model :model="formInline" class="formAdd" :rules="rules" ref="ruleForm">
<a-row :gutter="24">
<a-col :span="8">
<div class="box-title-text">
<div class="title-text">
<span class="Required">*</span>
<span class="title-text-text" :title="$t('title')">{{$t('title')}}</span>
</div>
<a-form-model-item class="itemModel" prop="title">
<a-input class="box-input"
:disabled="disabled"
v-model.trim="formInline.title"
:placeholder="$t('PleaseEnter')+$t('title')"/>
</a-form-model-item>
</div>
</a-col>
<a-col :span="8">
<div class="box-title-text">
<div class="title-text">
<span class="Required">*</span>
<span class="title-text-text"
:title="$t('problemClassification')">{{$t('problemClassification')}}</span>
</div>
<a-form-model-item class="itemModel" prop="problemType">
<a-select :placeholder="$t('PleaseSelect')+$t('problemClassification')"
@change="problemTypeChange"
v-model="formInline.problemType">
<a-select-option v-for="(item, key) in problemTypeList"
:key="key"
:value="item.id">
<span class="selectText" :title="item.problemLabel ">
{{item.problemLabel}}
</span>
</a-select-option>
</a-select>
</a-form-model-item>
</div>
</a-col>
<a-col :span="8">
<div class="box-title-text">
<div class="title-text">
<span class="Required">*</span>
<span class="title-text-text" :title="$t('market')">{{$t('market')}}</span>
</div>
<a-form-model-item class="itemModel" prop="targetMarket">
<j-multi-select-tag class="box-input" v-model="formInline.targetMarket"
:disabled="disabled"
:placeholder="$t('PleaseSelect')+$t('market')"
:type="'select'"
:triggerChange="false" :dictCode="'region'"/>
</a-form-model-item>
</div>
</a-col>
</a-row>
<a-row :gutter="24">
<a-col :span="8">
<div class="box-title-text">
<div class="title-text">
<span class="Required">*</span>
<span class="title-text-text" :title="$t('displayPermission')">{{$t('displayPermission')}}</span>
</div>
<a-form-model-item class="itemModel" prop="showPermissions">
<a-select :placeholder="$t('PleaseSelect')+$t('displayPermission')"
@change="showPermissionsChange"
v-model="formInline.showPermissions">
<a-select-option v-for="(item, key) in projectNameList"
:key="key"
:value="item.value">
<span class="selectText" :title=" item.name ">
{{ item.name}}
</span>
</a-select-option>
</a-select>
</a-form-model-item>
</div>
</a-col>
<a-col :span="8" v-if="isDisplay">
<div class="box-title-text">
<div class="title-text">
<span class="Required">*</span>
<span class="title-text-text" :title="$t('authorizedUser')">{{$t('authorizedUser')}}</span>
</div>
<a-form-model-item class="itemModel" prop="studioEngineerName">
<PersonnelSelection :query="{db_field_name:'studioEngineer',db_field_txt:$t('authorizedUser')}"
:personneQuery="formInline"
@change="PersonnelSelectionChange"
v-model="formInline.studioEngineerName"/>
</a-form-model-item>
</div>
</a-col>
<a-col :span="8">
<div class="box-title-text">
<div class="title-text">
<span class="title-text-text" :title="$t('standardNo')">{{$t('standardNo')}}</span>
</div>
<a-form-model-item class="itemModel" prop="standNumber">
<a-input class="box-input-index"
:title="formInline.standNumber"
:disabled="true"
v-model="formInline.standNumber"
:placeholder="$t('PleaseEnter')+$t('standardNo')"/>
<a-button class="box-button-index"
:title="$t('bringInDocumentInformation')"
type="primary" @click="bringInDocumentInformationClick">
{{$t('bringInDocumentInformation')}}
</a-button>
</a-form-model-item>
</div>
</a-col>
</a-row>
<a-row :gutter="24">
<a-col :span="24" style="height: 380px">
<div class="box-title-text">
<div class="title-text">
<span class="title-text-text">{{$t('content')}}</span>
</div>
<a-form-model-item style="height: 357px" class="itemModel itemModel-explain" prop="content">
<quill-editor
ref="myQuillEditor"
v-model="formInline.content"
style="height: 300px"
:content="formInline.content"
:options="editorOption"
@blur="quilleditorBlur"
@change="onEditorChange($event)"
/>
</a-form-model-item>
</div>
</a-col>
</a-row>
<a-row :gutter="24">
<a-col :span="8">
<div class="box-title-text">
<div class="title-text">
<span class="title-text-text"
:title="$t('enclosure')">{{$t('enclosure')}}</span>
</div>
<a-form-model-item class="itemModel" prop="prehomoDeliverableTemplate">
<a-button type="primary" class="button-text"
@click="clickButtonToUpload('accessoryFile')">
{{ (formInline.accessoryFile === 'null' || formInline.accessoryFile === ''
||
formInline.accessoryFile == null) ? $t('clickUpload') : $t('viewUploadedFiles')
}}
</a-button>
</a-form-model-item>
</div>
</a-col>
</a-row>
</a-form-model>
<div class="submit-button">
<a-button class="box-button" type="primary" @click="submit">{{$t('submit')}}</a-button>
</div>
</div>
</div>
</div>
<a-upload
name="file"
id="iviewUp"
accept='.png,.jpg,.gif,.jpeg,.pjpeg,.pjp'
:multiple="false"
:action="uploadAction"
:headers="headers"
style="width: 0;display: none"
@change="handleChange"
>
</a-upload>
<JLoading :loading="loading">{{$t('pleaseWaitWhileRunning')}}</JLoading>
<listAddModel ref="listAddModelRef" @listAddModelForm="listAddModelForm"/>
<uploadFile ref="uploadFile" @uploadSuccess="uploadSuccess"/>
</div>
</template>
<script>
import PersonnelSelection from '@/components/PersonnelSelection/index'
import uploadFile from '@/components/uploadFile/file'
import { getAction, postAction, putAction } from '@/api/manage'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import listAddModel from './listAddModel'
import { quillEditor } from 'vue-quill-editor'
import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import axios from 'axios'
const toolbarOptions = [
['bold', 'italic', 'underline', 'strike'], // toggled buttons
['blockquote', 'code-block'],
[{ 'header': 1 }, { 'header': 2 }], // custom button values
[{ 'list': 'ordered' }, { 'list': 'bullet' }],
[{ 'script': 'sub' }, { 'script': 'super' }], // superscript/subscript
[{ 'indent': '-1' }, { 'indent': '+1' }], // outdent/indent
[{ 'direction': 'rtl' }], // text direction
[{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
[{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme
[{ 'font': [] }],
[{ 'align': [] }],
['link', 'image', 'video'],
['clean'] // remove formatting button
]
export default {
name: 'problemKnowledgeBaseAdd',
components: {
PersonnelSelection,
uploadFile,
quillEditor,
listAddModel
},
data() {
return {
formInline: {},
headers: '',
uploadAction: window._CONFIG['domianURL'] + '/sys/common/upload',
loading: false,
problemTypeList: [],
editorOption: { // 富文本框配置
placeholder: '',
theme: 'snow', // or 'bubble'
modules: {
clipboard: {
// 粘贴版,处理粘贴时候带图片
matchers: [[Node.ELEMENT_NODE, this.handleCustomMatcher]]
},
toolbar: {
container: toolbarOptions, // 工具栏
handlers: {
'image': function(value) {
if (value) {
document.querySelector('.ant-upload input').click()
} else {
this.quill.format('image', false)
}
}
}
}
}
},
rules: {
showPermissions: [
{
required: true,
message: this.$t('displayPermission') + this.$t('cannotEmpty'),
trigger: 'change'
}
],
studioEngineerName: [
{
required: true,
message: this.$t('authorizedUser') + this.$t('cannotEmpty'),
trigger: 'change'
}
],
title: [
{
required: true,
message: this.$t('title') + this.$t('cannotEmpty'),
trigger: 'blur'
},
{
max: 100,
message: this.$t('title') + this.$t('cannotExceed') + 100 + this.$t('Characters'),
trigger: 'blur'
}
],
problemType: [
{
required: true,
message: this.$t('problemClassification') + this.$t('cannotEmpty'),
trigger: 'change'
}
],
targetMarket: [
{
required: true,
message: this.$t('market') + this.$t('cannotEmpty'),
trigger: 'change'
}
],
content: [
{
max: 5000,
message: this.$t('content') + this.$t('cannotExceed') + 5000 + this.$t('Characters'),
trigger: 'blur'
}
]
},
url: {
add: '/problemKnowledgeBase/problemKnowledgeBaseEO/add',
edit: '/problemKnowledgeBase/problemKnowledgeBaseEO/edit'
},
isDisplay: false,
disabled: false,
projectNameList: [
{
value: 'Open',
name: this.$t('OpenOne')
},
{
value: 'Privacy',
name: this.$t('Privacy')
}
],
content: '<h2>I am Example</h2>'
}
},
created() {
const token = Vue.ls.get(ACCESS_TOKEN)
this.headers = { 'X-Access-Token': token }
},
computed: {
editor() {
return this.$refs.myQuillEditor.quill
}
},
mounted() {
this.getBase()
if (this.$route.query.id) {
this.queryById()
document.title = this.$t('problemKnowledgeBase') + this.$t('edit')
} else {
document.title = this.$t('problemKnowledgeBase') + this.$t('newlyAdded')
}
let quill = this.$refs.myQuillEditor.quill
this.$forceUpdate()
quill.root.addEventListener(
'paste',
(evt) => {
if (
evt.clipboardData &&
evt.clipboardData.files &&
evt.clipboardData.files.length
) {
evt.preventDefault();
[].forEach.call(evt.clipboardData.files, (file) => {
if (!file.type.match(/^image\/(gif|jpe?g|a?png|bmp)/i)) {
return
}
const formData = new FormData()
formData.append('file', file)
axios({
url: this.uploadAction,
method: 'post',
data: formData,
headers: {
'Content-Type': 'multipart/form-data',
'X-Access-Token': Vue.ls.get(ACCESS_TOKEN)
}
})
.then((res) => {
if (res.data.success){
let quill = this.$refs.myQuillEditor.quill
let length = quill.getSelection().index
let fileName = res.data.result.fileName
let index1 = fileName.lastIndexOf('.')
let index2 = fileName.length
let fileSuffix = fileName.substring(index1, index2)
quill.insertEmbed(length, 'image', window._CONFIG['domianPreviewURL'] + '/sys/common/download/' + res.data.result.id + fileSuffix)
quill.setSelection(length + 1)
}
})
})
}
},
false
)
},
methods: {
quilleditorBlur() {
this.$refs.ruleForm.validateField('content')
},
handleCustomMatcher(node, Delta) {
let ops = []
Delta.ops.forEach(op => {
if (op.insert && typeof op.insert === 'string') {// 如果粘贴了图片,这里会是一个对象,如果是字符串则可以添加
ops.push({
insert: op.insert
})
}
})
Delta.ops = ops
return Delta
},
getBase() {
getAction('/problemKnowledgeBase/problemKnowledgeBaseClassifyEO/list', {}).then((res) => {
if (res.success) {
this.problemTypeList = res.result || []
} else {
this.problemTypeList = []
}
})
},
problemTypeChange(event) {
let content = this.problemTypeList.filter(res => {
return res.id == event
})
this.formInline.problemTypeName = content[0].problemLabel
this.formInline = { ...this.formInline }
},
queryById() {
let query = {
id: this.$route.query.id
}
getAction('/problemKnowledgeBase/problemKnowledgeBaseEO/queryById', query).then((res) => {
if (res.success) {
this.formInline = res.result || {}
if (this.formInline.showPermissions == 'Privacy') {
this.isDisplay = true
if (this.formInline.permissionUserList && this.formInline.permissionUserList.length > 0) {
let userId = []
let userName = []
this.formInline.permissionUserList.forEach(val => {
userId.push(val.userId)
userName.push(val.userName)
})
this.formInline.studioEngineerName = userName.join(',')
this.formInline.studioEngineer = userId.join(',')
}
} else {
this.isDisplay = false
}
this.formInline = { ...this.formInline }
} else {
this.formInline = {}
}
})
},
backClick() {
this.$router.go(-1)
}
,
showPermissionsChange(event, name) {
if (event == 'Open') {
this.isDisplay = false
} else {
this.isDisplay = true
}
}
,
onEditorBlur(quill) {
console.log('editor blur!', quill)
}
,
onEditorFocus(quill) {
console.log('editor focus!', quill)
}
,
onEditorReady(quill) {
console.log('editor ready!', quill)
}
,
onEditorChange({ quill, html, text }) {
console.log(html)
console.log(quill)
console.log(text)
this.formInline.content = html
}
,
PersonnelSelectionChange(value, id) {
this.formInline[value] = id
this.formInline = { ...this.formInline }
}
,
handleInput(value) {
this.$nextTick(() => {
this.formInline = { ...this.formInline }
this.$refs.ruleForm.validateField([value])
})
}
,
bringInDocumentInformationClick() {
this.$refs.listAddModelRef.addModel(this.formInline)
}
,
listAddModelForm(id, number) {
this.formInline.standNumber = number
this.formInline.bussDocumentLibraryId = id
this.formInline = { ...this.formInline }
},
handleChange(info) {
let { file } = info
const status = info.file.status
if (status === 'done') {
let vm = this
let quill = this.$refs.myQuillEditor.quill
let length = quill.getSelection().index
let fileName = file.response.result.fileName
let index1 = fileName.lastIndexOf('.')
let index2 = fileName.length
let fileSuffix = fileName.substring(index1, index2)
quill.insertEmbed(length, 'image', window._CONFIG['domianPreviewURL'] + '/sys/common/download/' + file.response.result.id + fileSuffix)
quill.setSelection(length + 1)
this.quillUpdateImg = false
} else if (status === 'uploading') {
}
},
clickButtonToUpload(item) {
this.$refs.uploadFile.perentHandleFunc()
this.$refs.uploadFile.visible = true
this.uploadName = item
getAction('sys/common/getFileInfos', { id: this.formInline[item] }).then((res) => {
if (res.success) {
this.$refs.uploadFile.perentHandleFunc(res.result)
} else {
this.$refs.uploadFile.perentHandleFunc()
}
})
}
,
/** 上传文件的回调 */
uploadSuccess(data) {
let attIdList = []
if (data && data.length > 0) {
data.map(item => {
attIdList.push(item.id || data.name)
})
}
/** 赋值给当前对应的表单文件 */
this.formInline[this.uploadName] = attIdList.join(',')
this.formInline = { ...this.formInline }
}
,
submit() {
this.$refs.ruleForm.validate(valid => {
if (valid) {
let formInline = JSON.parse(JSON.stringify(this.formInline))
this.loading = true
this.confirmLoading = true
let url = ''
let Action
if (this.formInline.id) {
url = this.url.edit
Action = putAction
} else {
url = this.url.add
Action = postAction
}
formInline.permissionUserList = []
if (formInline.showPermissions == 'Privacy') {
let studioEngineer = formInline.studioEngineer.split(',')
studioEngineer.forEach(res => {
formInline.permissionUserList.push({
userId: res
})
})
}
Action(url, formInline).then((res) => {
if (res.success) {
this.$message.success(this.$t('OperationSuccessful'))
this.loading = false
if (this.$route.query.id) {
this.$router.push({
path: '/problemKnowledgeBaseRelease'
})
} else {
this.$router.push({
path: '/problemknowledgeBase'
})
}
} else {
this.loading = false
this.$message.warning(this.$t('operationFailed'))
}
})
}
})
}
}
}
</script>
<style scoped lang="less">
@import '~@assets/less/common.less';
.doc-detail {
background: #fff;
height: 100%;
.doc-detail-wrap {
.doc-detail-header {
width: 100%;
height: 68px;
line-height: 68px;
padding: 0 0 0 32px;
box-sizing: border-box;
display: flex;
justify-content: space-between;
border-bottom: 2px #eff1f3 solid;
z-index: 1000;
background: #fff;
.doc-detail-title {
display: inline-block;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
font-size: 20px;
font-weight: 400;
color: #040B29;
line-height: 68px;
}
.doc-detail-right {
width: 800px;
line-height: 68px;
display: flex;
.doc-detail-btn {
margin-left: 10px;
}
}
}
.content-box {
padding: 0 32px;
box-sizing: border-box;
}
.header-text {
font-size: 16px;
font-weight: 400;
height: 80px;
color: #000F16;
line-height: 80px;
}
.processBackground-text {
font-size: 16px;
color: #000F16;
}
}
}
.box-title-text {
line-height: 1.4;
display: flex;
/*align-items: center;*/
}
.title-text {
width: 114px;
text-align: right;
display: inline-block;
font-weight: 500;
font-size: 14px;
margin-right: 16px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
height: 42px;
line-height: 48px;
}
.box-input {
display: inline-block;
height: 38px;
width: 100%;
}
.itemModel {
width: calc(100% - 130px);
display: inline-block;
margin-top: 2px;
height: 40px;
margin-bottom: 24px;
}
.Required {
color: red;
margin-right: 4px;
}
.title-text-text {
margin-top: 9px;
}
.formAdd {
margin-bottom: 40px;
}
.button-text {
height: 38px;
width: calc(100% - 100px);
line-height: 38px;
background: #fff;
border: 1px #00B3BE solid;
color: #00B3BE;
}
.box-button {
height: 38px;
margin-top: 4px;
}
.box-button-index {
height: 38px;
margin-top: 2px;
width: 120px;
overflow: hidden;
padding: 0 0;
float: right;
text-align: center;
}
::v-deep .box-button-index span {
display: inline-block;
width: 100px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
margin-top: 4px;
text-align: center;
}
.submit-button {
width: 100%;
margin-top: 20px;
text-align: right;
padding: 0 32px;
box-sizing: border-box;
}
::v-deep .itemModel-explain .ant-form-explain {
margin-top: 60px
}
::v-deep .ql-tooltip {
z-index: 10 !important;
}
::v-deep .ql-snow .ql-picker {
height: 36px;
}
.selectText {
width: 100%;
display: inline-block;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
word-break: break-word;
}
.box-input-index {
width: calc(100% - 130px);
display: inline-block;
height: 38px;
margin-right: 10px;
}
</style>