order.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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. disabled: false
  116. };
  117. },
  118. onLoad: function(e) {
  119. const that = this;
  120. uni.$on("id", async (id) => {
  121. let arr = await that.$api(`/address/${id}`, `GET`)
  122. if (arr.errcode == '0') {
  123. that.$set(that, `address`, arr.data)
  124. }
  125. })
  126. that.$set(that, `key`, e.key || '');
  127. that.watchLogin()
  128. },
  129. methods: {
  130. // 监听用户是否登录
  131. watchLogin() {
  132. const that = this;
  133. uni.getStorage({
  134. key: 'token',
  135. success: function(res) {
  136. let user = that.$jwt(res.data);
  137. that.$set(that, `user`, user);
  138. // 设备平台信息
  139. let config = that.$config;
  140. that.$set(that, `system`, config.system);
  141. that.search()
  142. },
  143. fail: function(err) {
  144. uni.navigateTo({
  145. url: `/pages/login/index`
  146. })
  147. }
  148. })
  149. },
  150. // 查询列表
  151. async search() {
  152. const that = this;
  153. let user = that.user;
  154. const res = await that.$api(`/address`, 'GET', {
  155. customer: user._id
  156. })
  157. if (res.errcode == '0') that.$set(that, `addressList`, res.data.reverse());
  158. const arr = await that.$api(`/groupOrder/toOrderPage`, 'POST', {
  159. key: that.key
  160. }, 'group')
  161. if (arr.errcode == '0') {
  162. // 地址
  163. that.$set(that, `address`, arr.data.address);
  164. // 订单
  165. that.$set(that, `info`, arr.data);
  166. // 总价
  167. that.$set(that, `total_detail`, arr.data.total_detail);
  168. that.computedTotal();
  169. }
  170. },
  171. // 选择收货地址
  172. toChoose() {
  173. const that = this;
  174. if (that.address?._id) {
  175. uni.navigateTo({
  176. url: `/pagesMy/address/index?type=${"shopping"}&id=${that.address._id}`
  177. })
  178. } else {
  179. uni.navigateTo({
  180. url: `/pagesMy/address/index?type=${"shopping"}`
  181. })
  182. }
  183. },
  184. // 提交订单
  185. async toSubmit() {
  186. const that = this;
  187. let system = that.system;
  188. if (that.disabled) return;
  189. that.$set(that, `disabled`, true);
  190. if (that.address) {
  191. let obj = {
  192. address: that.address,
  193. shop: that.info.shop._id,
  194. goods: that.info.goods._id,
  195. goodsSpec: that.info.goodsSpec._id,
  196. num: that.info.num,
  197. group: that.info.group,
  198. remarks: that.remarks
  199. }
  200. // 创建订单
  201. let p1 = await that.$api(`/groupOrder`, 'POST', obj, 'group');
  202. if (p1.errcode == '0') {
  203. if (system.uniPlatform == "mp-weixin") {
  204. // 微信支付
  205. uni.showLoading({
  206. title: '加载中'
  207. })
  208. // 支付信息
  209. let p2 = await that.$api('/orderDeal/pay', 'POST', {
  210. order_id: p1.data,
  211. }, 'group')
  212. if (p2.errcode == '0' && p2.data.paySign) {
  213. uni.requestPayment({
  214. "provider": "wxpay",
  215. ...p2.data,
  216. success: async function(res) {
  217. uni.reLaunch({
  218. url: `/pagesMy/dough/index`
  219. })
  220. },
  221. fail: function(err) {
  222. that.$set(that, `disabled`, false);
  223. uni.showToast({
  224. title: `支付失败`,
  225. icon: 'none'
  226. })
  227. uni.hideLoading();
  228. uni.reLaunch({
  229. url: `/pagesMy/dough/index`
  230. })
  231. }
  232. })
  233. } else {
  234. that.$set(that, `disabled`, false);
  235. uni.showToast({
  236. title: p2.errmsg,
  237. icon: 'none'
  238. })
  239. }
  240. } else if (system.uniPlatform == "app") {
  241. uni.requestPayment({
  242. provider: 'alipay',
  243. orderInfo: 'orderInfo',
  244. success: function(res) {
  245. console.log('success:' + JSON.stringify(res));
  246. },
  247. fail: function(err) {
  248. console.log('fail:' + JSON.stringify(err));
  249. }
  250. });
  251. } else {
  252. uni.showToast({
  253. title: `平台不支持支付`,
  254. icon: 'none'
  255. })
  256. }
  257. } else {
  258. uni.showToast({
  259. title: p1.errmsg,
  260. icon: 'none'
  261. })
  262. }
  263. } else {
  264. uni.showToast({
  265. title: `没有收货地址`,
  266. icon: 'none'
  267. })
  268. }
  269. },
  270. // 计算优惠券
  271. async computedTotal() {
  272. const total_detail = this.total_detail;
  273. let total = 0;
  274. for (let val of total_detail) total = this.$plus(total, val.money)
  275. if (total >= 0) {
  276. this.$set(this, `goods_total`, total);
  277. } else {
  278. uni.showToast({
  279. title: `实付金额不能为负数 不能使用该优惠劵`,
  280. icon: 'none'
  281. })
  282. }
  283. }
  284. }
  285. }
  286. </script>
  287. <style lang="scss">
  288. .main {
  289. display: flex;
  290. flex-direction: column;
  291. width: 100vw;
  292. height: 100vh;
  293. .one {
  294. position: relative;
  295. flex-grow: 1;
  296. background-color: var(--f1Color);
  297. .one_1 {
  298. display: flex;
  299. justify-content: space-between;
  300. align-items: center;
  301. width: 100vw;
  302. padding: 2vw;
  303. border-bottom: 1vw dashed var(--fcColor);
  304. .address {
  305. flex-grow: 1;
  306. margin: 0 0 0 2vw;
  307. font-size: var(--font14Size);
  308. color: var(--f85Color);
  309. }
  310. .iconfont {
  311. font-size: var(--font20Szie);
  312. }
  313. .other {
  314. width: 82vw;
  315. padding: 0 2vw;
  316. .name {
  317. font-size: var(--font16Size);
  318. }
  319. .other_1 {
  320. font-size: var(--font14Size);
  321. color: var(--f85Color);
  322. text {
  323. margin: 0 1vw 0 0;
  324. }
  325. }
  326. }
  327. }
  328. .one_2 {
  329. .list {
  330. width: 100vw;
  331. margin: 2vw 0;
  332. .list_1 {
  333. padding: 2vw;
  334. background-color: var(--mainColor);
  335. border-bottom: 0.1vw solid var(--fcColor);
  336. text {
  337. padding: 0 0 0 1vw;
  338. }
  339. }
  340. .list_2 {
  341. padding: 2vw;
  342. background-color: var(--mainColor);
  343. .list_2_1 {
  344. display: flex;
  345. .l {
  346. width: 20vw;
  347. .image {
  348. width: 100%;
  349. height: 20vw;
  350. border-radius: 5px;
  351. }
  352. }
  353. .c {
  354. width: 60vw;
  355. padding: 0 2vw;
  356. .Spec {
  357. font-size: var(--font12Size);
  358. color: var(--f85Color);
  359. }
  360. }
  361. .r {
  362. width: 15vw;
  363. text-align: right;
  364. }
  365. }
  366. .list_2_2 {
  367. padding: 0 1vw 1vw 0;
  368. font-size: var(--font14Size);
  369. }
  370. .list_2_3 {
  371. display: flex;
  372. justify-content: space-between;
  373. border: 1px solid var(--fcColor);
  374. border-radius: 5px;
  375. margin: 0 0 1vw 0;
  376. padding: 1vw;
  377. .left {
  378. .name {
  379. font-size: 14px;
  380. }
  381. .Spec {
  382. font-size: var(--font12Size);
  383. color: var(--f85Color);
  384. }
  385. }
  386. }
  387. }
  388. .list_3 {
  389. width: 96vw;
  390. padding: 2vw;
  391. background-color: var(--mainColor);
  392. .other {
  393. display: flex;
  394. justify-content: space-between;
  395. border-bottom: 0.1vw solid var(--fcColor);
  396. margin: 0 0 2vw 0;
  397. padding: 2vw 0;
  398. .other_1 {
  399. font-size: var(--font16Size);
  400. color: var(--f85Color);
  401. }
  402. .other_3 {
  403. flex-grow: 1;
  404. margin: 0 0 0 2vw;
  405. font-size: var(--font12Size);
  406. }
  407. text {
  408. padding: 0 1vw 0 0;
  409. font-size: var(--font20Szie);
  410. }
  411. }
  412. }
  413. }
  414. .other {
  415. display: flex;
  416. justify-content: space-between;
  417. background-color: var(--mainColor);
  418. border-bottom: 0.1vw solid var(--fcColor);
  419. width: 96vw;
  420. padding: 2vw;
  421. .other_1 {
  422. font-size: var(--font16Size);
  423. color: var(--f85Color);
  424. }
  425. .other_3 {
  426. flex-grow: 1;
  427. margin: 0 0 0 2vw;
  428. font-size: var(--font12Size);
  429. }
  430. .other_4 {
  431. color: var(--fFB1Color);
  432. }
  433. text {
  434. padding: 0 1vw 0 0;
  435. font-size: var(--font20Szie);
  436. }
  437. }
  438. }
  439. }
  440. .two {
  441. display: flex;
  442. justify-content: space-between;
  443. border-top: 0.1vw solid var(--fcColor);
  444. .two_1 {
  445. display: flex;
  446. align-items: center;
  447. padding: 0 2vw;
  448. font-size: var(--font16Size);
  449. view:last-child {
  450. margin: 0 0 0 2vw;
  451. color: var(--fFB1Color);
  452. font-weight: bold;
  453. }
  454. }
  455. .two_2 {
  456. padding: 3vw 4vw;
  457. color: var(--mainColor);
  458. font-size: var(--font16Size);
  459. background-color: var(--fFB1Color);
  460. }
  461. }
  462. }
  463. .scroll-view {
  464. position: absolute;
  465. top: 0;
  466. left: 0;
  467. right: 0;
  468. bottom: 0;
  469. .list-scroll-view {
  470. display: flex;
  471. flex-direction: row;
  472. flex-wrap: wrap;
  473. }
  474. }
  475. .popup {
  476. display: flex;
  477. flex-direction: column;
  478. height: 100vw;
  479. overflow-x: hidden;
  480. background-color: var(--f5Color);
  481. padding: 2vw;
  482. .list {
  483. .one {
  484. display: flex;
  485. justify-content: space-between;
  486. margin: 2vw 0 0 0;
  487. padding: 2vw;
  488. background-color: var(--mainColor);
  489. .name {
  490. font-size: var(--font16Size);
  491. }
  492. .address {
  493. font-size: var(--font14Size);
  494. }
  495. .iconfont {
  496. line-height: 15vw;
  497. font-size: var(--font20Szie);
  498. }
  499. }
  500. .two {
  501. display: flex;
  502. justify-content: space-between;
  503. border-top: 0.1vw solid var(--fcColor);
  504. padding: 2vw;
  505. background-color: var(--mainColor);
  506. font-size: var(--font14Size);
  507. .text {
  508. margin: 0 2vw 0 0;
  509. border: 0.1vw solid var(--fFB1Color);
  510. padding: 1vw;
  511. font-size: var(--font12Size);
  512. border-radius: 2vw;
  513. color: var(--fFB1Color);
  514. }
  515. }
  516. }
  517. }
  518. </style>