index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <view class="pay">
  3. <!-- header -->
  4. <cu-custom isBack bgColor="bg-gradual-blue"><view slot="content">确认订单</view></cu-custom>
  5. <view @click="addressListFunc" class="padding bg-white flex align-center">
  6. <view v-if="Object.keys(addressValue).length>0" style="flex: auto;">
  7. <view class="margin-bottom-sm flex align-center">
  8. <text class="cu-tag text-white round sm margin-right-xs" style="background-color:#ee0a24;">默认</text>
  9. {{addressValue.province}}{{addressValue.city}}{{addressValue.area}}
  10. </view>
  11. <view class="margin-bottom-sm text-bold text-black text-lg">{{addressValue.address}}</view>
  12. <view class=" text-black text-lg">{{addressValue.name}} {{addressValue.tel}}</view>
  13. </view>
  14. <view v-else class="text-grey text-center">
  15. 请挑选收货地址
  16. </view>
  17. <text style="min-width: 40upx;" class="cuIcon-right lg text-gray text-center"></text>
  18. </view>
  19. <view class="padding bg-white margin-tb-sm">
  20. <view class="padding-bottom-sm flex justify-between">
  21. <view class="text-black text-bold">商品清单</view>
  22. <view @click="show = true" class="text-gray flex align-center">
  23. 查看详情
  24. <text class="cuIcon-right lg "></text>
  25. </view>
  26. </view>
  27. <scroll-view style="width: 100%;flex-wrap: nowrap;height: 180upx;" class="flex " enable-flex scroll-x="true">
  28. <image
  29. @click="show = true"
  30. class="margin-right"
  31. v-for="(item, index) in list"
  32. :key="index"
  33. style="min-width: 180upx; width: 180upx;height: 180upx;"
  34. :src="item.img | lazyImage"
  35. mode="aspectFit"
  36. ></image>
  37. </scroll-view>
  38. </view>
  39. <view class="cu-form-group align-start">
  40. <view class="title">买家留言</view>
  41. <textarea placeholder-style="z-index:1;" :value="notes" @input="e=>notes=e.detail.value" maxlength="100" placeholder="请输入买家留言(可选)" cols="30" rows="10"></textarea>
  42. </view>
  43. <!-- footer -->
  44. <view class="footer">
  45. <view class="footer-content flex padding justify-between align-center bg-white">
  46. <view class="flex align-end">
  47. <view class="margin-right-xs text-black">实付款</view>
  48. <view style="transform: translateY(10upx);" class="text-price text-red"><cu-price :value="price" size="52" /></view>
  49. <view class="margin-left">
  50. {{point_price}}积分
  51. </view>
  52. </view>
  53. <button @click="handler" :disabled="!status" class="bg-red cu-btn round "> 提交订单</button>
  54. </view>
  55. </view>
  56. <!-- 工具 -->
  57. <cu-modalC :show.sync="show" custom="2">
  58. <view class="padding text-center text-lg text-black text-bold border">
  59. 商品清单
  60. <text class="text-sm" style="color:#999">(共{{list.length}}件)</text>
  61. </view>
  62. <cu-scrollView height="50vh">
  63. <view v-for="(item,index) in list" class="flex padding">
  64. <image
  65. class="radius margin-right-sm"
  66. style="width: 160upx;height: 160upx;min-width: 160upx;"
  67. lazy-load="true"
  68. :src="item.img | lazyImage"
  69. mode="aspectFit"
  70. ></image>
  71. <view style="flex:auto;position: relative;" class="content margin-right-sm">
  72. <view class="text-black">{{item.name}}</view>
  73. <view class="flex align-center">
  74. <view v-if="item.type==1" class="text-red">
  75. <cu-price :value="item.price" size="32" />
  76. </view>
  77. <view v-else>
  78. {{item.point_price}}积分
  79. </view>
  80. <view v-if="item.vip_price" class="bg-orange light text-xs padding-lr-xs">
  81. <text class="cuIcon-vip lg">会员价</text>
  82. <text class="text-price margin-left-xs">{{ item.vip_price }}</text>
  83. </view>
  84. </view>
  85. <view style="position: absolute;bottom: 0;right: 0;">
  86. x{{item.count}}
  87. </view>
  88. </view>
  89. </view>
  90. </cu-scrollView>
  91. </cu-modalC>
  92. <!-- 工具 -->
  93. <cu-modalA title="警告" :show.sync="showModal" content="请填写收货地址" />
  94. </view>
  95. </template>
  96. <script>
  97. import { mapState, mapActions } from 'vuex';
  98. import {requestPayment} from "@/common/device/index.js";
  99. import api from "./api.js";
  100. export default {
  101. data() {
  102. return {
  103. show: false,
  104. list:[],//商品列表
  105. showModal:false,
  106. price:0,
  107. notes:"",
  108. point_price:0,
  109. status:true,
  110. };
  111. },
  112. computed: {
  113. ...mapState(['openid','appId']),
  114. ...mapState('addressDefault', ['addressValue']),
  115. },
  116. onLoad(options) {
  117. let {list}=options;
  118. this.list=JSON.parse(list);
  119. let price=0,point_price=0;
  120. this.list.forEach(item=>(item.type==1 ? price+=item.price*1*item.count : point_price+=item.point_price*1*item.count));
  121. this.price=price;
  122. this.point_price=point_price;
  123. },
  124. async onShow(){
  125. await this.requestFunc();
  126. },
  127. methods:{
  128. ...mapActions('addressDefault', ['requestFunc']),
  129. addressListFunc(){
  130. uni.navigateTo({
  131. url:"/loginPages/addressList/index"
  132. })
  133. },
  134. async handler(){
  135. try{
  136. this.status=false;
  137. if(!this.addressValue.id){
  138. this.showModal=false;
  139. return false;
  140. }
  141. let list=this.list.map(item=>({id:item.id,count:item.count}));
  142. var result =await api.submit({details:JSON.stringify(list),notes:this.notes,openid:this.openid,appid:this.appId,address_id:this.addressValue.id});
  143. if(result.code!=0) return false;
  144. if(result.data===""){
  145. uni.navigateTo({
  146. url:"/pages/order/index?key=2"
  147. })
  148. return false;
  149. }
  150. result=await requestPayment(result.data);
  151. if(result){
  152. uni.showToast({
  153. title:"支付成功",
  154. icon:"success",
  155. success() {
  156. setTimeout(()=>uni.navigateTo({
  157. url:"/pages/order/index?key=2"
  158. }),3000)
  159. }
  160. })
  161. }else{
  162. uni.showToast({
  163. title:"未支付",
  164. icon:"error",
  165. success() {
  166. setTimeout(()=>uni.navigateTo({
  167. url:"/pages/order/index?key=1"
  168. }),3000)
  169. }
  170. })
  171. }
  172. }catch(err){
  173. uni.showToast({
  174. title:"支付失败",
  175. icon:"error"
  176. })
  177. }finally{
  178. this.status=true;
  179. }
  180. }
  181. }
  182. };
  183. </script>
  184. <style lang="scss" scoped>
  185. .pay {
  186. .border {
  187. position: relative;
  188. &::after {
  189. content: '';
  190. border-top: 1upx solid #ccc;
  191. position: absolute;
  192. left: 0;
  193. bottom: 0;
  194. transform: scale(1, 0.5);
  195. width: 100%;
  196. }
  197. }
  198. .footer {
  199. height: calc(120rpx + env(safe-area-inset-bottom));
  200. .footer-content {
  201. width: 100vw;
  202. padding-bottom: calc(30upx + env(safe-area-inset-bottom)) !important;
  203. box-sizing: border-box;
  204. position: fixed;
  205. left: 0;
  206. bottom: 0;
  207. z-index: 999;
  208. }
  209. }
  210. }
  211. </style>