confirmOrder.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. pay(res.data)
  107. })
  108. }
  109. const pay= (data) =>{
  110. let appId = data.appId;
  111. let timeStamp = data.timeStamp;
  112. let nonceStr = data.nonceStr;
  113. let packageX = data.packageX;
  114. let signType = data.signType;
  115. let paySign = data.paySign;
  116. console.log(appId, "appId")
  117. console.log(timeStamp, "timeStamp")
  118. console.log(nonceStr, "nonceStr")
  119. console.log(packageX, "package")
  120. console.log(signType, "signType")
  121. console.log(paySign, "paySign")
  122. uni.requestPayment({
  123. provider: "wxpay",
  124. timeStamp: timeStamp, // 时间戳(单位:秒)
  125. nonceStr: nonceStr, // 随机字符串
  126. package: packageX, // 固定值
  127. signType: signType,
  128. paySign: paySign, // 签名,这里用的 MD5/RSA 签名
  129. success : function (res) {
  130. console.log("success" + JSON.stringify(res))
  131. // uni.navigateTo({url: '/pages/order/detail'});
  132. sheep.$router.go('/pages/order/detail', {
  133. id:data.orderId,
  134. });
  135. sheep.$helper.toast('支付成功')
  136. },
  137. fail: function (res) {
  138. console.log("fail" + JSON.stringify(res))
  139. sheep.$helper.toast('支付失败')
  140. // pay(data)
  141. },
  142. complete: function (res){
  143. console.log("调用完成")
  144. }
  145. });
  146. }
  147. const tabSelect= (e) =>{
  148. console.log(e.currentTarget.dataset.id)
  149. TabCur.value = e.currentTarget.dataset.id;
  150. }
  151. </script>
  152. <style scoped lang="scss">
  153. .title{
  154. width: 99%;
  155. text-align: left;
  156. padding-left: 10px;
  157. border-left: 5px solid red;
  158. font-size: 18px;
  159. margin-left: 20px;
  160. margin-top: 10px;
  161. font-weight: 800;
  162. }
  163. .active {
  164. font-size: 30upx;
  165. color: #F9BE3E;
  166. }
  167. .active2 {
  168. font-size: 30upx;
  169. }
  170. .min {
  171. display: flex;
  172. flex-direction: row;
  173. justify-content: space-around;
  174. flex-wrap: wrap;
  175. // margin: 20px 0;
  176. background-color: white;
  177. padding-bottom: 20px;
  178. }
  179. .minmi {
  180. display: flex;
  181. width: 592upx;
  182. margin-left: 25upx;
  183. padding-top: 51upx;
  184. .imgPic {
  185. width: 208upx;
  186. height: 167upx;
  187. border-radius: 10upx;
  188. margin-left: 20upx;
  189. }
  190. .rightContainer {
  191. display: flex;
  192. flex-direction: column;
  193. height: 167upx;
  194. box-sizing: border-box;
  195. justify-content: space-between;
  196. align-items: flex-start;
  197. padding-left: 18upx;
  198. padding-right: 18upx;
  199. padding-top: 18upx;
  200. // padding-bottom: 18upx;
  201. flex: 1;
  202. .foodName {
  203. font-weight: 700;
  204. font-size: 25upx;
  205. }
  206. .foodPrice {
  207. display: flex;
  208. justify-content: space-between;
  209. width: 375upx;
  210. color: #F9BE3E;
  211. .priceflex {
  212. display: flex;
  213. align-items: center;
  214. .zero {
  215. font-size: 15upx;
  216. }
  217. }
  218. .shopCar {
  219. background-color: #F9BE3E;
  220. border-radius: 45upx;
  221. width: 112upx;
  222. height: 45upx;
  223. font-size: 25upx;
  224. text-align: center;
  225. line-height: 46upx;
  226. }
  227. }
  228. }
  229. }
  230. .aside-main {
  231. width: 100%;
  232. display: flex;
  233. flex-direction: row;
  234. justify-content: space-between;
  235. box-sizing: border-box;
  236. }
  237. .scroll-Y1 {
  238. flex: 1;
  239. box-sizing: border-box;
  240. }
  241. .scroll-Y1 view {
  242. text-align: center;
  243. padding-top: 33upx;
  244. // padding-bottom: 33upx;
  245. }
  246. .scroll-Y2 {
  247. flex: 3;
  248. box-sizing: border-box;
  249. // padding-bottom: 170upx;
  250. }
  251. .scroll-Y2 view {
  252. text-align: center;
  253. /* margin:20upx; */
  254. }
  255. .icon {
  256. width: 50upx;
  257. height: 50upx;
  258. margin-top: 10upx;
  259. }
  260. .icon1 {
  261. width: 30upx;
  262. height: 30upx;
  263. position: absolute;
  264. top: 15upx;
  265. left: 10upx;
  266. }
  267. .btn {
  268. width: 140upx;
  269. height: 60upx;
  270. line-height: 60upx;
  271. margin: 0;
  272. padding: 0;
  273. font-size: 30upx;
  274. }
  275. .serch {
  276. height: 60upx;
  277. flex: 2;
  278. margin-left: 20upx;
  279. margin-right: 20upx;
  280. box-sizing: border-box;
  281. border: solid 1upx #ccc;
  282. border-radius: 10upx;
  283. position: relative;
  284. }
  285. .serch input {
  286. height: 60upx;
  287. margin-left: 60upx;
  288. }
  289. </style>