settlement.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. <template>
  2. <view>
  3. <!-- #ifdef MP-ALIPAY -->
  4. <u-navbar title="提交订单" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" leftIconSize="0"/>
  5. <!-- #endif -->
  6. <!-- #ifdef MP-WEIXIN -->
  7. <u-navbar title="提交订单" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
  8. <!-- #endif -->
  9. <!-- #ifdef H5 -->
  10. <view v-if="$pagesNum() > 1">
  11. <u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" :border="true" title="提交订单" />
  12. </view>
  13. <view v-else>
  14. <u-navbar leftIconSize="0" :placeholder="true" bgColor="#fff" :border="true" title="提交订单">
  15. <view class="nav-left flex" slot="left" @click="$toIndex()">
  16. <u-icon name="arrow-left" size="20" color="#333"></u-icon>
  17. </view>
  18. </u-navbar>
  19. </view>
  20. <!-- #endif -->
  21. <view class="settlement">
  22. <view class="settlement-address">
  23. <!-- 选择地址、获取微信地址 -->
  24. <view class="flex settlement-address-top" v-if="info.addr !== null">
  25. <view class="settlement-address-top__left">配送地址</view>
  26. <view class="flex settlement-address-top__right" @click="toAddress">
  27. <view class="">更改地址</view>
  28. <u-icon name="arrow-right" size="18" color="#237ED4 100%"></u-icon>
  29. </view>
  30. </view>
  31. <view class="flex settlement-address-top" v-else>
  32. <view class="settlement-address-top__left">配送地址</view>
  33. <view class="flex settlement-address-top__right" @click="toWeixinAddress">
  34. <view class="">微信地址</view>
  35. <u-icon name="arrow-right" size="18" color="#237ED4 100%"></u-icon>
  36. </view>
  37. </view>
  38. <!-- 收货人、地址 -->
  39. <view class="settlement-address-desc" v-if="info.addr !== null">
  40. <view class="settlement-address-desc__item">{{ addr.receiver || '-' }}<text>{{ addr.mobile || '-' }}</text></view>
  41. <view class="settlement-address-desc__item">
  42. {{ `${ addr.province || '-' } ${ addr.city || '-' } ${ addr.area || '-' }` }} {{ addr.addr || '-' }}</view>
  43. </view>
  44. <!-- 地址form -->
  45. <view class="settlement-address-form" v-else>
  46. <view class="address-add">
  47. <u-form labelPosition="left" ref="form" labelWidth="90"> <u-form-item label="收货人:" borderBottom required>
  48. <u-input v-model="form.receiver" border="none" placeholder="请输入收货人"></u-input>
  49. </u-form-item>
  50. <u-form-item label="手机号码:" borderBottom required>
  51. <u-input v-model="form.mobile" border="none" placeholder="请输入手机号码"></u-input>
  52. </u-form-item>
  53. <u-form-item label="所在地区:" borderBottom required @click="selectArea">
  54. <u-input v-model="form.cityShow" border="none" disabled disabledColor="#ffffff"
  55. placeholder="请选择地区">
  56. </u-input>
  57. <u-icon slot="right" name="arrow-right"></u-icon>
  58. </u-form-item>
  59. <u-form-item label="详细地址:" :borderBottom="false" required>
  60. <u-textarea v-model="form.addr" placeholder="请输入详细地址"></u-textarea>
  61. </u-form-item>
  62. </u-form>
  63. </view>
  64. <!-- 操作按钮 -->
  65. <view class="save-btn">
  66. <button :loading="loading" type="default" @click="saveAddress">保存并使用</button>
  67. </view>
  68. </view>
  69. </view>
  70. <!-- 商品 -->
  71. <view class="settlement-goods">
  72. <view class="settlement-goods-item" v-for="(item, index) in list" :key="index">
  73. <image :src="item.picUrl" mode="aspectFit"></image>
  74. <view class="info">
  75. <view class="info-title ells">{{ item.title }}</view>
  76. <view class="info-num flex">
  77. <view class="info-num-sku ells-one">规格:{{ item.properties || '-' }}</view>
  78. <view class="info-num-goods">数量:{{ item.goodsNum }}</view>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. <view class="settlement-freight flex">
  84. <text>留言</text>
  85. <!-- #ifndef MP-ALIPAY -->
  86. <u-input v-model="info.memo" placeholder="请输入留言" clearable inputAlign="right" border="none" />
  87. <!-- #endif -->
  88. <!-- #ifdef MP-ALIPAY -->
  89. <u-input v-model="info.memo" placeholder="请输入留言" inputAlign="right" border="none" />
  90. <!-- #endif -->
  91. </view>
  92. <view class="settlement-freight flex">
  93. <text>运费</text>
  94. <text>¥{{ $numberFormat(info.freightAmt) }}</text>
  95. </view>
  96. <view class="settlement-tip">
  97. <view class="settlement-tip-title">尊敬的用户您好!</view>
  98. <view class="settlement-tip-content">您提交的商品订单将会在第一时间为您处理,正常产品都会在48小时内发货,由于因疫情原因可能导致到货时间延后,我们深表歉意,有任何问题可以点击“我的”一“联系我们”,或者关注盲票公众号联系我们。</view>
  99. </view>
  100. </view>
  101. <view class="footer-fixed">
  102. <view class="content">
  103. <view class="content-not flex" v-if="info.freightType == 2">
  104. <icon type="warn" color="#F9832E" style="vertical-align: bottom; margin-right: 20rpx; " size="20"/>
  105. <text>当前收货地址暂不支持发货</text>
  106. </view>
  107. <view class="content-btn flex">
  108. <view class="content-btn-left">
  109. <view class="money">
  110. <text>合计:</text>
  111. <text class="value">¥{{ $numberFormat(info.payAmt) }}</text>
  112. </view>
  113. </view>
  114. <view class="content-btn-right">
  115. <text class="save not" v-if="info.freightType == 2">提交</text>
  116. <text class="save" @click="save" v-else>提交</text>
  117. </view>
  118. </view>
  119. </view>
  120. </view>
  121. <area-picker :area-show="areaShow" @cancel="cancel" @confirmArea="confirmArea" />
  122. <auth :auth-show="authShow" @close="authShow = false" />
  123. </view>
  124. </template>
  125. <script>
  126. import env from '../../config/env.js'
  127. import $http from '@/utils/request.js'
  128. import appId from '@/config/appId.js'
  129. import AreaPicker from '../../components/area-picker/area-picker.vue'
  130. import Auth from '../../components/auth/auth.vue'
  131. export default {
  132. components: {
  133. AreaPicker,
  134. Auth
  135. },
  136. data() {
  137. return {
  138. ids: [],
  139. info: {},
  140. addr: {},
  141. list: [],
  142. loading: false,
  143. addrId: '',
  144. form: {
  145. receiver: '',
  146. mobile: '',
  147. name: '',
  148. cityShow: '',
  149. addr: '',
  150. provinceId: '', // 省ID/编码
  151. province: '', // 省
  152. cityId: '', // 市ID/编码
  153. city: '', // 市
  154. areaId: '', // 区ID/编码
  155. area: '', // 区
  156. },
  157. areaShow: false,
  158. toAddressShow: false,
  159. wxAddress: {},
  160. payment: '',
  161. authShow: false,
  162. }
  163. },
  164. onLoad(opthios) {
  165. if (opthios.ids) {
  166. this.ids = JSON.parse(opthios.ids)
  167. this.getDetail()
  168. }
  169. if(opthios.goodsId){
  170. this.payment = {
  171. goodsId:opthios.goodsId,
  172. skuId:opthios.skuId,
  173. num:opthios.num,
  174. resource:2,
  175. }
  176. this.getDetail()
  177. }
  178. },
  179. onShow() {
  180. if (this.toAddressShow) {
  181. this.getDetail()
  182. }
  183. },
  184. methods: {
  185. save() {
  186. if (this.info.addr == null) {
  187. uni.$u.toast('请先保存配送地址');
  188. return
  189. }
  190. let _this = this
  191. let payIng = false
  192. if (payIng) return
  193. uni.showLoading({
  194. title: '加载中'
  195. });
  196. $http.post('/api/v1/mp/user/deliver/order/submit', {memo:this.info.memo}).then(res => {
  197. payIng = true
  198. uni.hideLoading();
  199. if (res.code == 0) {
  200. if (res.data.needPay == 1) {
  201. // #ifdef MP-ALIPAY
  202. let data = {
  203. orderId: res.data.orderId,
  204. payType: 1,
  205. appSource: appId
  206. }
  207. // #endif
  208. // #ifndef MP-ALIPAY
  209. let data = {
  210. orderId: res.data.orderId,
  211. payType: 2,
  212. appSource: appId
  213. }
  214. // #endif
  215. $http.post('/api/v1/mp/user/deliver/order/pay', data).then(ele => {
  216. if (ele.code == 0) {
  217. // #ifdef MP-ALIPAY
  218. my.tradePay({
  219. tradeNO: ele.data.pay_info,
  220. success(resu) {
  221. if(resu.resultCode == '9000'){
  222. uni.showToast({
  223. title: '支付成功',
  224. icon: 'success',
  225. duration: 2000
  226. })
  227. setTimeout(() => {
  228. uni.redirectTo({
  229. url: `/packageGoods/order/index`
  230. })
  231. }, 500)
  232. }else {
  233. payIng = false
  234. setTimeout(() => {
  235. uni.redirectTo({
  236. url: `/packageGoods/order/index`
  237. })
  238. }, 500)
  239. }
  240. },
  241. fail() {
  242. payIng = false
  243. setTimeout(() => {
  244. uni.redirectTo({
  245. url: `/packageGoods/order/index`
  246. })
  247. }, 500)
  248. }
  249. })
  250. // #endif
  251. // #ifndef MP-ALIPAY
  252. uni.requestPayment({
  253. timeStamp: ele.data.timeStamp,
  254. nonceStr: ele.data.nonceStr,
  255. package: ele.data.package,
  256. signType: ele.data.signType,
  257. paySign: ele.data.paySign,
  258. success() {
  259. uni.showToast({
  260. title: '支付成功',
  261. icon: 'success',
  262. duration: 2000
  263. })
  264. setTimeout(() => {
  265. uni.redirectTo({
  266. url: `/packageGoods/order/index`
  267. })
  268. }, 500)
  269. },
  270. fail() {
  271. payIng = false
  272. setTimeout(() => {
  273. uni.redirectTo({
  274. url: `/packageGoods/order/index`
  275. })
  276. }, 500)
  277. }
  278. })
  279. // #endif
  280. } else if (ele.code == 1005) {
  281. _this.authShow = true
  282. } else if (ele.code == 1026) {
  283. _this.authShow = true
  284. } else {
  285. payIng = false
  286. uni.$u.toast('支付失败');
  287. setTimeout(() => {
  288. uni.redirectTo({
  289. url: `/packageGoods/order/index`
  290. })
  291. }, 500)
  292. }
  293. }).catch(() => {
  294. payIng = false
  295. uni.$u.toast('支付异常');
  296. setTimeout(() => {
  297. uni.redirectTo({
  298. url: `/packageGoods/order/index`
  299. })
  300. }, 500)
  301. })
  302. } else {
  303. uni.showToast({
  304. title: '提交成功',
  305. icon: 'success',
  306. duration: 2000
  307. })
  308. setTimeout(() => {
  309. uni.redirectTo({
  310. url: `/packageGoods/order/index`
  311. })
  312. }, 500)
  313. }
  314. } else {
  315. payIng = false
  316. uni.$u.toast(res.msg);
  317. }
  318. }).catch(() => {
  319. payIng = false
  320. uni.$u.toast('订单创建失败');
  321. uni.hideLoading();
  322. })
  323. },
  324. getDetail() {
  325. uni.showLoading({
  326. title: '加载中'
  327. });
  328. let data = {
  329. ids: this.ids,
  330. }
  331. if(this.payment != ""){
  332. data = this.payment
  333. }
  334. data.appSource = appId
  335. $http.post('/api/v1/mp/user/deliver/order/settle', data ).then(res => {
  336. uni.hideLoading();
  337. if (res.code == 0) {
  338. this.info = res.data
  339. this.addr = res.data.addr
  340. res.data.prizeList.forEach(item => {
  341. let picUrlArr = item.picUrl.split(',')
  342. item.picUrl = env.filePublic + picUrlArr[0] + '?imageView2/2/w/170'
  343. })
  344. this.list = res.data.prizeList
  345. }
  346. }).catch(() => {
  347. uni.hideLoading();
  348. })
  349. },
  350. selectArea() {
  351. this.areaShow = true
  352. },
  353. confirmArea(obj) {
  354. this.form.province = obj.province
  355. this.form.provinceId = obj.provinceId
  356. this.form.city = obj.city
  357. this.form.cityId = obj.cityId
  358. this.form.area = obj.area
  359. this.form.areaId = obj.areaId
  360. this.form.cityShow = obj.cityShow
  361. this.areaShow = false
  362. },
  363. cancel() {
  364. this.areaShow = false
  365. },
  366. toAddress() {
  367. this.toAddressShow = true
  368. uni.navigateTo({
  369. url: "/packageOperate/address/index"
  370. })
  371. },
  372. toWeixinAddress() {
  373. let _this = this
  374. uni.chooseAddress({
  375. success(res) {
  376. _this.wxAddress = res
  377. _this.getArea()
  378. }
  379. })
  380. },
  381. // 回显微信地址
  382. async getArea() {
  383. // 获取省
  384. let provinceRes = await $http.post('/api/v1/mp/area/listByPid', {
  385. pid: 0
  386. })
  387. let provinceItem = provinceRes && provinceRes.data.find((item=> item.areaName == this.wxAddress.provinceName))
  388. // 获取市
  389. let cityRes = await $http.post('/api/v1/mp/area/listByPid', {
  390. pid: provinceItem && provinceItem.areaId
  391. })
  392. let cityItem = cityRes && cityRes.data.find((item=> item.areaName == this.wxAddress.cityName))
  393. // 获取区
  394. let areaRes = await $http.post('/api/v1/mp/area/listByPid', {
  395. pid: cityItem && cityItem.areaId
  396. })
  397. let areaItem = areaRes && areaRes.data.find((item=> item.areaName == this.wxAddress.countyName))
  398. // 赋值
  399. this.form.province = provinceItem.areaName
  400. this.form.provinceId = provinceItem.areaId
  401. this.form.city = cityItem.areaName
  402. this.form.cityId = cityItem.areaId
  403. this.form.area = areaItem.areaName
  404. this.form.areaId = areaItem.areaId
  405. this.form.cityShow = `${ provinceItem.areaName }-${ cityItem.areaName }-${ areaItem.areaName }`
  406. this.form.addr = this.wxAddress.detailInfo
  407. this.form.receiver = this.wxAddress.userName
  408. this.form.mobile = this.wxAddress.telNumber
  409. },
  410. saveAddress() {
  411. let _this = this
  412. if (!_this.form.receiver) {
  413. uni.$u.toast('请输入收货人');
  414. return
  415. }
  416. if (!_this.form.mobile) {
  417. uni.$u.toast('请输入手机号码');
  418. return
  419. }
  420. const rule = /^[1][0-9][0-9]{9}$/
  421. if (!rule.test(_this.form.mobile)) {
  422. uni.$u.toast('请输入正确的手机号');
  423. return
  424. }
  425. if (!_this.form.cityShow) {
  426. uni.$u.toast('请选择所在地区');
  427. return
  428. }
  429. if (!_this.form.addr) {
  430. uni.$u.toast('请输入详细地址');
  431. return
  432. }
  433. let url = '/api/v1/mp/user/addr/create'
  434. $http.post(url, this.form).then(res => {
  435. if (res.code == 0) {
  436. uni.$u.toast('保存成功');
  437. this.getDetail()
  438. }
  439. })
  440. },
  441. },
  442. }
  443. </script>
  444. <style lang="scss" scoped>
  445. .settlement {
  446. margin: 34rpx;
  447. padding-bottom: 150rpx;
  448. &-address {
  449. background-color: #fff;
  450. padding: 34rpx;
  451. margin-bottom: 34rpx;
  452. border-radius: 22rpx;
  453. // 选择地址、获取微信地址
  454. &-top {
  455. justify-content: space-between;
  456. padding: 0 0 34rpx;
  457. border-bottom: 1px solid rgba(236, 236, 236, 100);
  458. &__left {
  459. line-height: 40rpx;
  460. }
  461. &__right {
  462. line-height: 40rpx;
  463. color: rgba(35, 126, 212, 100);
  464. }
  465. }
  466. // 收货人、地址
  467. &-desc {
  468. margin-top: 34rpx;
  469. &__item {
  470. line-height: 28rpx;
  471. margin-bottom: 20rpx;
  472. text {
  473. padding-left: 8rpx;
  474. font-size: 24rpx;
  475. color: #666;
  476. }
  477. }
  478. &__item:last-child {
  479. margin-bottom: 0;
  480. color: #999;
  481. }
  482. }
  483. // 地址form
  484. &-form {
  485. .save-btn {
  486. padding: 10rpx 20rpx;
  487. ::v-deep button {
  488. line-height: 76rpx;
  489. font-size: 28rpx;
  490. height: 76rpx;
  491. color: #fff;
  492. background-color: $uni-bg-color;
  493. border: none;
  494. border-radius: 100rpx;
  495. }
  496. }
  497. }
  498. }
  499. // 商品
  500. &-goods {
  501. // 商品列表
  502. &-item{
  503. display: flex;
  504. padding: 34rpx 32rpx 34rpx 22rpx;
  505. box-shadow: 0px 0px 8px 0px rgba(26, 35, 113, 0.08);
  506. background-color: #fff;
  507. border-radius: 22rpx;
  508. margin-bottom: 34rpx;
  509. image {
  510. width: 176rpx;
  511. height: 176rpx;
  512. border-radius: 12rpx;
  513. margin-right: 22rpx;
  514. }
  515. .info {
  516. display: flex;
  517. flex-direction: column;
  518. justify-content: space-between;
  519. flex: 1;
  520. padding: 8rpx 0;
  521. &-title {
  522. font-size: 30rpx;
  523. font-weight: bold;
  524. line-height: 40rpx;
  525. }
  526. &-num {
  527. justify-content: space-between;
  528. &-sku {
  529. flex: 1;
  530. color: #666666;
  531. font-size: 26rpx;
  532. }
  533. &-goods {
  534. color: #666666;
  535. font-size: 26rpx;
  536. }
  537. }
  538. }
  539. }
  540. }
  541. // 留言、运费
  542. &-freight {
  543. font-size: 30rpx;
  544. margin-bottom: 34rpx;
  545. background-color: #fff;
  546. justify-content: space-between;
  547. padding: 34rpx;
  548. border-radius: 22rpx;
  549. }
  550. // 留言、运费
  551. &-tip {
  552. font-size: 30rpx;
  553. margin-bottom: 34rpx;
  554. background-color: #fff;
  555. justify-content: space-between;
  556. padding: 34rpx;
  557. border-radius: 22rpx;
  558. &-title {
  559. font-size: 26rpx;
  560. line-height: 24rpx;
  561. margin-bottom: 24rpx;
  562. }
  563. &-content {
  564. font-size: 24rpx;
  565. line-height: 40rpx;
  566. }
  567. }
  568. }
  569. .footer-fixed {
  570. position: fixed;
  571. bottom: var(--window-bottom);
  572. left: 0;
  573. right: 0;
  574. z-index: 11;
  575. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  576. background: #fff;
  577. // 设置ios刘海屏底部横线安全区域
  578. padding-bottom: constant(safe-area-inset-bottom);
  579. padding-bottom: env(safe-area-inset-bottom);
  580. .content {
  581. padding: 20rpx 0;
  582. font-size: 30rpx;
  583. // 不发货提示
  584. &-not {
  585. justify-content: flex-start;
  586. font-size: 30rpx;
  587. color: #F9832E;
  588. margin: 0 0 30rpx;
  589. padding: 0 40rpx 24rpx;
  590. border-bottom: 1px solid #eee;
  591. }
  592. // 提交按钮
  593. &-btn {
  594. justify-content: space-between;
  595. padding: 0 40rpx;
  596. &-left {
  597. .value {
  598. color: #FF4208;
  599. }
  600. }
  601. &-right {
  602. display: flex;
  603. align-items: center;
  604. justify-content: flex-end;
  605. .save {
  606. width: 210rpx;
  607. height: 82rpx;
  608. line-height: 82rpx;
  609. background: #F9822C;
  610. border-radius: 40rpx;
  611. text-align: center;
  612. color: #fff;
  613. }
  614. .not {
  615. background-color: #6c6c6c;
  616. }
  617. }
  618. }
  619. }
  620. }
  621. </style>