confirmOrder.vue 8.9 KB

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