createOrder.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. <template>
  2. <view class="padding-t-30">
  3. <!-- 地址 -->
  4. <navigator url="/pages/set/address?source=1" class="address-section">
  5. <view class="order-content" v-if="addressData.real_name">
  6. <view class="cen">
  7. <view class="top">
  8. <text class="name">{{ addressData.real_name }}</text>
  9. <text class="mobile">{{ addressData.phone }}</text>
  10. </view>
  11. <text
  12. class="address flex">{{ addressData.province + addressData.city + addressData.district }}{{ addressData.detail }}</text>
  13. </view>
  14. <text class="iconfont iconenter"></text>
  15. </view>
  16. <view class="order-content" v-if="!addressData.real_name">
  17. <view class="addAddress">
  18. <text class="iconfont iconaddition"></text>
  19. <text>添加收货地址</text>
  20. </view>
  21. </view>
  22. </navigator>
  23. <view class="goodsList">
  24. <view class="goods-section" v-for="(ls, ind) in shopList" :key="ind">
  25. <!-- 商品列表 -->
  26. <view class="g-item">
  27. <image :src="ls.productInfo.image"></image>
  28. <view class="right">
  29. <text class="title clamp">{{ ls.productInfo.store_name }}</text>
  30. <text class="spec">{{ ls.productInfo.attrInfo ? ls.productInfo.attrInfo.suk : '默认' }}</text>
  31. <view class="price-box">
  32. <text
  33. class="price">¥{{ ls.productInfo.attrInfo ? ls.productInfo.attrInfo.price : ls.productInfo.price }}</text>
  34. <text class="number">{{ 'x ' + ls.cart_num + (ls.productInfo.unit_name || '') }}</text>
  35. <!-- <view class="number">
  36. <uni-number-box class="step" :value="lss.number" :index="indx" @eventChange="numberChange"></uni-number-box>
  37. </view> -->
  38. </view>
  39. <view class="serverSet" v-if="ls.day>0">
  40. (<text>服务费:{{ls.day_deducted}}</text>
  41. <text class="margin-l-10">服务天数:{{ls.day}}天</text>)
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <!-- 金额明细 -->
  48. <view class="yt-list">
  49. <view class="yt-list-cell b-b">
  50. <text class="cell-tit clamp">运费</text>
  51. <text class="cell-tip disabled">{{ Postage }}</text>
  52. </view>
  53. <view class="yt-list-cell b-b">
  54. <text class="cell-tit clamp">备注</text>
  55. <input class="desc" type="text" v-model="desc" placeholder="请填写备注信息" placeholder-class="placeholder" />
  56. </view>
  57. </view>
  58. <view class="yt-list">
  59. <view class="yt-list-cell b-b" v-if="fx" @click="payType='weixin'">
  60. <view class="cell-tit flex">
  61. <image class="orderIcon" src="../../static/icon/orderWx.png" mode="widthFix"></image>
  62. <text class="margin-l-10">微信支付</text>
  63. </view>
  64. <image class="checked" v-if="payType=='weixin'" src="../../static/icon/addressIconXz.png"
  65. mode="widthFix"></image>
  66. <view v-else class="noChecked"></view>
  67. </view>
  68. <!-- #ifdef APP-PLUS -->
  69. <view class="yt-list-cell b-b" @click="payType='ali'">
  70. <view class="cell-tit flex">
  71. <image class="orderIcon" src="../../static/icon/orderAli.png" mode="widthFix"></image>
  72. <text class="margin-l-10">支付宝</text>
  73. </view>
  74. <image class="checked" v-if="payType=='ali'" src="../../static/icon/addressIconXz.png" mode="widthFix">
  75. </image>
  76. <view v-else class="noChecked"></view>
  77. </view>
  78. <!-- #endif -->
  79. <view class="yt-list-cell b-b" @click="payType='yue'">
  80. <view class="cell-tit flex">
  81. <image class="orderIcon" src="../../static/icon/ye.png" mode="widthFix"></image>
  82. <text class="margin-l-10">余额({{now_money}})</text>
  83. </view>
  84. <image class="checked" v-if="payType=='yue'" src="../../static/icon/addressIconXz.png" mode="widthFix">
  85. </image>
  86. <view v-else class="noChecked"></view>
  87. </view>
  88. </view>
  89. <!-- 底部 -->
  90. <view class="footer">
  91. <view class="price-content">
  92. <text>实付款</text>
  93. <text class="price-tip">¥</text>
  94. <text class="price">{{ payPrice }}</text>
  95. </view>
  96. <text class="submit" :class="{submitNo:payLoding}" @click="payLoding?'':submit()">提交订单</text>
  97. </view>
  98. </view>
  99. </template>
  100. <script>
  101. import {
  102. mapState
  103. } from 'vuex';
  104. import {
  105. confirm,
  106. computedOrderkey,
  107. createOrderkey,
  108. orderPay
  109. } from '@/api/order.js';
  110. import {
  111. getUserInfo
  112. } from '@/api/user.js';
  113. // #ifdef H5
  114. import weixinObj from "@/plugin/jweixin-module/index.js";
  115. // #endif
  116. export default {
  117. data() {
  118. return {
  119. payType: 'ali',
  120. desc: '', //备注
  121. // 收货地址
  122. addressData: {},
  123. // 商品列表
  124. shopList: [],
  125. // 购物车id
  126. cartId: '',
  127. //购物金额详情
  128. moneyAll: {
  129. storeFreePostage: 0, //邮费优惠
  130. storePostage: 0, //邮费
  131. totalPrice: 0, //总支付金额
  132. vipPrice: 0 //vip优惠价
  133. },
  134. payPrice: 0, //总支付金额
  135. orderKey: '', //订单id
  136. payLoding: false, //判断是否支付中
  137. orderId: '', //订单id
  138. now_money: 0, //余额
  139. onShopId: -1, //默认-1为不存在商家id
  140. };
  141. },
  142. onLoad(option) {
  143. // 保存当前商品在购物车中的id
  144. this.cartId = option.id;
  145. // 判断是否要读取商家id
  146. if (option.shopId) {
  147. this.onShopId = option.shopId;
  148. }
  149. this.loadData();
  150. this.userinfo();
  151. },
  152. computed: {
  153. Postage() {
  154. let money = +this.moneyAll.storePostage;
  155. if (money == 0) {
  156. return '免运费';
  157. } else {
  158. return '¥' + money;
  159. }
  160. },
  161. payAllMoney() {
  162. return +this.moneyAll.totalPrice + +this.moneyAll.vipPrice;
  163. },
  164. ...mapState('shop', ['shopDetail']),
  165. ...mapState(['fx'])
  166. },
  167. methods: {
  168. // 加载用户基础信息
  169. userinfo() {
  170. getUserInfo({}).then(({
  171. data
  172. }) => {
  173. this.now_money = data.now_money;
  174. });
  175. },
  176. // 计算支付金额
  177. payMoneyNub() {
  178. computedOrderkey({
  179. orderkey: this.orderKey,
  180. useIntegral: 0, //是否积分抵扣
  181. addressId: this.addressData.id //地址编号
  182. })
  183. .then(({
  184. data
  185. }) => {
  186. this.integralShow = true;
  187. // 获取支付金额
  188. this.payPrice = +data.result.pay_price;
  189. this.integralMoney = data.result.deduction_price;
  190. })
  191. .catch(e => {
  192. console.log(e);
  193. this.integralShow = false;
  194. });
  195. },
  196. // 加载基础数据
  197. loadData() {
  198. let obj = this;
  199. confirm({
  200. cartId: obj.cartId + ''
  201. }).then(({
  202. data
  203. }) => {
  204. obj.addressData = data.addressInfo || {};
  205. obj.shopList = data.cartInfo; //商品列表
  206. obj.moneyAll = data.priceGroup; //金额数据
  207. obj.orderKey = data.orderKey; //订单key
  208. // 计算金额
  209. this.payMoneyNub();
  210. });
  211. },
  212. // 提交订单
  213. submit() {
  214. let obj = this;
  215. if (!this.addressData.real_name) {
  216. this.$api.msg('请选择收货地址');
  217. return false;
  218. }
  219. // 判断是否余额不足
  220. if (obj.payType == 'yue' && +obj.now_money < obj.payPrice) {
  221. uni.showModal({
  222. title: '提示',
  223. content: '账户余额不足!',
  224. showCancel: false,
  225. });
  226. return;
  227. }
  228. uni.showLoading({
  229. title: '支付中',
  230. mask: true
  231. })
  232. // 支付中
  233. obj.payLoding = true;
  234. // 判断是否为未支付订单中跳转进入
  235. obj.firstCreateOrder();
  236. },
  237. // 订单金额支付
  238. orderMoneyPay() {
  239. let obj = this;
  240. orderPay({
  241. uni: obj.orderId,
  242. // #ifdef H5
  243. from: 'weixin', //来源
  244. // #endif
  245. // #ifdef MP-WEIXIN
  246. from: 'routine', //来源
  247. // #endif
  248. // #ifdef APP-PLUS
  249. from: 'app', //来源
  250. // #endif
  251. paytype: obj.payType //支付类型 weixin-微信 yue-余额
  252. })
  253. .then(e => {
  254. // 判断是否微信小程序支付
  255. if (obj.payType == 'weixin') {
  256. // #ifdef H5 || MP
  257. let da = e.data.result.jsConfig;
  258. let data = {
  259. nonceStr: da.nonceStr,
  260. package: da.package,
  261. signType: da.signType,
  262. paySign: da.paySign,
  263. success: function(res) {
  264. obj.paySuccessTo();
  265. },
  266. fail: () => {
  267. uni.navigateTo({
  268. url: '/pages/order/order?state=0'
  269. });
  270. }
  271. };
  272. // #endif
  273. // #ifdef H5
  274. data.timestamp = da.timestamp;
  275. weixinObj.chooseWXPay(data);
  276. // #endif
  277. // #ifdef MP-WEIXIN
  278. data.timeStamp = da.timestamp;
  279. wx.requestPayment(data);
  280. // #endif
  281. // #ifdef APP
  282. console.log( e.data.result.jsConfig,'返回数值');
  283. uni.requestPayment({
  284. provider: 'wxpay',
  285. orderInfo: e.data.result.jsConfig,
  286. success(e) {
  287. obj.paySuccessTo();
  288. },
  289. fail: (e) => {
  290. console.log(e,'支付失败');
  291. uni.navigateTo({
  292. url: '/pages/order/order?state=0'
  293. });
  294. }
  295. })
  296. // #endif
  297. }
  298. // #ifdef APP
  299. if(obj.payType == 'ali'){
  300. uni.requestPayment({
  301. provider: 'alipay',
  302. orderInfo: e.data.result.jsConfig,
  303. success(e) {
  304. obj.paySuccessTo();
  305. },
  306. fail: (e) => {
  307. console.log(e,'支付失败');
  308. uni.navigateTo({
  309. url: '/pages/order/order?state=0'
  310. });
  311. }
  312. })
  313. }
  314. // #endif
  315. uni.hideLoading();
  316. obj.payLoding = false;
  317. })
  318. .catch(e => {
  319. // 支付完成
  320. uni.hideLoading();
  321. obj.payLoding = false;
  322. console.log(e);
  323. });
  324. },
  325. // 支付成功跳转
  326. paySuccessTo() {
  327. uni.hideLoading();
  328. uni.redirectTo({
  329. url: '/pages/user/money/paySuccess?orderid=' + this.orderId,
  330. });
  331. },
  332. // 初次订单创建
  333. firstCreateOrder() {
  334. let obj = this;
  335. // 获取下单页面数据
  336. let prepage = obj;
  337. let data = {
  338. real_name: prepage.addressData.real_name, //联系人名称
  339. phone: prepage.addressData.phone, //联系人号码
  340. addressId: prepage.addressData.id, //支付地址id
  341. useIntegral: 0, //是否积分抵扣1为是0为否
  342. payType: obj.payType, //支付类型 weixin-微信 yue-余额
  343. mark: prepage.desc, //备注
  344. // #ifdef H5
  345. from: 'weixin', //来源
  346. // #endif
  347. // #ifdef MP-WEIXIN
  348. from: 'routine', //来源
  349. // #endif
  350. // #ifdef APP-PLUS
  351. from: 'app', //来源
  352. // #endif
  353. shipping_type: 1, //提货方式 1 快递 2自提
  354. };
  355. // 判断是否需要读取非默认商家id
  356. if (obj.onShopId != -1) {
  357. data.store_id = obj.onShopId;
  358. } else {
  359. data.store_id = obj.shopDetail.id;
  360. }
  361. // 生成订单
  362. createOrderkey(data, obj.orderKey)
  363. .then(({
  364. data,
  365. status,
  366. msg
  367. }) => {
  368. // 判断是否支付失败
  369. if (data.status == 'ORDER_EXIST') {
  370. uni.showModal({
  371. title: '提示',
  372. content: msg,
  373. showCancel: false
  374. });
  375. uni.hideLoading();
  376. obj.payLoding = false;
  377. return;
  378. }
  379. // 保存订单号
  380. obj.orderId = data.result.orderId;
  381. // 判断是否为余额支付
  382. if (obj.payType == 'yue') {
  383. console.log('余额支付', status == 200 && data.status == 'SUCCESS');
  384. if (status == 200 && data.status == 'SUCCESS') {
  385. obj.paySuccessTo();
  386. } else {
  387. obj.$api.msg(msg);
  388. }
  389. } else {
  390. // 立即支付
  391. obj.orderMoneyPay();
  392. }
  393. })
  394. .catch(e => {
  395. uni.hideLoading();
  396. obj.payLoding = false;
  397. console.log(e);
  398. });
  399. }
  400. }
  401. };
  402. </script>
  403. <style lang="scss">
  404. page {
  405. background: $page-color-base;
  406. padding-bottom: 100rpx;
  407. }
  408. .address-section {
  409. border-radius: 20rpx;
  410. padding: 30rpx;
  411. margin: 0 $page-row-spacing;
  412. background: #fff;
  413. position: relative;
  414. .order-content {
  415. min-height: 100rpx;
  416. display: flex;
  417. align-items: center;
  418. .leftIcon {
  419. width: 36rpx;
  420. margin: 0 30rpx;
  421. }
  422. .addAddress {
  423. text-align: center;
  424. width: 100%;
  425. display: flex;
  426. justify-content: center;
  427. align-items: center;
  428. .iconaddition {
  429. font-size: 55rpx;
  430. line-height: 1;
  431. border-radius: 100rpx;
  432. margin-right: 20rpx;
  433. }
  434. }
  435. }
  436. .iconlocation {
  437. flex-shrink: 0;
  438. display: flex;
  439. align-items: center;
  440. justify-content: center;
  441. width: 90rpx;
  442. color: #888;
  443. font-size: 44rpx;
  444. }
  445. .cen {
  446. display: flex;
  447. flex-direction: column;
  448. flex: 1;
  449. font-size: 28rpx;
  450. color: $font-color-dark;
  451. }
  452. .name {
  453. font-size: 34rpx;
  454. margin-right: 24rpx;
  455. }
  456. .address {
  457. margin-top: 16rpx;
  458. margin-right: 20rpx;
  459. color: $font-color-light;
  460. }
  461. .icon-you {
  462. font-size: 32rpx;
  463. color: $font-color-light;
  464. margin-right: 30rpx;
  465. }
  466. .a-bg {
  467. position: absolute;
  468. left: 0;
  469. bottom: 0;
  470. display: block;
  471. width: 100%;
  472. height: 5rpx;
  473. }
  474. }
  475. .goodsList {
  476. margin: 0 $page-row-spacing;
  477. padding: 30rpx;
  478. background: #fff;
  479. border-radius: 20rpx;
  480. margin-top: 30rpx;
  481. }
  482. .goods-section {
  483. .logo {
  484. display: block;
  485. width: 50rpx;
  486. height: 50rpx;
  487. border-radius: 100px;
  488. }
  489. .name {
  490. font-size: 30rpx;
  491. color: $font-color-base;
  492. margin-left: 24rpx;
  493. }
  494. .g-item {
  495. display: flex;
  496. image {
  497. flex-shrink: 0;
  498. display: block;
  499. width: 170rpx;
  500. height: 170rpx;
  501. border-radius: 4rpx;
  502. }
  503. .right {
  504. flex: 1;
  505. padding-left: 24rpx;
  506. overflow: hidden;
  507. .serverSet {
  508. font-size: 22rpx;
  509. color: $font-color-light;
  510. }
  511. }
  512. .title {
  513. font-size: 30rpx;
  514. color: $font-color-dark;
  515. }
  516. .spec {
  517. font-size: 26rpx;
  518. color: $font-color-light;
  519. }
  520. .price-box {
  521. display: flex;
  522. align-items: center;
  523. font-size: 32rpx;
  524. padding-top: 10rpx;
  525. color: $font-color-light;
  526. .price {
  527. margin-bottom: 4rpx;
  528. }
  529. .number {
  530. font-size: 26rpx;
  531. margin-left: 20rpx;
  532. }
  533. }
  534. .step-box {
  535. position: relative;
  536. }
  537. }
  538. }
  539. .yt-list {
  540. background: #fff;
  541. margin: 0 $page-row-spacing;
  542. margin-top: 30rpx;
  543. border-radius: 20rpx;
  544. }
  545. .yt-list-cell {
  546. display: flex;
  547. align-items: center;
  548. justify-content: space-between;
  549. padding: 10rpx 30rpx 10rpx 40rpx;
  550. line-height: 70rpx;
  551. position: relative;
  552. .checked,
  553. .noChecked {
  554. width: 36rpx;
  555. height: 36rpx;
  556. }
  557. .noChecked {
  558. border: 1px solid $font-color-light;
  559. border-radius: 100rpx;
  560. }
  561. &.cell-hover {
  562. background: #fafafa;
  563. }
  564. &.b-b:after {
  565. left: 30rpx;
  566. }
  567. .cell-icon {
  568. height: 32rpx;
  569. width: 32rpx;
  570. font-size: 22rpx;
  571. color: #fff;
  572. text-align: center;
  573. line-height: 32rpx;
  574. background: #f85e52;
  575. border-radius: 4rpx;
  576. margin-right: 12rpx;
  577. &.hb {
  578. background: #ffaa0e;
  579. }
  580. &.lpk {
  581. background: #3ab54a;
  582. }
  583. }
  584. .cell-more {
  585. align-self: center;
  586. font-size: 24rpx;
  587. color: $font-color-light;
  588. margin-left: 8rpx;
  589. margin-right: -10rpx;
  590. }
  591. .cell-tit {
  592. font-size: 26rpx;
  593. color: $font-color-light;
  594. margin-right: 10rpx;
  595. .orderIcon {
  596. width: 48rpx;
  597. }
  598. }
  599. .cell-tip {
  600. font-size: 26rpx;
  601. color: $font-color-dark;
  602. &.disabled {
  603. color: $font-color-light;
  604. }
  605. &.active {
  606. color: $base-color;
  607. }
  608. &.red {
  609. color: $base-color;
  610. }
  611. }
  612. &.desc-cell {
  613. .cell-tit {
  614. max-width: 90rpx;
  615. }
  616. }
  617. .desc {
  618. text-align: right;
  619. font-size: $font-base;
  620. color: $font-color-light;
  621. }
  622. }
  623. /* 支付列表 */
  624. .pay-list {
  625. padding-left: 40rpx;
  626. margin-top: 16rpx;
  627. background: #fff;
  628. .pay-item {
  629. display: flex;
  630. align-items: center;
  631. padding-right: 20rpx;
  632. line-height: 1;
  633. height: 110rpx;
  634. position: relative;
  635. }
  636. .icon-weixinzhifu {
  637. width: 80rpx;
  638. font-size: 40rpx;
  639. color: #6bcc03;
  640. }
  641. .icon-alipay {
  642. width: 80rpx;
  643. font-size: 40rpx;
  644. color: #06b4fd;
  645. }
  646. .icon-xuanzhong2 {
  647. display: flex;
  648. align-items: center;
  649. justify-content: center;
  650. width: 60rpx;
  651. height: 60rpx;
  652. font-size: 40rpx;
  653. color: $base-color;
  654. }
  655. .tit {
  656. font-size: 32rpx;
  657. color: $font-color-dark;
  658. flex: 1;
  659. }
  660. }
  661. .footer {
  662. position: fixed;
  663. left: 0;
  664. bottom: 0;
  665. z-index: 995;
  666. display: flex;
  667. align-items: center;
  668. width: 100%;
  669. height: 90rpx;
  670. justify-content: space-between;
  671. font-size: 30rpx;
  672. background-color: #fff;
  673. z-index: 998;
  674. color: $font-color-base;
  675. box-shadow: 0 -1px 5px rgba(0, 0, 0, 0.1);
  676. .price-content {
  677. padding-left: 30rpx;
  678. }
  679. .price-tip {
  680. color: $font-color-base;
  681. margin-left: 8rpx;
  682. }
  683. .price {
  684. font-size: 36rpx;
  685. color: $font-color-base;
  686. }
  687. .submit {
  688. display: flex;
  689. align-items: center;
  690. justify-content: center;
  691. width: 280rpx;
  692. height: 100%;
  693. color: #fff;
  694. font-size: 32rpx;
  695. background-color: $base-color;
  696. &.submitNo {
  697. background-color: $font-color-disabled;
  698. }
  699. }
  700. }
  701. </style>