submitOrder.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. data.carlist[0].imgUrl = data.carlist[0].imgUrl.url;
  114. this.data = data
  115. // 打印解码后的数据
  116. console.log('eeeeeeeeeeeee============data', data);
  117. },
  118. methods: {
  119. sendTypeChange(v) {},
  120. radioChange(v) {
  121. console.log('2=================', v)
  122. console.log('2=================22222', this.val)
  123. },
  124. onConfirm(v) {
  125. console.log('vvvvvvvvvvvvvvv', v)
  126. this.value = v.value
  127. this.show = false
  128. },
  129. onCancel() {
  130. this.show = false
  131. },
  132. toBuy() {
  133. console.log('this.val', this.val)
  134. if (this.value == '') {
  135. uni.showToast({
  136. title: '请选择取餐时间',
  137. icon: 'error',
  138. duration: 1000
  139. })
  140. return
  141. }
  142. if (this.val == null && this.val == undefined && this.val == '') {
  143. uni.showToast({
  144. title: '请选择取餐方式',
  145. icon: 'error',
  146. duration: 1000
  147. })
  148. return
  149. }
  150. const userId = uni.getStorageSync('appUserId');
  151. const userName = uni.getStorageSync('userName');
  152. const itemListArray = this.data.carlist.map(item => ({
  153. skuId: item.skuId,
  154. gift: 1, // 假设所有商品都不是礼物
  155. basePrice: Number(item.basePrice),
  156. price: Number(item.price),
  157. quantity: item.quantity,
  158. sellerType: 'C', // 假设所有商品卖家类型都是 'C'
  159. spuId: item.spuId,
  160. skuName: item.skuName,
  161. title: item.skuTitle,
  162. picUrl: item.imgUrl,
  163. skuProperties: item.skuProperties,
  164. totalFee: multiply(Number(item.price), item.quantity),
  165. adjustFee: 0
  166. }))
  167. const params = {
  168. orderState: 1,
  169. orderType: 1,
  170. serviceType: 1,
  171. payAmount: Number(this.data.total),
  172. totalAmount: Number(this.data.total),
  173. discountAmount: 0,
  174. adjustAmount: 0,
  175. postAmount: 0,
  176. receivedAmount: Number(this.data.total),
  177. commissionAmount: 0,
  178. payOnDeliveryAmount: 0,
  179. payOnDelivery: 1,
  180. payType: 1,
  181. payChannel: 1,
  182. invoice: 1,
  183. storeId: this.cList.id,
  184. storeName: this.cList.name,
  185. sellerNick: this.cList.name,
  186. buyerNick: userName,
  187. customerId: userId,
  188. orderItemList: itemListArray,
  189. shippingType: 4,
  190. orderPickup: {
  191. pickupType: this.val,
  192. verify: 2,
  193. // writeOffTime: this.value
  194. }
  195. }
  196. console.log('params', params);
  197. // uni.navigateTo({
  198. // url: `/pages/order/orderPaid/orderPaid`
  199. // })
  200. this.$request('post', `/order/tradeOrder/addTradeOrder`, params, true).then(response => {
  201. // 请求成功
  202. console.log('response', response)
  203. if (response.code == 200) {
  204. const ids = this.data.carlist.map(car => car.id);
  205. this.$request('delete', `/front/shoppingCart/${ids}`)
  206. console.log('response.data', response.data)
  207. uni.showToast({
  208. title: '已下单,因目前是演示阶段,暂时不能付款',
  209. icon: 'success',
  210. duration: 2000,
  211. complete: () => {
  212. // 页面跳转放在complete回调中
  213. uni.navigateTo({
  214. url: `/pages/order/myOrder/myOrder?type=0`
  215. })
  216. }
  217. })
  218. // uni.navigateTo({
  219. // url: `/pages/order/orderPaid/orderPaid?id=${response.data}`
  220. // })
  221. } else if (response.code == 500) {
  222. uni.showToast({
  223. title: response.msg,
  224. icon: 'error',
  225. duration: 2000
  226. });
  227. }
  228. }).catch(error => {
  229. // 请求失败
  230. console.error('请求失败:', error);
  231. })
  232. }
  233. }
  234. }
  235. </script>
  236. <style lang="scss" scoped>
  237. .addr-label {
  238. padding: 6upx 0;
  239. border-radius: 3px;
  240. background-color: #F6390D;
  241. color: #fff;
  242. width: 120upx;
  243. text-align: center;
  244. flex-shrink: 0;
  245. margin-right: 14upx;
  246. }
  247. .order-spec {
  248. padding-bottom: 10upx;
  249. }
  250. .shop {
  251. padding-top: 20upx;
  252. }
  253. .goods-num {
  254. font-size: 16px;
  255. padding-left: 20upx;
  256. }
  257. .goods-cont {
  258. width: 100%;
  259. box-sizing: border-box;
  260. }
  261. .total-goods {
  262. font-size: 12px;
  263. color: #999;
  264. }
  265. .submit-bar {
  266. height: 130rpx;
  267. width: 100%;
  268. background-color: #FFF;
  269. position: fixed;
  270. left: 0;
  271. bottom: 0;
  272. box-shadow: 0px -4px 16px 0px rgba(0, 0, 0, 0.15);
  273. z-index: 10;
  274. .submit-btn {
  275. background-color: #0581FE;
  276. height: 100%;
  277. width: 100%;
  278. color: #FFF;
  279. font-size: 14px;
  280. // font-weight: 700;
  281. border-radius: 35upx;
  282. }
  283. }
  284. .good-num {
  285. font-size: 12px;
  286. padding-top: 65rpx;
  287. }
  288. .send-label {
  289. font-size: 14px;
  290. font-weight: 700;
  291. }
  292. </style>