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.

333 lines
10 KiB

1 year ago
1 year ago
1 year ago
11 months ago
1 year ago
1 year ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. <template>
  2. <div class="customer-css">
  3. <el-dialog :title="titleCon" :close-on-click-modal="false" :visible.sync="visible" width="400px" style="height: 520px;" class="customer-dialog" @close="deleteFile">
  4. <el-form :inline="true" label-position="top" label-width="80px">
  5. <el-row>
  6. <el-form-item label="BU">
  7. <el-select v-model="pageData.buNo" placeholder="请选择" disabled style="width: 120px">
  8. <el-option
  9. v-for = "i in buList"
  10. :key = "i.buNo"
  11. :label = "i.buDesc"
  12. :value = "i.buNo">
  13. </el-option>
  14. </el-select>
  15. </el-form-item>
  16. <el-form-item :label="'CMC Invoice:'">
  17. <el-input v-model="pageData.cmcInvoice" disabled style="width: 120px"></el-input>
  18. </el-form-item>
  19. <el-form-item label=" ">
  20. <!-- <download-excel
  21. :fields="fields()"
  22. :data="exportData"
  23. type="xls"
  24. :name="exportName"
  25. :header="exportHeader"
  26. :footer="exportFooter"
  27. :fetch="createExportData"
  28. :before-generate="startDownload"
  29. :before-finish="finishDownload"
  30. worksheet="导出信息"
  31. class="el-button el-button&#45;&#45;primary el-button&#45;&#45;medium">
  32. {{ '导出模版' }}
  33. </download-excel>-->
  34. <el-button type="primary" @click="exportExcel()">下载文件模板</el-button>
  35. </el-form-item>
  36. </el-row>
  37. <el-row>
  38. <el-col :span="24">
  39. <el-upload class="customer-upload" drag action="javascript:void(0);" ref="uploadFile" :limit="1" accept=".xlsx,.xls"
  40. :before-upload="beforeUploadHandle" :on-change="onChange" :auto-upload="false" style="text-align: left;">
  41. <i class="el-icon-upload"></i>
  42. <div class="el-upload__text">将文件拖到此处<em>点击上传</em></div>
  43. </el-upload>
  44. </el-col>
  45. </el-row>
  46. </el-form>
  47. <span slot="footer" class="dialog-footer">
  48. <el-button type="primary" @click="saveUploadFile">保存</el-button>
  49. <el-button type="primary" @click="closeDialog">关闭</el-button>
  50. </span>
  51. </el-dialog>
  52. </div>
  53. </template>
  54. <script>
  55. import {queryFileId} from "@/api/qc/qc.js"
  56. import {saveCoDelPalletDataByExcel,searchEcssCoDelNotifyDetail} from '@/api/ecss/ecss.js'
  57. import {downLoadObjectFile} from '@/api/eam/eam_object_list.js'
  58. import {getBuList}from '@/api/factory/site.js'
  59. import excel from "@/utils/excel-util.js";
  60. import excelOpts from '@/utils/export-options.js'
  61. export default {
  62. name: 'bomComponentUpload',
  63. data() {
  64. return {
  65. buList: [],
  66. titleCon: '文件导入',
  67. visible: false,
  68. fileList: [],
  69. pageData: {
  70. site: '',
  71. buNo: '',
  72. delNo:'',
  73. cmcInvoice:'',
  74. createBy: this.$store.state.user.name,
  75. },
  76. // 导出 start
  77. exportData: [],
  78. exportName: '装箱数据导入模版',
  79. exportHeader: [""],
  80. exportFooter: [],
  81. // 导出 end
  82. columnList1: [
  83. {
  84. columnProp: "seqNo",
  85. columnLabel: "序号",
  86. },
  87. {
  88. columnProp: "cmcInvoice",
  89. columnLabel: "发票号",
  90. },
  91. {
  92. columnProp: "seqNo",
  93. columnLabel: "托盘号/箱号",
  94. },
  95. {
  96. columnProp: "customerPO",
  97. columnLabel: "PO",
  98. },
  99. {
  100. columnProp: "pn",
  101. columnLabel: "PN",
  102. },
  103. {
  104. columnProp: "qty",
  105. columnLabel: "数量",
  106. },
  107. {
  108. columnProp: "boxQty",
  109. columnLabel: "箱数",
  110. },
  111. {
  112. columnProp: "Rolls",
  113. columnLabel: "Rolls",
  114. },
  115. {
  116. columnProp: "pallet_qty",
  117. columnLabel: "托数",
  118. },
  119. {
  120. columnProp: "length",
  121. columnLabel: "长(M)",
  122. },
  123. {
  124. columnProp: "width",
  125. columnLabel: "宽(M)",
  126. },
  127. {
  128. columnProp: "height",
  129. columnLabel: "高(M)",
  130. },
  131. {
  132. columnProp: "volume",
  133. columnLabel: "体积",
  134. },
  135. {
  136. columnProp: "grossWeight",
  137. columnLabel: "毛重",
  138. },
  139. {
  140. columnProp: "netWeight",
  141. columnLabel: "净重",
  142. }
  143. ],
  144. }
  145. },
  146. methods: {
  147. async exportExcel() {
  148. let searchData={
  149. site: this.pageData.site,
  150. buNo: this.pageData.buNo,
  151. delNo: this.pageData.delNo,
  152. cmcInvoice: this.pageData.cmcInvoice,
  153. shippingMode: this.pageData.shippingMode,
  154. destination : this.pageData.destination,
  155. createBy: this.$store.state.user.name,
  156. }
  157. excel.exportTable({
  158. url: "/select/ecssMapper/searchEcssCoDelNotifyDetail/list",
  159. columnMapping: excelOpts.PalletSku.columnMapping,//可以直接用table,不需要的列就剔除
  160. mergeSetting: [],//需要合并的列
  161. params: searchData,
  162. fileName: this.exportName+".xlsx",
  163. rowFetcher: res => res.data,
  164. columnFormatter: [],
  165. dropColumns: [],//需要剔除的列,例如dropColumns: ["netWeight"],即剔除净重列
  166. });
  167. },
  168. // 初始化组件的参数
  169. init (inData) {
  170. this.fileList = []
  171. let tempData = {
  172. username: this.$store.state.user.name,
  173. }
  174. getBuList(tempData).then(({data}) => {
  175. if (data.code === 0) {
  176. this.buList = data.row2
  177. }
  178. })
  179. console.log(inData)
  180. this.pageData={
  181. site: inData.site,
  182. buNo: inData.buNo,
  183. delNo: inData.delNo,
  184. cmcInvoice: inData.cmcInvoice,
  185. shippingMode: inData.shippingMode,
  186. destination : inData.destination,
  187. walMartOrderFlag: inData.walMartOrderFlag,
  188. createBy: this.$store.state.user.name,
  189. }
  190. // 打开页面
  191. this.visible = true
  192. },
  193. // 上传之前
  194. beforeUploadHandle (file) {
  195. let extName = file[0].name.substring(file[0].name.lastIndexOf('.')).toLowerCase()
  196. if (!(extName === '.xlsx' || extName === '.xls')) {
  197. this.$message.error('数据导入失败,请选择正确的xlsx模板文件')
  198. return false
  199. }
  200. },
  201. // 选择上传文件时
  202. onChange (file) {
  203. this.fileList.push(file)
  204. },
  205. // 关闭modal
  206. closeDialog () {
  207. this.deleteFile()
  208. // 关闭当前的页面
  209. this.visible = false
  210. },
  211. deleteFile(){
  212. this.fileList = []
  213. // 清空文件上传记录
  214. this.$refs.uploadFile.clearFiles()
  215. // 刷新报工的页面
  216. this.$emit('refreshTable')
  217. },
  218. // 保修当前的数据
  219. saveUploadFile () {
  220. // 判断文件是否上传
  221. if (null == this.fileList || 0 === this.fileList.length) {
  222. this.$message.error("请先上传文件!")
  223. return false
  224. }
  225. const formData = new FormData()
  226. formData.append("buNo",this.pageData.buNo)
  227. formData.append("site",this.pageData.site)
  228. formData.append("delNo",this.pageData.delNo)
  229. formData.append("cmcInvoice",this.pageData.cmcInvoice)
  230. formData.append("walMartOrderFlag",this.pageData.walMartOrderFlag)
  231. formData.append("username",this.$store.state.user.name)
  232. formData.append("file", this.fileList[0].raw)
  233. // formData.append("createBy", this.pageData.createBy)
  234. saveCoDelPalletDataByExcel(formData).then(({data}) => {
  235. if (data.code === 0) {
  236. this.$message.success(data.msg)
  237. // 关闭窗口并刷新页面
  238. this.closeDialog()
  239. } else {
  240. this.$alert(data.msg, '错误', {
  241. confirmButtonText: '确定'
  242. })
  243. }
  244. })
  245. },
  246. // 下载
  247. async downloadFile () {
  248. let file = {
  249. id: 0,
  250. fileName: ''
  251. }
  252. let tempData = {
  253. orderRef1: 'ecss',
  254. orderRef2: 'upLoadPallet'
  255. }
  256. await queryFileId(tempData).then(({data}) => {
  257. if (data && data.code === 0) {
  258. file.id = data.data.id
  259. file.fileName = data.data.fileName
  260. } else {
  261. this.$alert(data.msg, '错误', {
  262. confirmButtonText: '确定'
  263. })
  264. }
  265. })
  266. await downLoadObjectFile(file).then(({data}) => {
  267. // 不限制文件下载类型
  268. const blob = new Blob([data], {type: "application/octet-stream"})
  269. // 下载文件名称
  270. const fileName = file.fileName
  271. // a标签下载
  272. const linkNode = document.createElement('a')
  273. // a标签的download属性规定下载文件的名称
  274. linkNode.download = fileName
  275. linkNode.style.display = 'none'
  276. // 生成一个Blob URL
  277. linkNode.href = URL.createObjectURL(blob)
  278. document.body.appendChild(linkNode)
  279. // 模拟在按钮上的一次鼠标单击
  280. linkNode.click()
  281. // 释放URL 对象
  282. URL.revokeObjectURL(linkNode.href)
  283. document.body.removeChild(linkNode)
  284. })
  285. },
  286. //导出excel
  287. async createExportData() {
  288. let searchData={
  289. site: this.pageData.site,
  290. buNo: this.pageData.buNo,
  291. delNo: this.pageData.delNo,
  292. cmcInvoice: this.pageData.cmcInvoice,
  293. createBy: this.$store.state.user.name,
  294. }
  295. await searchEcssCoDelNotifyDetail(searchData).then(({data}) => {
  296. this.exportList= data.rows
  297. this.exportList.forEach(o => o.cmcInvoice=this.pageData.cmcInvoice);
  298. })
  299. return this.exportList;
  300. },
  301. startDownload() {
  302. // this.exportData = this.dataList
  303. },
  304. finishDownload() {
  305. },
  306. fields() {
  307. let json = "{"
  308. this.columnList1.forEach((item, index) => {
  309. if (index == this.columnList1.length - 1) {
  310. json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\""
  311. } else {
  312. json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\"" + ","
  313. }
  314. })
  315. json += "}"
  316. let s = eval("(" + json + ")")
  317. return s
  318. },
  319. }
  320. }
  321. </script>