settlement.vue 18 KB

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