index.vue 16 KB

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