settlement.vue 15 KB

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