sendOutOrder.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <div class="orderImport pagePadding" v-loading="loading">
  3. <div v-if="tableData && tableData.length > 0" class="tr" style="padding: 10px 0 0 0">
  4. <el-button @click="cancel" :size="'mini'">取消</el-button>
  5. <el-button type="primary" @click="submit" :size="'mini'">提交</el-button>
  6. </div>
  7. <div v-else>
  8. <upload-excel :on-success="handleSuccess" :before-upload="beforeUpload" />
  9. </div>
  10. <div>
  11. <el-alert title="多物流单号请用逗号','隔开" type="warning" :closable="false">
  12. </el-alert>
  13. </div>
  14. <ex-table
  15. :columns="columns"
  16. :table="table"
  17. :data="tableData"
  18. style="margin: 15px 0 0 0"
  19. >
  20. </ex-table>
  21. </div>
  22. </template>
  23. <script>
  24. import asyncRequest from "@/apis/service/sellOut/deliveryWorkOrder";
  25. import { sendOutOrderColumns, head } from "./columns";
  26. import { isnumber, isNumeric } from "@/utils/validate";
  27. import resToken from "@/mixins/resToken";
  28. export default {
  29. mixins: [resToken],
  30. name: "orderImport",
  31. data() {
  32. return {
  33. code_msg: "物流单号必传,且支持纯数字或字母数字组合(9~20位)!",
  34. ruleForm: {
  35. order_addr: [], //收货地址
  36. },
  37. // 表格 - 参数
  38. table: {
  39. stripe: true,
  40. border: true,
  41. "max-height": "800px",
  42. // _defaultHeader_: ["setcol"],
  43. },
  44. tableData: [],
  45. // 表格 - 分页
  46. pageInfo: {
  47. size: 15,
  48. curr: 1,
  49. total: 0,
  50. },
  51. head,
  52. loading: false,
  53. // 表格 - 列参数
  54. columns: sendOutOrderColumns,
  55. //按钮锁
  56. btnFlag: false,
  57. //编辑全局锁
  58. editBtnFlag: false,
  59. };
  60. },
  61. methods: {
  62. beforeUpload(file) {
  63. const isLt1M = file.size / 1024 < 500;
  64. if (isLt1M) {
  65. return true;
  66. }
  67. this.$message({
  68. message: "请不要上传大于500KB的文件.",
  69. type: "warning",
  70. });
  71. return false;
  72. },
  73. handleSuccess({ results, header }) {
  74. // alert(this.head.length, header.length)
  75. // console.log(results)
  76. if (!this.loading) {
  77. this.loading = true;
  78. if (results.length === 0) {
  79. this.$message.error("表格无有效数据!");
  80. this.loading = false;
  81. return;
  82. }
  83. console.log(this.head.length,header.length);
  84. if (this.head.length !== header.length) {
  85. this.$message.error("表头与导入模板不匹配!");
  86. this.loading = false;
  87. return;
  88. }
  89. let hederOk = true;
  90. this.head.forEach((v1, i1) => {
  91. if (v1.replace(/\s*/g, "") !== header[i1].replace(/\s*/g, "")) {
  92. hederOk = false;
  93. }
  94. });
  95. if (!hederOk) {
  96. this.$message.error("表头与导入模板不匹配!");
  97. this.loading = false;
  98. return;
  99. }
  100. this.tableData = [];
  101. let list = results;
  102. try {
  103. list.forEach((obj, index) => {
  104. let model = {};
  105. let arr = Object.values(obj);
  106. arr.forEach((key, ii) => {
  107. let key_n = (key ?? "") + "";
  108. key_n = key_n.replace(/\s+/g, "");
  109. const s = /\\|\/|\?|\?|\*|\"|\“|\”|\'|\‘|\’|\,|\;|\?|\<|\>|\{|\}|\[|\]|\[|\]|\:|\:|\.|\^|\$|\!|\~|\`|\|/g;
  110. Object.defineProperty(model, `value${ii}`, {
  111. value: ii === 28 ? key_n.replace(s, ",") : key_n,
  112. });
  113. });
  114. this.tableData.push(model);
  115. // console.log(this.tableData);
  116. });
  117. } catch (e) {
  118. console.log(e);
  119. }
  120. this.loading = false;
  121. }
  122. },
  123. //取消
  124. cancel() {
  125. this.tableData = [];
  126. },
  127. validateCode(str) {
  128. let arr = str.split(",");
  129. let isok = true;
  130. arr.forEach((value) => {
  131. const l = value.length;
  132. let res = true;
  133. // else if (value === "0") {//之前支持0
  134. // res = true;
  135. // }
  136. if (value === "") {
  137. res = false;
  138. } else if (l >= 9 && l <= 20) {
  139. if (isnumber(value)) {
  140. res = true;
  141. } else if (!isNumeric(value)) {
  142. res = false;
  143. } else {
  144. res = true;
  145. }
  146. } else {
  147. isok = false;
  148. }
  149. if (!res) {
  150. isok = false;
  151. }
  152. });
  153. return isok;
  154. },
  155. //提交
  156. async submit() {
  157. if (!this.loading) {
  158. this.loading = true;
  159. if (this.tableData.length === 0) {
  160. this.$message.warning("导入数据不能为空");
  161. this.loading = false;
  162. return;
  163. }
  164. // if(this.tableData.length > 100){
  165. // this.$message.warning("导入数据最多不能超过100条");
  166. // this.loading = false
  167. // }
  168. let isok = true,
  169. list = [],
  170. is_codeok = true;
  171. this.tableData.forEach((key, index) => {
  172. if (
  173. key["value0"] === "" ||
  174. key["value22"] === "" ||
  175. key["value23"] === "" ||
  176. key["value24"] === ""
  177. // key['value25'] === "" ||
  178. // key['value26'] === "" ||
  179. // key['valye27'] === "" ||
  180. // key['value28'] === "" ||
  181. // key['value29'] === ""
  182. ) {
  183. isok = false;
  184. }
  185. let ketitem = {
  186. outChildCode: key["value0"],
  187. post_name: key["value22"],
  188. post_code: key["value23"],
  189. post_fee: key["value24"],
  190. };
  191. if (!this.validateCode(key["value23"])) {
  192. is_codeok = false;
  193. }
  194. list.push(ketitem);
  195. });
  196. if (!isok) {
  197. this.$notify.warning({
  198. title: "以下字段不能为空!",
  199. message:
  200. "发货工单号/发货工单物流公司/发货工单物流单号/发货工单物流费用"
  201. });
  202. this.loading = false;
  203. return;
  204. }
  205. if (!is_codeok) {
  206. this.$notify.warning({
  207. title: "部分物流单号不符合规则!",
  208. message: this.code_msg,
  209. });
  210. this.loading = false;
  211. return;
  212. }
  213. let model = {
  214. list: JSON.parse(JSON.stringify(list)),
  215. };
  216. const { code, data, message } = await asyncRequest.express(model);
  217. this.loading = false;
  218. if (code === 0) {
  219. this.$notify.success({
  220. title: "导入成功!",
  221. message: "",
  222. });
  223. this.tableData = [];
  224. // await this.routeReGoto("sellOutOrder", {});
  225. } else if (code >= 100 && code <= 104) {
  226. await this.logout();
  227. } else if (code == 1003) {
  228. this.showal(data, message, "");
  229. } else if (code == 1005) {
  230. this.showal(data, message, "outCode");
  231. } else if (code == 1011) {
  232. this.showal(data, message, "outCode");
  233. } else {
  234. this.$message.warning(message);
  235. }
  236. }
  237. },
  238. showal(list, message, code) {
  239. let htmlList = "<ul>";
  240. list.forEach((v) => {
  241. htmlList += `<li>${code !== "" ? v[code] : v}</li>`;
  242. });
  243. htmlList += "</ul>";
  244. this.$notify({
  245. title: message,
  246. dangerouslyUseHTMLString: true,
  247. message: htmlList,
  248. });
  249. },
  250. },
  251. };
  252. </script>
  253. <style lang="scss" scoped>
  254. .box {
  255. width: 100%;
  256. // padding-top: 50px;
  257. box-sizing: border-box;
  258. // height: 100vh;
  259. // overflow: hidden;
  260. background: #fff;
  261. }
  262. .con {
  263. width: 100%;
  264. margin: 0px auto;
  265. background: #fff;
  266. // padding: 50px;
  267. box-sizing: border-box;
  268. h1 {
  269. margin-bottom: 20px;
  270. margin-top: 20px;
  271. font-size: 16px;
  272. color: #333;
  273. }
  274. }
  275. // .tab{
  276. // width: 100%;
  277. // overflow: hidden;
  278. // margin: auto;
  279. // box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
  280. // padding: 30px;
  281. // }
  282. .btn {
  283. width: 50%;
  284. margin: 50px auto 0;
  285. display: flex;
  286. justify-content: space-around;
  287. }
  288. </style>