group-pay.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <view class="flex-common-css iPhone-bottom box-border-box">
  3. <Nav title='提交订单' bgckgroundBox='transparent'></Nav>
  4. <scroll-view :scroll-y="true" class="scroll-view-css" @scrolltolower="scrolltolower">
  5. <view class="p-24 box-border-box bgc-f b-rad-20 mb-20">
  6. <view class="align-items-flex-end flex-justify-space p-b-20 b-b-F9F9F9 mb-20">
  7. <view class="align-items-flex-start">
  8. <image :src="goods_info.cover_img" mode="scaleToFill" class="goods-img mr-18"></image>
  9. <view class="">
  10. <view class="fs-32 w-150 text-overflow-ellipsis-one mb-10">
  11. {{goods_info.title}}
  12. </view>
  13. <view class="mb-10 fs-22 fc-9">
  14. 可用时间:
  15. {{goods_info.usable_time == 1?'24小时可用':goods_info.timeData}}
  16. </view>
  17. <view class="fs-22 fc-9 mb-10">
  18. {{goods_info.is_quota == 0?'不限购':'限购'+ goods_info.quota_num +'张'}} .
  19. {{goods_info.pre_book == 1?'无需预约':'需预约'}}
  20. </view>
  21. <view class="fs-22 fc-9">
  22. 随时退 . 过期自动退
  23. </view>
  24. </view>
  25. </view>
  26. <view class="">
  27. <view class="align-items-center mb-10 flex-justify-end">
  28. <view class="fs-22 fc-9 mr-6 sc-class">
  29. {{goods_info.line_price}}
  30. </view>
  31. <view class="goods_info.price fs-22">
  32. 现价¥<span class="fs-28">{{goods_info.price}}</span>
  33. </view>
  34. </view>
  35. <view class="align-items-center">
  36. <image src="@/static/img/takeout/j.png" mode="" class="j" @click="setNum(1)"></image>
  37. <input type="number" v-model="fromData.number" class="input" @blur='blur' />
  38. <image src="@/static/img/takeout/add.png" mode="" class="j" @click="setNum(2)"></image>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="text-align-center flex-justify-end">
  43. <view class="fs-28 mr-20">
  44. 优惠 <span
  45. class="fc-41ABF5 fs-28">¥{{((Number(goods_info.line_price) - Number(goods_info.price)) * Number(fromData.number)).toFixed(2)}}</span>
  46. </view>
  47. <view class="fs-28">
  48. 小计 <span
  49. class="fc-41ABF5 fs-28 fw-600">¥{{(Number(goods_info.price) * Number(fromData.number)).toFixed(2)}}</span>
  50. </view>
  51. </view>
  52. </view>
  53. </scroll-view>
  54. <view class="but-box align-items-center flex-justify-space bgc-f p-24 box-border-box">
  55. <view class="">
  56. <view class="fs-34 fw-600 fc-41ABF5">
  57. <span class="fs-24 fc-41ABF5 fw-400 mr-12">合计</span><span
  58. class="fs-20 fw-600 fc-41ABF5">¥</span>{{(Number(goods_info.price) * Number(fromData.number)).toFixed(2)}}
  59. </view>
  60. <view class="fc-9">
  61. <span
  62. class="mr-12">共{{fromData.number}}件</span>已优惠¥{{((Number(goods_info.line_price) - Number(goods_info.price)) * Number(fromData.number)).toFixed(2)}}
  63. </view>
  64. </view>
  65. <view class="but bgc-41ABF5 fc-f b-rad-200 text-align-center fs-34" @click="toSave()">
  66. 立即支付
  67. </view>
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. import {
  73. groupInfo,
  74. groupCreate
  75. } from '@/api/group.js'
  76. import {
  77. groupPay
  78. } from '@/api/groupOrder.js';
  79. import tools from '@/service/tools';
  80. export default {
  81. components: {},
  82. data() {
  83. return {
  84. fromData: {
  85. id: 0,
  86. shop_id: 0,
  87. number: 1
  88. },
  89. goods_info: {},
  90. usable_time: '',
  91. isAJAX: false
  92. };
  93. },
  94. onLoad(data) {
  95. console.log(data);
  96. if (data) {
  97. this.fromData.id = data.goods_id
  98. this.fromData.shop_id = data.shop_id
  99. this.groupInfo()
  100. }
  101. },
  102. mounted() {},
  103. methods: {
  104. toSave() {
  105. if (this.isAJAX) {
  106. return
  107. }
  108. this.isAJAX = true;
  109. this.fromData.school_id = uni.getStorageSync('school_id');
  110. groupCreate(this.fromData).then((res) => {
  111. if (res.code === 1) {
  112. uni.redirectTo({
  113. url: `/pages-buy/group-pay-page?orderId=${res.data.order_id}`
  114. });
  115. // groupPay({
  116. // order_id: res.data.order_id
  117. // }).then((ret) => {
  118. // if (ret.code === 1) {
  119. // uni.requestPayment({
  120. // provider: "wxpay", //支付类型-固定值
  121. // timeStamp: ret.data.wx_pay.timeStamp + "", // 时间戳(单位:秒)
  122. // nonceStr: ret.data.wx_pay.nonceStr, // 随机字符串
  123. // package: ret.data.wx_pay.package, // 固定值
  124. // signType: ret.data.wx_pay.signType, //固定值
  125. // paySign: ret.data.wx_pay.paySign, //签名
  126. // success: (ren) => {
  127. // this.isAJAX = false;
  128. // tools.success("支付成功");
  129. // uni.setStorageSync('orderPayType', 3)
  130. // setTimeout(() => {
  131. // uni.switchTab({
  132. // url: "/pages/order/index"
  133. // })
  134. // }, 1000)
  135. // },
  136. // fail: (err) => {
  137. // this.isAJAX = false;
  138. // tools.error("支付失败");
  139. // uni.setStorageSync('orderPayType', 3)
  140. // setTimeout(() => {
  141. // uni.switchTab({
  142. // url: "/pages/order/index"
  143. // })
  144. // }, 1000)
  145. // },
  146. // });
  147. // } else {
  148. // this.isAJAX = false;
  149. // tools.error("支付失败");
  150. // uni.setStorageSync('orderPayType', 3)
  151. // setTimeout(() => {
  152. // uni.switchTab({
  153. // url: "/pages/order/index"
  154. // })
  155. // }, 1000)
  156. // }
  157. // })
  158. } else {
  159. this.isAJAX = false;
  160. tools.error(res.msg);
  161. }
  162. })
  163. },
  164. scrolltolower() {
  165. console.log('触底');
  166. },
  167. blur() {
  168. if (this.goods_info.is_quota == 1) {
  169. if (this.fromData.number >= this.goods_info.quota_num) {
  170. tools.error('限购'+ this.goods_info.quota_num + '张')
  171. this.fromData.number = this.goods_info.quota_num
  172. }
  173. }
  174. if (this.fromData.number >= 99) {
  175. tools.error('购买数量最大为99')
  176. this.fromData.number = 99
  177. } else if (this.fromData.number <= 0) {
  178. tools.error('购买数量最少为1')
  179. this.fromData.number = 1
  180. }
  181. },
  182. setNum(num) {
  183. if (num === 1) {
  184. // 减
  185. if (this.fromData.number <= 1) {
  186. tools.error('购买数量最少为1')
  187. return
  188. }
  189. --this.fromData.number
  190. } else {
  191. // 加
  192. if (this.goods_info.is_quota == 1) {
  193. if (this.fromData.number >= this.goods_info.quota_num) {
  194. tools.error('限购'+ this.goods_info.quota_num + '张')
  195. return
  196. } else if (this.fromData.number >= 99) {
  197. tools.error('购买数量已达最大值')
  198. return
  199. }
  200. }
  201. ++this.fromData.number
  202. }
  203. },
  204. setTimeData(timeData) {
  205. let time = ''
  206. let array = ''
  207. timeData.forEach((v, k) => {
  208. v.forEach((i, j) => {
  209. let timeTwo = ''
  210. if (j == 0 || j == 3) {
  211. timeTwo = i + '-'
  212. } else {
  213. timeTwo = i
  214. }
  215. array = array + timeTwo
  216. })
  217. if (timeData.length === k + 1) {
  218. time = time + array + ''
  219. } else {
  220. time = time + array + ' / '
  221. }
  222. array = ''
  223. })
  224. console.log(time);
  225. return time
  226. },
  227. groupInfo() {
  228. groupInfo({
  229. id: this.fromData.id,
  230. shop_id: this.fromData.shop_id
  231. }).then((res) => {
  232. if (res.code === 1) {
  233. if (res.data.usable_time === 2) {
  234. res.data.timeData = this.setTimeData(res.data.usable_time_arr)
  235. }
  236. this.goods_info = res.data
  237. }
  238. })
  239. },
  240. },
  241. }
  242. </script>
  243. <style lang="scss" scoped>
  244. .sc-class {
  245. text-decoration: line-through
  246. }
  247. .goods-img {
  248. width: 120rpx;
  249. height: 120rpx;
  250. border-radius: 20rpx;
  251. }
  252. .but {
  253. width: 40%;
  254. height: 80rpx;
  255. line-height: 80rpx;
  256. }
  257. .w-150 {
  258. width: 340rpx;
  259. }
  260. .j {
  261. width: 40rpx;
  262. height: 40rpx;
  263. }
  264. .input {
  265. max-width: 50rpx;
  266. margin: 0 10rpx;
  267. text-align: center;
  268. }
  269. </style>