order.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <scroll-view scroll-y="true" class="scroll-view">
  6. <view class="list-scroll-view">
  7. <view class="one_1" @tap="toChoose">
  8. <text class="localicon iconfont icon-dingweixiao"></text>
  9. <view class="other" v-if="address._id">
  10. <view class="name">
  11. <text>{{address.name}},</text>{{address.phone}}
  12. </view>
  13. <view class="other_1">
  14. <text>{{address.province}}</text><text>{{address.city}}</text>
  15. <text>{{address.area}}</text><text>{{address.address}}</text>
  16. </view>
  17. </view>
  18. <view class="address" v-else><text>请选择一个收货地址</text></view>
  19. <text class="iconfont icon-jiantouyou"></text>
  20. </view>
  21. <view class="one_2">
  22. <view class="list">
  23. <view class="list_1">
  24. <view class="l">
  25. <text class="iconfont icon-shangdian"></text>
  26. <text>{{info.shop.name}}</text>
  27. </view>
  28. </view>
  29. <view class="list_2">
  30. <view class="list_2_1">
  31. <view class="l">
  32. <image class="image"
  33. v-if="info.goodsSpec.file&&info.goodsSpec.file.length>0"
  34. :src="info.goodsSpec.file&&info.goodsSpec.file.length>0?info.goodsSpec.file[0].url:''"
  35. mode=""></image>
  36. <image class="image" v-else
  37. :src="info.goods.file&&info.goods.file.length>0?info.goods.file[0].url:''"
  38. mode=""></image>
  39. </view>
  40. <view class="c">
  41. <view class="name">
  42. {{info.goods.name}}
  43. </view>
  44. <view class="Spec">
  45. 规格:{{info.goodsSpec.name}}
  46. </view>
  47. </view>
  48. <view class="r">
  49. <view class="price">
  50. ¥{{info.goodsSpec.price}}
  51. </view>
  52. <view class="num">
  53. ×{{info.num}}
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. <view class="list_3">
  59. <view class="other">
  60. <view class="other_1">配送方式</view>
  61. <view class="other_2"><text class="iconfont icon-duihao"></text>快递配送</view>
  62. </view>
  63. <view class="other">
  64. <view class="other_1">运费</view>
  65. <view class="other_2" v-if="info.goodsSpec.freight!='0'">
  66. ¥{{info.goodsSpec.freight}}
  67. </view>
  68. <view class="other_2" v-else>包邮</view>
  69. </view>
  70. <view class="other">
  71. <view class="other_1">订单备注</view>
  72. <view class="other_3">
  73. <input type="text" v-model="remarks" placeholder="选填,可填写您与卖家达成一致的要求" />
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. <view class="other" v-for="(item,index) in total_detail" :key="index">
  79. <view class="other_1">{{item.zh}}</view>
  80. <view class="other_2">¥{{item.money}}</view>
  81. </view>
  82. </view>
  83. </view>
  84. </scroll-view>
  85. </view>
  86. <view class="two">
  87. <view class="two_1">
  88. <view>实付金额:</view>
  89. <view>¥{{goods_total}}</view>
  90. </view>
  91. <view class="two_2">
  92. <text @tap="toSubmit">提交订单</text>
  93. </view>
  94. </view>
  95. </view>
  96. </mobile-frame>
  97. </template>
  98. <script>
  99. export default {
  100. data() {
  101. return {
  102. // 设备平台信息
  103. system: {},
  104. user: {},
  105. key: '',
  106. address: {},
  107. info: {},
  108. goods_total: 0,
  109. // 金额明细
  110. total_detail: [],
  111. // 收货地址
  112. addressList: [],
  113. // 备注
  114. remarks: ''
  115. };
  116. },
  117. onLoad: function(e) {
  118. const that = this;
  119. uni.$on("id", async (id) => {
  120. let arr = await that.$api(`/address/${id}`, `GET`)
  121. if (arr.errcode == '0') {
  122. that.$set(that, `address`, arr.data)
  123. }
  124. })
  125. that.$set(that, `key`, e.key || '');
  126. that.watchLogin()
  127. },
  128. methods: {
  129. // 监听用户是否登录
  130. watchLogin() {
  131. const that = this;
  132. uni.getStorage({
  133. key: 'token',
  134. success: function(res) {
  135. let user = that.$jwt(res.data);
  136. that.$set(that, `user`, user);
  137. // 设备平台信息
  138. let config = that.$config;
  139. that.$set(that, `system`, config.system);
  140. that.search()
  141. },
  142. fail: function(err) {
  143. uni.navigateTo({
  144. url: `/pages/login/index`
  145. })
  146. }
  147. })
  148. },
  149. // 查询列表
  150. async search() {
  151. const that = this;
  152. let user = that.user;
  153. const res = await that.$api(`/address`, 'GET', {
  154. customer: user._id
  155. })
  156. if (res.errcode == '0') that.$set(that, `addressList`, res.data.reverse());
  157. const arr = await that.$api(`/groupOrder/toOrderPage`, 'POST', {
  158. key: that.key
  159. }, 'group')
  160. if (arr.errcode == '0') {
  161. // 地址
  162. that.$set(that, `address`, arr.data.address);
  163. // 订单
  164. that.$set(that, `info`, arr.data);
  165. // 总价
  166. that.$set(that, `total_detail`, arr.data.total_detail);
  167. that.computedTotal();
  168. }
  169. },
  170. // 选择收货地址
  171. toChoose() {
  172. const that = this;
  173. if (that.address?._id) {
  174. uni.navigateTo({
  175. url: `/pagesMy/address/index?type=${"shopping"}&id=${that.address._id}`
  176. })
  177. } else {
  178. uni.navigateTo({
  179. url: `/pagesMy/address/index?type=${"shopping"}`
  180. })
  181. }
  182. },
  183. // 提交订单
  184. async toSubmit() {
  185. const that = this;
  186. let system = that.system;
  187. if (that.address) {
  188. let obj = {
  189. address: that.address,
  190. shop: that.info.shop._id,
  191. goods: that.info.goods._id,
  192. goodsSpec: that.info.goodsSpec._id,
  193. num: that.info.num,
  194. group: that.info.group,
  195. remarks: that.remarks
  196. }
  197. // 创建订单
  198. let p1 = await that.$api(`/groupOrder`, 'POST', obj, 'group');
  199. if (p1.errcode == '0') {
  200. if (system.uniPlatform == "mp-weixin") {
  201. // 微信支付
  202. uni.showLoading({
  203. title: '加载中'
  204. })
  205. // 支付信息
  206. let p2 = await that.$api('/orderDeal/pay', 'POST', {
  207. order_id: p1.data,
  208. }, 'group')
  209. if (p2.errcode == '0' && p2.data.paySign) {
  210. uni.requestPayment({
  211. "provider": "wxpay",
  212. ...p2.data,
  213. success: async function(res) {
  214. console.log(res);
  215. uni.reLaunch({
  216. url: `/pagesMy/dough/index`
  217. })
  218. },
  219. fail: function(err) {
  220. console.log(err);
  221. uni.showToast({
  222. title: `支付失败`,
  223. icon: 'none'
  224. })
  225. uni.hideLoading();
  226. uni.reLaunch({
  227. url: `/pagesMy/dough/index`
  228. })
  229. }
  230. })
  231. } else {
  232. uni.showToast({
  233. title: p2.errmsg,
  234. icon: 'none'
  235. })
  236. }
  237. } else if (system.uniPlatform == "app") {
  238. uni.requestPayment({
  239. provider: 'alipay',
  240. orderInfo: 'orderInfo',
  241. success: function(res) {
  242. console.log('success:' + JSON.stringify(res));
  243. },
  244. fail: function(err) {
  245. console.log('fail:' + JSON.stringify(err));
  246. }
  247. });
  248. } else {
  249. uni.showToast({
  250. title: `平台不支持支付`,
  251. icon: 'none'
  252. })
  253. }
  254. } else {
  255. uni.showToast({
  256. title: p1.errmsg,
  257. icon: 'none'
  258. })
  259. }
  260. } else {
  261. uni.showToast({
  262. title: `没有收货地址`,
  263. icon: 'none'
  264. })
  265. }
  266. },
  267. // 计算优惠券
  268. async computedTotal() {
  269. const total_detail = this.total_detail;
  270. let total = 0;
  271. for (let val of total_detail) total = this.$plus(total, val.money)
  272. if (total >= 0) {
  273. this.$set(this, `goods_total`, total);
  274. } else {
  275. uni.showToast({
  276. title: `实付金额不能为负数 不能使用该优惠劵`,
  277. icon: 'none'
  278. })
  279. }
  280. }
  281. }
  282. }
  283. </script>
  284. <style lang="scss">
  285. .main {
  286. display: flex;
  287. flex-direction: column;
  288. width: 100vw;
  289. height: 100vh;
  290. .one {
  291. position: relative;
  292. flex-grow: 1;
  293. background-color: var(--f1Color);
  294. .one_1 {
  295. display: flex;
  296. justify-content: space-between;
  297. align-items: center;
  298. width: 100vw;
  299. padding: 2vw;
  300. border-bottom: 1vw dashed var(--fcColor);
  301. .address {
  302. flex-grow: 1;
  303. margin: 0 0 0 2vw;
  304. font-size: var(--font14Size);
  305. color: var(--f85Color);
  306. }
  307. .iconfont {
  308. font-size: var(--font20Szie);
  309. }
  310. .other {
  311. width: 82vw;
  312. padding: 0 2vw;
  313. .name {
  314. font-size: var(--font16Size);
  315. }
  316. .other_1 {
  317. font-size: var(--font14Size);
  318. color: var(--f85Color);
  319. text {
  320. margin: 0 1vw 0 0;
  321. }
  322. }
  323. }
  324. }
  325. .one_2 {
  326. .list {
  327. width: 100vw;
  328. margin: 2vw 0;
  329. .list_1 {
  330. padding: 2vw;
  331. background-color: var(--mainColor);
  332. border-bottom: 0.1vw solid var(--fcColor);
  333. text {
  334. padding: 0 0 0 1vw;
  335. }
  336. }
  337. .list_2 {
  338. padding: 2vw;
  339. background-color: var(--mainColor);
  340. .list_2_1 {
  341. display: flex;
  342. .l {
  343. width: 20vw;
  344. .image {
  345. width: 100%;
  346. height: 20vw;
  347. border-radius: 5px;
  348. }
  349. }
  350. .c {
  351. width: 60vw;
  352. padding: 0 2vw;
  353. .Spec {
  354. font-size: var(--font12Size);
  355. color: var(--f85Color);
  356. }
  357. }
  358. .r {
  359. width: 15vw;
  360. text-align: right;
  361. }
  362. }
  363. .list_2_2 {
  364. padding: 0 1vw 1vw 0;
  365. font-size: var(--font14Size);
  366. }
  367. .list_2_3 {
  368. display: flex;
  369. justify-content: space-between;
  370. border: 1px solid var(--fcColor);
  371. border-radius: 5px;
  372. margin: 0 0 1vw 0;
  373. padding: 1vw;
  374. .left {
  375. .name {
  376. font-size: 14px;
  377. }
  378. .Spec {
  379. font-size: var(--font12Size);
  380. color: var(--f85Color);
  381. }
  382. }
  383. }
  384. }
  385. .list_3 {
  386. width: 96vw;
  387. padding: 2vw;
  388. background-color: var(--mainColor);
  389. .other {
  390. display: flex;
  391. justify-content: space-between;
  392. border-bottom: 0.1vw solid var(--fcColor);
  393. margin: 0 0 2vw 0;
  394. padding: 2vw 0;
  395. .other_1 {
  396. font-size: var(--font16Size);
  397. color: var(--f85Color);
  398. }
  399. .other_3 {
  400. flex-grow: 1;
  401. margin: 0 0 0 2vw;
  402. font-size: var(--font12Size);
  403. }
  404. text {
  405. padding: 0 1vw 0 0;
  406. font-size: var(--font20Szie);
  407. }
  408. }
  409. }
  410. }
  411. .other {
  412. display: flex;
  413. justify-content: space-between;
  414. background-color: var(--mainColor);
  415. border-bottom: 0.1vw solid var(--fcColor);
  416. width: 96vw;
  417. padding: 2vw;
  418. .other_1 {
  419. font-size: var(--font16Size);
  420. color: var(--f85Color);
  421. }
  422. .other_3 {
  423. flex-grow: 1;
  424. margin: 0 0 0 2vw;
  425. font-size: var(--font12Size);
  426. }
  427. .other_4 {
  428. color: var(--fFB1Color);
  429. }
  430. text {
  431. padding: 0 1vw 0 0;
  432. font-size: var(--font20Szie);
  433. }
  434. }
  435. }
  436. }
  437. .two {
  438. display: flex;
  439. justify-content: space-between;
  440. border-top: 0.1vw solid var(--fcColor);
  441. .two_1 {
  442. display: flex;
  443. align-items: center;
  444. padding: 0 2vw;
  445. font-size: var(--font16Size);
  446. view:last-child {
  447. margin: 0 0 0 2vw;
  448. color: var(--ff0Color);
  449. font-weight: bold;
  450. }
  451. }
  452. .two_2 {
  453. padding: 3vw 4vw;
  454. color: var(--mainColor);
  455. font-size: var(--font16Size);
  456. background-color: var(--ff0Color);
  457. }
  458. }
  459. }
  460. .scroll-view {
  461. position: absolute;
  462. top: 0;
  463. left: 0;
  464. right: 0;
  465. bottom: 0;
  466. .list-scroll-view {
  467. display: flex;
  468. flex-direction: row;
  469. flex-wrap: wrap;
  470. }
  471. }
  472. .popup {
  473. display: flex;
  474. flex-direction: column;
  475. height: 100vw;
  476. overflow-x: hidden;
  477. background-color: var(--f5Color);
  478. padding: 2vw;
  479. .list {
  480. .one {
  481. display: flex;
  482. justify-content: space-between;
  483. margin: 2vw 0 0 0;
  484. padding: 2vw;
  485. background-color: var(--mainColor);
  486. .name {
  487. font-size: var(--font16Size);
  488. }
  489. .address {
  490. font-size: var(--font14Size);
  491. }
  492. .iconfont {
  493. line-height: 15vw;
  494. font-size: var(--font20Szie);
  495. }
  496. }
  497. .two {
  498. display: flex;
  499. justify-content: space-between;
  500. border-top: 0.1vw solid var(--fcColor);
  501. padding: 2vw;
  502. background-color: var(--mainColor);
  503. font-size: var(--font14Size);
  504. .text {
  505. margin: 0 2vw 0 0;
  506. border: 0.1vw solid var(--fFB1Color);
  507. padding: 1vw;
  508. font-size: var(--font12Size);
  509. border-radius: 2vw;
  510. color: var(--fFB1Color);
  511. }
  512. }
  513. }
  514. }
  515. </style>