sendOutOrder.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. let isok = true,
  169. list = [],
  170. is_codeok = true;
  171. this.tableData.forEach((key, index) => {
  172. if (
  173. key["value0"] === "" ||
  174. key["value18"] === "" ||
  175. key["value19"] === "" ||
  176. key["value20"] === ""
  177. ) {
  178. isok = false;
  179. }
  180. let ketitem = {
  181. outChildCode: key["value0"],
  182. post_name: key["value18"],
  183. post_code: key["value19"],
  184. post_fee: key["value20"]
  185. };
  186. if (!this.validateCode(key["value19"])) {
  187. is_codeok = false;
  188. }
  189. list.push(ketitem);
  190. });
  191. if (!isok) {
  192. this.$notify.warning({
  193. title: "以下单号不能为空!",
  194. message:
  195. "发货单号/发货单物流公司/发货单物流单号/发货单物流费用/发货单备注",
  196. });
  197. this.loading = false;
  198. return;
  199. }
  200. if (!is_codeok) {
  201. this.$notify.warning({
  202. title: "部分物流单号不符合规则!",
  203. message: this.code_msg,
  204. });
  205. this.loading = false;
  206. return;
  207. }
  208. let model = {
  209. list: JSON.parse(JSON.stringify(list)),
  210. };
  211. const { code, data, message } = await asyncRequest.express(model);
  212. this.loading = false;
  213. if (code === 0) {
  214. this.$notify.success({
  215. title: "导入成功!",
  216. message: "",
  217. });
  218. this.tableData = [];
  219. // await this.routeReGoto("sellOutOrder", {});
  220. } else if (code >= 100 && code <= 104) {
  221. await this.logout();
  222. } else if (code == 1003) {
  223. this.showal(data, message, "");
  224. } else if (code == 1005) {
  225. this.showal(data, message, "outCode");
  226. } else if (code == 1011) {
  227. this.showal(data, message, "outCode");
  228. } else {
  229. this.$message.warning(message);
  230. }
  231. }
  232. },
  233. showal(list, message, code) {
  234. let htmlList = "<ul>";
  235. list.forEach((v) => {
  236. htmlList += `<li>${code !== "" ? v[code] : v}</li>`;
  237. });
  238. htmlList += "</ul>";
  239. this.$notify({
  240. title: message,
  241. dangerouslyUseHTMLString: true,
  242. message: htmlList,
  243. });
  244. },
  245. },
  246. };
  247. </script>
  248. <style lang="scss" scoped>
  249. .box {
  250. width: 100%;
  251. // padding-top: 50px;
  252. box-sizing: border-box;
  253. // height: 100vh;
  254. // overflow: hidden;
  255. background: #fff;
  256. }
  257. .con {
  258. width: 100%;
  259. margin: 0px auto;
  260. background: #fff;
  261. // padding: 50px;
  262. box-sizing: border-box;
  263. h1 {
  264. margin-bottom: 20px;
  265. margin-top: 20px;
  266. font-size: 16px;
  267. color: #333;
  268. }
  269. }
  270. // .tab{
  271. // width: 100%;
  272. // overflow: hidden;
  273. // margin: auto;
  274. // box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
  275. // padding: 30px;
  276. // }
  277. .btn {
  278. width: 50%;
  279. margin: 50px auto 0;
  280. display: flex;
  281. justify-content: space-around;
  282. }
  283. </style>