templatePopup.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <el-dialog
  3. class="mydialog"
  4. :title="templateTitle"
  5. :visible.sync="dialogVisible"
  6. width="500px"
  7. height="60%"
  8. :before-close="handleClose"
  9. center
  10. >
  11. <div class="dialog-container">
  12. <div class="dialog-container-item">
  13. <div class="left-box">{{ templateType }}模板名称:</div>
  14. <div class="right-box">
  15. <el-input style="width: 300px" v-model="formData.name"></el-input>
  16. </div>
  17. </div>
  18. <div class="dialog-container-item">
  19. <div class="left-box">{{ templateType }}模板格式:</div>
  20. <div class="right-box">
  21. <el-select placeholder="请选择报表模板格式" v-model="formData.format">
  22. <el-option
  23. v-for="item in temFormatOptions"
  24. :key="item.value"
  25. :label="item.label"
  26. :value="item.value"
  27. ></el-option>
  28. </el-select>
  29. </div>
  30. </div>
  31. <div class="dialog-container-item" v-if="templateType === '报告'">
  32. <div class="left-box">{{ templateType }}模板类型</div>
  33. <div class="right-box">
  34. <el-select
  35. placeholder="请选择报表模板格式"
  36. v-model="formData.reportType"
  37. >
  38. <el-option
  39. v-for="item in reportTypeOptions"
  40. :key="item.value"
  41. :label="item.label"
  42. :value="item.value"
  43. ></el-option>
  44. </el-select>
  45. </div>
  46. </div>
  47. <div class="dialog-container-info">
  48. <div class="left-box">{{ templateType }}模板简介:</div>
  49. <div class="right-box">
  50. <el-input
  51. style="width: 300px"
  52. type="textarea"
  53. v-model="formData.introduction"
  54. ></el-input>
  55. </div>
  56. </div>
  57. <div class="dialog-container-upload">
  58. <div class="left-box">{{ templateType }}模板上传:</div>
  59. <div class="right-box">
  60. <el-upload
  61. class="upload-demo"
  62. action="https://jsonplaceholder.typicode.com/posts/"
  63. :on-success="handleSuccess"
  64. :before-upload="beforeUpload"
  65. :on-remove="handleRemove"
  66. :accept="'.doc,.docx,.xls,.xlsx,.pdf'"
  67. :file-list="fileList"
  68. >
  69. <el-button slot="trigger"
  70. ><i class="el-icon-upload"></i> 请将文件拖拽或点击上传</el-button
  71. >
  72. <div slot="tip" class="el-upload__tip" style="width: 265px;line-height:20px;">
  73. 仅支持 .doc / .docx / .xls / .xlsx / .pdf 格式的文件
  74. </div>
  75. </el-upload>
  76. </div>
  77. </div>
  78. <div class="dialog-container-bottom">
  79. <el-button class="reset-btn" @click="resetEvent">重置</el-button>
  80. <el-button class="search-btn" @click="searchEvent">确认</el-button>
  81. </div>
  82. </div>
  83. </el-dialog>
  84. </template>
  85. <script>
  86. /**
  87. * 添加,编辑模板弹窗 -- 报表配置,报告配置
  88. */
  89. export default {
  90. name: "templatePopup",
  91. props: {
  92. templateTitle: {
  93. type: String,
  94. default: "",
  95. },
  96. templateType: {
  97. type: String,
  98. default: "",
  99. },
  100. },
  101. data() {
  102. return {
  103. fileList:[],
  104. dialogVisible: false,
  105. formData: {
  106. name: "",
  107. format: "Excel",
  108. introduction: "",
  109. id: "",
  110. reportType: "",
  111. templateType: 0,
  112. file: "",
  113. },
  114. temFormatOptions: [
  115. {
  116. value: "Word",
  117. label: "Word",
  118. },
  119. {
  120. value: "Excel",
  121. label: "Excel",
  122. },
  123. {
  124. value: "PDF",
  125. label: "PDF",
  126. },
  127. ],
  128. reportTypeOptions: [
  129. {
  130. value: "",
  131. label: "未知",
  132. },
  133. {
  134. value: "年度报告",
  135. label: "年度报告",
  136. },
  137. {
  138. value: "季度报告",
  139. label: "季度报告",
  140. },
  141. {
  142. value: "月度报告",
  143. label: "月度报告",
  144. },
  145. ],
  146. };
  147. },
  148. methods: {
  149. resetEvent() {
  150. this.formData.name = "";
  151. this.formData.format = "Excel";
  152. this.formData.introduction = "";
  153. this.formData.reportType = "";
  154. this.formData.file = "";
  155. this.fileList=[]
  156. },
  157. searchEvent() {
  158. this.$emit("confirmEvent", this.formData);
  159. },
  160. handleClose(){
  161. this.fileList=[]
  162. this.dialogVisible = false
  163. },
  164. beforeUpload(file) {
  165. const isAllowedSize = file.size / 1024 / 1024 < 10; // 限制文件大小小于10MB
  166. const isAllowedType = [".doc", ".docx", ".xls", ".xlsx", ".pdf"].includes(
  167. file.name
  168. .substring(file.name.lastIndexOf("."), file.name.length)
  169. .toLowerCase()
  170. ); // 限制文件格式
  171. if (!isAllowedSize) {
  172. this.$message.error("文件大小超过限制");
  173. return false;
  174. }
  175. if (!isAllowedType) {
  176. this.$message.error("文件格式不支持");
  177. return false;
  178. }
  179. return true;
  180. },
  181. handleRemove(file,fileList){
  182. this.fileList=[]
  183. },
  184. handleSuccess(response, file, fileList) {
  185. this.formData.file = file.raw;
  186. this.fileList.push(file)
  187. },
  188. },
  189. };
  190. </script>
  191. <style lang="less" scoped>
  192. /deep/.el-dialog__header {
  193. padding: 20px 20px 16px;
  194. border-bottom: 1px solid #f2f2f2;
  195. text-align: left;
  196. font-size: 16px;
  197. font-weight: 600;
  198. color: #333;
  199. }
  200. /deep/.el-dialog__body {
  201. .dialog-container {
  202. &-item,
  203. &-upload,
  204. &-info {
  205. margin: 0 auto;
  206. width: 90%;
  207. margin-bottom: 20px;
  208. display: flex;
  209. align-items: center;
  210. .left-box {
  211. height: 100%;
  212. width: 30%;
  213. font-size: 14px;
  214. line-height: 27px;
  215. }
  216. .right-box {
  217. height: 100%;
  218. width: 30%;
  219. }
  220. }
  221. &-item {
  222. height: 40px;
  223. }
  224. &-info {
  225. height: 60px;
  226. }
  227. &-upload {
  228. height: 95px;
  229. }
  230. &-bottom {
  231. margin: 0 auto;
  232. width: 60%;
  233. height: 40px;
  234. display: flex;
  235. align-items: center;
  236. justify-content: space-around;
  237. .reset-btn,
  238. .search-btn {
  239. height: 30px;
  240. width: 90px;
  241. color: #fff;
  242. display: flex;
  243. align-items: center;
  244. justify-content: center;
  245. }
  246. .reset-btn {
  247. background-color: #b3b3b3;
  248. }
  249. .search-btn {
  250. background-color: #2ea8e6;
  251. }
  252. }
  253. }
  254. }
  255. </style>