submitOrder.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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 cartData" :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="price">{{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. cartData:[],
  89. total: 0,
  90. data: [],
  91. show: false,
  92. value: '',
  93. bussinessInfo:{},
  94. cList: {},
  95. val: null,
  96. vals: null,
  97. tenantId:'',
  98. list: [{
  99. text: "店内用餐",
  100. value: 0
  101. },
  102. {
  103. text: "打包带走",
  104. value: 1
  105. }
  106. ]
  107. }
  108. },
  109. onLoad(option) {
  110. const e = uni.getStorageSync('carl')
  111. this.cList = e
  112. // console.log('233333333333333', e)
  113. // // 解码 URL 编码的字符串
  114. // var dataString = decodeURIComponent(option.data);
  115. // // 尝试将字符串转换为 JSON 对象
  116. // var data = JSON.parse(dataString);
  117. // if(data.carlist[0].imgUrl.url) {
  118. // data.carlist[0].imgUrl = data.carlist[0].imgUrl.url;
  119. // }
  120. // this.data = data
  121. // // 打印解码后的数据
  122. // console.log('eeeeeeeeeeeee============data', data);
  123. const config = process.env.ENV_PATH ? require('../../../' + process.env.ENV_PATH) : require(
  124. '../../../env/dev.js');
  125. this.tenantId = config.tenantId;
  126. this.initCart()
  127. // this.loadBussinessInfo()
  128. },
  129. methods: {
  130. initCart() {
  131. let cartInfo = uni.getStorageSync('cartInfo');
  132. if(cartInfo){
  133. try{
  134. this.cartData = JSON.parse(cartInfo)
  135. this.totalPrice()
  136. }catch(e){}
  137. }
  138. },
  139. totalPrice() {
  140. let total = 0;
  141. for (let i = 0; i < this.cartData.length; i++) {
  142. let priceInCents = Math.round(this.carList[i].price * 100);
  143. let quant = this.carList[i].quantity;
  144. total += priceInCents * quant;
  145. }
  146. this.total = (total / 100).toFixed(2);
  147. },
  148. sendTypeChange(v) {},
  149. radioChange(v) {
  150. console.log('2=================', v)
  151. console.log('2=================22222', this.val)
  152. },
  153. onConfirm(v) {
  154. console.log('vvvvvvvvvvvvvvv', v)
  155. this.value = v.value
  156. this.show = false
  157. },
  158. onCancel() {
  159. this.show = false
  160. },
  161. toBuy() {
  162. console.log('this.val', this.val)
  163. if (this.value == '') {
  164. uni.showToast({
  165. title: '请选择取餐时间',
  166. icon: 'error',
  167. duration: 1000
  168. })
  169. return
  170. }
  171. if (this.val == null && this.val == undefined && this.val == '') {
  172. uni.showToast({
  173. title: '请选择取餐方式',
  174. icon: 'error',
  175. duration: 1000
  176. })
  177. return
  178. }
  179. const userId = uni.getStorageSync('appUserId');
  180. const userName = uni.getStorageSync('userName');
  181. const itemListArray = this.cartData.map(item => ({
  182. skuId: item.skuId,
  183. gift: 1, // 假设所有商品都不是礼物
  184. basePrice: Number(item.basePrice),
  185. price: Number(item.price),
  186. quantity: item.quantity,
  187. sellerType: 'C', // 假设所有商品卖家类型都是 'C'
  188. spuId: item.spuId,
  189. skuName: item.skuName,
  190. title: item.skuTitle,
  191. picUrl: item.imgUrl,
  192. skuProperties: item.skuProperties,
  193. totalFee: multiply(Number(item.price), item.quantity),
  194. adjustFee: 0,
  195. skuCode: item.skuCode,
  196. splitMergeId: item.splitMergeId,
  197. productWeight: item.productWeight,
  198. freightTemplateId: item.freightTemplateId
  199. }))
  200. const params = {
  201. buyerRate:'1',
  202. distributionOrder:'1',
  203. orderState: 'WaitPay',
  204. partConsign:'1',
  205. orderType: 1,
  206. serviceType: '1',
  207. payAmount: Number(this.total),
  208. totalAmount: Number(this.total),
  209. discountAmount: 0,
  210. adjustAmount: 0,
  211. postAmount: 0,
  212. receivedAmount: Number(this.total),
  213. commissionAmount: 0,
  214. payOnDeliveryAmount: 0,
  215. payOnDelivery: '1',
  216. payType: '1',
  217. payChannel: '1',
  218. invoice: '1',
  219. orderSource:'2',
  220. storeId: this.cList.id,
  221. storeName: this.cList.name,
  222. sellerNick: this.cList.name,
  223. sellerId: this.bussinessInfo.id,
  224. buyerNick: userName,
  225. customerId: userId,
  226. sellerRate:'1',
  227. orderItemList: itemListArray,
  228. shippingType: '4',
  229. orderPickup: {
  230. pickupType: this.val,
  231. verify: 2,
  232. // writeOffTime: this.value
  233. }
  234. }
  235. console.log('params', params);
  236. // uni.navigateTo({
  237. // url: `/pages/order/orderPaid/orderPaid`
  238. // })
  239. return
  240. const that = this;
  241. this.$request('post', `/order/tradeOrder/addTradeOrder`, params, true).then(response => {
  242. // 请求成功
  243. console.log('response', response)
  244. if (response.code == 200) {
  245. // const ids = this.data.carlist.map(car => car.id);
  246. // this.$request('delete', `/front/shoppingCart/${ids}`)
  247. // console.log('response.data', response.data)
  248. // uni.$emit('register_refresh');
  249. // uni.showToast({
  250. // title: '已下单,因目前是演示阶段,暂时不能付款',
  251. // icon: 'success',
  252. // duration: 2000,
  253. // complete: () => {
  254. // // 页面跳转放在complete回调中
  255. // uni.navigateTo({
  256. // url: `/pages/order/myOrder/myOrder?type=0`
  257. // })
  258. // }
  259. // })
  260. // // uni.navigateTo({
  261. // // url: `/pages/order/orderPaid/orderPaid?id=${response.data}`
  262. // // })
  263. uni.removeStorageSync('cartInfo');
  264. that.pay(response.msg)
  265. } else if (response.code == 500) {
  266. uni.showToast({
  267. title: response.msg,
  268. icon: 'error',
  269. duration: 2000
  270. });
  271. }
  272. }).catch(error => {
  273. // 请求失败
  274. console.error('请求失败:', error);
  275. })
  276. },
  277. //获取商家信息
  278. loadBussinessInfo() {
  279. const that = this;
  280. this.$req({
  281. url: '/sale/business/queryBusiness',
  282. method: 'GET',
  283. data: {
  284. pageNum: 1, //当前页
  285. pageSize: 20 //每页条数
  286. },
  287. success: res => {
  288. that.bussinessInfo = res.rows[0]
  289. },
  290. fail: err => {
  291. let msg = ''
  292. if (err && err.msg && err.msg.length < 15) {
  293. msg = err.msg
  294. } else {
  295. msg = '系统繁忙'
  296. }
  297. that.$refs.uToast.show({
  298. message: msg
  299. })
  300. },
  301. complete: () => {
  302. }
  303. })
  304. },
  305. //支付
  306. pay(id) {
  307. let that = this;
  308. const openId = uni.getStorageSync("openId");
  309. // let outTradeNo = this.uuid()
  310. this.$req({
  311. url: '/weChatPay/payment/miniPay',
  312. method: 'POST',
  313. data: {
  314. tenantId: this.tenantId,
  315. outTradeNo: id,
  316. openId: openId,
  317. total: this.totalPrice * 100,
  318. },
  319. other: res => {
  320. wx.requestPayment({
  321. "timeStamp": res.timeStamp,
  322. "nonceStr": res.nonceStr,
  323. "package": res.packageValue,
  324. "signType": "RSA",
  325. "paySign": res.paySign,
  326. "success": function(res) {
  327. // console.log('调用支付接口成功', res)
  328. // that.$refs.uToast.show({
  329. // type:'success',
  330. // message: '操作成功!'
  331. // })
  332. uni.redirectTo({
  333. url: '/pages/order/paySuccess/paySuccess?price=' + that
  334. .totalPrice
  335. });
  336. },
  337. "fail": function(res) {
  338. that.$refs.uToast.show({
  339. type: 'error',
  340. message: '支付失败!'
  341. })
  342. setTimeout(() => {
  343. uni.redirectTo({
  344. url: '/pages/order/myOrder/myOrder?type=1'
  345. });
  346. }, 1000)
  347. console.log('调用支付接口fail', res)
  348. },
  349. "complete": function(res) {
  350. console.log('调用支付接口完成', res)
  351. }
  352. })
  353. },
  354. complete: () => {
  355. this.load = false
  356. }
  357. })
  358. }
  359. }
  360. }
  361. </script>
  362. <style lang="scss" scoped>
  363. .addr-label {
  364. padding: 6upx 0;
  365. border-radius: 3px;
  366. background-color: #F6390D;
  367. color: #fff;
  368. width: 120upx;
  369. text-align: center;
  370. flex-shrink: 0;
  371. margin-right: 14upx;
  372. }
  373. .order-spec {
  374. padding-bottom: 10upx;
  375. }
  376. .shop {
  377. padding-top: 20upx;
  378. }
  379. .goods-num {
  380. font-size: 16px;
  381. padding-left: 20upx;
  382. }
  383. .goods-cont {
  384. width: 100%;
  385. box-sizing: border-box;
  386. }
  387. .total-goods {
  388. font-size: 12px;
  389. color: #999;
  390. }
  391. .submit-bar {
  392. height: 130rpx;
  393. width: 100%;
  394. background-color: #FFF;
  395. position: fixed;
  396. left: 0;
  397. bottom: 0;
  398. box-shadow: 0px -4px 16px 0px rgba(0, 0, 0, 0.15);
  399. z-index: 10;
  400. .submit-btn {
  401. background-color: #0581FE;
  402. height: 100%;
  403. width: 100%;
  404. color: #FFF;
  405. font-size: 14px;
  406. // font-weight: 700;
  407. border-radius: 35upx;
  408. }
  409. }
  410. .good-num {
  411. font-size: 12px;
  412. padding-top: 65rpx;
  413. }
  414. .send-label {
  415. font-size: 14px;
  416. font-weight: 700;
  417. }
  418. </style>