赫艾前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

263 lines
8.7 KiB

  1. <template>
  2. <div class="customer-css">
  3. <el-dialog :title="titleCon" :close-on-click-modal="false" :visible.sync="visible" width="390px" style="height: 520px;" class="customer-dialog">
  4. <el-form :inline="true" label-position="top" label-width="80px">
  5. <el-button type="primary" @click="downloadFile()">下载文件模板</el-button>
  6. <el-form-item label="BU">
  7. <el-select v-model="bu" placeholder="请选择" style="width: 295px">
  8. <el-option
  9. v-for = "i in userBuList"
  10. :key = "i.buNo"
  11. :label = "i.sitename"
  12. :value = "i.buNo">
  13. <span style="float: left;width: 100px">{{ i.sitename }}</span>
  14. <span style="float: right; color: #8492a6;white-space:nowrap;overflow:hidden;text-overflow:ellipsis; font-size: 11px;">
  15. {{ i.buDesc }}
  16. </span>
  17. </el-option>
  18. </el-select>
  19. </el-form-item>
  20. <el-row>
  21. <el-col :span="24">
  22. <el-upload class="customer-upload" drag action="javascript:void(0);" ref="uploadFile" :limit="1" accept=".xlsx,.xls"
  23. :before-upload="beforeUploadHandle" :on-change="onChange" :auto-upload="false" style="text-align: left;">
  24. <i class="el-icon-upload"></i>
  25. <div class="el-upload__text">将文件拖到此处<em>点击上传</em></div>
  26. </el-upload>
  27. </el-col>
  28. </el-row>
  29. </el-form>
  30. <span slot="footer" class="dialog-footer">
  31. <el-button type="primary" @click="saveUploadFile()">保存</el-button>
  32. <el-button type="primary" @click="closeDialog">关闭</el-button>
  33. </span>
  34. </el-dialog>
  35. </div>
  36. </template>
  37. <script>
  38. import {
  39. uploadExcel, // 导入项目文件
  40. uploadTemplateExcel, // 导入模板文件
  41. uploadPartAttributeExcel, // 导入物料属性文件
  42. uploadFamilyAttributeExcel, // 导入类别属性文件
  43. queryFileId, // 查询文件ID
  44. getSiteAndBuByUserName
  45. } from "@/api/qc/qc.js"
  46. import { downLoadObjectFile } from '@/api/eam/eam_object_list.js'
  47. import axios from 'axios'
  48. import Vue from 'vue'
  49. export default {
  50. data() {
  51. return {
  52. titleCon: '文件导入',
  53. visible: false,
  54. fileList: [],
  55. bu: '',
  56. userBuList:[],
  57. pageData: {
  58. flag: '',
  59. createBy: '',
  60. site: ''
  61. },
  62. }
  63. },
  64. created(){
  65. this.getSiteAndBu();
  66. },
  67. methods: {
  68. // 获取用户的bu
  69. getSiteAndBu () {
  70. let tempData = {
  71. username: this.$store.state.user.name,
  72. }
  73. getSiteAndBuByUserName(tempData).then(({data}) => {
  74. if (data.code === 0) {
  75. this.userBuList = data.rows
  76. }
  77. })
  78. },
  79. //初始化组件的参数
  80. init(currentRow) {
  81. // 获得类别
  82. this.pageData = JSON.parse(JSON.stringify(currentRow))
  83. //打开页面
  84. this.visible = true;
  85. },
  86. // 上传之前
  87. beforeUploadHandle(file) {
  88. let extName = file[0].name.substring(file[0].name.lastIndexOf('.')).toLowerCase()
  89. if (!(extName === '.xlsx' || extName === '.xls')) {
  90. this.$message.error('数据导入失败,请选择正确的xlsx模板文件')
  91. return false
  92. }
  93. },
  94. /*选择上传文件时*/
  95. onChange(file){
  96. this.fileList.push(file);
  97. },
  98. /*关闭modal*/
  99. closeDialog(){
  100. this.fileList = [];
  101. // 刷新报工的页面
  102. this.$emit('refreshPageTables');
  103. // 关闭当前的页面
  104. this.visible = false;
  105. },
  106. /*保修当前的数据*/
  107. saveUploadFile(){
  108. if (this.bu==''||this.bu == null){
  109. this.$message.warning("请选择BU!");
  110. return false;
  111. }
  112. /*判断文件是否上传*/
  113. if(null == this.fileList || 0 == this.fileList.length){
  114. this.$message.error("请先上传文件!");
  115. return false;
  116. }
  117. const formData = new FormData();
  118. formData.append("file", this.fileList[0].raw);
  119. formData.append("createBy", this.pageData.createBy);
  120. formData.append("site", this.bu.split('_')[0]);
  121. if (this.pageData.flag === 'item'){
  122. uploadExcel(formData).then(({data}) => {
  123. if (data.code === 0) {
  124. this.$message.success(data.msg);
  125. // 清空文件上传记录
  126. this.$refs.uploadFile.clearFiles();
  127. // 关闭窗口并刷新页面
  128. this.closeDialog();
  129. }else {
  130. this.$message.warning(data.msg);
  131. }
  132. })
  133. } else if (this.pageData.flag === 'template'){
  134. formData.set('site',this.bu)
  135. uploadTemplateExcel(formData).then(({data}) => {
  136. if (data.code === 0) {
  137. this.$message.success(data.msg);
  138. // 清空文件上传记录
  139. this.$refs.uploadFile.clearFiles();
  140. // 关闭窗口并刷新页面
  141. this.closeDialog();
  142. }else {
  143. this.$message.warning(data.msg);
  144. }
  145. })
  146. }else if (this.pageData.flag === 'partAttribute'){
  147. formData.set('site',this.bu)
  148. uploadPartAttributeExcel(formData).then(({data}) => {
  149. if (data.code === 0) {
  150. this.$message.success(data.msg);
  151. // 清空文件上传记录
  152. this.$refs.uploadFile.clearFiles();
  153. // 关闭窗口并刷新页面
  154. this.closeDialog();
  155. }else {
  156. this.$message.warning(data.msg);
  157. }
  158. })
  159. }else if (this.pageData.flag === 'familyAttribute'){
  160. uploadFamilyAttributeExcel(formData).then(({data}) => {
  161. if (data.code === 0) {
  162. this.$message.success(data.msg);
  163. // 清空文件上传记录
  164. this.$refs.uploadFile.clearFiles();
  165. // 关闭窗口并刷新页面
  166. this.closeDialog();
  167. }else {
  168. this.$message.warning(data.msg);
  169. }
  170. })
  171. }
  172. this.bu = '';
  173. },
  174. // 下载
  175. async downloadFile(){
  176. let file = {
  177. id: 0,
  178. fileName: ''
  179. }
  180. let tempData = {
  181. orderRef1: '',
  182. orderRef2: ''
  183. }
  184. if(this.pageData.flag === 'item'){ // 检验项目
  185. tempData.orderRef1 = 'qc';
  186. tempData.orderRef2 = 'itemFormat';
  187. await queryFileId(tempData).then(({data}) => {
  188. if (data && data.code === 0) {
  189. file.id = data.data.id
  190. file.fileName = data.data.fileName
  191. } else {
  192. this.$alert(data.msg, '错误', {
  193. confirmButtonText: '确定'
  194. })
  195. }
  196. })
  197. }else if (this.pageData.flag === 'template'){ // 检验模板
  198. tempData.orderRef1 = 'qc';
  199. tempData.orderRef2 = 'templateFormat';
  200. await queryFileId(tempData).then(({data}) => {
  201. if (data && data.code === 0) {
  202. file.id = data.data.id
  203. file.fileName = data.data.fileName
  204. } else {
  205. this.$alert(data.msg, '错误', {
  206. confirmButtonText: '确定'
  207. })
  208. }
  209. })
  210. }else if (this.pageData.flag === 'partAttribute'){ // 物料属性设置
  211. tempData.orderRef1 = 'qc';
  212. tempData.orderRef2 = 'partAttributeFormat';
  213. await queryFileId(tempData).then(({data}) => {
  214. if (data && data.code === 0) {
  215. file.id = data.data.id
  216. file.fileName = data.data.fileName
  217. } else {
  218. this.$alert(data.msg, '错误', {
  219. confirmButtonText: '确定'
  220. })
  221. }
  222. })
  223. }else if (this.pageData.flag === 'familyAttribute'){ // 类别属性设置
  224. tempData.orderRef1 = 'qc';
  225. tempData.orderRef2 = 'familyAttributeFormat';
  226. await queryFileId(tempData).then(({data}) => {
  227. if (data && data.code === 0) {
  228. file.id = data.data.id
  229. file.fileName = data.data.fileName
  230. } else {
  231. this.$alert(data.msg, '错误', {
  232. confirmButtonText: '确定'
  233. })
  234. }
  235. })
  236. }
  237. await downLoadObjectFile(file).then(({data}) => {
  238. // 不限制文件下载类型
  239. const blob = new Blob([data], {type: "application/octet-stream"})
  240. // 下载文件名称
  241. const fileName = file.fileName
  242. // a标签下载
  243. const linkNode = document.createElement('a')
  244. // a标签的download属性规定下载文件的名称
  245. linkNode.download = fileName
  246. linkNode.style.display = 'none'
  247. // 生成一个Blob URL
  248. linkNode.href = URL.createObjectURL(blob)
  249. document.body.appendChild(linkNode)
  250. // 模拟在按钮上的一次鼠标单击
  251. linkNode.click()
  252. // 释放URL 对象
  253. URL.revokeObjectURL(linkNode.href)
  254. document.body.removeChild(linkNode)
  255. })
  256. },
  257. }
  258. }
  259. </script>
  260. <style scoped lang="scss">
  261. </style>