| ¶Ô±ÈÐÂÎļþ | 
 |  |  | 
 |  |  | <template> | 
 |  |  |   <el-dialog | 
 |  |  |     width="500px" | 
 |  |  |     :title="title" | 
 |  |  |     :visible.sync="visible" | 
 |  |  |     append-to-body | 
 |  |  |     custom-class="eva-dialog import-window" | 
 |  |  |     :close-on-click-modal="false" | 
 |  |  |     :close-on-press-escape="false" | 
 |  |  |     :show-close="false" | 
 |  |  |   > | 
 |  |  |     <el-upload | 
 |  |  |       drag | 
 |  |  |       :show-file-list="false" | 
 |  |  |       action="none" | 
 |  |  |       accept=".xlsx" | 
 |  |  |       :before-upload="handleBeforeUpload" | 
 |  |  |     > | 
 |  |  |       <template v-if="form.file == null"> | 
 |  |  |         <i class="el-icon-upload"></i> | 
 |  |  |         <div class="el-upload__text">å°æä»¶æå°æ¤å¤ï¼æ<em>ç¹å»ä¸ä¼ </em></div> | 
 |  |  |       </template> | 
 |  |  |       <template v-else> | 
 |  |  |         <i class="el-icon-files"></i> | 
 |  |  |         <div class="el-upload__text">{{form.file.name}}<em></em></div> | 
 |  |  |       </template> | 
 |  |  |     </el-upload> | 
 |  |  |     <div slot="footer" class="import-window__footer"> | 
 |  |  |       <div class="sync-exists"> | 
 |  |  |         <el-checkbox v-model="form.sync"/><span>忥已åå¨çæ°æ®</span> | 
 |  |  |       </div> | 
 |  |  |       <div class="opera"> | 
 |  |  |         <el-button type="text" icon="el-icon-download" @click="downloadTemplate">ä¸è½½æ¨¡ç</el-button> | 
 |  |  |         <el-button @click="cancel">{{cancelText}}</el-button> | 
 |  |  |         <el-button type="primary" @click="confirm" :loading="isWorking">{{confirmText}}</el-button> | 
 |  |  |       </div> | 
 |  |  |     </div> | 
 |  |  |   </el-dialog> | 
 |  |  | </template> | 
 |  |  |  | 
 |  |  | <script> | 
 |  |  | import request from '@/utils/request' | 
 |  |  | import { downloadLocalFile } from '@/api/system/common' | 
 |  |  | export default { | 
 |  |  |   name: 'ImportWindow', | 
 |  |  |   props: { | 
 |  |  |     // å¯¼å
¥æ¥å£å°å | 
 |  |  |     action: { | 
 |  |  |       required: true | 
 |  |  |     }, | 
 |  |  |     // ç¡®è®¤æé®ææ¡ | 
 |  |  |     confirmText: { | 
 |  |  |       type: String, | 
 |  |  |       default: '导å
¥' | 
 |  |  |     }, | 
 |  |  |     // åæ¶æé®ææ¡ | 
 |  |  |     cancelText: { | 
 |  |  |       type: String, | 
 |  |  |       default: 'åæ¶' | 
 |  |  |     }, | 
 |  |  |     // æ¨¡çå°å | 
 |  |  |     templatePath: { | 
 |  |  |       required: true | 
 |  |  |     }, | 
 |  |  |     // ä¸è½½åçæ¨¡çæä»¶åç§° | 
 |  |  |     templateName: { | 
 |  |  |       required: true | 
 |  |  |     } | 
 |  |  |   }, | 
 |  |  |   data () { | 
 |  |  |     return { | 
 |  |  |       visible: false, | 
 |  |  |       isWorking: false, | 
 |  |  |       title: '导å
¥æ°æ®', | 
 |  |  |       form: { | 
 |  |  |         sync: false, | 
 |  |  |         file: false | 
 |  |  |       } | 
 |  |  |     } | 
 |  |  |   }, | 
 |  |  |   methods: { | 
 |  |  |     /** | 
 |  |  |      * æå¼çªå£ | 
 |  |  |      * | 
 |  |  |      * @param title çªå£æ é¢ | 
 |  |  |      */ | 
 |  |  |     open (title) { | 
 |  |  |       this.visible = true | 
 |  |  |       this.title = title | 
 |  |  |       this.form.sync = false | 
 |  |  |       this.form.file = null | 
 |  |  |     }, | 
 |  |  |     /** | 
 |  |  |      * ç¡®å®å¯¼å
¥ | 
 |  |  |      */ | 
 |  |  |     confirm () { | 
 |  |  |       if (this.form.file == null) { | 
 |  |  |         this.$tip.warning('è¯·éæ©æä»¶') | 
 |  |  |         return | 
 |  |  |       } | 
 |  |  |       this.isWorking = true | 
 |  |  |       const param = new FormData() | 
 |  |  |       param.set('file', this.form.file) | 
 |  |  |       param.set('sync', this.form.sync) | 
 |  |  |       request.post(this.action, param, { | 
 |  |  |         headers: { | 
 |  |  |           'Content-Type': 'multipart/form-data;charset=UTF-8' | 
 |  |  |         } | 
 |  |  |       }) | 
 |  |  |         .then(data => { | 
 |  |  |           this.$tip.success('导å
¥æåï¼å
±å¯¼å
¥' + data + 'æ¡è®°å½') | 
 |  |  |           this.visible = false | 
 |  |  |           this.$emit('success') | 
 |  |  |         }) | 
 |  |  |         .catch(e => { | 
 |  |  |           this.$tip.apiFailed(e) | 
 |  |  |         }) | 
 |  |  |         .finally(() => { | 
 |  |  |           this.isWorking = false | 
 |  |  |         }) | 
 |  |  |     }, | 
 |  |  |     /** | 
 |  |  |      * åæ¶ | 
 |  |  |      */ | 
 |  |  |     cancel () { | 
 |  |  |       this.visible = false | 
 |  |  |     }, | 
 |  |  |     /** | 
 |  |  |      * ä¸è½½æ¨¡ç | 
 |  |  |      */ | 
 |  |  |     downloadTemplate () { | 
 |  |  |       downloadLocalFile({ | 
 |  |  |         path: this.templatePath, | 
 |  |  |         name: this.templateName | 
 |  |  |       }) | 
 |  |  |         .then(data => { | 
 |  |  |           this.download(data) | 
 |  |  |         }) | 
 |  |  |         .catch(e => { | 
 |  |  |           this.$tip.apiFailed(e) | 
 |  |  |         }) | 
 |  |  |     }, | 
 |  |  |     /** | 
 |  |  |      * æä»¶ä¸ä¼ ååå¨ä¸ä¼ çæä»¶ | 
 |  |  |      * | 
 |  |  |      * @param file é导å
¥çæä»¶ | 
 |  |  |      */ | 
 |  |  |     handleBeforeUpload (file) { | 
 |  |  |       this.form.file = file | 
 |  |  |       return false | 
 |  |  |     } | 
 |  |  |   } | 
 |  |  | } | 
 |  |  | </script> | 
 |  |  |  | 
 |  |  | <style lang="scss"> | 
 |  |  | @import "../../assets/style/variables"; | 
 |  |  | .import-window { | 
 |  |  |   .el-upload { | 
 |  |  |     width: 100%; | 
 |  |  |     .el-upload-dragger { | 
 |  |  |       width: 100%; | 
 |  |  |       .el-icon-upload, .el-icon-files { | 
 |  |  |         font-size: 67px; | 
 |  |  |         color: #C0C4CC; | 
 |  |  |         margin: 40px 0 16px; | 
 |  |  |         line-height: 50px; | 
 |  |  |       } | 
 |  |  |     } | 
 |  |  |   } | 
 |  |  |   .import-window__footer { | 
 |  |  |     display: flex; | 
 |  |  |     .sync-exists { | 
 |  |  |       width: 200px; | 
 |  |  |       flex-shrink: 0; | 
 |  |  |       text-align: left; | 
 |  |  |       font-size: 13px; | 
 |  |  |       display: flex; | 
 |  |  |       align-items: center; | 
 |  |  |       .el-checkbox { | 
 |  |  |         margin-right: 10px; | 
 |  |  |       } | 
 |  |  |       & > * { | 
 |  |  |         vertical-align: middle; | 
 |  |  |       } | 
 |  |  |     } | 
 |  |  |     .opera { | 
 |  |  |       flex-grow: 1; | 
 |  |  |       a { | 
 |  |  |         font-size: 12px; | 
 |  |  |         margin-right: 10px; | 
 |  |  |         text-decoration: none; | 
 |  |  |         .el-icon-download { | 
 |  |  |           font-size: 15px; | 
 |  |  |           position: relative; | 
 |  |  |           top: 2px; | 
 |  |  |         } | 
 |  |  |       } | 
 |  |  |     } | 
 |  |  |   } | 
 |  |  | } | 
 |  |  | </style> |