index.vue 18 KB

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