index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <view class="order">
  3. <!-- header -->
  4. <cu-custom isBack custom bgColor="bg-gradual-blue"><view slot="content">我的订单</view></cu-custom>
  5. <!-- section -->
  6. <view class="section"><cu-tab :value="defaultKey" @change="change" :list="list" /></view>
  7. <cu-scrollView @refresherpulling="refresherpulling" @scroll="scroll" :height="height">
  8. <view @click="flexible(index)" v-for="(item, index) in ListValue" :key="index" class="item padding bg-white margin-bottom-lg">
  9. <view class="flex justify-between padding-tb-sm">
  10. <view class="">订单号:{{ item.no }}</view>
  11. <view class="">{{ item.status_text }}</view>
  12. </view>
  13. <!-- 伸拉外壳 -->
  14. <view class="flexible" :class="{'flexible-open':item.flexible}">
  15. <!-- 商品列表 -->
  16. <view v-for="(it, ind) in item.details" :key="ind" class="padding-tb">
  17. <view class="flex">
  18. <image @click.stop="detailFunc(it.commodity_id)" style="width: 160rpx;height: 160rpx;min-width: 160rpx;" mode="aspectFit" :src="it.show_image | lazyImage"></image>
  19. <view class="margin-left " style="flex: auto;">
  20. <view class="text-black cut">{{ it.name}}</view>
  21. <view class="flex align-center margin-top-sm justify-between">
  22. <view class="">x{{ it.count }}</view>
  23. <view>
  24. <view v-if="it.type == 1" class="price text-red"><cu-price :value="it.amount" /></view>
  25. <view v-else class="text-yellow">{{ it.point_amount }}积分</view>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <view v-if="item.details.length>1" class="text-center">
  33. {{item.flexible ? '收起' : '查看更多('+item.details.length+')'}}
  34. </view>
  35. <!-- 物流信息 -->
  36. <view class="padding margin-top-sm" style="border:1rpx dotted #aaa">
  37. <view class="text-black">{{item.name}} {{item.tel}}</view>
  38. <view class="text-grey">{{item.user_address}}</view>
  39. </view>
  40. <!-- 待支付定制 -->
  41. <view v-if="defaultKey == 1" class="flex justify-between margin-top">
  42. <view class="flex justify-end align-center">
  43. <view>
  44. 合计:
  45. <text class="text-price"></text>
  46. <cu-price :value="item.total_amount" />
  47. </view>
  48. <view class="margin-left">
  49. <cu-price :value="item.total_point" />
  50. 积分
  51. </view>
  52. </view>
  53. <button @click.stop="handler(item.id)" class="cu-btn bg-green">
  54. <text v-if="payloadding" class="cuIcon-loadding2 iconfont-spin"></text>
  55. 支付
  56. </button>
  57. </view>
  58. <view v-else class="flex justify-end margin-top">
  59. <view>
  60. 合计:
  61. <text class="text-price"></text>
  62. <cu-price :value="item.total_amount" />
  63. </view>
  64. <view class="margin-left">
  65. <cu-price :value="item.total_point" />
  66. 积分
  67. </view>
  68. </view>
  69. </view>
  70. <!-- 状态管理 -->
  71. <view class="cu-load" :class="{ loading: currentPage <= totalPage, over: currentPage > totalPage }"></view>
  72. </cu-scrollView>
  73. <!-- 工具 -->
  74. <cu-modalB :show.sync="show" title="提示" content="确认支付订单?" cancelText="取消支付" confirmText="确认支付" @confirm="payItem" />
  75. </view>
  76. </template>
  77. <script>
  78. import { mapState, mapActions, mapMutations } from 'vuex';
  79. import { CustomBarHeight, requestPayment } from '@/common/device/index.js';
  80. import api from './api.js';
  81. export default {
  82. computed: {
  83. ...mapState(['openid', 'appId']),
  84. ...mapState('requestList', ['ListValue', 'currentPage', 'totalPage']),
  85. height() {
  86. return `calc(100vh - 60rpx - ${CustomBarHeight}px)`;
  87. }
  88. },
  89. data() {
  90. return {
  91. defaultKey: 0,
  92. list: [
  93. { id: '', label: '全部' },
  94. { id: 0, label: '待支付' },
  95. { id: 1, label: '待发货' },
  96. { id: 2, label: '已发货' }
  97. // {id:5,label:"已完成"},
  98. // {id:6,label:"待评价"}
  99. ],
  100. payloadding: false,
  101. id: '',
  102. show: false
  103. };
  104. },
  105. onLoad(options) {
  106. if(options.key || options.key==0) this.defaultKey =options.key;
  107. },
  108. async onShow() {
  109. await this.reset();
  110. await this.requestFunc({ url: '/customer/order/list/', data: { status: this.list[this.defaultKey]['id'] } });
  111. },
  112. methods: {
  113. ...mapMutations('requestList', ['changeValue']),
  114. ...mapActions('requestList', ['reset', 'requestFunc']),
  115. flexible(key){
  116. let ListValue=JSON.parse(JSON.stringify(this.ListValue));
  117. ListValue=ListValue.map((item,index)=>{
  118. item['flexible']=(index==key && !item['flexible']);
  119. return item;
  120. })
  121. this.changeValue(ListValue);
  122. },
  123. handler(id) {
  124. this.id = id;
  125. this.show = true;
  126. },
  127. detailFunc(id) {
  128. uni.navigateTo({
  129. url: `/pages/detail/index?id=${id}`
  130. });
  131. },
  132. async payItem() {
  133. try {
  134. if (this.payloadding) return false;
  135. this.payloadding = true;
  136. var result = await api.pay({ id: this.id, appid: this.appId, openid: this.openid });
  137. if (result.code != 0) return false;
  138. if (result.data === '') {
  139. this.refresherpulling();
  140. return false;
  141. }
  142. result = await requestPayment(result.data);
  143. if (result) {
  144. uni.showToast({
  145. title: '支付成功',
  146. icon: 'success',
  147. success: () => this.refresherpulling()
  148. });
  149. } else {
  150. uni.showToast({
  151. title: '取消支付',
  152. icon: 'error'
  153. });
  154. }
  155. } catch (err) {
  156. uni.showToast({
  157. title: '支付失败',
  158. icon: 'error'
  159. });
  160. } finally {
  161. this.payloadding = false;
  162. }
  163. },
  164. async change(index, item) {
  165. this.defaultKey = index;
  166. await this.reset();
  167. await this.requestFunc({ url: '/customer/order/list/', data: { status: this.list[this.defaultKey]['id'] } });
  168. },
  169. async refresherpulling() {
  170. await this.reset();
  171. await this.requestFunc({ url: '/customer/order/list/', data: { status: this.list[this.defaultKey]['id'] } });
  172. },
  173. // 上拉加载
  174. async scroll() {
  175. await this.requestFunc({ url: '/customer/order/list/', data: { status: this.list[this.defaultKey]['id'] } });
  176. }
  177. }
  178. };
  179. </script>
  180. <style lang="scss" scoped>
  181. .order {
  182. .item {
  183. > view:first-child {
  184. position: relative;
  185. &::after {
  186. content: '';
  187. position: absolute;
  188. left: 0;
  189. bottom: 0;
  190. border-bottom: 1rpx solid #f37b1d;
  191. transform: scale(1, 0.5);
  192. width: 100%;
  193. }
  194. }
  195. .cut{
  196. display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 3;
  197. overflow: hidden;
  198. }
  199. .flexible{
  200. height: 220rpx;
  201. overflow: hidden;
  202. position: relative;
  203. transition: height .3s linear;
  204. }
  205. .flexible-open{
  206. height: auto;
  207. }
  208. }
  209. }
  210. </style>