settlement.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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. console.log(opthios);
  140. if (opthios.ids) {
  141. this.ids = JSON.parse(opthios.ids)
  142. this.getDetail()
  143. }
  144. if(opthios.goodsId){
  145. this.payment = {
  146. goodsId:opthios.goodsId,
  147. skuId:opthios.skuId,
  148. num:opthios.num,
  149. resource:2,
  150. }
  151. this.getDetail()
  152. }
  153. },
  154. onShow() {
  155. if (this.toAddressShow) {
  156. this.getDetail()
  157. }
  158. },
  159. methods: {
  160. save() {
  161. if (this.info.addr == null) {
  162. uni.$u.toast('请先保存配送地址');
  163. return
  164. }
  165. let _this = this
  166. let payIng = false
  167. if (payIng) return
  168. uni.showLoading({
  169. title: '加载中'
  170. });
  171. $http.post('/api/v1/mp/user/deliver/order/submit', {memo:this.info.memo}).then(res => {
  172. payIng = true
  173. uni.hideLoading();
  174. if (res.code == 0) {
  175. if (res.data.needPay == 1) {
  176. $http.post('/api/v1/mp/user/deliver/order/pay', {
  177. orderId: res.data.orderId,
  178. payType: 2
  179. }).then(ele => {
  180. if (ele.code == 0) {
  181. uni.requestPayment({
  182. timeStamp: ele.data.timeStamp,
  183. nonceStr: ele.data.nonceStr,
  184. package: ele.data.package,
  185. signType: ele.data.signType,
  186. paySign: ele.data.paySign,
  187. success() {
  188. uni.showToast({
  189. title: '支付成功',
  190. icon: 'success',
  191. duration: 2000
  192. })
  193. setTimeout(() => {
  194. uni.redirectTo({
  195. url: `/packageGoods/order/index`
  196. })
  197. }, 500)
  198. },
  199. fail() {
  200. payIng = false
  201. setTimeout(() => {
  202. uni.redirectTo({
  203. url: `/packageGoods/order/index`
  204. })
  205. }, 500)
  206. }
  207. })
  208. } else {
  209. payIng = false
  210. uni.$u.toast('支付失败!');
  211. setTimeout(() => {
  212. uni.redirectTo({
  213. url: `/packageGoods/order/index`
  214. })
  215. }, 500)
  216. }
  217. }).catch(() => {
  218. payIng = false
  219. uni.$u.toast('支付失败!');
  220. setTimeout(() => {
  221. uni.redirectTo({
  222. url: `/packageGoods/order/index`
  223. })
  224. }, 500)
  225. })
  226. } else {
  227. uni.showToast({
  228. title: '提交成功',
  229. icon: 'success',
  230. duration: 2000
  231. })
  232. setTimeout(() => {
  233. uni.redirectTo({
  234. url: `/packageGoods/order/index`
  235. })
  236. }, 500)
  237. }
  238. } else {
  239. payIng = false
  240. uni.$u.toast('提交失败!');
  241. }
  242. }).catch(() => {
  243. payIng = false
  244. uni.$u.toast('提交失败!');
  245. uni.hideLoading();
  246. })
  247. },
  248. getDetail() {
  249. uni.showLoading({
  250. title: '加载中'
  251. });
  252. let data = {
  253. ids: this.ids
  254. }
  255. if(this.payment != ""){
  256. data = this.payment
  257. }
  258. $http.post('/api/v1/mp/user/deliver/order/settle', data ).then(res => {
  259. uni.hideLoading();
  260. console.log(res);
  261. if (res.code == 0) {
  262. this.info = res.data
  263. this.addr = res.data.addr
  264. res.data.prizeList.forEach(item => {
  265. let picUrlArr = item.picUrl.split(',')
  266. item.picUrl = env.filePublic + picUrlArr[0] + '?imageView2/2/w/170'
  267. })
  268. this.list = res.data.prizeList
  269. }
  270. }).catch(() => {
  271. uni.hideLoading();
  272. })
  273. },
  274. selectArea() {
  275. this.areaShow = true
  276. },
  277. confirmArea(obj) {
  278. this.form.province = obj.province
  279. this.form.provinceId = obj.provinceId
  280. this.form.city = obj.city
  281. this.form.cityId = obj.cityId
  282. this.form.area = obj.area
  283. this.form.areaId = obj.areaId
  284. this.form.cityShow = obj.cityShow
  285. this.areaShow = false
  286. },
  287. cancel() {
  288. this.areaShow = false
  289. },
  290. toAddress() {
  291. this.toAddressShow = true
  292. uni.navigateTo({
  293. url: "/packageOperate/address/index"
  294. })
  295. },
  296. toWeixinAddress() {
  297. let _this = this
  298. uni.chooseAddress({
  299. success(res) {
  300. _this.wxAddress = res
  301. _this.getArea()
  302. }
  303. })
  304. },
  305. // 回显微信地址
  306. async getArea() {
  307. // 获取省
  308. let provinceRes = await $http.post('/api/v1/mp/area/listByPid', {
  309. pid: 0
  310. })
  311. let provinceItem = provinceRes && provinceRes.data.find((item=> item.areaName == this.wxAddress.provinceName))
  312. // 获取市
  313. let cityRes = await $http.post('/api/v1/mp/area/listByPid', {
  314. pid: provinceItem && provinceItem.areaId
  315. })
  316. let cityItem = cityRes && cityRes.data.find((item=> item.areaName == this.wxAddress.cityName))
  317. // 获取区
  318. let areaRes = await $http.post('/api/v1/mp/area/listByPid', {
  319. pid: cityItem && cityItem.areaId
  320. })
  321. let areaItem = areaRes && areaRes.data.find((item=> item.areaName == this.wxAddress.countyName))
  322. // 赋值
  323. this.form.province = provinceItem.areaName
  324. this.form.provinceId = provinceItem.areaId
  325. this.form.city = cityItem.areaName
  326. this.form.cityId = cityItem.areaId
  327. this.form.area = areaItem.areaName
  328. this.form.areaId = areaItem.areaId
  329. this.form.cityShow = `${ provinceItem.areaName }-${ cityItem.areaName }-${ areaItem.areaName }`
  330. this.form.addr = this.wxAddress.detailInfo
  331. this.form.receiver = this.wxAddress.userName
  332. this.form.mobile = this.wxAddress.telNumber
  333. },
  334. saveAddress() {
  335. let _this = this
  336. if (!_this.form.receiver) {
  337. uni.$u.toast('请输入收货人');
  338. return
  339. }
  340. if (!_this.form.mobile) {
  341. uni.$u.toast('请输入手机号码');
  342. return
  343. }
  344. const rule = /^[1][0-9][0-9]{9}$/
  345. if (!rule.test(_this.form.mobile)) {
  346. uni.$u.toast('请输入正确的手机号');
  347. return
  348. }
  349. if (!_this.form.cityShow) {
  350. uni.$u.toast('请选择所在地区');
  351. return
  352. }
  353. if (!_this.form.addr) {
  354. uni.$u.toast('请输入详细地址');
  355. return
  356. }
  357. let url = '/api/v1/mp/user/addr/create'
  358. $http.post(url, this.form).then(res => {
  359. if (res.code == 0) {
  360. uni.$u.toast('保存成功');
  361. this.getDetail()
  362. }
  363. })
  364. },
  365. },
  366. }
  367. </script>
  368. <style lang="scss" scoped>
  369. .settlement {
  370. margin: 34rpx;
  371. padding-bottom: 100rpx;
  372. &-address {
  373. background-color: #fff;
  374. padding: 34rpx;
  375. margin-bottom: 34rpx;
  376. border-radius: 22rpx;
  377. // 选择地址、获取微信地址
  378. &-top {
  379. justify-content: space-between;
  380. padding: 0 0 34rpx;
  381. border-bottom: 1px solid rgba(236, 236, 236, 100);
  382. &__left {
  383. line-height: 40rpx;
  384. }
  385. &__right {
  386. line-height: 40rpx;
  387. color: rgba(35, 126, 212, 100);
  388. }
  389. }
  390. // 收货人、地址
  391. &-desc {
  392. margin-top: 34rpx;
  393. &__item {
  394. line-height: 28rpx;
  395. margin-bottom: 20rpx;
  396. text {
  397. padding-left: 8rpx;
  398. font-size: 24rpx;
  399. color: #666;
  400. }
  401. }
  402. &__item:last-child {
  403. margin-bottom: 0;
  404. color: #999;
  405. }
  406. }
  407. // 地址form
  408. &-form {
  409. .save-btn {
  410. padding: 10rpx 20rpx;
  411. /deep/ button {
  412. line-height: 76rpx;
  413. font-size: 28rpx;
  414. height: 76rpx;
  415. color: #fff;
  416. background-color: $uni-bg-color;
  417. border: none;
  418. border-radius: 100rpx;
  419. }
  420. }
  421. }
  422. }
  423. // 商品
  424. &-goods {
  425. // 商品列表
  426. &-item{
  427. display: flex;
  428. padding: 34rpx 32rpx 34rpx 22rpx;
  429. box-shadow: 0px 0px 8px 0px rgba(26, 35, 113, 0.08);
  430. background-color: #fff;
  431. border-radius: 22rpx;
  432. margin-bottom: 34rpx;
  433. image {
  434. width: 176rpx;
  435. height: 176rpx;
  436. border-radius: 12rpx;
  437. margin-right: 22rpx;
  438. }
  439. .info {
  440. display: flex;
  441. flex-direction: column;
  442. justify-content: space-between;
  443. flex: 1;
  444. padding: 8rpx 0;
  445. &-title {
  446. font-size: 30rpx;
  447. font-weight: bold;
  448. line-height: 40rpx;
  449. }
  450. &-num {
  451. justify-content: space-between;
  452. &-sku {
  453. flex: 1;
  454. color: #666666;
  455. font-size: 26rpx;
  456. }
  457. &-goods {
  458. color: #666666;
  459. font-size: 26rpx;
  460. }
  461. }
  462. }
  463. }
  464. }
  465. // 留言、运费
  466. &-freight {
  467. font-size: 30rpx;
  468. margin-bottom: 34rpx;
  469. background-color: #fff;
  470. justify-content: space-between;
  471. padding: 34rpx;
  472. border-radius: 22rpx;
  473. }
  474. // 留言、运费
  475. &-tip {
  476. font-size: 30rpx;
  477. margin-bottom: 34rpx;
  478. background-color: #fff;
  479. justify-content: space-between;
  480. padding: 34rpx;
  481. border-radius: 22rpx;
  482. &-title {
  483. font-size: 26rpx;
  484. line-height: 24rpx;
  485. margin-bottom: 24rpx;
  486. }
  487. &-content {
  488. font-size: 24rpx;
  489. line-height: 40rpx;
  490. }
  491. }
  492. }
  493. .footer-fixed {
  494. position: fixed;
  495. bottom: var(--window-bottom);
  496. left: 0;
  497. right: 0;
  498. z-index: 11;
  499. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  500. background: #fff;
  501. // 设置ios刘海屏底部横线安全区域
  502. padding-bottom: constant(safe-area-inset-bottom);
  503. padding-bottom: env(safe-area-inset-bottom);
  504. .content {
  505. padding: 20rpx 0;
  506. font-size: 30rpx;
  507. // 不发货提示
  508. &-not {
  509. justify-content: flex-start;
  510. font-size: 30rpx;
  511. color: #F9832E;
  512. margin: 0 0 30rpx;
  513. padding: 0 40rpx 24rpx;
  514. border-bottom: 1px solid #eee;
  515. }
  516. // 提交按钮
  517. &-btn {
  518. justify-content: space-between;
  519. padding: 0 40rpx;
  520. &-left {
  521. .value {
  522. color: #FF4208;
  523. }
  524. }
  525. &-right {
  526. display: flex;
  527. align-items: center;
  528. justify-content: flex-end;
  529. .save {
  530. width: 210rpx;
  531. height: 82rpx;
  532. line-height: 82rpx;
  533. background: #F9822C;
  534. border-radius: 40rpx;
  535. text-align: center;
  536. color: #fff;
  537. }
  538. .not {
  539. background-color: #6c6c6c;
  540. }
  541. }
  542. }
  543. }
  544. }
  545. </style>