Home.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <template>
  2. <div class="mainContent">
  3. <el-row class="order_tab">
  4. <el-col class="tab-list-wrap" :span="12">
  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="12" class="search">
  14. <div class="header_serch">
  15. <div class="inp-content">
  16. <span>门店</span>
  17. <el-select size="small" @change="changeShopIds" v-model="searchShopIdStr" multiple collapse-tags filterable clearable placeholder="默认全部门店">
  18. <el-option v-for="i in shopList" :key="i.id" :label="i.name" :value="i.id"></el-option>
  19. </el-select>
  20. </div>
  21. <el-input size="small" class="inp input-with-select" v-model="params.searchKey" placeholder="请输入关键字" @keydown.enter.native="seachEnterFun" clearable>
  22. <el-select v-model="params.searchKeyType" slot="prepend" placeholder="请选择关键字">
  23. <el-option label="流水号" value="1"></el-option>
  24. <el-option label="手机号" value="2"></el-option>
  25. <el-option label="姓名" value="3"></el-option>
  26. <el-option label="地址" value="4"></el-option>
  27. <el-option label="外卖订单号" value="6"></el-option>
  28. </el-select>
  29. </el-input>
  30. <el-button size="small" style="background: #0D1E40;color:#fff" type="info" @click.stop="search" slot="append" icon="el-icon-search"></el-button>
  31. </div>
  32. </el-col>
  33. </el-row>
  34. <el-row class="order_list">
  35. <el-col :span="24" v-loading="isLoading" v-if="orderList.length">
  36. <order-list class="list" :list="orderList" :tabNum="tabNum"></order-list>
  37. <div style="text-align: center">
  38. <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>
  39. </el-pagination>
  40. </div>
  41. </el-col>
  42. <el-col class="empty-data" v-else>
  43. <img src="../../static/image/empty-data.png" />
  44. <div class="no-data">暂无订单数据</div>
  45. </el-col>
  46. </el-row>
  47. </div>
  48. </template>
  49. <script>
  50. import bus from "../common/bus.js";
  51. import sendOrderPopup from "./orderComponents/sendOrderPopup.vue";
  52. import OrderList from "./orderComponents/orderList.vue";
  53. import { getOrderList, getOrderMarker, getRefreshOrder } from "../api/order.js";
  54. import { getShopList } from "../api/shop";
  55. export default {
  56. name: "HomeIndex",
  57. data() {
  58. return {
  59. isLoading: false,
  60. total: 0,
  61. orderList: [],
  62. tabList: [
  63. {
  64. name: "新订单",
  65. num: 0,
  66. status: 0,
  67. },
  68. {
  69. name: "预约单",
  70. num: 0,
  71. status: 10,
  72. },
  73. {
  74. name: "待接单",
  75. num: 0,
  76. status: 1,
  77. },
  78. {
  79. name: "取货中",
  80. num: 0,
  81. status: 2,
  82. },
  83. {
  84. name: "配送中",
  85. num: 0,
  86. status: 3,
  87. },
  88. {
  89. name: "异常单",
  90. num: 0,
  91. status: -2,
  92. },
  93. {
  94. name: "完成/取消",
  95. num: 0,
  96. status: 93,
  97. },
  98. {
  99. name: "全部",
  100. num: 0,
  101. status: 94,
  102. },
  103. ],
  104. tabNum: 0,
  105. needTrack: false,
  106. orderDetailStutus: 1,
  107. searchShopIdStr: [],
  108. params: {
  109. status: 0,
  110. searchType: 0,
  111. searchKey: "",
  112. searchKeyType: "1",
  113. pageNum: 1,
  114. pageSize: 10,
  115. },
  116. markerNum: "",
  117. clickBool: false,
  118. timer: null,
  119. timer2: null,
  120. shopList: [],
  121. };
  122. },
  123. components: {
  124. sendOrderPopup,
  125. OrderList,
  126. },
  127. watch: {
  128. "$store.state.userInfo": {
  129. handler(newVal, oldVal) {
  130. if (newVal.memberType !== 1) {
  131. this.getShopList();
  132. }
  133. },
  134. deep: true,
  135. immediate: true,
  136. },
  137. },
  138. created() {
  139. if (this.$route.params.tabNum === 2) {
  140. this.changeTab(2, 1);
  141. }
  142. if (this.$route.params.tabNum === 1) {
  143. this.changeTab(1, 10);
  144. }
  145. this.init();
  146. this.getOrder();
  147. this.getMarker();
  148. this.timer = setInterval(() => {
  149. this.getMarker();
  150. // 近三日不用插入或者删除数据
  151. if (this.tabNum !== 7) {
  152. this.getRefreshOrder();
  153. }
  154. }, 5000);
  155. },
  156. mounted() {},
  157. beforeDestroy() {
  158. clearInterval(this.timer);
  159. this.timer = null;
  160. },
  161. destroyed() {
  162. bus.$off("pullData");
  163. bus.$off("refreshData");
  164. },
  165. methods: {
  166. changeShopIds() {
  167. this.params.searchShopIdStr = String(this.searchShopIdStr);
  168. localStorage.setItem("searchShopIdStr", this.params.searchShopIdStr);
  169. this.params.pageNum = 1;
  170. this.orderList = [];
  171. this.getOrder();
  172. this.getMarker();
  173. },
  174. getShopList() {
  175. getShopList().then((res) => {
  176. if (res.code === 200) {
  177. this.shopList = res.data;
  178. } else {
  179. this.$message({
  180. type: "error",
  181. message: res.msg,
  182. });
  183. }
  184. });
  185. },
  186. init() {
  187. bus.$on("pullData", (index) => {
  188. this.tabNum = index;
  189. this.params.status = this.tabList[index].status;
  190. this.params.pageNum = 1;
  191. this.orderList = [];
  192. Promise.all([this.getOrder(), this.getMarker()]);
  193. });
  194. bus.$on("refreshData", () => {
  195. console.log("执行refreshData");
  196. this.params.pageNum = 1;
  197. this.orderList = [];
  198. Promise.all([this.getOrder(), this.getMarker()]);
  199. });
  200. },
  201. seachEnterFun(e) {
  202. var keyCode = window.event ? e.keyCode : e.which;
  203. if (keyCode == 13) {
  204. this.search();
  205. }
  206. },
  207. search() {
  208. if (!this.params.searchKey) {
  209. this.params.pageNum = 1;
  210. this.orderList = [];
  211. this.getOrder();
  212. } else {
  213. this.changeTab(7, 94);
  214. }
  215. },
  216. handleSizeChange(val) {
  217. this.params.pageNum = 1;
  218. this.params.pageSize = val;
  219. this.orderList = [];
  220. this.getOrder();
  221. },
  222. handleCurrentChange(val) {
  223. this.params.pageNum = val;
  224. this.orderList = [];
  225. this.getOrder();
  226. },
  227. getMarker() {
  228. getOrderMarker({ searchShopIdStr: this.params.searchShopIdStr }).then(
  229. (res) => {
  230. if (res.code === 200) {
  231. this.markerNum = res.data;
  232. this.tabList[0].num = res.data.toBeBillNum;
  233. this.tabList[1].num = res.data.appointNum;
  234. this.tabList[2].num = res.data.toBeReceivedNum;
  235. this.tabList[3].num = res.data.toBePickedNum;
  236. this.tabList[4].num = res.data.inDeliveryNum;
  237. this.tabList[5].num = res.data.exceptionNum;
  238. this.tabList[6].num = res.data.cancelNum;
  239. } else {
  240. this.$message({
  241. type: "error",
  242. message: res.msg,
  243. });
  244. }
  245. }
  246. );
  247. },
  248. sendOrder() {
  249. this.$refs.sendOrderPopup.init();
  250. },
  251. changeTab(i, status) {
  252. // 切换状态不是近三天,搜索输入框清空
  253. if (i !== 7) {
  254. this.params.searchKey = "";
  255. }
  256. this.tabNum = i;
  257. this.params.status = status;
  258. this.orderList = [];
  259. this.params.pageNum = 1;
  260. this.getOrder();
  261. },
  262. getOrder() {
  263. let _this = this;
  264. var minute = 1000 * 60;
  265. var hour = minute * 60;
  266. var day = hour * 24;
  267. this.isLoading = true;
  268. this.params.searchShopIdStr = String(this.searchShopIdStr);
  269. getOrderList(this.params).then((res) => {
  270. this.isLoading = false;
  271. if (res.code == 200) {
  272. this.orderList = [];
  273. this.total = res.data.totalNums || 0;
  274. this.params.pageNum = res.data.pageNum;
  275. res.data.data.forEach((element) => {
  276. element.takeTimeTxt = this.$tool.timeago(
  277. new Date(element.sendTime).getTime()
  278. );
  279. if (element.exceptTime && element.delayTime) {
  280. element.timeTxt = _this.$tool.eosFormatTime2(
  281. element.exceptTime,
  282. element.delayTime
  283. );
  284. } else {
  285. element.timeTxt = "";
  286. }
  287. this.orderList.push(element);
  288. });
  289. } else {
  290. this.$message({
  291. message: res.msg,
  292. type: "error",
  293. });
  294. }
  295. });
  296. },
  297. getRefreshOrder() {
  298. let noRefresh = [93, 94];
  299. if (noRefresh.includes(this.params.status)) {
  300. return;
  301. }
  302. let orderIds = this.orderList.map((v) => {
  303. return v.id;
  304. });
  305. let params = {
  306. orderIds: orderIds,
  307. status: this.tabList[this.tabNum].status,
  308. searchShopIdStr: this.params.searchShopIdStr,
  309. };
  310. getRefreshOrder(params).then((res) => {
  311. if (res.code === 200) {
  312. let newList = res.data.newList;
  313. let deliveryList = res.data.deliveryList;
  314. if (!newList.length && !deliveryList.length) return;
  315. // 根据exceptTime判断是新订单还是预约单
  316. let normalList = newList
  317. .filter((v) => {
  318. return !v.exceptTime;
  319. })
  320. .map((item) => {
  321. item.buttonStatus = 0;
  322. return item;
  323. });
  324. let appointList = newList
  325. .filter((v) => {
  326. return v.exceptTime;
  327. })
  328. .map((item) => {
  329. item.buttonStatus = 10;
  330. item.exceptTime = this.$tool.getFormatDate(
  331. item.exceptTime * 1000
  332. );
  333. return item;
  334. });
  335. // tabNum 0 是新订单 1是预约单
  336. if (this.tabNum === 1) {
  337. this.orderList = appointList.concat(this.orderList);
  338. } else if (this.tabNum === 0) {
  339. this.orderList = normalList.concat(this.orderList);
  340. } else {
  341. this.orderList = newList.concat(this.orderList);
  342. }
  343. deliveryList.forEach((item) => {
  344. this.orderList = this.orderList.filter((v) => {
  345. return v.id !== item;
  346. });
  347. });
  348. this.total = this.orderList.length;
  349. } else {
  350. this.$message({
  351. type: "error",
  352. message: res.msg,
  353. });
  354. }
  355. });
  356. },
  357. },
  358. };
  359. </script>
  360. <style lang="scss" scoped="scoped">
  361. /deep/ .el-input__inner {
  362. padding-right: 30px;
  363. }
  364. .mainContent {
  365. width: 100%;
  366. height: 100%;
  367. .order_tab {
  368. display: flex;
  369. width: 100%;
  370. min-width: 550px;
  371. overflow-x: auto;
  372. height: 74px;
  373. background: #fff;
  374. .tab-list-wrap {
  375. min-width: 550px;
  376. .tabList {
  377. display: flex;
  378. justify-content: space-around;
  379. width: 100%;
  380. padding-top: 26px;
  381. // padding-left: 36px;
  382. // box-sizing: border-box;
  383. .tab_item {
  384. flex-shrink: 0;
  385. font-size: 16px;
  386. font-weight: 500;
  387. color: #b1b1b1;
  388. position: relative;
  389. text-align: center;
  390. cursor: pointer;
  391. .tab_line {
  392. width: 58px;
  393. height: 6px;
  394. background: #fff;
  395. border-radius: 3px;
  396. margin-top: 15px;
  397. }
  398. .point {
  399. width: 16px;
  400. height: 16px;
  401. border-radius: 50%;
  402. background: #f74141;
  403. font-size: 12px;
  404. font-weight: 400;
  405. color: #ffffff;
  406. position: absolute;
  407. top: -5px;
  408. right: -10px;
  409. text-align: center;
  410. line-height: 16px;
  411. }
  412. }
  413. .tab_item_ac {
  414. color: #fc7200;
  415. .tab_line {
  416. background: #fc7200;
  417. }
  418. }
  419. }
  420. }
  421. .search {
  422. display: flex;
  423. justify-content: flex-end;
  424. min-width: 700px;
  425. .header_serch {
  426. height: 74px;
  427. padding-right: 25px;
  428. box-sizing: border-box;
  429. display: flex;
  430. align-items: center;
  431. justify-content: flex-end;
  432. .inp-content {
  433. display: flex;
  434. align-items: center;
  435. font-size: 15px;
  436. color: #999;
  437. span {
  438. flex-shrink: 0;
  439. margin-right: 5px;
  440. }
  441. }
  442. .inp {
  443. width: 120px;
  444. margin-left: 15px;
  445. /deep/ .el-input-group__prepend {
  446. background: #fff;
  447. .el-input__inner {
  448. width: 114px;
  449. }
  450. }
  451. /deep/ .el-input__inner {
  452. width: 200px;
  453. }
  454. }
  455. .Manual {
  456. width: 118px;
  457. height: 44px;
  458. background: #fc7200;
  459. border-radius: 6px;
  460. font-size: 16px;
  461. font-weight: 500;
  462. color: #ffffff;
  463. text-align: center;
  464. line-height: 44px;
  465. margin-left: 18px;
  466. }
  467. .btn {
  468. background: #fc7200;
  469. border-color: #fc7200;
  470. color: #fff !important;
  471. margin-left: 10px;
  472. }
  473. .search_inp {
  474. width: 380px;
  475. height: 44px;
  476. display: flex;
  477. align-items: center;
  478. position: relative;
  479. .btn {
  480. font-size: 22px;
  481. position: absolute;
  482. right: 15px;
  483. }
  484. }
  485. }
  486. }
  487. }
  488. .order_list {
  489. width: 100%;
  490. height: calc(100vh - 180px);
  491. margin-top: 10px;
  492. .list {
  493. position: relative;
  494. height: calc(100vh - 210px);
  495. overflow: hidden;
  496. }
  497. .empty-data {
  498. display: flex;
  499. flex-direction: column;
  500. align-items: center;
  501. justify-content: center;
  502. background-color: #fff;
  503. height: 100%;
  504. img {
  505. width: 349px;
  506. height: 222px;
  507. }
  508. .no-data {
  509. color: #9ea7b7;
  510. }
  511. }
  512. }
  513. }
  514. </style>