importGuideModal.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <a-modal
  3. centered
  4. class="importGuide-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="导入费用明细"
  8. v-model="isShow"
  9. @cancel="isShow=false"
  10. :width="800">
  11. <div class="importGuide-con">
  12. <div class="explain-con">
  13. <div class="explain-item">
  14. <div class="explain-tit">
  15. <span>1</span>准备导入
  16. </div>
  17. <ul>
  18. <li>1) 导入的Excel文件中必须包含名为“记账类型”、“记账名称”、“费用承担方类型”、“费用承担方”、“费用承担金额”的列,且名称必须相同</li>
  19. <li>2) 其他列可根据实际情况填写,如果符合规则,系统会一起导入</li>
  20. </ul>
  21. <a-button type="link" icon="download" style="padding: 0 0 0 23px;" @click="handleExport">下载导入模板</a-button>
  22. </div>
  23. <div class="explain-item">
  24. <div class="explain-tit">
  25. <span>2</span>上传数据文件
  26. </div>
  27. <p>目前支持的文件类型*.xls,*.xlsx.</p>
  28. <div style="overflow: hidden;padding-left: 23px;">
  29. <Upload
  30. id="importGuide-attachList"
  31. ref="importUpload"
  32. :maxNums="1"
  33. fileType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
  34. uploadType="attach"
  35. :action="attachAction"
  36. :uploadParams="uploadParams"
  37. upText="选择导入文件"
  38. @remove="resetSearchForm"
  39. @change="changeImport"></Upload>
  40. </div>
  41. </div>
  42. </div>
  43. <!-- 按钮 -->
  44. <div class="btn-con">
  45. <a-button
  46. type="primary"
  47. id="importGuide-nextStep"
  48. size="large"
  49. class="button-primary"
  50. @click="handlerNextStep"
  51. style="padding: 0 60px;">下一步</a-button>
  52. <a-button
  53. id="importGuide-cancel"
  54. size="large"
  55. class="button-cancel"
  56. @click="isShow=false"
  57. style="padding: 0 60px;margin-left: 15px;">取消</a-button>
  58. </div>
  59. </div>
  60. <!-- 导入 -->
  61. <chooseImportModal :openModal="openImportModal" :paramsData="paramsData" @close="handleClose" @ok="hanldeOk" />
  62. </a-modal>
  63. </template>
  64. <script>
  65. import ChooseImportModal from './chooseImportModal.vue'
  66. import { Upload } from '@/components'
  67. export default {
  68. name: 'ImportGuideModal',
  69. components: { ChooseImportModal, Upload },
  70. props: {
  71. openModal: { // 弹框显示状态
  72. type: Boolean,
  73. default: false
  74. },
  75. params: {
  76. type: Object,
  77. default: null
  78. }
  79. },
  80. data () {
  81. return {
  82. isShow: this.openModal, // 是否打开弹框
  83. openImportModal: false, // 导入
  84. attachAction: process.env.VUE_APP_API_BASE_URL + '/expenseAcctDetail/importDetail',
  85. paramsData: null,
  86. uploadParams: {
  87. savePathType: 'local'
  88. }
  89. }
  90. },
  91. methods: {
  92. // 清空数据
  93. resetSearchForm () {
  94. this.$refs.importUpload.setFileList() // 清空导入文件
  95. this.paramsData = null // 清空上传数据
  96. },
  97. // 下一步
  98. handlerNextStep () {
  99. if (this.paramsData) {
  100. this.openImportModal = true
  101. } else {
  102. this.$message.warning('添加文件后再进行下一步操作!')
  103. }
  104. },
  105. // 上传文件 change
  106. changeImport (file) {
  107. console.log(file, JSON.parse(file))
  108. if (file && JSON.parse(file).length > 0) {
  109. this.paramsData = Object.assign({}, JSON.parse(file)[0] || null, this.params)
  110. } else {
  111. this.paramsData = null
  112. }
  113. console.log(this.paramsData)
  114. },
  115. // 导入
  116. hanldeOk (obj) {
  117. if (obj && obj.length > 0) {
  118. this.$emit('ok', obj)
  119. this.isShow = false
  120. }
  121. },
  122. // 关闭
  123. handleClose () {
  124. this.openImportModal = false
  125. this.isShow = false
  126. },
  127. // 下载模板
  128. handleExport () {
  129. const link = document.createElement('a')
  130. link.style.display = 'none'
  131. link.href = 'https://jg-ocs.oss-cn-beijing.aliyuncs.com/templ/promo/expenseAccountDetailImport.xlsx'
  132. link.setAttribute('download', '费用明细模板' + '.xlsx')
  133. document.body.appendChild(link)
  134. link.click()
  135. document.body.removeChild(link)
  136. }
  137. },
  138. watch: {
  139. // 父页面传过来的弹框状态
  140. openModal (newValue, oldValue) {
  141. this.isShow = newValue
  142. },
  143. // 重定义的弹框状态
  144. isShow (newValue, oldValue) {
  145. if (!newValue) {
  146. this.$emit('close')
  147. this.resetSearchForm()
  148. }
  149. }
  150. }
  151. }
  152. </script>
  153. <style lang="less" scoped>
  154. .importGuide-modal{
  155. .importGuide-con{
  156. .explain-con{
  157. .explain-item{
  158. margin-bottom: 10px;
  159. .explain-tit{
  160. font-weight: bold;
  161. span{
  162. display: inline-block;
  163. width: 18px;
  164. height: 18px;
  165. line-height: 16px;
  166. text-align: center;
  167. margin-right: 5px;
  168. border-radius: 50%;
  169. border: 1px solid rgba(0, 0, 0, 0.3);
  170. }
  171. }
  172. p{
  173. margin: 8px 0;
  174. padding-left: 23px;
  175. }
  176. ul{
  177. list-style: none;
  178. padding: 0;
  179. padding-left: 23px;
  180. margin: 0;
  181. li{
  182. line-height: 26px;
  183. }
  184. }
  185. }
  186. #importGuide-attachList{
  187. width: 100%;
  188. }
  189. }
  190. .btn-con{
  191. margin: 10px 0 20px;
  192. text-align: center;
  193. .button-cancel{
  194. font-size: 12px;
  195. }
  196. }
  197. }
  198. }
  199. </style>