resultUplodModel.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <el-dialog
  3. v-loading="loading"
  4. title="导入数据"
  5. :center="true"
  6. align="left"
  7. top="5vh"
  8. width="1040px"
  9. :close-on-click-modal="false"
  10. :visible.sync="showModelThis"
  11. element-loading-text="拼命加载中"
  12. element-loading-spinner="el-icon-loading"
  13. element-loading-background="rgba(0, 0, 0, 0.8)"
  14. @close="closeModel"
  15. >
  16. <el-card style="margin: -20px">
  17. <el-row :gutter="10" style="height: 550px">
  18. <el-col :span="24">
  19. <upload-excel
  20. :on-success="handleSuccess"
  21. :before-upload="beforeUpload"
  22. />
  23. <el-table
  24. :data="tableData"
  25. size="mini"
  26. border
  27. max-height="400px"
  28. highlight-current-row
  29. style="width: 100%; margin-top: 20px"
  30. >
  31. <el-table-column
  32. show-overflow-tooltip
  33. v-for="(item, index) in columns"
  34. :key="item.prop + index"
  35. :prop="item.prop"
  36. :label="item.label"
  37. min-width="96px"
  38. />
  39. </el-table>
  40. </el-col>
  41. <el-col :span="24" style="text-align: right; margin: 15px 0 0 0">
  42. <el-button v-if="!isDetail" type="primary" @click="submitForm"
  43. >保 存
  44. </el-button>
  45. <el-button @click="showModelThis = false">{{
  46. isDetail ? "关 闭" : "取 消"
  47. }}</el-button>
  48. </el-col>
  49. </el-row>
  50. </el-card>
  51. </el-dialog>
  52. </template>
  53. <script>
  54. import urlConfig from "@/apis/url-config";
  55. import { getToken } from "@/utils/auth";
  56. import resToken from "@/mixins/resToken";
  57. import asyncRequest from "@/apis/service/stock/check/detail";
  58. export default {
  59. name: "resultUplodModel",
  60. props: ["showModel",'id'],
  61. mixins: [resToken],
  62. data() {
  63. return {
  64. imgAPI: urlConfig.baseURL,
  65. loading: false,
  66. length: 0,
  67. showModelThis: this.showModel,
  68. isfile: false,
  69. head: [
  70. "商品编码",
  71. "商品属性编码",
  72. "商品名称",
  73. "商品描述",
  74. "品牌",
  75. "单位",
  76. "供应商编码",
  77. "供应商名称",
  78. "一级分类",
  79. "二级分类",
  80. "三级分类",
  81. "新建时间",
  82. "仓库编码",
  83. "仓库名称",
  84. "可用库存",
  85. "盘点库存",
  86. ],
  87. tableData: [],
  88. ruleForm: {
  89. execl: "",
  90. },
  91. rules: {
  92. execl: [
  93. {
  94. required: true,
  95. message: "请选择文件",
  96. trigger: "change",
  97. },
  98. ],
  99. },
  100. columns: [],
  101. };
  102. },
  103. watch: {
  104. showModel: function (val) {
  105. this.showModelThis = val;
  106. if (val) {
  107. this.initForm();
  108. }
  109. },
  110. showModelThis(val) {
  111. if (!val) {
  112. this.$emit("cancel");
  113. }
  114. },
  115. },
  116. methods: {
  117. closeModel() {
  118. console.log("closeModel!!");
  119. },
  120. async initForm() {
  121. this.loading = true;
  122. console.log(this.id);
  123. this.isfile = false;
  124. this.tableData = [];
  125. this.columns = [];
  126. this.head.forEach((v, i) => {
  127. let model = {
  128. prop: "value" + i,
  129. label: v,
  130. };
  131. this.columns.push(model);
  132. });
  133. this.loading = false;
  134. },
  135. beforeUpload(file) {
  136. const isLt1M = file.size / 1024 / 1024 < 1;
  137. if (isLt1M) {
  138. return true;
  139. }
  140. this.$message({
  141. message: "请不要上传大于1MB的文件.",
  142. type: "warning",
  143. });
  144. return false;
  145. },
  146. handleSuccess({ results, header }) {
  147. this.length = 0;
  148. if (this.head.length !== header.length) {
  149. this.$message.error("表头与导入模板不匹配!");
  150. return;
  151. }
  152. let isok = true;
  153. this.head.forEach((v, i) => {
  154. if (v !== header[i]) {
  155. isok = false;
  156. }
  157. });
  158. if (!isok) {
  159. this.$message.error("表头与导入模板不匹配!");
  160. return;
  161. }
  162. this.length = header.length;
  163. this.tableHeader = header;
  164. let list = results;
  165. this.tableData = [];
  166. list.forEach((v1) => {
  167. let b = Object.values(v1);
  168. let model = {};
  169. for (let i = 0; i < b.length; i++) {
  170. model["value" + i] = b[i];
  171. }
  172. this.tableData.push(model);
  173. });
  174. },
  175. async submitForm() {
  176. if (!this.loading) {
  177. this.loading = true;
  178. let model = {
  179. id: this.id,
  180. data: this.tableData,
  181. };
  182. const res = await asyncRequest.checkimport(model);
  183. if (res && res.code === 0) {
  184. this.$notify.success({
  185. title: "盘点数据提交成功!",
  186. message: "",
  187. });
  188. } else if (res && res.code >= 100 && res.code <= 104) {
  189. await this.logout();
  190. } else {
  191. this.$message.warning(res.message);
  192. }
  193. }
  194. },
  195. },
  196. };
  197. </script>
  198. <style lang="scss" scoped>
  199. .checkDetail {
  200. .excelUploadBox {
  201. position: relative;
  202. width: 100%;
  203. height: 120px;
  204. line-height: 120px;
  205. box-sizing: border-box;
  206. &:hover {
  207. cursor: pointer;
  208. }
  209. .el-icon-receiving {
  210. width: 100%;
  211. text-align: center;
  212. height: 50px;
  213. display: block;
  214. font-size: 32px;
  215. line-height: 90px;
  216. color: #d3d4d6;
  217. }
  218. .boxM {
  219. width: 100%;
  220. display: block;
  221. text-align: center;
  222. line-height: 65px;
  223. height: 60px;
  224. color: #909399;
  225. }
  226. }
  227. .excelUpload {
  228. top: 0;
  229. left: 0;
  230. position: absolute;
  231. z-index: 2;
  232. width: 100%;
  233. height: 120px;
  234. line-height: 120px;
  235. box-sizing: border-box;
  236. // opacity: 0!important;
  237. // .excel-upload-input {
  238. // top: 0 !important;
  239. // left: 0 !important;
  240. // position: absolute !important;
  241. // z-index: 2 !important;
  242. // width: 100% !important;
  243. // height: 120px !important;
  244. // line-height: 120px !important;
  245. // box-sizing: border-box !important;
  246. // }
  247. }
  248. .excelUploadRes {
  249. width: 100%;
  250. height: 120px;
  251. line-height: 120px;
  252. box-sizing: border-box;
  253. i {
  254. width: 55px;
  255. height: 120px;
  256. line-height: 120px;
  257. text-align: center;
  258. font-size: 20px;
  259. &.fl {
  260. padding-left: 16px;
  261. }
  262. &.fr {
  263. padding-right: 16px;
  264. &:hover {
  265. cursor: pointer;
  266. }
  267. }
  268. }
  269. span {
  270. width: 386px;
  271. line-height: 16px;
  272. margin: 52px 0 0 0;
  273. font-size: 16px;
  274. }
  275. }
  276. }
  277. </style>