2024-10-16 18:15:19 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<AiDetail class="add-label">
|
|
|
|
|
|
<template #title>
|
2024-10-25 15:31:01 +08:00
|
|
|
|
<ai-title title="添加模板" isShowBack :isShowBottomBorder="true" @onBackClick="cancel">
|
2024-10-26 13:55:47 +08:00
|
|
|
|
<template #center>
|
2024-10-25 15:31:01 +08:00
|
|
|
|
<label>模板名称:</label>
|
2024-10-26 13:55:47 +08:00
|
|
|
|
<el-input placeholder="请输入模板名称" size="small" v-model="name" style="width: 200px;"></el-input>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template #rightBtn>
|
2024-10-16 18:15:19 +08:00
|
|
|
|
<el-button @click="preview" size="small" type="danger">预览</el-button>
|
2024-10-26 23:15:03 +08:00
|
|
|
|
<!-- <el-button @click="savePdf" size="small" type="primary">下载pdf</el-button> -->
|
2024-10-16 18:15:19 +08:00
|
|
|
|
<el-button @click="print" size="small">打印</el-button>
|
|
|
|
|
|
<el-button @click="clearPaper" size="small" type="danger">清空纸张</el-button>
|
2024-10-26 22:49:11 +08:00
|
|
|
|
<el-button @click="saveTemplate" size="small" type="primary" :loading="isLoading">保存</el-button>
|
2024-10-16 18:15:19 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</ai-title>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<template #content>
|
|
|
|
|
|
<ai-card title="标签模板" class="card" :hideTitle="true">
|
|
|
|
|
|
<template #content>
|
|
|
|
|
|
<div class="add-label__wrapper">
|
2024-10-27 18:29:16 +08:00
|
|
|
|
<Print
|
|
|
|
|
|
ref="printRef"
|
|
|
|
|
|
:template="template"
|
|
|
|
|
|
:printData="printData"
|
|
|
|
|
|
:isPrint="false"
|
|
|
|
|
|
:params="params">
|
|
|
|
|
|
</Print>
|
2024-10-16 18:15:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</ai-card>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</AiDetail>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
import Print from '@/components/print/Print'
|
2024-10-25 15:31:01 +08:00
|
|
|
|
import template from '@/components/print/template'
|
2024-10-16 18:15:19 +08:00
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
components: {
|
|
|
|
|
|
Print
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
2024-10-25 15:31:01 +08:00
|
|
|
|
name: '',
|
2024-10-27 18:29:16 +08:00
|
|
|
|
template: {
|
|
|
|
|
|
"panels": [{
|
|
|
|
|
|
"index": 0,
|
|
|
|
|
|
"name": 1,
|
|
|
|
|
|
"height": 200,
|
|
|
|
|
|
"width": 200,
|
|
|
|
|
|
"paperHeader": 0,
|
|
|
|
|
|
"paperFooter": 547,
|
|
|
|
|
|
"printElements": [],
|
|
|
|
|
|
"paperNumberLeft": 500,
|
|
|
|
|
|
"paperNumberTop": 530,
|
|
|
|
|
|
"paperNumberDisabled": true,
|
|
|
|
|
|
"paperNumberContinue": true,
|
|
|
|
|
|
"fontFamily": "Microsoft YaHei",
|
|
|
|
|
|
"scale": 1,
|
|
|
|
|
|
"watermarkOptions": {}
|
|
|
|
|
|
}]
|
|
|
|
|
|
},
|
2024-10-26 22:49:11 +08:00
|
|
|
|
printData: {},
|
|
|
|
|
|
id: '',
|
2024-10-27 18:29:16 +08:00
|
|
|
|
info: {},
|
|
|
|
|
|
params: [],
|
2024-10-26 22:49:11 +08:00
|
|
|
|
isLoading: false
|
2024-10-26 13:55:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
|
|
this.printData = {
|
|
|
|
|
|
labelCode: 96778555251,
|
|
|
|
|
|
productSkuId: 6606980005,
|
|
|
|
|
|
skuExtCode: 'AAA1100mWh-orange',
|
|
|
|
|
|
skuSpecName: '8pcs'
|
2024-10-16 18:15:19 +08:00
|
|
|
|
}
|
2024-10-27 18:29:16 +08:00
|
|
|
|
|
|
|
|
|
|
if (this.$route.query.id) {
|
|
|
|
|
|
this.id = this.$route.query.id
|
|
|
|
|
|
|
|
|
|
|
|
this.getInfo()
|
|
|
|
|
|
}
|
2024-10-16 18:15:19 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
cancel() {
|
|
|
|
|
|
this.$router.go(-1)
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2024-10-27 18:29:16 +08:00
|
|
|
|
getInfo () {
|
|
|
|
|
|
this.$http.post(`/api/template/detail?id=${this.$route.query.id}`).then(res => {
|
|
|
|
|
|
if (res.code === 0) {
|
|
|
|
|
|
this.info = res.data
|
|
|
|
|
|
this.name = res.data.name
|
|
|
|
|
|
this.params = JSON.parse(res.data.params)
|
|
|
|
|
|
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
this.template = JSON.parse(res.data.content)
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
|
2024-10-16 18:15:19 +08:00
|
|
|
|
preview () {
|
2024-10-26 22:49:11 +08:00
|
|
|
|
this.$refs.printRef.preview()
|
2024-10-16 18:15:19 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
savePdf () {
|
|
|
|
|
|
this.$refs.printRef.savePdf()
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
rotatePaper () {
|
|
|
|
|
|
this.$refs.printRef.rotatePaper()
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
saveTemplate () {
|
2024-10-25 15:31:01 +08:00
|
|
|
|
if (!this.name) {
|
|
|
|
|
|
return this.$message.error('模板名称不能为空')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-26 22:49:11 +08:00
|
|
|
|
const data = this.$refs.printRef.save()
|
|
|
|
|
|
this.isLoading = true
|
2024-10-27 18:29:16 +08:00
|
|
|
|
|
|
|
|
|
|
const url = this.id ? `/api/template/modify` : `/api/template/addTemplate`
|
|
|
|
|
|
this.$http.post(url, {
|
2024-10-26 22:49:11 +08:00
|
|
|
|
name: this.name,
|
|
|
|
|
|
codes: data.html,
|
|
|
|
|
|
content: JSON.stringify(data.json),
|
2024-10-27 18:29:16 +08:00
|
|
|
|
params: data.params,
|
|
|
|
|
|
id: this.id || ''
|
2024-10-26 22:49:11 +08:00
|
|
|
|
}).then(res => {
|
|
|
|
|
|
if (res.code === 0) {
|
|
|
|
|
|
this.isLoading = false
|
2024-10-27 18:29:16 +08:00
|
|
|
|
this.$message.success('模板创建成功')
|
|
|
|
|
|
this.cancel()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.isLoading = false
|
2024-10-26 22:49:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
2024-10-16 18:15:19 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
2024-10-26 13:55:47 +08:00
|
|
|
|
print() {
|
2024-10-16 18:15:19 +08:00
|
|
|
|
this.$refs.printRef.print()
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
clearPaper () {
|
|
|
|
|
|
this.$refs.printRef.clearPaper()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
.add-label {
|
|
|
|
|
|
::v-deep(.ai-detail__content--wrapper) {
|
|
|
|
|
|
max-width: 100%;
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
margin: 0 20px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.card {
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
|
|
|
|
::v-deep(.ai-card__body) {
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.add-label__wrapper {
|
|
|
|
|
|
padding-bottom: 20px;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|