orderList.vue 11 KB

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