confirmOrder.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <s-layout style="margin-top: 40px;">
  3. <view style="background-color: #fff;">
  4. <!-- <view class="cu-bar bg-white ">
  5. <view class="action">
  6. <text class="cuIcon-titles text-orange"></text> 配送方式
  7. </view>
  8. </view> -->
  9. <!-- <scroll-view scroll-x class="bg-white nav">
  10. <view class="flex text-center">
  11. <view class="cu-item flex-sub" :class="TabCur=='1'?'text-orange cur':''" @tap="tabSelect" :data-id="1">
  12. 配送
  13. </view>
  14. <view class="cu-item flex-sub" :class="TabCur=='2'?'text-orange cur':''" @tap="tabSelect" :data-id="2">
  15. 到店
  16. </view>
  17. </view>
  18. </scroll-view> -->
  19. <uni-datetime-picker type="datetime" v-model="datetimesingle" placeholder="预计时间" />
  20. </view>
  21. <!-- <view style="background-color: #fff;">
  22. <view class="cu-bar bg-white ">
  23. <view class="action">
  24. <text class="cuIcon-titles text-orange"></text> 收货地址
  25. </view>
  26. </view>
  27. <view style="width: 100%;padding:10px;" class="ss-flex">
  28. <view style="width: 40%;font-size: 20px;">{{ addressList.name }}</view>
  29. <view style="width: 50%;font-size: 20px;">{{ addressList.phone }}</view>
  30. </view>
  31. <view style="width: 100%;padding:10px;">{{ addressList.address }}</view>
  32. <button style="margin: 20px;" type="primary"
  33. @tap="sheep.$router.go('/pages/user/address/edit')">修改地址</button>
  34. </view> -->
  35. <view style="height: 80vh;">
  36. <view class="cu-bar bg-white ">
  37. <view class="action">
  38. <text class="cuIcon-titles text-orange"></text> 购物车
  39. </view>
  40. </view>
  41. <view style="height: 70vh;overflow-y: auto;background-color: #fff;">
  42. <view v-for="(i, j) in nowCartList" :key="j" class="minmi" style="width: 100vw;">
  43. <image class="imgPic" :src="i.url" mode=""></image>
  44. <view class="rightContainer">
  45. <view class="foodName">
  46. {{ i.name }}
  47. </view>
  48. <view class="foodPrice">
  49. <view class="priceflex">
  50. <text class="zero">¥</text>
  51. {{ i.priceVisable }}
  52. </view>
  53. <view class="shopCar iconfont-themeColor-write" v-show="i.num == 0" @tap="addcart(i)">
  54. <text class="lg text-white cuIcon-add"></text>
  55. </view>
  56. <view class="" v-if="i.num > 0">
  57. <!-- <text class="lg text-white cuIcon-minus" @tap="addcart(i)" ></text> -->
  58. <!-- <uni-number-box :min="0" :max="100" :step="1" v-model="i.num" @tap="chengeCart(i)" /> -->
  59. <text>{{ i.num }}</text>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. <button class="bg-red submit" @click="handleOk()">立即支付</button>
  66. </view>
  67. </s-layout>
  68. </template>
  69. <script setup>
  70. import sheep from '@/sheep';
  71. import { onLaunch, onShow, onError } from '@dcloudio/uni-app';
  72. import { computed, reactive, ref } from 'vue';
  73. import goodsApi from '@/sheep/api/restaurant/goods'
  74. const cart = sheep.$store('cart');
  75. const TabCur = ref(1)
  76. const datetimesingle = ref('')
  77. const nowCartList= computed(() => cart.list)
  78. const addressList = computed(() => {
  79. let addressList = sheep.$store('user').addressList
  80. console.log('restaurant', addressList)
  81. return addressList
  82. })
  83. const handleOk= async () =>{
  84. if(datetimesingle.value ==''){
  85. sheep.$helper.toast('请选择用餐时间')
  86. return
  87. }
  88. let pamser = {
  89. name: addressList.value.name,
  90. phone: addressList.value.phone,
  91. address: addressList.value.address,
  92. useTime:datetimesingle.value,
  93. type: TabCur.value,
  94. goodsList:nowCartList.value,
  95. openid :uni.getStorageSync('openid')
  96. }
  97. const formData = {
  98. ...pamser
  99. }
  100. console.log('pamser',formData)
  101. await goodsApi.createOrder(formData).then(res => {
  102. // console.log(res)
  103. let data = JSON.stringify(res.data)
  104. console.log("res.data:"+JSON.stringify(res.data))
  105. console.log("data.appId:"+data.appId)
  106. let appId = res.data.appId;
  107. let timeStamp = res.data.timeStamp;
  108. let nonceStr = res.data.nonceStr;
  109. let packageX = res.data.packageX;
  110. let signType = res.data.signType;
  111. let paySign = res.data.paySign;
  112. console.log(appId, "appId")
  113. console.log(timeStamp, "timeStamp")
  114. console.log(nonceStr, "nonceStr")
  115. console.log(packageX, "package")
  116. console.log(signType, "signType")
  117. console.log(paySign, "paySign")
  118. uni.requestPayment({
  119. provider: "wxpay",
  120. timeStamp: timeStamp, // 时间戳(单位:秒)
  121. nonceStr: nonceStr, // 随机字符串
  122. package: packageX, // 固定值
  123. signType: signType,
  124. paySign: paySign, // 签名,这里用的 MD5/RSA 签名
  125. success(res) {
  126. console.log("success" + JSON.stringify(res))
  127. uni.reLaunch({
  128. url: 'pages/order/list'
  129. });
  130. sheep.$helper.toast('支付成功')
  131. },
  132. fail(res) {
  133. console.log("fail" + JSON.stringify(res))
  134. sheep.$helper.toast('支付失败')
  135. }
  136. });
  137. })
  138. }
  139. const tabSelect= (e) =>{
  140. console.log(e.currentTarget.dataset.id)
  141. TabCur.value = e.currentTarget.dataset.id;
  142. }
  143. </script>
  144. <style scoped lang="scss">
  145. .title{
  146. width: 99%;
  147. text-align: left;
  148. padding-left: 10px;
  149. border-left: 5px solid red;
  150. font-size: 18px;
  151. margin-left: 20px;
  152. margin-top: 10px;
  153. font-weight: 800;
  154. }
  155. .active {
  156. font-size: 30upx;
  157. color: #F9BE3E;
  158. }
  159. .active2 {
  160. font-size: 30upx;
  161. }
  162. .min {
  163. display: flex;
  164. flex-direction: row;
  165. justify-content: space-around;
  166. flex-wrap: wrap;
  167. // margin: 20px 0;
  168. background-color: white;
  169. padding-bottom: 20px;
  170. }
  171. .minmi {
  172. display: flex;
  173. width: 592upx;
  174. margin-left: 25upx;
  175. padding-top: 51upx;
  176. .imgPic {
  177. width: 208upx;
  178. height: 167upx;
  179. border-radius: 10upx;
  180. margin-left: 20upx;
  181. }
  182. .rightContainer {
  183. display: flex;
  184. flex-direction: column;
  185. height: 167upx;
  186. box-sizing: border-box;
  187. justify-content: space-between;
  188. align-items: flex-start;
  189. padding-left: 18upx;
  190. padding-right: 18upx;
  191. padding-top: 18upx;
  192. // padding-bottom: 18upx;
  193. flex: 1;
  194. .foodName {
  195. font-weight: 700;
  196. font-size: 25upx;
  197. }
  198. .foodPrice {
  199. display: flex;
  200. justify-content: space-between;
  201. width: 375upx;
  202. color: #F9BE3E;
  203. .priceflex {
  204. display: flex;
  205. align-items: center;
  206. .zero {
  207. font-size: 15upx;
  208. }
  209. }
  210. .shopCar {
  211. background-color: #F9BE3E;
  212. border-radius: 45upx;
  213. width: 112upx;
  214. height: 45upx;
  215. font-size: 25upx;
  216. text-align: center;
  217. line-height: 46upx;
  218. }
  219. }
  220. }
  221. }
  222. .aside-main {
  223. width: 100%;
  224. display: flex;
  225. flex-direction: row;
  226. justify-content: space-between;
  227. box-sizing: border-box;
  228. }
  229. .scroll-Y1 {
  230. flex: 1;
  231. box-sizing: border-box;
  232. }
  233. .scroll-Y1 view {
  234. text-align: center;
  235. padding-top: 33upx;
  236. // padding-bottom: 33upx;
  237. }
  238. .scroll-Y2 {
  239. flex: 3;
  240. box-sizing: border-box;
  241. // padding-bottom: 170upx;
  242. }
  243. .scroll-Y2 view {
  244. text-align: center;
  245. /* margin:20upx; */
  246. }
  247. .icon {
  248. width: 50upx;
  249. height: 50upx;
  250. margin-top: 10upx;
  251. }
  252. .icon1 {
  253. width: 30upx;
  254. height: 30upx;
  255. position: absolute;
  256. top: 15upx;
  257. left: 10upx;
  258. }
  259. .btn {
  260. width: 140upx;
  261. height: 60upx;
  262. line-height: 60upx;
  263. margin: 0;
  264. padding: 0;
  265. font-size: 30upx;
  266. }
  267. .serch {
  268. height: 60upx;
  269. flex: 2;
  270. margin-left: 20upx;
  271. margin-right: 20upx;
  272. box-sizing: border-box;
  273. border: solid 1upx #ccc;
  274. border-radius: 10upx;
  275. position: relative;
  276. }
  277. .serch input {
  278. height: 60upx;
  279. margin-left: 60upx;
  280. }
  281. </style>