Home.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <template>
  2. <div class="mainContent">
  3. <el-row class="order_tab">
  4. <el-col :span="15">
  5. <div class="tabList">
  6. <div class="tab_item" @click="changeTab(i, item.status)" :class="{ tab_item_ac: tabNum == i ? true : false }" v-for="(item, i) in tabList" :key="i">
  7. <div class="point" v-show="item.num">{{ item.num }}</div>
  8. <span>{{ item.name }}</span>
  9. <div class="tab_line"></div>
  10. </div>
  11. </div>
  12. </el-col>
  13. <el-col :span="9" class="search">
  14. <div class="header_serch">
  15. <div class="search_inp">
  16. <el-input size="medium" class="inp" v-model="searchKey" placeholder="请输入手机号/姓名/地址/订单编号" @keydown.enter.native="seachEnterFun" clearable></el-input>
  17. <el-button size="medium" type="primary" @click.stop="search" slot="append" icon="el-icon-search"></el-button>
  18. </div>
  19. <!-- 1.0.0版本暂不开发该功能 -->
  20. <!-- <div class="Manual">手动发单</div> -->
  21. </div>
  22. </el-col>
  23. </el-row>
  24. <el-row class="order_list">
  25. <el-col :span="24" v-loading="isLoading" v-if="orderList.length">
  26. <order-list class="list" :list="orderList" :tabNum="tabNum"></order-list>
  27. <div style="text-align: center">
  28. <el-pagination :current-page.sync="params.pageNum" @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-sizes="[10, 20, 50, 100]" :page-size="params.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total" background>
  29. </el-pagination>
  30. </div>
  31. </el-col>
  32. <el-col class="empty-data" v-else>
  33. <img src="../../static/image/empty-data.png" />
  34. </el-col>
  35. </el-row>
  36. </div>
  37. </template>
  38. <script>
  39. import bus from "../common/bus.js";
  40. import sendOrderPopup from "./orderComponents/sendOrderPopup.vue";
  41. import OrderList from "./orderComponents/orderList.vue";
  42. import { getOrderList, getOrderMarker, getRefreshOrder } from "../api/order.js";
  43. export default {
  44. data() {
  45. return {
  46. isLoading: false,
  47. total: 0,
  48. orderList: [],
  49. tabList: [
  50. {
  51. name: "新订单",
  52. num: 0,
  53. status: 0,
  54. },
  55. {
  56. name: "预约单",
  57. num: 0,
  58. status: 10,
  59. },
  60. {
  61. name: "待接单",
  62. num: 0,
  63. status: 1,
  64. },
  65. {
  66. name: "取货中",
  67. num: 0,
  68. status: 2,
  69. },
  70. {
  71. name: "配送中",
  72. num: 0,
  73. status: 3,
  74. },
  75. {
  76. name: "异常单",
  77. num: 0,
  78. status: -2,
  79. },
  80. {
  81. name: "已取消",
  82. num: 0,
  83. status: -1,
  84. },
  85. ],
  86. tabNum: 0,
  87. needTrack: false,
  88. orderDetailStutus: 1,
  89. params: {
  90. status: 0,
  91. searchType: 0,
  92. pageNum: 1,
  93. pageSize: 10,
  94. },
  95. markerNum: "",
  96. clickBool: false,
  97. timer: null,
  98. timer2: null,
  99. searchKey: "",
  100. };
  101. },
  102. components: {
  103. sendOrderPopup,
  104. OrderList,
  105. },
  106. created() {
  107. this.init();
  108. this.getOrder();
  109. this.getMarker();
  110. this.timer = setInterval(() => {
  111. this.getMarker();
  112. this.getRefreshOrder();
  113. }, 5000);
  114. // this.timer2 = setInterval(() => {
  115. // this.getMarker();
  116. // if (this.tabNum >= 2) {
  117. // this.getOrder();
  118. // }
  119. // }, 60000);
  120. },
  121. mounted() {},
  122. beforeDestroy() {
  123. clearInterval(this.timer);
  124. this.timer = null;
  125. clearInterval(this.timer2);
  126. this.timer2 = null;
  127. },
  128. destroyed() {
  129. bus.$off("pullData");
  130. bus.$off("refreshData");
  131. },
  132. methods: {
  133. init() {
  134. bus.$on("pullData", (index) => {
  135. this.tabNum = index;
  136. this.params.status = this.tabList[index].status;
  137. this.params.pageNum = 1;
  138. this.orderList = [];
  139. Promise.all([this.getOrder(), this.getMarker()]);
  140. });
  141. bus.$on("refreshData", () => {
  142. console.log("执行refreshData");
  143. this.params.pageNum = 1;
  144. this.orderList = [];
  145. Promise.all([this.getOrder(), this.getMarker()]);
  146. });
  147. },
  148. seachEnterFun(e) {
  149. var keyCode = window.event ? e.keyCode : e.which;
  150. if (keyCode == 13) {
  151. this.search();
  152. }
  153. },
  154. search() {
  155. this.$router.push({
  156. path: "/orderSearch",
  157. query: {
  158. searchKey: this.searchKey,
  159. },
  160. });
  161. // this.params.pageNum = 1;
  162. // this.orderList = [];
  163. // this.getOrder();
  164. },
  165. handleSizeChange(val) {
  166. this.params.pageNum = 1;
  167. this.params.pageSize = val;
  168. this.orderList = [];
  169. this.getOrder();
  170. },
  171. handleCurrentChange(val) {
  172. this.params.pageNum = val;
  173. this.orderList = [];
  174. this.getOrder();
  175. },
  176. getMarker() {
  177. getOrderMarker().then((res) => {
  178. if (res.code === 200) {
  179. this.markerNum = res.data;
  180. this.tabList[0].num = res.data.toBeBillNum;
  181. this.tabList[1].num = res.data.appointNum;
  182. this.tabList[2].num = res.data.toBeReceivedNum;
  183. this.tabList[3].num = res.data.toBePickedNum;
  184. this.tabList[4].num = res.data.inDeliveryNum;
  185. this.tabList[5].num = res.data.exceptionNum;
  186. this.tabList[6].num = res.data.cancelNum;
  187. } else {
  188. this.$message({
  189. type: "error",
  190. message: res.msg,
  191. });
  192. }
  193. });
  194. },
  195. sendOrder() {
  196. this.$refs.sendOrderPopup.init();
  197. },
  198. changeTab(i, status) {
  199. this.tabNum = i;
  200. this.params.status = status;
  201. this.orderList = [];
  202. this.params.pageNum = 1;
  203. this.getOrder();
  204. },
  205. getOrder() {
  206. let _this = this;
  207. var minute = 1000 * 60;
  208. var hour = minute * 60;
  209. var day = hour * 24;
  210. this.isLoading = true;
  211. getOrderList(this.params).then((res) => {
  212. this.isLoading = false;
  213. if (res.code == 200) {
  214. this.orderList = [];
  215. this.total = res.data.totalNums || 0;
  216. this.params.pageNum = res.data.pageNum;
  217. res.data.data.forEach((element) => {
  218. element.takeTimeTxt = this.$tool.timeago(
  219. new Date(element.sendTime).getTime()
  220. );
  221. if (element.exceptTime && element.delayTime) {
  222. element.timeTxt = _this.$tool.eosFormatTime2(
  223. element.exceptTime,
  224. element.delayTime
  225. );
  226. } else {
  227. element.timeTxt = "";
  228. }
  229. this.orderList.push(element);
  230. });
  231. } else {
  232. this.$message({
  233. message: res.msg,
  234. type: "error",
  235. });
  236. }
  237. });
  238. },
  239. getRefreshOrder() {
  240. let orderIds = this.orderList.map((v) => {
  241. return v.id;
  242. });
  243. let params = {
  244. orderIds: orderIds,
  245. status: this.tabList[this.tabNum].status,
  246. };
  247. getRefreshOrder(params).then((res) => {
  248. if (res.code === 200) {
  249. let newList = res.data.newList;
  250. let deliveryList = res.data.deliveryList;
  251. if (!newList.length && !deliveryList.length) return;
  252. // 根据exceptTime判断是新订单还是预约单
  253. let normalList = newList
  254. .filter((v) => {
  255. return !v.exceptTime;
  256. })
  257. .map((item) => {
  258. item.buttonStatus = 0;
  259. return item;
  260. });
  261. let appointList = newList
  262. .filter((v) => {
  263. return v.exceptTime;
  264. })
  265. .map((item) => {
  266. item.buttonStatus = 10;
  267. item.exceptTime = this.$tool.getFormatDate(
  268. item.exceptTime * 1000
  269. );
  270. return item;
  271. });
  272. // tabNum 0 是新订单 1是预约单
  273. if (this.tabNum === 1) {
  274. this.orderList = this.orderList.concat(appointList);
  275. } else if (this.tabNum === 0) {
  276. this.orderList = this.orderList.concat(normalList);
  277. } else {
  278. this.orderList = this.orderList.concat(newList);
  279. }
  280. console.log("deliveryList", deliveryList);
  281. deliveryList.forEach((item) => {
  282. this.orderList = this.orderList.filter((v) => {
  283. return v.id !== item;
  284. });
  285. });
  286. this.total = this.orderList.length;
  287. } else {
  288. this.$message({
  289. type: "error",
  290. message: res.msg,
  291. });
  292. }
  293. });
  294. },
  295. },
  296. };
  297. </script>
  298. <style lang="scss" scoped="scoped">
  299. /deep/ .el-input__inner {
  300. padding-right: 30px;
  301. }
  302. .mainContent {
  303. width: 100%;
  304. height: 100%;
  305. .order_tab {
  306. width: 100%;
  307. height: 74px;
  308. background: #fff;
  309. .tabList {
  310. display: flex;
  311. justify-content: space-around;
  312. width: 100%;
  313. padding-top: 20px;
  314. padding-left: 36px;
  315. box-sizing: border-box;
  316. overflow-x: auto;
  317. .tab_item {
  318. font-size: 16px;
  319. font-weight: 500;
  320. color: #b1b1b1;
  321. position: relative;
  322. text-align: center;
  323. cursor: pointer;
  324. .tab_line {
  325. width: 58px;
  326. height: 6px;
  327. background: #fff;
  328. border-radius: 3px;
  329. margin-top: 15px;
  330. }
  331. .point {
  332. width: 16px;
  333. height: 16px;
  334. border-radius: 50%;
  335. background: #f74141;
  336. font-size: 12px;
  337. font-weight: 400;
  338. color: #ffffff;
  339. position: absolute;
  340. top: -5px;
  341. right: -10px;
  342. text-align: center;
  343. line-height: 16px;
  344. }
  345. }
  346. .tab_item_ac {
  347. color: #fc7200;
  348. .tab_line {
  349. background: #fc7200;
  350. }
  351. }
  352. }
  353. .search {
  354. display: flex;
  355. justify-content: flex-end;
  356. .header_serch {
  357. width: 80%;
  358. height: 74px;
  359. padding-right: 25px;
  360. box-sizing: border-box;
  361. display: flex;
  362. align-items: center;
  363. justify-content: flex-end;
  364. .Manual {
  365. width: 118px;
  366. height: 44px;
  367. background: #fc7200;
  368. border-radius: 6px;
  369. font-size: 16px;
  370. font-weight: 500;
  371. color: #ffffff;
  372. text-align: center;
  373. line-height: 44px;
  374. margin-left: 18px;
  375. }
  376. .search_inp {
  377. width: 380px;
  378. height: 44px;
  379. display: flex;
  380. align-items: center;
  381. position: relative;
  382. .inp {
  383. width: 100%;
  384. // height: 44px;
  385. border: none;
  386. }
  387. .btn {
  388. font-size: 22px;
  389. position: absolute;
  390. right: 15px;
  391. }
  392. }
  393. }
  394. }
  395. }
  396. .order_list {
  397. width: 100%;
  398. height: calc(100vh - 180px);
  399. margin-top: 10px;
  400. .list {
  401. position: relative;
  402. height: calc(100vh - 210px);
  403. overflow: hidden;
  404. }
  405. .empty-data {
  406. display: flex;
  407. align-items: center;
  408. justify-content: center;
  409. background-color: #fff;
  410. height: 100%;
  411. img {
  412. width: 349px;
  413. height: 222px;
  414. }
  415. }
  416. }
  417. }
  418. </style>