settlement.vue 14 KB

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