orderList.vue 11 KB

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