index.vue 16 KB

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