createOrder.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  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. uni.showToast({
  217. title: '请选择收货地址',
  218. icon:'none'
  219. });
  220. return false;
  221. }
  222. // 判断是否余额不足
  223. if (obj.payType == 'yue' && +obj.now_money < obj.payPrice) {
  224. uni.showModal({
  225. title: '提示',
  226. content: '账户余额不足!',
  227. showCancel: false,
  228. });
  229. return;
  230. }
  231. uni.showLoading({
  232. title: '支付中',
  233. mask: true
  234. })
  235. // 支付中
  236. obj.payLoding = true;
  237. // 判断是否为未支付订单中跳转进入
  238. obj.firstCreateOrder();
  239. },
  240. // 订单金额支付
  241. orderMoneyPay() {
  242. let obj = this;
  243. orderPay({
  244. uni: obj.orderId,
  245. // #ifdef H5
  246. from: 'weixin', //来源
  247. // #endif
  248. // #ifdef MP-WEIXIN
  249. from: 'routine', //来源
  250. // #endif
  251. // #ifdef APP-PLUS
  252. from: 'app', //来源
  253. // #endif
  254. paytype: obj.payType //支付类型 weixin-微信 yue-余额
  255. })
  256. .then(e => {
  257. // 判断是否微信小程序支付
  258. if (obj.payType == 'weixin') {
  259. // #ifdef H5 || MP
  260. let da = e.data.result.jsConfig;
  261. let data = {
  262. nonceStr: da.nonceStr,
  263. package: da.package,
  264. signType: da.signType,
  265. paySign: da.paySign,
  266. success: function(res) {
  267. obj.paySuccessTo();
  268. },
  269. fail: () => {
  270. uni.navigateTo({
  271. url: '/pages/order/order?state=0'
  272. });
  273. }
  274. };
  275. // #endif
  276. // #ifdef H5
  277. data.timestamp = da.timestamp;
  278. weixinObj.chooseWXPay(data);
  279. // #endif
  280. // #ifdef MP-WEIXIN
  281. data.timeStamp = da.timestamp;
  282. wx.requestPayment(data);
  283. // #endif
  284. // #ifdef APP
  285. console.log( e.data.result.jsConfig,'返回数值');
  286. uni.requestPayment({
  287. provider: 'wxpay',
  288. orderInfo: e.data.result.jsConfig,
  289. success(e) {
  290. obj.paySuccessTo();
  291. },
  292. fail: (e) => {
  293. console.log(e,'支付失败');
  294. uni.navigateTo({
  295. url: '/pages/order/order?state=0'
  296. });
  297. }
  298. })
  299. // #endif
  300. }
  301. // #ifdef APP
  302. if(obj.payType == 'ali'){
  303. uni.requestPayment({
  304. provider: 'alipay',
  305. orderInfo: e.data.result.jsConfig,
  306. success(e) {
  307. obj.paySuccessTo();
  308. },
  309. fail: (e) => {
  310. console.log(e,'支付失败');
  311. uni.navigateTo({
  312. url: '/pages/order/order?state=0'
  313. });
  314. }
  315. })
  316. }
  317. // #endif
  318. uni.hideLoading();
  319. obj.payLoding = false;
  320. })
  321. .catch(e => {
  322. // 支付完成
  323. uni.hideLoading();
  324. obj.payLoding = false;
  325. console.log(e);
  326. });
  327. },
  328. // 支付成功跳转
  329. paySuccessTo() {
  330. uni.hideLoading();
  331. uni.redirectTo({
  332. url: '/pages/user/money/paySuccess?orderid=' + this.orderId,
  333. });
  334. },
  335. // 初次订单创建
  336. firstCreateOrder() {
  337. let obj = this;
  338. // 获取下单页面数据
  339. let prepage = obj;
  340. let data = {
  341. real_name: prepage.addressData.real_name, //联系人名称
  342. phone: prepage.addressData.phone, //联系人号码
  343. addressId: prepage.addressData.id, //支付地址id
  344. useIntegral: 0, //是否积分抵扣1为是0为否
  345. payType: obj.payType, //支付类型 weixin-微信 yue-余额
  346. mark: prepage.desc, //备注
  347. // #ifdef H5
  348. from: 'weixin', //来源
  349. // #endif
  350. // #ifdef MP-WEIXIN
  351. from: 'routine', //来源
  352. // #endif
  353. // #ifdef APP-PLUS
  354. from: 'app', //来源
  355. // #endif
  356. shipping_type: 1, //提货方式 1 快递 2自提
  357. };
  358. // 判断是否需要读取非默认商家id
  359. if (obj.onShopId != -1) {
  360. data.store_id = obj.onShopId;
  361. } else {
  362. data.store_id = obj.shopDetail.id;
  363. }
  364. // 生成订单
  365. createOrderkey(data, obj.orderKey)
  366. .then(({
  367. data,
  368. status,
  369. msg
  370. }) => {
  371. // 判断是否支付失败
  372. if (data.status == 'ORDER_EXIST') {
  373. uni.showModal({
  374. title: '提示',
  375. content: msg,
  376. showCancel: false
  377. });
  378. uni.hideLoading();
  379. obj.payLoding = false;
  380. return;
  381. }
  382. // 保存订单号
  383. obj.orderId = data.result.orderId;
  384. // 判断是否为余额支付
  385. if (obj.payType == 'yue') {
  386. console.log('余额支付', status == 200 && data.status == 'SUCCESS');
  387. if (status == 200 && data.status == 'SUCCESS') {
  388. obj.paySuccessTo();
  389. } else {
  390. uni.showToast({
  391. title: msg,
  392. icon:'none'
  393. });
  394. }
  395. } else {
  396. // 立即支付
  397. obj.orderMoneyPay();
  398. }
  399. })
  400. .catch(e => {
  401. uni.hideLoading();
  402. obj.payLoding = false;
  403. console.log(e);
  404. });
  405. }
  406. }
  407. };
  408. </script>
  409. <style lang="scss">
  410. page {
  411. background: $page-color-base;
  412. padding-bottom: 100rpx;
  413. }
  414. .address-section {
  415. border-radius: 20rpx;
  416. padding: 30rpx;
  417. margin: 0 $page-row-spacing;
  418. background: #fff;
  419. position: relative;
  420. .order-content {
  421. min-height: 100rpx;
  422. display: flex;
  423. align-items: center;
  424. .leftIcon {
  425. width: 36rpx;
  426. margin: 0 30rpx;
  427. }
  428. .addAddress {
  429. text-align: center;
  430. width: 100%;
  431. display: flex;
  432. justify-content: center;
  433. align-items: center;
  434. .iconaddition {
  435. font-size: 55rpx;
  436. line-height: 1;
  437. border-radius: 100rpx;
  438. margin-right: 20rpx;
  439. }
  440. }
  441. }
  442. .iconlocation {
  443. flex-shrink: 0;
  444. display: flex;
  445. align-items: center;
  446. justify-content: center;
  447. width: 90rpx;
  448. color: #888;
  449. font-size: 44rpx;
  450. }
  451. .cen {
  452. display: flex;
  453. flex-direction: column;
  454. flex: 1;
  455. font-size: 28rpx;
  456. color: $font-color-dark;
  457. }
  458. .name {
  459. font-size: 34rpx;
  460. margin-right: 24rpx;
  461. }
  462. .address {
  463. margin-top: 16rpx;
  464. margin-right: 20rpx;
  465. color: $font-color-light;
  466. }
  467. .icon-you {
  468. font-size: 32rpx;
  469. color: $font-color-light;
  470. margin-right: 30rpx;
  471. }
  472. .a-bg {
  473. position: absolute;
  474. left: 0;
  475. bottom: 0;
  476. display: block;
  477. width: 100%;
  478. height: 5rpx;
  479. }
  480. }
  481. .goodsList {
  482. margin: 0 $page-row-spacing;
  483. padding: 30rpx;
  484. background: #fff;
  485. border-radius: 20rpx;
  486. margin-top: 30rpx;
  487. }
  488. .goods-section {
  489. .logo {
  490. display: block;
  491. width: 50rpx;
  492. height: 50rpx;
  493. border-radius: 100px;
  494. }
  495. .name {
  496. font-size: 30rpx;
  497. color: $font-color-base;
  498. margin-left: 24rpx;
  499. }
  500. .g-item {
  501. display: flex;
  502. image {
  503. flex-shrink: 0;
  504. display: block;
  505. width: 170rpx;
  506. height: 170rpx;
  507. border-radius: 4rpx;
  508. }
  509. .right {
  510. flex: 1;
  511. padding-left: 24rpx;
  512. overflow: hidden;
  513. .serverSet {
  514. font-size: 22rpx;
  515. color: $font-color-light;
  516. }
  517. }
  518. .title {
  519. font-size: 30rpx;
  520. color: $font-color-dark;
  521. }
  522. .spec {
  523. font-size: 26rpx;
  524. color: $font-color-light;
  525. }
  526. .price-box {
  527. display: flex;
  528. align-items: center;
  529. font-size: 32rpx;
  530. padding-top: 10rpx;
  531. color: $font-color-light;
  532. .price {
  533. margin-bottom: 4rpx;
  534. }
  535. .number {
  536. font-size: 26rpx;
  537. margin-left: 20rpx;
  538. }
  539. }
  540. .step-box {
  541. position: relative;
  542. }
  543. }
  544. }
  545. .yt-list {
  546. background: #fff;
  547. margin: 0 $page-row-spacing;
  548. margin-top: 30rpx;
  549. border-radius: 20rpx;
  550. }
  551. .yt-list-cell {
  552. display: flex;
  553. align-items: center;
  554. justify-content: space-between;
  555. padding: 10rpx 30rpx 10rpx 40rpx;
  556. line-height: 70rpx;
  557. position: relative;
  558. .checked,
  559. .noChecked {
  560. width: 36rpx;
  561. height: 36rpx;
  562. }
  563. .noChecked {
  564. border: 1px solid $font-color-light;
  565. border-radius: 100rpx;
  566. }
  567. &.cell-hover {
  568. background: #fafafa;
  569. }
  570. &.b-b:after {
  571. left: 30rpx;
  572. }
  573. .cell-icon {
  574. height: 32rpx;
  575. width: 32rpx;
  576. font-size: 22rpx;
  577. color: #fff;
  578. text-align: center;
  579. line-height: 32rpx;
  580. background: #f85e52;
  581. border-radius: 4rpx;
  582. margin-right: 12rpx;
  583. &.hb {
  584. background: #ffaa0e;
  585. }
  586. &.lpk {
  587. background: #3ab54a;
  588. }
  589. }
  590. .cell-more {
  591. align-self: center;
  592. font-size: 24rpx;
  593. color: $font-color-light;
  594. margin-left: 8rpx;
  595. margin-right: -10rpx;
  596. }
  597. .cell-tit {
  598. font-size: 26rpx;
  599. color: $font-color-light;
  600. margin-right: 10rpx;
  601. .orderIcon {
  602. width: 48rpx;
  603. }
  604. }
  605. .cell-tip {
  606. font-size: 26rpx;
  607. color: $font-color-dark;
  608. &.disabled {
  609. color: $font-color-light;
  610. }
  611. &.active {
  612. color: $base-color;
  613. }
  614. &.red {
  615. color: $base-color;
  616. }
  617. }
  618. &.desc-cell {
  619. .cell-tit {
  620. max-width: 90rpx;
  621. }
  622. }
  623. .desc {
  624. text-align: right;
  625. font-size: $font-base;
  626. color: $font-color-light;
  627. }
  628. }
  629. /* 支付列表 */
  630. .pay-list {
  631. padding-left: 40rpx;
  632. margin-top: 16rpx;
  633. background: #fff;
  634. .pay-item {
  635. display: flex;
  636. align-items: center;
  637. padding-right: 20rpx;
  638. line-height: 1;
  639. height: 110rpx;
  640. position: relative;
  641. }
  642. .icon-weixinzhifu {
  643. width: 80rpx;
  644. font-size: 40rpx;
  645. color: #6bcc03;
  646. }
  647. .icon-alipay {
  648. width: 80rpx;
  649. font-size: 40rpx;
  650. color: #06b4fd;
  651. }
  652. .icon-xuanzhong2 {
  653. display: flex;
  654. align-items: center;
  655. justify-content: center;
  656. width: 60rpx;
  657. height: 60rpx;
  658. font-size: 40rpx;
  659. color: $base-color;
  660. }
  661. .tit {
  662. font-size: 32rpx;
  663. color: $font-color-dark;
  664. flex: 1;
  665. }
  666. }
  667. .footer {
  668. position: fixed;
  669. left: 0;
  670. bottom: 0;
  671. z-index: 995;
  672. display: flex;
  673. align-items: center;
  674. width: 100%;
  675. height: 90rpx;
  676. justify-content: space-between;
  677. font-size: 30rpx;
  678. background-color: #fff;
  679. z-index: 998;
  680. color: $font-color-base;
  681. box-shadow: 0 -1px 5px rgba(0, 0, 0, 0.1);
  682. .price-content {
  683. padding-left: 30rpx;
  684. }
  685. .price-tip {
  686. color: $font-color-base;
  687. margin-left: 8rpx;
  688. }
  689. .price {
  690. font-size: 36rpx;
  691. color: $font-color-base;
  692. }
  693. .submit {
  694. display: flex;
  695. align-items: center;
  696. justify-content: center;
  697. width: 280rpx;
  698. height: 100%;
  699. color: #fff;
  700. font-size: 32rpx;
  701. background-color: $base-color;
  702. &.submitNo {
  703. background-color: $font-color-disabled;
  704. }
  705. }
  706. }
  707. </style>