123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- <template>
- <el-dialog
- class="mydialog"
- :title="templateTitle"
- :visible.sync="dialogVisible"
- width="500px"
- height="60%"
- :before-close="handleClose"
- center
- >
- <div class="dialog-container">
- <div class="dialog-container-item">
- <div class="left-box">{{ templateType }}模板名称:</div>
- <div class="right-box">
- <el-input style="width: 300px" v-model="formData.name"></el-input>
- </div>
- </div>
- <div class="dialog-container-item">
- <div class="left-box">{{ templateType }}模板格式:</div>
- <div class="right-box">
- <el-select placeholder="请选择报表模板格式" v-model="formData.format">
- <el-option
- v-for="item in temFormatOptions"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- ></el-option>
- </el-select>
- </div>
- </div>
- <div class="dialog-container-item" v-if="templateType === '报告'">
- <div class="left-box">{{ templateType }}模板类型</div>
- <div class="right-box">
- <el-select
- placeholder="请选择报表模板格式"
- v-model="formData.reportType"
- >
- <el-option
- v-for="item in reportTypeOptions"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- ></el-option>
- </el-select>
- </div>
- </div>
- <div class="dialog-container-info">
- <div class="left-box">{{ templateType }}模板简介:</div>
- <div class="right-box">
- <el-input
- style="width: 300px"
- type="textarea"
- v-model="formData.introduction"
- ></el-input>
- </div>
- </div>
- <div class="dialog-container-upload">
- <div class="left-box">{{ templateType }}模板上传:</div>
- <div class="right-box">
- <el-upload
- class="upload-demo"
- action="https://jsonplaceholder.typicode.com/posts/"
- :on-success="handleSuccess"
- :before-upload="beforeUpload"
- :on-remove="handleRemove"
- :accept="'.doc,.docx,.xls,.xlsx,.pdf'"
- :file-list="fileList"
- >
- <el-button slot="trigger"
- ><i class="el-icon-upload"></i> 请将文件拖拽或点击上传</el-button
- >
- <div slot="tip" class="el-upload__tip" style="width: 265px;line-height:20px;">
- 仅支持 .doc / .docx / .xls / .xlsx / .pdf 格式的文件
- </div>
- </el-upload>
- </div>
- </div>
- <div class="dialog-container-bottom">
- <el-button class="reset-btn" @click="resetEvent">重置</el-button>
- <el-button class="search-btn" @click="searchEvent">确认</el-button>
- </div>
- </div>
- </el-dialog>
- </template>
- <script>
- /**
- * 添加,编辑模板弹窗 -- 报表配置,报告配置
- */
- export default {
- name: "templatePopup",
- props: {
- templateTitle: {
- type: String,
- default: "",
- },
- templateType: {
- type: String,
- default: "",
- },
- },
- data() {
- return {
- fileList:[],
- dialogVisible: false,
- formData: {
- name: "",
- format: "Excel",
- introduction: "",
- id: "",
- reportType: "",
- templateType: 0,
- file: "",
- },
- temFormatOptions: [
- {
- value: "Word",
- label: "Word",
- },
- {
- value: "Excel",
- label: "Excel",
- },
- {
- value: "PDF",
- label: "PDF",
- },
- ],
- reportTypeOptions: [
- {
- value: "",
- label: "未知",
- },
- {
- value: "年度报告",
- label: "年度报告",
- },
- {
- value: "季度报告",
- label: "季度报告",
- },
- {
- value: "月度报告",
- label: "月度报告",
- },
- ],
- };
- },
- methods: {
- resetEvent() {
- this.formData.name = "";
- this.formData.format = "Excel";
- this.formData.introduction = "";
- this.formData.reportType = "";
- this.formData.file = "";
- this.fileList=[]
- },
- searchEvent() {
- this.$emit("confirmEvent", this.formData);
- },
- handleClose(){
- this.fileList=[]
- this.dialogVisible = false
- },
- beforeUpload(file) {
- const isAllowedSize = file.size / 1024 / 1024 < 10; // 限制文件大小小于10MB
- const isAllowedType = [".doc", ".docx", ".xls", ".xlsx", ".pdf"].includes(
- file.name
- .substring(file.name.lastIndexOf("."), file.name.length)
- .toLowerCase()
- ); // 限制文件格式
- if (!isAllowedSize) {
- this.$message.error("文件大小超过限制");
- return false;
- }
- if (!isAllowedType) {
- this.$message.error("文件格式不支持");
- return false;
- }
- return true;
- },
- handleRemove(file,fileList){
- this.fileList=[]
- },
- handleSuccess(response, file, fileList) {
- this.formData.file = file.raw;
- this.fileList.push(file)
- },
- },
- };
- </script>
- <style lang="less" scoped>
- /deep/.el-dialog__header {
- padding: 20px 20px 16px;
- border-bottom: 1px solid #f2f2f2;
- text-align: left;
- font-size: 16px;
- font-weight: 600;
- color: #333;
- }
- /deep/.el-dialog__body {
- .dialog-container {
- &-item,
- &-upload,
- &-info {
- margin: 0 auto;
- width: 90%;
- margin-bottom: 20px;
- display: flex;
- align-items: center;
- .left-box {
- height: 100%;
- width: 30%;
- font-size: 14px;
- line-height: 27px;
- }
- .right-box {
- height: 100%;
- width: 30%;
- }
- }
- &-item {
- height: 40px;
- }
- &-info {
- height: 60px;
- }
- &-upload {
- height: 95px;
- }
- &-bottom {
- margin: 0 auto;
- width: 60%;
- height: 40px;
- display: flex;
- align-items: center;
- justify-content: space-around;
- .reset-btn,
- .search-btn {
- height: 30px;
- width: 90px;
- color: #fff;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .reset-btn {
- background-color: #b3b3b3;
- }
- .search-btn {
- background-color: #2ea8e6;
- }
- }
- }
- }
- </style>
|