myorder.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <view class="pages">
  3. <view class="status-bar">
  4. <view class="status-bar-item" :class="params.status == -1?'active':''" @click="changestatus(-1)">全部</view>
  5. <view class="status-bar-item" :class="params.status == 0?'active':''" @click="changestatus(0)">待付款</view>
  6. <view class="status-bar-item" :class="params.status == 1?'active':''" @click="changestatus(1)">待发货</view>
  7. <view class="status-bar-item" :class="params.status == 2?'active':''" @click="changestatus(2)">已发货</view>
  8. <view class="status-bar-item" :class="params.status == 3?'active':''" @click="changestatus(3)">已完成</view>
  9. <view class="status-bar-item" :class="params.status == 4?'active':''" @click="changestatus(4)">已关闭</view>
  10. <!-- <view class="status-bar-item" :class="params.status == 5?'active':''" @click="changestatus(5)">无效</view> -->
  11. </view>
  12. <mescroll-body class="" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  13. <view class="order">
  14. <view v-for="(item,index) in orderlist" :key="index" class="order-item" @click="goOrderDetails(item.id)">
  15. <view class="status" v-if="item.status == 0">待付款</view>
  16. <view class="status" v-if="item.status == 1">待发货</view>
  17. <view class="status" v-if="item.status == 2">已发货</view>
  18. <view class="status" v-if="item.status == 3">已完成</view>
  19. <view class="status" v-if="item.status == 4">已关闭</view>
  20. <view class="status" v-if="item.status == 5">无效订单</view>
  21. <view class="order-info">
  22. <view class="order-info-imgwrap">
  23. <image :src="item.orderItemList[0].productPic" class="order-info-img" mode="aspectFill"></image>
  24. </view>
  25. <view class="order-info-text">
  26. <view class="order-info-title">
  27. {{item.orderItemList[0].productBrand}}{{item.orderItemList[0].productName}}
  28. </view>
  29. <view class="order-info-num">
  30. <view class="order-info-bynum">数量<text class="bynum">X{{item.orderItemList[0].productQuantity}}</text></view>
  31. <view class="order-info-amount">商品总额<text class="rmb">¥</text><text class="amount">{{item.orderItemList[0].productQuantity*item.orderItemList[0].realAmount}}</text></view>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- order-info end -->
  36. <view class="order-tool" v-if="item.status == 0">
  37. <!-- <view class="order-tool-more">
  38. <svg class="icon" aria-hidden="true">
  39. <use xlink:href="#iconfengyunbang"></use>
  40. </svg>
  41. 更多操作
  42. </view> -->
  43. <!-- <button type="default" class="btn" v-if="item.status != 0" @click="delOrder">删除订单</button> -->
  44. <button type="default" class="btn" v-if="item.status == 0" @click.stop="cancelOrder(item)">取消订单</button>
  45. <button type="default" class="btn" v-if="item.status == 0" @click.stop="pay(item)">我要付款</button>
  46. </view>
  47. </view>
  48. <!-- order-item end -->
  49. </view>
  50. <!-- order end -->
  51. </mescroll-body>
  52. <uni-popup ref="popup" type="dialog">
  53. <uni-popup-dialog type="info" content="确认取消此订单吗?" :duration="2000" :before-close="true" @close="closepopup" @confirm="confirmpopup"></uni-popup-dialog>
  54. </uni-popup>
  55. </view>
  56. </template>
  57. <script>
  58. // 引入mescroll-mixins.js
  59. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  60. // 引入mescroll-body组件 (如已在main.js注册全局组件,则省略此步骤)
  61. import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"; // 注意.vue后缀不能省
  62. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  63. import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue';
  64. export default {
  65. mixins: [MescrollMixin], // 使用mixin
  66. components: {
  67. MescrollBody,
  68. uniPopup,
  69. uniPopupDialog,
  70. },
  71. data() {
  72. return {
  73. mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
  74. // 下拉刷新的配置(可选, 绝大部分情况无需配置)
  75. downOption: {
  76. // ...
  77. },
  78. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  79. upOption: {
  80. page: {
  81. size: 10 // 每页数据的数量,默认10
  82. },
  83. noMoreSize: 4, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  84. empty: {
  85. tip: '暂无相关数据'
  86. }
  87. },
  88. tokenhead:'',
  89. token:'',
  90. params:{
  91. status:-1,
  92. // tokenhead:'',
  93. // token:'',
  94. },
  95. orderlist:[],
  96. cancelId:null,
  97. }
  98. },
  99. onShow() {
  100. let serf = this;
  101. //检查登录,获取token
  102. // let loginRes = this.checkLogin('/pages/index/index', '2');
  103. // if(!loginRes){return false;}
  104. // serf.params.token=loginRes[0];
  105. },
  106. onLoad() {
  107. let self = this;
  108. uni.getStorage({
  109. key:'token',
  110. success: function (res) {
  111. self.token = res.data;
  112. // console.log(res.data);
  113. }
  114. });
  115. uni.getStorage({
  116. key:'tokenhead',
  117. success: function (res) {
  118. self.tokenhead = res.data;
  119. // console.log(res.data);
  120. }
  121. });
  122. },
  123. methods: {
  124. /*mescroll组件初始化的回调,可获取到mescroll对象 (此处可删,mixins已默认)*/
  125. mescrollInit(mescroll) {
  126. this.mescroll = mescroll;
  127. },
  128. /*下拉刷新的回调, 有三种处理方式:*/
  129. downCallback(){
  130. // 第2种: 下拉刷新和上拉加载调同样的接口, 那么不用第1种方式, 直接mescroll.resetUpScroll()即可
  131. this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  132. },
  133. /*上拉加载的回调*/
  134. upCallback(page) {
  135. let pageNum = page.num; // 页码, 默认从1开始
  136. let pageSize = page.size; // 页长, 默认每页10条
  137. this.params = Object.assign(this.params,{pageNum:pageNum,pageSize:pageSize});
  138. let thetoken = this.tokenhead + this.token;
  139. // console.log('thetoken',thetoken);
  140. this.$api.http.get(this.config.apiBaseurl+'/order/list',{params:this.params,header: {Authorization:thetoken}}).then(data => {
  141. // console.log('1111111111',data);
  142. if(data.data.code=='1001'){
  143. // uni.redirectTo({
  144. // url:'/pages/login/login?backpage=/pages/index/index'+'&backtype='+2,
  145. // });
  146. };
  147. // console.log(data);
  148. // 接口返回的当前页数据列表 (数组)
  149. let curPageData = data.data.data.list;
  150. // console.log('curPageData',curPageData);
  151. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  152. let curPageLen = curPageData.length;
  153. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  154. // let totalPage = data.xxx;
  155. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  156. let totalSize = data.data.data.total;
  157. // this.mescrollList = curPageData;
  158. // 接口返回的是否有下一页 (true/false)
  159. // let hasNext = data.xxx;
  160. //设置列表数据
  161. if(page.num == 1) this.orderlist = []; //如果是第一页需手动置空列表
  162. this.orderlist = this.orderlist.concat(curPageData); //追加新数据
  163. // console.log('page.num',page.num);
  164. console.log('this.orderlist',JSON.parse(JSON.stringify(this.orderlist)));
  165. //方法二(推荐): 后台接口有返回列表的总数据量 totalSize
  166. this.mescroll.endBySize(curPageLen, totalSize);
  167. // setTimeout(()=>{
  168. // this.mescroll.endSuccess(curPageLen)
  169. // },20)
  170. }).catch(err => {
  171. this.mescroll.endErr()
  172. console.log(err)
  173. });
  174. },
  175. //删除订单
  176. delOrder(item){
  177. },
  178. cancelOrder(item){
  179. console.log(JSON.parse(JSON.stringify(item)));
  180. this.cancelId = item.id;
  181. this.$refs.popup.open();
  182. },
  183. closepopup(done){
  184. done()
  185. },
  186. confirmpopup(done,value){
  187. this.$api.http.post(this.config.apiBaseurl + '/order/cancelUserOrder/?orderId='+this.cancelId,{},{
  188. header: {
  189. Accept:'application/json',
  190. Authorization: 'Bearer '+ this.token, //注意Bearer后面有一空格
  191. },
  192. }).then(res => {
  193. this.downCallback();
  194. // console.log('res',res)
  195. }).catch(err =>{
  196. console.log('err',err)
  197. });
  198. done()
  199. },
  200. changestatus(status){
  201. this.params.status = status;
  202. this.downCallback();
  203. },
  204. goOrderDetails(id){
  205. console.log(id)
  206. uni.navigateTo({
  207. url: './orderdetails/orderdetails?orderid=' + id,
  208. });
  209. },
  210. pay(item){
  211. let userInfo = uni.getStorageSync("userInfo");
  212. let params = {
  213. orderId:item.id,
  214. payType:item.payType,
  215. openid:userInfo.wxUsers.openid,
  216. // "tradeType":"test"
  217. }
  218. this.$pay.wxPay(params).then(res =>{
  219. this.downCallback();
  220. // console.log('payres',res);
  221. }).catch(err =>{console.log('err',err);});
  222. },
  223. }
  224. }
  225. </script>
  226. <style scoped>
  227. @import url("./myorder.css");
  228. </style>