index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <template>
  2. <view class="container">
  3. <view class="status-box">
  4. <view class="status_tap_box" style="position: relative">
  5. <view @tap="statusTap" class="status-label" v-for="(item, index) in statusType" :key="index" :class="item[0] == currentType ? 'active' : ''" :data-index="item[0]">{{ item[1] }}</view>
  6. </view>
  7. </view>
  8. <not-goods v-if="haveGoods" textStr="抱歉!暂无相关订单" />
  9. <view class="order-list" v-if="orderList && orderList.length > 0">
  10. <view v-for="(li, index) in orderList" :key="index">
  11. <view class="a-order">
  12. <view class="overflow" :data-id="li.id">
  13. <view class="list-title flex_r flex_ac flex_jb">
  14. <view :class="['fz_text', 'typetag', 'tagcolor' + li.type]">{{ tidyTpye(li.type) }}</view>
  15. <view class="fz_text">{{ tidyStatus([li.pay_status, li.order_status]) }}</view>
  16. </view>
  17. <view class="goods-info flex_r flex_jb" :data-type="li.type" @tap="toDetails(li)">
  18. <image :src="li.original_img" mode="cover" class="goods-img" />
  19. <view class="goodsDetail_info">
  20. <view class="good_name ellipsis2">{{ li.goods_name || "" }}</view>
  21. <view class="good_text flex_r flex_ac flex_jb">
  22. <view class="unimport dinB">x {{ li.goods_num }}</view>
  23. <view class="goods_price r_color">¥<text class="r_color">{{ li.total_amount }}</text></view>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="price-box flex_r flex_ac">
  29. <template v-if="li.order_status != 5">
  30. <view class="btn cancel-btn" v-if="[0].includes(li.order_status)" @tap="toCancel(li)">取消订单</view>
  31. <view class="btn topay-btn" v-if="[0,2].includes(li.pay_status)" @tap="toPay(li)">立即支付</view>
  32. <view class="btn topay-btn" @tap="toTake(li)" v-if="[0,1,7].includes(li.order_status) && [1].includes(li.pay_status)">确认收货</view>
  33. <view class="btn topay-btn" @tap="toCode(li)" v-if="[8].includes(li.order_status)">待自提</view>
  34. </template>
  35. <template v-else>
  36. <view class="btn cancel-btn" @tap="removeItem(li.order_id)">删除</view>
  37. </template>
  38. <view class="btn cancel-btn" @click="toDetails(li)">查看订单</view>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="loading-indicator opacity">{{ loadingTip }}</view>
  44. </view>
  45. </template>
  46. <script>
  47. var page = 1;
  48. var app = getApp();
  49. var appEv = app.$vm.$options;
  50. import notGoods from "@/components/not-goods/index";
  51. import { post } from "@/request/api.js";
  52. import { ToPayOpre } from "@/utils/reqTools.js";
  53. var toPayOpre = new ToPayOpre();
  54. export default {
  55. components: {
  56. notGoods,
  57. // terraceTagbar
  58. },
  59. data() {
  60. return {
  61. statusType: [
  62. ["0", "全部"],
  63. ["1", "待付款"],
  64. ["5", "待自提"],
  65. ["2", "待发货"],
  66. ["3", "待收货"],
  67. ["4", "已完成"],
  68. ],
  69. orderList: [],
  70. currentType: "0",
  71. haveGoods: false,
  72. loadingMoreHidden: true,
  73. loadingTip: "没有更多了",
  74. userId: "",
  75. isweixin: "",
  76. pt: {},
  77. };
  78. },
  79. onLoad(options) {
  80. this.currentType = options.status ? options.status : 0;
  81. },
  82. onShow() {
  83. this.loadData();
  84. },
  85. methods: {
  86. clearData(isclearCat = true, callBack) {
  87. page = 1;
  88. this.orderList = [];
  89. this.haveGoods = false;
  90. if (callBack) {
  91. callBack();
  92. }
  93. },
  94. loadData() {
  95. if (page == -1) {
  96. return;
  97. }
  98. uni.showLoading({
  99. title: "加载中…",
  100. mask: true,
  101. });
  102. var data = {
  103. page,
  104. type: this.currentType,
  105. };
  106. post("v1/my/order", data).then((res) => {
  107. if (res.code === 0) {
  108. uni.hideLoading();
  109. uni.stopPullDownRefresh();
  110. let da = res.data.data.data;
  111. if (page <= 1) {
  112. this.orderList = [];
  113. if (!da.length) this.haveGoods = true;
  114. }
  115. this.orderList = [...this.orderList, ...da];
  116. } else {
  117. appEv.errTips(res.msg || "");
  118. this.loadingMoreHidden = false;
  119. }
  120. });
  121. },
  122. toDetails(da) {
  123. this.goto("/pages/szw-order-details/index", { id: da.order_id });
  124. },
  125. // 立即支付
  126. toPay(e) {
  127. let type = "H5";
  128. // #ifdef  H5
  129. type = "H5";
  130. // #endif
  131. // #ifdef  APP
  132. type = "app";
  133. // #endif
  134. // #ifdef  MP-WEIXIN
  135. type = "jsapi";
  136. // #endif
  137. post("v1/goods/payOrder", {
  138. id: e.order_id,
  139. trade_type: type,
  140. }).then((res) => {
  141. if (res.code === 0) {
  142. toPayOpre.toPay(res.data.data, (da) => {
  143. if (!da) {
  144. // 支付成功
  145. appEv.errTips("支付成功");
  146. } else {
  147. // 支付失败
  148. appEv.errTips("支付已取消");
  149. }
  150. // appEv.errTips('支付成功');
  151. this.loadData();
  152. });
  153. }
  154. });
  155. },
  156. // 取消订单
  157. toCancel(e) {
  158. let that = this;
  159. uni.showModal({
  160. title: "温馨提示",
  161. content: "取消订单后,微信支付部分也将退至云宝账户",
  162. // showCancel: false,
  163. confirmText: "知道了",
  164. confirmColor: "#f02f2f",
  165. cancelText: "取消",
  166. cancelColor: "#bbb",
  167. success(res) {
  168. if (res.confirm) {
  169. post("v1/my/orderCancel", {
  170. order_id: e.order_id,
  171. }).then((res) => {
  172. if (res.code === 0) {
  173. appEv.errTips(res.msg);
  174. that.loadData();
  175. }
  176. });
  177. }
  178. },
  179. });
  180. },
  181. // 确认收货
  182. toTake(e) {
  183. let that = this;
  184. uni.showModal({
  185. content: "亲,“确定收货”代表着本订单的交付流程已经完成,不再支持任何形式的退换货。",
  186. confirmText: "确认收货",
  187. confirmColor: "#fa2f2e",
  188. cancelText: "取消",
  189. cancelColor: "#bbb",
  190. success(res) {
  191. if (res.confirm) {
  192. post("v1/goods/confirmOrder", {
  193. order_id: e.order_id,
  194. }).then((res) => {
  195. if (res.code === 0) {
  196. appEv.errTips(res.msg);
  197. that.loadData();
  198. }
  199. });
  200. }
  201. },
  202. });
  203. },
  204. toCode(e) {
  205. this.goto("/pagesB/order/verificationCode", { id: e.order_id });
  206. },
  207. //菜单切换
  208. statusTap(e) {
  209. //重置数据
  210. var curType = e.currentTarget.dataset.index;
  211. this.currentType = curType;
  212. this.clearData(false, this.loadData);
  213. },
  214. //删除订单
  215. removeItem(order_id) {
  216. let that = this;
  217. uni.showModal({
  218. content: "亲,确认删除本订单吗?",
  219. confirmText: "确认删除",
  220. confirmColor: "#fa2f2e",
  221. cancelText: "取消",
  222. cancelColor: "#bbb",
  223. success(res) {
  224. if (res.confirm) {
  225. post("v1/my/orderDel", {
  226. order_id
  227. }).then(res => {
  228. if (res.code === 0) {
  229. appEv.errTips(res.msg);
  230. that.loadData();
  231. }
  232. });
  233. }
  234. },
  235. });
  236. }
  237. },
  238. computed: {
  239. // 0 支付状态 1 订单状态
  240. tidyStatus() {
  241. return (da) => {
  242. let str;
  243. if (da[1] === 0) str = "待发货";
  244. if (da[1] === 1) str = "已发货";
  245. if (da[1] === 2) str = "已完成";
  246. if (da[1] === 3) str = "申请退货";
  247. if (da[1] === 4) str = "确认退货";
  248. if (da[1] === 5) str = "已作废";
  249. if (da[1] === 6) str = "转邮寄";
  250. if (da[1] === 7) str = "待收货";
  251. if (da[1] === 8) str = "待自提";
  252. if ([0, 2].includes(da[0]) && da[1] != 5) str = "待支付";
  253. return str;
  254. };
  255. },
  256. },
  257. //上拉加载事件
  258. onReachBottom() {
  259. if (page != -1) {
  260. var that = this;
  261. setTimeout(() => {
  262. // 为页数迭加1
  263. ++page;
  264. that.loadData();
  265. }, 800);
  266. }
  267. },
  268. // 下拉刷新
  269. onPullDownRefresh() {
  270. var that = this;
  271. that.clearData(false, () => {
  272. that.loadData();
  273. });
  274. },
  275. // 监听卸载页面 同等于 返回拦截
  276. onUnload() {
  277. let pages = getCurrentPages();
  278. let prevPage = pages[pages.length - 2]?.route
  279. if (prevPage == "pages/to-pay-list/index") {
  280. uni.switchTab({ url: "/pages/my/index" });
  281. }
  282. },
  283. };
  284. </script>
  285. <style lang="scss">
  286. page {
  287. background-color: #f3f5f7;
  288. }
  289. .container {
  290. width: 100%;
  291. }
  292. .fl {
  293. float: left;
  294. }
  295. .fr {
  296. float: right;
  297. }
  298. .overflow {
  299. overflow: hidden;
  300. }
  301. .r_color {
  302. color: #fa2f2e;
  303. }
  304. .loading-indicator {
  305. width: 100%;
  306. text-align: center;
  307. font-size: 24rpx;
  308. color: #666;
  309. margin: 20rpx 0;
  310. line-height: 1.5;
  311. }
  312. .opacity {
  313. opacity: 0;
  314. display: none;
  315. }
  316. .terraceComp {
  317. height: 84rpx;
  318. }
  319. .terraceComp_fix {
  320. position: fixed;
  321. top: -12rpx;
  322. left: 0;
  323. right: 0;
  324. z-index: 15;
  325. }
  326. .status-box {
  327. width: 100%;
  328. height: 94rpx;
  329. }
  330. .status_tap_box {
  331. position: fixed;
  332. left: 0;
  333. top: 0;
  334. width: 100%;
  335. overflow: hidden;
  336. line-height: 88rpx;
  337. display: flex;
  338. justify-content: space-between;
  339. align-items: center;
  340. background-color: #fff;
  341. z-index: 300;
  342. box-shadow: 0rpx 8rpx 8rpx rgba(0, 0, 0, 0.025);
  343. }
  344. .status-box .status-label {
  345. flex-grow: 1;
  346. height: 100%;
  347. text-align: center;
  348. font-size: 28rpx;
  349. color: #353535;
  350. box-sizing: border-box;
  351. position: relative;
  352. border-bottom: 6rpx solid transparent;
  353. }
  354. .status-box .status-label.active {
  355. color: #e05f0b;
  356. border-bottom-color: #e05f0b;
  357. }
  358. .order-list {
  359. width: 100%;
  360. overflow: hidden;
  361. }
  362. .order-list .a-order {
  363. width: 100%;
  364. background-color: #fff;
  365. margin-top: 24rpx;
  366. }
  367. .order-list .a-order .order-date {
  368. padding: 16rpx 30rpx 20rpx;
  369. line-height: 40rpx;
  370. font-size: 26rpx;
  371. color: #000;
  372. overflow: hidden;
  373. }
  374. .order-list .a-order .order-date .red {
  375. font-size: 26rpx;
  376. color: #fa2f2e;
  377. }
  378. .order-list .a-order .order-date text.r_color {
  379. font-weight: 600;
  380. }
  381. .a-order .list-title {
  382. font-size: 28rpx;
  383. font-weight: 600;
  384. color: #000;
  385. padding: 16rpx 30rpx;
  386. }
  387. .avaImgs {
  388. width: 54rpx;
  389. height: 54rpx;
  390. overflow: hidden;
  391. border-radius: 50%;
  392. background-color: #f3f5f7;
  393. margin-right: 20rpx;
  394. }
  395. .order-list .a-order .price-box {
  396. position: relative;
  397. width: 100%;
  398. box-sizing: border-box;
  399. padding: 16rpx 30rpx;
  400. display: flex;
  401. justify-content: flex-end;
  402. font-size: 26rpx;
  403. }
  404. .a-order .price-box .btn {
  405. box-sizing: border-box;
  406. text-align: center;
  407. border-radius: 40rpx;
  408. margin-left: 20rpx;
  409. border: 1rpx solid #ccc;
  410. padding: 12rpx 24rpx;
  411. }
  412. .order-list .a-order .price-box .total-price {
  413. color: #e05f0b;
  414. }
  415. .a-order .price-box .topay-btn {
  416. border-color: #e05f0b;
  417. color: #e05f0b;
  418. }
  419. .a-order .price-box .r_topay-btn {
  420. border-color: #e05f0b;
  421. background-color: #e05f0b;
  422. color: #fff;
  423. }
  424. .goods-info{
  425. padding: 12rpx 30rpx;
  426. .goods-img{
  427. width: 160rpx;
  428. height: 140rpx;
  429. border-radius: 10rpx;
  430. }
  431. .goodsDetail_info{
  432. width: calc(100% - 160rpx);
  433. padding-left: 28rpx;
  434. position: relative;
  435. }
  436. .good_name{
  437. font-size: 30rpx;
  438. font-weight: 600;
  439. }
  440. .good_text{
  441. width: 100%;
  442. padding-left: 28rpx;
  443. position: absolute;
  444. bottom: 0;
  445. left: 0;
  446. }
  447. .goods_price{
  448. font-weight: 600;
  449. font-size: 32rpx;
  450. }
  451. .unimport{
  452. font-size: 26rpx;
  453. }
  454. }
  455. .typetag {
  456. border: 1px solid #ccc;
  457. border-radius: 10rpx;
  458. padding: 2rpx 10rpx;
  459. font-size: 22rpx;
  460. font-weight: 500;
  461. }
  462. .tagcolor1 {
  463. border-color: #007aff;
  464. color: #007aff;
  465. }
  466. .tagcolor2 {
  467. border-color: #4cd964;
  468. color: #4cd964;
  469. }
  470. .tagcolor3 {
  471. border-color: #f0ad4e;
  472. color: #f0ad4e;
  473. }
  474. .tagcolor4 {
  475. border-color: #dd524d;
  476. color: #dd524d;
  477. }
  478. .tagcolor5 {
  479. border-color: #4335d6;
  480. color: #4335d6;
  481. }
  482. .tagcolor6 {
  483. border-color: rgb(245, 8, 8);
  484. color: rgb(245, 8, 8);
  485. }
  486. </style>