|
@@ -245,10 +245,10 @@
|
|
|
type="primary"
|
|
|
@click="previewTemplate(scope.row)"
|
|
|
>预览</el-button>
|
|
|
- <el-button
|
|
|
+ <!-- <el-button
|
|
|
type="primary"
|
|
|
@click="replaceTemplate(scope.row)"
|
|
|
- >替换</el-button>
|
|
|
+ >替换</el-button> -->
|
|
|
<el-dropdown
|
|
|
style="margin-left: 10px"
|
|
|
trigger="click"
|
|
@@ -371,7 +371,9 @@ import {
|
|
|
htmlWordNew,
|
|
|
createDocument,
|
|
|
searchlistDoc,
|
|
|
- getDocumentInfo
|
|
|
+ getDocumentInfo,
|
|
|
+ updateDocument,
|
|
|
+ searchlistDocTemplate
|
|
|
} from '@/api/document'
|
|
|
import { searchCustomer } from '@/api/customer'
|
|
|
import { searchProduct } from '@/api/product'
|
|
@@ -552,9 +554,23 @@ export default {
|
|
|
|
|
|
// 更新导出方法
|
|
|
async exportDocumentWithHtmlDocx(template) {
|
|
|
- console.log(template);
|
|
|
+ /* console.log(template); */
|
|
|
+ const res = await searchlistDocTemplate({
|
|
|
+ /* page: 1,
|
|
|
+ pageSize: 10, */
|
|
|
+ project_id:this.currentData.id,
|
|
|
+ id: template.id
|
|
|
+ })
|
|
|
+ if(res.status!==200) return
|
|
|
+ let templateData
|
|
|
try {
|
|
|
- const templateData = JSON.parse(template.data || '[]')
|
|
|
+ if(res.data.documents.length!==0){
|
|
|
+ templateData = JSON.parse(res.data.documents[0].data || '[]')
|
|
|
+ }else{
|
|
|
+ const template_Data = await getDocumentInfo({id:template.id})
|
|
|
+ if(template_Data.status!==200) return
|
|
|
+ templateData = JSON.parse(template_Data.data.data || '[]')
|
|
|
+ }
|
|
|
const contentContainer = document.createElement('div')
|
|
|
contentContainer.className = 'content'
|
|
|
|
|
@@ -1715,7 +1731,7 @@ export default {
|
|
|
viewBoundTemplates(row) {
|
|
|
this.currentData = row
|
|
|
this.boundTemplateLoading = true
|
|
|
- searchTemplateList({ ids: row.documentIds.join(',') || 0 })
|
|
|
+ searchTemplateListNoData({ ids: row.documentIds.join(',') || 0 })
|
|
|
.then((res) => {
|
|
|
if (res.status === 200) {
|
|
|
this.boundTemplateList = res.data
|
|
@@ -1728,18 +1744,20 @@ export default {
|
|
|
},
|
|
|
|
|
|
async previewTemplate(template) {
|
|
|
+ console.log(template);
|
|
|
this.currentTemplate = template
|
|
|
/* this.loadDocumentVersions(template); */
|
|
|
- const res = await searchlistDoc({
|
|
|
- page: 1,
|
|
|
- pageSize: 10,
|
|
|
- template_id: template.id
|
|
|
+ const res = await searchlistDocTemplate({
|
|
|
+ /* page: 1,
|
|
|
+ pageSize: 10, */
|
|
|
+ project_id:this.currentData.id,
|
|
|
+ id: template.id
|
|
|
})
|
|
|
|
|
|
if (res.status === 200) {
|
|
|
/* this.documentVersions = res.data.dataList[0]; */
|
|
|
- if (res.data.dataList.length !== 0) {
|
|
|
- const url = `#/document/viewCreate?articleId=${res.data.dataList[0].id}&type=document`
|
|
|
+ if (res.data.documents.length !== 0) {
|
|
|
+ const url = `#/document/viewCreate?articleId=${res.data.documents[0].id}&type=document`
|
|
|
window.open(url, '_blank')
|
|
|
} else {
|
|
|
const a = document.createElement('a')
|
|
@@ -1814,12 +1832,25 @@ export default {
|
|
|
// 依次处理每个选中的模版
|
|
|
for (const template of this.selectedBoundTemplates) {
|
|
|
this.docAttr = template
|
|
|
-
|
|
|
+ const res = await searchlistDocTemplate({
|
|
|
+ /* page: 1,
|
|
|
+ pageSize: 10, */
|
|
|
+ project_id:this.currentData.id,
|
|
|
+ id: template.id
|
|
|
+ })
|
|
|
+ if(res.status!== 200) return
|
|
|
// 检查模板数据格式
|
|
|
let templateData
|
|
|
try {
|
|
|
// 优先尝试使用 data 字段
|
|
|
- templateData = JSON.parse(template.data || '[]')
|
|
|
+ if(res.data.documents.length!==0){
|
|
|
+ templateData = JSON.parse(res.data.documents[0].data || '[]')
|
|
|
+ }else{
|
|
|
+ const template_Data = await getDocumentInfo({id:template.id})
|
|
|
+ if(template_Data.status!==200) return
|
|
|
+ templateData = JSON.parse(template_Data.data.data || '[]')
|
|
|
+ }
|
|
|
+
|
|
|
} catch (e) {
|
|
|
// 如果解析失败,尝试使用 content 字段
|
|
|
templateData = template.content
|
|
@@ -2006,7 +2037,7 @@ export default {
|
|
|
},
|
|
|
|
|
|
/* 更新 */
|
|
|
- onUpload() {
|
|
|
+ async onUpload() {
|
|
|
const _this = this
|
|
|
if (_this.TemList.length <= 0) {
|
|
|
_this.$message.error('增加组件')
|
|
@@ -2016,6 +2047,14 @@ export default {
|
|
|
_this.$message.error('请填写模版标题')
|
|
|
return
|
|
|
}
|
|
|
+ const res = await searchlistDocTemplate({
|
|
|
+ /* page: 1,
|
|
|
+ pageSize: 10, */
|
|
|
+ project_id:this.currentData.id,
|
|
|
+ id: _this.docAttr.id
|
|
|
+ })
|
|
|
+ if(res.status!==200) return
|
|
|
+ if(res.data.documents.length==0){
|
|
|
_this.docAttr.title = _this.docAttr.title + new Date().getTime()
|
|
|
_this.docAttr.links = JSON.stringify(_this.docAttr.linkProduct)
|
|
|
_this.docAttr.projects = JSON.stringify(_this.docAttr.linkProject)
|
|
@@ -2034,6 +2073,23 @@ export default {
|
|
|
pageSize: 999
|
|
|
})
|
|
|
})
|
|
|
+ }else{
|
|
|
+ updateDocument({
|
|
|
+ id:res.data.documents[0].id,
|
|
|
+ data :JSON.stringify(_this.TemList),
|
|
|
+ title:res.data.documents[0].title,
|
|
|
+ status:5,
|
|
|
+ document_type:res.data.documents[0].document_type,
|
|
|
+ is_template:0,
|
|
|
+ template_id:res.data.documents[0].template_id,
|
|
|
+ user_id:res.data.documents[0].user_id
|
|
|
+ }).then(res=>{
|
|
|
+ if (res.status != 200) return
|
|
|
+ _this.$message.success('文档更新成功')
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
},
|
|
|
|
|
|
// 添加统一的内容处理方法
|