submitOrder.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <view class="w-full">
  3. <send-type @sendTypeChange="sendTypeChange" />
  4. <view class="gap"></view>
  5. <!-- <view class="address">
  6. <u-cell-group>
  7. <u-cell title="添加收货地址" :border="false" url='' isLink>
  8. <u-icon slot="icon" size="24" name="plus"></u-icon>
  9. </u-cell>
  10. </u-cell-group>
  11. </view> -->
  12. <view class="padding-sm dflex-b bg-main" @click="show = true">
  13. <view class="dflex">
  14. <!-- <view class="addr-label">配送至</view> -->
  15. <view class="w-full dflex-wrap-w send-label">
  16. 取餐时间
  17. </view>
  18. </view>
  19. <u-icon slot="icon" size="20" name="arrow-right" :label="value" labelPos="left"></u-icon>
  20. <!-- <view class="iconfont iconjiantou-01 fs-sm"></view> -->
  21. </view>
  22. <u-datetime-picker :show="show" v-model="value" mode="time" @confirm="onConfirm"
  23. @cancel="onCancel"></u-datetime-picker>
  24. <view class="gap"></view>
  25. <view class="padding-sm dflex-b bg-main">
  26. <view class="dflex">
  27. <!-- <view class="addr-label">配送至</view> -->
  28. <view class="w-full dflex-wrap-w send-label">
  29. 取餐方式
  30. </view>
  31. </view>
  32. <view>
  33. <uni-data-checkbox v-model="val" :localdata="list" @change="radioChange"
  34. selectedColor="#F54319"></uni-data-checkbox>
  35. <!-- <radio style="margin: 0 10px; transform: scale(0.85)" value="r1" :checked="typePicking" color="#ff0000" class="radio">店内用餐
  36. </radio >
  37. <radio style="transform: scale(0.85)" value="r1" :checked="typePickings" color="#ff0000" class="radio">打包带走
  38. </radio> -->
  39. </view>
  40. <!-- <view class="iconfont iconjiantou-01 fs-sm"></view> -->
  41. </view>
  42. <view class="gap"></view>
  43. <view class="goods-order-list w-full padding-lr-sm">
  44. <view class="shop dflex-b ">
  45. <view class="shop-check">
  46. <text class="shop-name">{{cList.name}}</text>
  47. </view>
  48. </view>
  49. <view class="goods-cart w-full">
  50. <view class="goods-cont padding-tb" v-for="(item, index) in data.carlist" :key="index">
  51. <my-goods :item="item">
  52. <view class="good-num">×{{item.quantity}}</view>
  53. </my-goods>
  54. </view>
  55. </view>
  56. </view>
  57. <!-- 金额明细 -->
  58. <view class="gap"></view>
  59. <view class="bg-main">
  60. <view class="dflex-b padding-lr padding-tb-sm">
  61. <view class="flex1">总金额</view>
  62. <view class=""><text style="font-size: 24rpx;">¥</text>{{data.total}}</view>
  63. </view>
  64. <!-- <view class="dflex-b padding-lr padding-tb-sm">
  65. <view class="flex1">运费 (总重:4.960 kg )</view>
  66. <view class="ft-base">¥10.00</view>
  67. </view>
  68. <view class="dflex-b padding-lr padding-tb-sm">
  69. <view class="margin-right-xl">备注</view>
  70. <input class="flex1 padding-sm" type="text" v-model="order_desc" placeholder="请填写买家备注"
  71. placeholder-class="placeholder" />
  72. </view> -->
  73. </view>
  74. <view class="gap"></view>
  75. <!-- <my-gap :height="130" /> -->
  76. <view class="submit-bar padding-sm dflex-b">
  77. <view class="submit-btn dflex-c background-gradient" @click="toBuy">立即下单</view>
  78. </view>
  79. </view>
  80. </template>
  81. <script>
  82. import {
  83. multiply
  84. } from '@/utils/accuracy.js'
  85. export default {
  86. data() {
  87. return {
  88. data: [],
  89. show: false,
  90. value: '',
  91. cList: {},
  92. val: null,
  93. vals: null,
  94. list: [{
  95. text: "店内用餐",
  96. value: 0
  97. },
  98. {
  99. text: "打包带走",
  100. value: 1
  101. }
  102. ]
  103. }
  104. },
  105. onLoad(option) {
  106. const e = uni.getStorageSync('carl')
  107. this.cList = e
  108. console.log('233333333333333', e)
  109. // 解码 URL 编码的字符串
  110. var dataString = decodeURIComponent(option.data);
  111. // 尝试将字符串转换为 JSON 对象
  112. var data = JSON.parse(dataString);
  113. this.data = data
  114. // 打印解码后的数据
  115. console.log('eeeeeeeeeeeee============data', data);
  116. },
  117. methods: {
  118. sendTypeChange(v) {},
  119. radioChange(v) {
  120. console.log('2=================', v)
  121. console.log('2=================22222', this.val)
  122. },
  123. onConfirm(v) {
  124. console.log('vvvvvvvvvvvvvvv', v)
  125. this.value = v.value
  126. this.show = false
  127. },
  128. onCancel() {
  129. this.show = false
  130. },
  131. toBuy() {
  132. console.log('this.val', this.val)
  133. if (this.value == '') {
  134. uni.showToast({
  135. title: '请选择取餐时间',
  136. icon: 'error',
  137. duration: 1000
  138. })
  139. return
  140. }
  141. if (this.val == null && this.val == undefined && this.val == '') {
  142. uni.showToast({
  143. title: '请选择取餐方式',
  144. icon: 'error',
  145. duration: 1000
  146. })
  147. return
  148. }
  149. const userId = uni.getStorageSync('appUserId');
  150. const userName = uni.getStorageSync('userName');
  151. const itemListArray = this.data.carlist.map(item => ({
  152. skuId: item.skuId,
  153. gift: 1, // 假设所有商品都不是礼物
  154. basePrice: Number(item.basePrice),
  155. price: Number(item.price),
  156. quantity: item.quantity,
  157. sellerType: 'C', // 假设所有商品卖家类型都是 'C'
  158. spuId: item.spuId,
  159. skuName: item.skuName,
  160. title: item.skuTitle,
  161. picUrl: item.imgUrl,
  162. skuProperties: item.skuProperties,
  163. totalFee: multiply(Number(item.price), item.quantity),
  164. adjustFee: 0
  165. }))
  166. const params = {
  167. orderState: 1,
  168. orderType: 1,
  169. serviceType: 1,
  170. payAmount: Number(this.data.total),
  171. totalAmount: Number(this.data.total),
  172. discountAmount: 0,
  173. adjustAmount: 0,
  174. postAmount: 0,
  175. receivedAmount: Number(this.data.total),
  176. commissionAmount: 0,
  177. payOnDeliveryAmount: 0,
  178. payOnDelivery: 1,
  179. payType: 1,
  180. payChannel: 1,
  181. invoice: 1,
  182. storeId: this.cList.id,
  183. storeName: this.cList.name,
  184. sellerNick: this.cList.name,
  185. buyerNick: userName,
  186. customerId: userId,
  187. orderItemList: itemListArray,
  188. shippingType: 4,
  189. orderPickup: {
  190. pickupType: this.val,
  191. verify: 2,
  192. // writeOffTime: this.value
  193. }
  194. }
  195. console.log('params', params);
  196. // uni.navigateTo({
  197. // url: `/pages/order/orderPaid/orderPaid`
  198. // })
  199. this.$request('post', `/order/tradeOrder/addTradeOrder`, params, true).then(response => {
  200. // 请求成功
  201. console.log('response', response)
  202. if (response.code == 200) {
  203. const ids = this.data.carlist.map(car => car.id);
  204. this.$request('delete', `/front/shoppingCart/${ids}`)
  205. console.log('response.data', response.data)
  206. uni.showToast({
  207. title: '已下单,因目前是演示阶段,暂时不能付款',
  208. icon: 'success',
  209. duration: 2000,
  210. complete: () => {
  211. // 页面跳转放在complete回调中
  212. uni.navigateTo({
  213. url: `/pages/order/myOrder/myOrder?type=0`
  214. })
  215. }
  216. })
  217. // uni.navigateTo({
  218. // url: `/pages/order/orderPaid/orderPaid?id=${response.data}`
  219. // })
  220. } else if (response.code == 500) {
  221. uni.showToast({
  222. title: response.msg,
  223. icon: 'error',
  224. duration: 2000
  225. });
  226. }
  227. }).catch(error => {
  228. // 请求失败
  229. console.error('请求失败:', error);
  230. })
  231. }
  232. }
  233. }
  234. </script>
  235. <style lang="scss" scoped>
  236. .addr-label {
  237. padding: 6upx 0;
  238. border-radius: 3px;
  239. background-color: #F6390D;
  240. color: #fff;
  241. width: 120upx;
  242. text-align: center;
  243. flex-shrink: 0;
  244. margin-right: 14upx;
  245. }
  246. .order-spec {
  247. padding-bottom: 10upx;
  248. }
  249. .shop {
  250. padding-top: 20upx;
  251. }
  252. .goods-num {
  253. font-size: 16px;
  254. padding-left: 20upx;
  255. }
  256. .goods-cont {
  257. width: 100%;
  258. box-sizing: border-box;
  259. }
  260. .total-goods {
  261. font-size: 12px;
  262. color: #999;
  263. }
  264. .submit-bar {
  265. height: 130rpx;
  266. width: 100%;
  267. background-color: #FFF;
  268. position: fixed;
  269. left: 0;
  270. bottom: 0;
  271. box-shadow: 0px -4px 16px 0px rgba(0, 0, 0, 0.15);
  272. z-index: 10;
  273. .submit-btn {
  274. background-color: #0581FE;
  275. height: 100%;
  276. width: 100%;
  277. color: #FFF;
  278. font-size: 14px;
  279. // font-weight: 700;
  280. border-radius: 35upx;
  281. }
  282. }
  283. .good-num {
  284. font-size: 12px;
  285. padding-top: 65rpx;
  286. }
  287. .send-label {
  288. font-size: 14px;
  289. font-weight: 700;
  290. }
  291. </style>