sureOrder.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <view class="sure-order">
  3. <view class="order-detail">
  4. <view class="order-title">
  5. <uv-text text="订单详情" :customStyle="{
  6. fontWeight:'bold'
  7. }" size="16"></uv-text>
  8. </view>
  9. <view class="order-content">
  10. <uv-image :src="imageUrl(orderData.rotatingImages) || ''" width="90" height="90" radius="0">
  11. </uv-image>
  12. <view class="order-content-detail">
  13. <uv-text :text="orderData.name" :lines="2" size="14"></uv-text>
  14. <uv-text text="x1" type="content" size="14" :customStyle="{
  15. background:'#eee',
  16. padding:'2rpx 16rpx',
  17. borderRadius:'4rpx',
  18. margin:'10rpx 0'
  19. }"></uv-text>
  20. <uv-text :text="orderData.price" type="error" size="16" mode="price"></uv-text>
  21. </view>
  22. </view>
  23. <view class="order-item">
  24. <uv-text text="优惠券" size="14"></uv-text>
  25. <view class="text-flex"
  26. @tap="$navigateTo('/subPages/workarkPage/coupon/coupon?productLevelId=' + orderData.productLevelId + '&price=' + orderData.price)">
  27. <text class="order-item-icon">-</text>
  28. <uv-text :text="minus" type="error" size="14" mode="price"></uv-text>
  29. <uv-icon name="arrow-right" size="16"></uv-icon>
  30. </view>
  31. </view>
  32. <view class="order-count">
  33. <view class="text-flex">
  34. <uv-text text="合计:" size="14"></uv-text>
  35. <uv-text :text="countPriceData.totalFee" type="error" size="14" mode="price"></uv-text>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="hui-button-box">
  40. <view class="button-flex">
  41. <uv-text :text="countPriceData.totalFee" type="error" size="14" mode="price"></uv-text>
  42. <view class="text-flex">
  43. <uv-text text="-" type="error" size="12"></uv-text>
  44. <uv-text :text="minus" type="error" size="12" mode="price"></uv-text>
  45. </view>
  46. </view>
  47. <uv-button type="primary" text="立即支付" @tap="payment" :disabled="isCount"></uv-button>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import {
  53. getServeById,
  54. countPriceAPI,
  55. createOrder,
  56. getWxPay,
  57. getOrderPayState
  58. } from '@/request/api/workark.js'
  59. export default {
  60. props: {
  61. orderId: {
  62. type: Number,
  63. default: 0
  64. },
  65. },
  66. data() {
  67. return {
  68. orderData: {
  69. price: 0
  70. },
  71. countPriceData: {
  72. productCoupon: [],
  73. totalFee: 0
  74. },
  75. isCount: false,
  76. couponChecked: [],
  77. order: {}
  78. };
  79. },
  80. mounted() {
  81. uni.$on('changeCoupon', this.changeCoupon);
  82. if (this.orderId) this.init();
  83. },
  84. beforeDestroy() {
  85. uni.$off('changeCoupon', this.changeCoupon);
  86. },
  87. computed: {
  88. minus() {
  89. let data = this.countPriceData.productCoupon || [];
  90. let num = 0;
  91. for (var i = 0; i < data.length; i++) {
  92. num += data[i].minus
  93. }
  94. return num;
  95. }
  96. },
  97. methods: {
  98. async init() {
  99. let orderData = await getServeById(this.orderId);
  100. if (!orderData.state) return;
  101. this.orderData = orderData.data;
  102. this.countPrice();
  103. },
  104. imageUrl(data) {
  105. if (!data) return '';
  106. let imgData = JSON.parse(data)[0];
  107. if (!imgData) return '';
  108. return imgData.url;
  109. },
  110. async countPrice() {
  111. this.isCount = true;
  112. let couponIds = this.couponChecked.map(node => node.id).join(',') || -1;
  113. let countPriceData = await countPriceAPI(this.orderData.id, couponIds);
  114. this.isCount = false;
  115. if (!countPriceData.state) return;
  116. this.countPriceData = countPriceData.data;
  117. },
  118. changeCoupon(data) {
  119. this.couponChecked = data;
  120. this.countPrice();
  121. },
  122. logout() {
  123. this.$chat.disConnect();
  124. uni.clearStorageSync();
  125. this.$store.dispatch('app/changeOrganization', {});
  126. this.$store.dispatch('app/changeUser', {});
  127. uni.removeTabBarBadge({
  128. index: 3
  129. })
  130. },
  131. async payment() {
  132. if (!uni.getStorageSync('openId')) {
  133. this.$toast('未获取到OpenId,请重新登录');
  134. this.logout();
  135. this.$emit('closePopup');
  136. setTimeout(() => {
  137. uni.navigateTo({
  138. url: '/pages/login/login'
  139. });
  140. }, 400)
  141. return;
  142. }
  143. uni.showLoading({
  144. title: '订单确认中...'
  145. })
  146. let couponIds = this.couponChecked.map(node => node.id).join(',') || -1;
  147. let orderData = await createOrder(this.orderData.id, this.$store.getters.organization.id, couponIds);
  148. if (orderData.state) {
  149. let wxConfig = await getWxPay(orderData.data.orderNo, uni.getStorageSync('openId'));
  150. if (!wxConfig.state) return this.$emit('closePopup');
  151. uni.requestPayment({
  152. provider: 'wxpay',
  153. timeStamp: wxConfig.data.timeStamp,
  154. nonceStr: wxConfig.data.nonceStr,
  155. package: wxConfig.data.prepayId,
  156. signType: wxConfig.data.signType,
  157. paySign: wxConfig.data.paySign,
  158. success: async (res) => {
  159. let payStatus = await getOrderPayState(orderData.data.orderNo);
  160. if (payStatus.state) this.paymentCallback(orderData.data.id);
  161. },
  162. fail: err => {
  163. this.paymentCallback(orderData.data.id);
  164. }
  165. });
  166. }
  167. },
  168. paymentCallback(orderId, status) {
  169. this.$emit('closePopup');
  170. uni.hideLoading();
  171. this.$navigateTo(`/subPages/workarkPage/paymentStatus/paymentStatus?orderId=${orderId}`);
  172. }
  173. },
  174. }
  175. </script>
  176. <style lang="scss">
  177. .sure-order {
  178. padding: 30rpx;
  179. }
  180. .order-detail {
  181. background: #fff;
  182. padding: 30rpx;
  183. border-radius: 16rpx;
  184. }
  185. .order-title {
  186. padding-bottom: 30rpx;
  187. }
  188. .order-content {
  189. display: flex;
  190. }
  191. .order-content-detail {
  192. flex: 1;
  193. width: 0;
  194. margin-left: 30rpx;
  195. }
  196. .order-item {
  197. display: flex;
  198. justify-content: space-between;
  199. align-items: center;
  200. height: 88rpx;
  201. border-bottom: 1px solid $uv-border-color;
  202. margin-bottom: 30rpx;
  203. }
  204. .order-item-icon {
  205. color: $uv-error;
  206. }
  207. .order-count {
  208. display: flex;
  209. justify-content: flex-end;
  210. }
  211. .button-flex {
  212. margin-right: 20rpx;
  213. }
  214. </style>