orderList.vue 9.4 KB

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