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.

324 lines
11 KiB

6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
  1. <template>
  2. <div class="customer-css">
  3. <el-dialog :title="titleCon" :close-on-click-modal="false" :visible.sync="visible" @close="handleDialogClose" 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" v-if="pageData.flag !== 'poPartPrint'">
  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. </el-option>
  14. </el-select>
  15. </el-form-item>
  16. <el-row>
  17. <el-col :span="24">
  18. <el-upload class="customer-upload" drag action="javascript:void(0);" ref="uploadFile" :limit="1" accept=".xlsx,.xls"
  19. :before-upload="beforeUploadHandle" :on-change="onChange" :auto-upload="false" style="text-align: left;">
  20. <i class="el-icon-upload"></i>
  21. <div class="el-upload__text">将文件拖到此处<em>点击上传</em></div>
  22. </el-upload>
  23. </el-col>
  24. </el-row>
  25. </el-form>
  26. <span slot="footer" class="dialog-footer">
  27. <el-button type="primary" @click="saveUploadFile()" :loading="uploadLoading">保存</el-button>
  28. <el-button type="primary" @click="closeDialog">关闭</el-button>
  29. </span>
  30. </el-dialog>
  31. </div>
  32. </template>
  33. <script>
  34. import {
  35. uploadExcel, // 导入项目文件
  36. uploadTemplateExcel, // 导入模板文件
  37. uploadPartAttributeExcel, // 导入物料属性文件
  38. queryFileId, // 查询文件ID
  39. getSiteAndBuByUserName
  40. } from "@/api/qc/qc.js"
  41. import { uploadPoPartPrintExcel, queryFileIdWms } from '@/api/wms/wms.js'
  42. import { downLoadObjectFile } from '@/api/eam/eam_object_list.js'
  43. import axios from 'axios'
  44. import Vue from 'vue'
  45. export default {
  46. data() {
  47. return {
  48. titleCon: '文件导入',
  49. visible: false,
  50. fileList: [],
  51. bu: '',
  52. userBuList:[],
  53. uploadLoading: false, // 上传loading状态
  54. pageData: {
  55. flag: '',
  56. createBy: '',
  57. site: ''
  58. },
  59. }
  60. },
  61. created(){
  62. this.getSiteAndBu();
  63. },
  64. methods: {
  65. // 获取用户的bu
  66. getSiteAndBu () {
  67. let tempData = {
  68. username: this.$store.state.user.name,
  69. }
  70. getSiteAndBuByUserName(tempData).then(({data}) => {
  71. if (data.code === 0) {
  72. this.userBuList = data.rows
  73. }
  74. })
  75. },
  76. //初始化组件的参数
  77. init(currentRow) {
  78. // 获得类别
  79. this.pageData = JSON.parse(JSON.stringify(currentRow))
  80. //打开页面
  81. this.visible = true;
  82. },
  83. // 上传之前
  84. beforeUploadHandle(file) {
  85. let extName = file[0].name.substring(file[0].name.lastIndexOf('.')).toLowerCase()
  86. if (!(extName === '.xlsx' || extName === '.xls')) {
  87. this.$message.error('数据导入失败,请选择正确的xlsx模板文件')
  88. return false
  89. }
  90. },
  91. /*选择上传文件时*/
  92. onChange(file){
  93. this.fileList.push(file);
  94. },
  95. /*关闭modal*/
  96. closeDialog(){
  97. // 清空文件列表数据
  98. this.fileList = [];
  99. // 清空 el-upload 组件的文件列表
  100. if (this.$refs.uploadFile) {
  101. this.$refs.uploadFile.clearFiles();
  102. }
  103. // 重置 BU 选择
  104. this.bu = '';
  105. // 重置loading状态
  106. this.uploadLoading = false;
  107. // 刷新报工的页面
  108. this.$emit('refreshPageTables');
  109. // 关闭当前的页面
  110. this.visible = false;
  111. },
  112. /*对话框关闭事件 - 确保清理所有数据*/
  113. handleDialogClose(){
  114. // 清空文件列表数据
  115. this.fileList = [];
  116. // 清空 el-upload 组件的文件列表
  117. if (this.$refs.uploadFile) {
  118. this.$refs.uploadFile.clearFiles();
  119. }
  120. // 重置 BU 选择
  121. this.bu = '';
  122. // 重置loading状态
  123. this.uploadLoading = false;
  124. // 重置 pageData
  125. this.pageData = {
  126. flag: '',
  127. createBy: '',
  128. site: ''
  129. };
  130. },
  131. /*保修当前的数据*/
  132. saveUploadFile(){
  133. if (this.pageData.flag !== 'poPartPrint' && (this.bu === '' || this.bu == null)){
  134. this.$message.warning("请选择BU!");
  135. return false;
  136. }
  137. /*判断文件是否上传*/
  138. if(null == this.fileList || 0 == this.fileList.length){
  139. this.$message.error("请先上传文件!");
  140. return false;
  141. }
  142. // 开启loading
  143. this.uploadLoading = true;
  144. const formData = new FormData();
  145. formData.append("file", this.fileList[0].raw);
  146. formData.append("createBy", this.pageData.createBy);
  147. formData.append("site", this.pageData.site);
  148. if (this.pageData.flag === 'item'){
  149. uploadExcel(formData).then(({data}) => {
  150. if (data.code === 0) {
  151. this.$message.success(data.msg);
  152. // 清空文件上传记录
  153. this.$refs.uploadFile.clearFiles();
  154. // 关闭窗口并刷新页面
  155. this.closeDialog();
  156. }else {
  157. this.$message.warning(data.msg);
  158. }
  159. }).catch((error) => {
  160. this.$message.error('上传失败:' + (error.message || '网络错误'));
  161. }).finally(() => {
  162. // 关闭loading
  163. this.uploadLoading = false;
  164. })
  165. } else if (this.pageData.flag === 'template') {
  166. formData.set('site',this.bu)
  167. uploadTemplateExcel(formData).then(({data}) => {
  168. if (data.code === 0) {
  169. this.$message.success(data.msg);
  170. // 清空文件上传记录
  171. this.$refs.uploadFile.clearFiles();
  172. // 关闭窗口并刷新页面
  173. this.closeDialog();
  174. }else {
  175. this.$message.warning(data.msg);
  176. }
  177. }).catch((error) => {
  178. this.$message.error('上传失败:' + (error.message || '网络错误'));
  179. }).finally(() => {
  180. // 关闭loading
  181. this.uploadLoading = false;
  182. })
  183. } else if (this.pageData.flag === 'partAttribute') {
  184. uploadPartAttributeExcel(formData).then(({data}) => {
  185. if (data.code === 0) {
  186. this.$message.success(data.msg);
  187. // 清空文件上传记录
  188. this.$refs.uploadFile.clearFiles();
  189. // 关闭窗口并刷新页面
  190. this.closeDialog();
  191. } else {
  192. this.$message.warning(data.msg);
  193. }
  194. }).catch((error) => {
  195. this.$message.error('上传失败:' + (error.message || '网络错误'));
  196. }).finally(() => {
  197. // 关闭loading
  198. this.uploadLoading = false;
  199. })
  200. } else if (this.pageData.flag === 'poPartPrint') {
  201. // 采购标签导入
  202. formData.append("buNo", this.pageData.buNo);
  203. formData.append("orderNo", this.pageData.orderNo);
  204. formData.append("partNo", this.pageData.partNo);
  205. formData.append("partDesc", this.pageData.partDesc);
  206. formData.append("poOrderNo", this.pageData.poOrderNo);
  207. formData.append("poItemNo", this.pageData.poItemNo);
  208. formData.append("supplierId", this.pageData.supplierId);
  209. formData.append("supplierName", this.pageData.supplierName);
  210. formData.append("orderQty", this.pageData.orderQty);
  211. formData.append("inspectionNo", this.pageData.inspectionNo);
  212. uploadPoPartPrintExcel(formData).then(({data}) => {
  213. if (data.code === 0) {
  214. this.$message.success(data.msg);
  215. // 清空文件上传记录
  216. this.$refs.uploadFile.clearFiles();
  217. // 关闭窗口并刷新页面
  218. this.closeDialog();
  219. } else {
  220. this.$message.warning(data.msg);
  221. }
  222. }).catch((error) => {
  223. this.$message.error('上传失败:' + (error.message || '网络错误'));
  224. }).finally(() => {
  225. // 关闭loading
  226. this.uploadLoading = false;
  227. })
  228. }
  229. // 不要在这里重置 bu,因为已经在 closeDialog 中重置了
  230. },
  231. // 下载
  232. async downloadFile(){
  233. let file = {
  234. id: 0,
  235. fileName: ''
  236. }
  237. let tempData = {
  238. orderRef1: '',
  239. orderRef2: ''
  240. }
  241. if (this.pageData.flag === 'item') { // 检验项目
  242. tempData.orderRef1 = 'qc';
  243. tempData.orderRef2 = 'itemFormat';
  244. await queryFileId(tempData).then(({data}) => {
  245. if (data && data.code === 0) {
  246. file.id = data.data.id
  247. file.fileName = data.data.fileName
  248. } else {
  249. this.$alert(data.msg, '错误', {
  250. confirmButtonText: '确定'
  251. })
  252. }
  253. })
  254. } else if (this.pageData.flag === 'template') { // 检验模板
  255. tempData.orderRef1 = 'qc';
  256. tempData.orderRef2 = 'templateFormat';
  257. await queryFileId(tempData).then(({data}) => {
  258. if (data && data.code === 0) {
  259. file.id = data.data.id
  260. file.fileName = data.data.fileName
  261. } else {
  262. this.$alert(data.msg, '错误', {
  263. confirmButtonText: '确定'
  264. })
  265. }
  266. })
  267. } else if (this.pageData.flag === 'partAttribute') { // 物料属性设置
  268. tempData.orderRef1 = 'qc';
  269. tempData.orderRef2 = 'partAttributeFormat';
  270. await queryFileId(tempData).then(({data}) => {
  271. if (data && data.code === 0) {
  272. file.id = data.data.id
  273. file.fileName = data.data.fileName
  274. } else {
  275. this.$alert(data.msg, '错误', {
  276. confirmButtonText: '确定'
  277. })
  278. }
  279. })
  280. } else if (this.pageData.flag === 'poPartPrint') { // 采购标签导入
  281. tempData.orderRef1 = 'wms';
  282. tempData.orderRef2 = 'PoPartPrint';
  283. await queryFileIdWms(tempData).then(({data}) => {
  284. if (data && data.code === 0) {
  285. file.id = data.data.id
  286. file.fileName = data.data.fileName
  287. } else {
  288. this.$alert(data.msg, '错误', {
  289. confirmButtonText: '确定'
  290. })
  291. }
  292. })
  293. }
  294. await downLoadObjectFile(file).then(({data}) => {
  295. console.log(file)
  296. // 不限制文件下载类型
  297. const blob = new Blob([data], {type: "application/octet-stream"})
  298. // 下载文件名称
  299. const fileName = file.fileName
  300. // a标签下载
  301. const linkNode = document.createElement('a')
  302. // a标签的download属性规定下载文件的名称
  303. linkNode.download = fileName
  304. linkNode.style.display = 'none'
  305. // 生成一个Blob URL
  306. linkNode.href = URL.createObjectURL(blob)
  307. document.body.appendChild(linkNode)
  308. // 模拟在按钮上的一次鼠标单击
  309. linkNode.click()
  310. // 释放URL 对象
  311. URL.revokeObjectURL(linkNode.href)
  312. document.body.removeChild(linkNode)
  313. })
  314. },
  315. }
  316. }
  317. </script>
  318. <style scoped lang="scss">
  319. </style>