sendOutOrder.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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 resToken from "@/mixins/resToken";
  26. import { sendOutOrderColumns, head } from "./columns";
  27. import { isnumber, isNumeric } from "@/utils/validate";
  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. mounted() {
  62. // alert(this.head.length)
  63. },
  64. methods: {
  65. beforeUpload(file) {
  66. const isLt1M = file.size / 1024 < 500;
  67. if (isLt1M) {
  68. return true;
  69. }
  70. this.$message({
  71. message: "请不要上传大于500KB的文件.",
  72. type: "warning",
  73. });
  74. return false;
  75. },
  76. handleSuccess({ results, header }) {
  77. // alert(this.head.length, header.length)
  78. // console.log(results)
  79. if (!this.loading) {
  80. this.loading = true;
  81. if (results.length === 0) {
  82. this.$message.error("表格无有效数据!");
  83. this.loading = false;
  84. return;
  85. }
  86. console.log(this.head.length,header.length);
  87. if (this.head.length !== header.length) {
  88. this.$message.error("表头与导入模板不匹配!");
  89. this.loading = false;
  90. return;
  91. }
  92. let hederOk = true;
  93. this.head.forEach((v1, i1) => {
  94. if (v1 !== header[i1].replace(/\s*/g, "")) {
  95. console.log(v1 + "----" + header[i1]);
  96. hederOk = false;
  97. }
  98. });
  99. if (!hederOk) {
  100. this.$message.error("表头与导入模板不匹配!");
  101. this.loading = false;
  102. return;
  103. }
  104. this.tableData = [];
  105. let list = results;
  106. try {
  107. list.forEach((obj, index) => {
  108. let model = {};
  109. let arr = Object.values(obj);
  110. arr.forEach((key, ii) => {
  111. let key_n = (key ?? "") + "";
  112. key_n = key_n.replace(/\s+/g, "");
  113. const s = /\\|\/|\?|\?|\*|\"|\“|\”|\'|\‘|\’|\,|\;|\?|\<|\>|\{|\}|\[|\]|\[|\]|\:|\:|\.|\^|\$|\!|\~|\`|\|/g;
  114. Object.defineProperty(model, `value${ii}`, {
  115. value: ii === 28 ? key_n.replace(s, ",") : key_n,
  116. });
  117. });
  118. this.tableData.push(model);
  119. // console.log(this.tableData);
  120. });
  121. } catch (e) {
  122. console.log(e);
  123. }
  124. this.loading = false;
  125. }
  126. },
  127. //取消
  128. cancel() {
  129. this.tableData = [];
  130. },
  131. validateCode(str) {
  132. let arr = str.split(",");
  133. let isok = true;
  134. arr.forEach((value) => {
  135. const l = value.length;
  136. let res = true;
  137. // else if (value === "0") {//之前支持0
  138. // res = true;
  139. // }
  140. if (value === "") {
  141. res = false;
  142. } else if (l >= 9 && l <= 20) {
  143. if (isnumber(value)) {
  144. res = true;
  145. } else if (!isNumeric(value)) {
  146. res = false;
  147. } else {
  148. res = true;
  149. }
  150. } else {
  151. isok = false;
  152. }
  153. if (!res) {
  154. isok = false;
  155. }
  156. });
  157. return isok;
  158. },
  159. //提交
  160. async submit() {
  161. if (!this.loading) {
  162. this.loading = true;
  163. if (this.tableData.length === 0) {
  164. this.$message.warning("导入数据不能为空");
  165. this.loading = false;
  166. return;
  167. }
  168. if(this.tableData.length > 100){
  169. this.$message.warning("导入数据最多不能超过100条");
  170. this.loading = false
  171. }
  172. let isok = true,
  173. list = [],
  174. is_codeok = true;
  175. this.tableData.forEach((key, index) => {
  176. if (
  177. key["value0"] === "" ||
  178. key["value18"] === "" ||
  179. key["value19"] === "" ||
  180. key["value20"] === ""
  181. ) {
  182. isok = false;
  183. }
  184. let ketitem = {
  185. outChildCode: key["value0"],
  186. post_name: key["value18"],
  187. post_code: key["value19"],
  188. post_fee: key["value20"]
  189. };
  190. if (!this.validateCode(key["value19"])) {
  191. is_codeok = false;
  192. }
  193. list.push(ketitem);
  194. });
  195. if (!isok) {
  196. this.$notify.warning({
  197. title: "以下单号不能为空!",
  198. message:
  199. "发货工单号/发货工单物流公司/发货工单物流单号/发货工单物流费用",
  200. });
  201. this.loading = false;
  202. return;
  203. }
  204. if (!is_codeok) {
  205. this.$notify.warning({
  206. title: "部分物流单号不符合规则!",
  207. message: this.code_msg,
  208. });
  209. this.loading = false;
  210. return;
  211. }
  212. let model = {
  213. list: JSON.parse(JSON.stringify(list)),
  214. };
  215. const { code, data, message } = await asyncRequest.express(model);
  216. this.loading = false;
  217. if (code === 0) {
  218. this.$notify.success({
  219. title: "导入成功!",
  220. message: "",
  221. });
  222. this.tableData = [];
  223. // await this.routeReGoto("sellOutOrder", {});
  224. } else if (code >= 100 && code <= 104) {
  225. await this.logout();
  226. } else if (code == 1003) {
  227. this.showal(data, message, "");
  228. } else if (code == 1005) {
  229. this.showal(data, message, "outCode");
  230. } else if (code == 1011) {
  231. this.showal(data, message, "outCode");
  232. } else {
  233. this.$message.warning(message);
  234. }
  235. }
  236. },
  237. showal(list, message, code) {
  238. let htmlList = "<ul>";
  239. list.forEach((v) => {
  240. htmlList += `<li>${code !== "" ? v[code] : v}</li>`;
  241. });
  242. htmlList += "</ul>";
  243. this.$notify({
  244. title: message,
  245. dangerouslyUseHTMLString: true,
  246. message: htmlList,
  247. });
  248. },
  249. },
  250. };
  251. </script>
  252. <style lang="scss" scoped>
  253. .box {
  254. width: 100%;
  255. // padding-top: 50px;
  256. box-sizing: border-box;
  257. // height: 100vh;
  258. // overflow: hidden;
  259. background: #fff;
  260. }
  261. .con {
  262. width: 100%;
  263. margin: 0px auto;
  264. background: #fff;
  265. // padding: 50px;
  266. box-sizing: border-box;
  267. h1 {
  268. margin-bottom: 20px;
  269. margin-top: 20px;
  270. font-size: 16px;
  271. color: #333;
  272. }
  273. }
  274. // .tab{
  275. // width: 100%;
  276. // overflow: hidden;
  277. // margin: auto;
  278. // box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
  279. // padding: 30px;
  280. // }
  281. .btn {
  282. width: 50%;
  283. margin: 50px auto 0;
  284. display: flex;
  285. justify-content: space-around;
  286. }
  287. </style>