settlement.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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. <view class="flex settlement-address-top" v-if="info.addr !== null">
  7. <view class="settlement-address-top__left">配送地址</view>
  8. <view class="flex settlement-address-top__right" @click="toAddress">
  9. <view class="">更改地址</view>
  10. <u-icon name="arrow-right" size="18" color="#237ED4 100%"></u-icon>
  11. </view>
  12. </view>
  13. <view class="flex settlement-address-top" v-else>
  14. <view class="settlement-address-top__left">配送地址</view>
  15. <view class="flex settlement-address-top__right" @click="toWeixinAddress">
  16. <view class="">微信地址</view>
  17. <u-icon name="arrow-right" size="18" color="#237ED4 100%"></u-icon>
  18. </view>
  19. </view>
  20. <view class="settlement-address-desc" v-if="info.addr !== null">
  21. <view class="settlement-address-desc__item">
  22. {{ `${ addr.province || '-' }-${ addr.city || '-' }-${ addr.area || '-' }` }}
  23. {{ addr.addr || '-' }}
  24. </view>
  25. <view class="settlement-address-desc__item">{{ addr.receiver || '-' }} {{ addr.mobile || '-' }}
  26. </view>
  27. </view>
  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. <view class="settlement-goods">
  55. <view class="flex settlement-goods__detail" v-for="(item, index) in list" :key="index">
  56. <view class="settlement-goods__detail__left">
  57. <view class="img">
  58. <image class="img" :src="item.picUrl" mode="aspectFill">
  59. </image>
  60. </view>
  61. </view>
  62. <view class="settlement-goods__detail__right">
  63. <view class="ells title">{{ item.title }}</view>
  64. <view class="sku" v-if="item.properties">规格:{{ item.properties }}</view>
  65. <view class="">数量:{{ item.goodsNum }}</view>
  66. </view>
  67. </view>
  68. </view>
  69. <view class="flex settlement-freight">
  70. <text>运费</text>
  71. <text>¥{{ $numberFormat(info.freightAmt) }}</text>
  72. </view>
  73. </view>
  74. <view class="footer-fixed">
  75. <view v-if="info.freightType == 2" class="footer-fixed-color"><icon type="warn" style="vertical-align: bottom; margin-right: 20rpx; " size="20"/><text>当前收货地址暂不支持发货</text></view>
  76. <view class="flex btn">
  77. <view class="btn-left">
  78. <view class="money">
  79. <text>合计:</text>
  80. <text class="value">¥{{ $numberFormat(info.payAmt) }}</text>
  81. </view>
  82. </view>
  83. <view class="btn-rightTwo" v-if="info.freightType == 2">
  84. <text class="save" >提交</text>
  85. </view>
  86. <view class="btn-right" v-else>
  87. <text class="save" @click="save">提交</text>
  88. </view>
  89. </view>
  90. </view>
  91. <area-picker :area-show="areaShow" @cancel="cancel" @confirmArea="confirmArea" />
  92. </view>
  93. </template>
  94. <script>
  95. import env from '../../config/env.js'
  96. import $http from '@/utils/request.js'
  97. import AreaPicker from '../../components/area-picker/area-picker.vue'
  98. export default {
  99. components: {
  100. AreaPicker
  101. },
  102. data() {
  103. return {
  104. ids: [],
  105. info: {},
  106. addr: {},
  107. list: [],
  108. loading: false,
  109. addrId: '',
  110. form: {
  111. receiver: '',
  112. mobile: '',
  113. name: '',
  114. cityShow: '',
  115. addr: '',
  116. provinceId: '', // 省ID/编码
  117. province: '', // 省
  118. cityId: '', // 市ID/编码
  119. city: '', // 市
  120. areaId: '', // 区ID/编码
  121. area: '', // 区
  122. },
  123. areaShow: false,
  124. toAddressShow: false,
  125. wxAddress: {}
  126. }
  127. },
  128. onLoad(opthios) {
  129. if (opthios.ids) {
  130. this.ids = JSON.parse(opthios.ids)
  131. this.getDetail()
  132. }
  133. },
  134. onShow() {
  135. if (this.toAddressShow) {
  136. this.getDetail()
  137. }
  138. },
  139. methods: {
  140. save() {
  141. if (this.info.addr == null) {
  142. uni.$u.toast('请先保存配送地址');
  143. return
  144. }
  145. let _this = this
  146. let payIng = false
  147. if (payIng) return
  148. uni.showLoading({
  149. title: '加载中'
  150. });
  151. $http.post('/api/v1/mp/user/deliver/order/submit', {}).then(res => {
  152. payIng = true
  153. uni.hideLoading();
  154. if (res.code == 0) {
  155. if (res.data.needPay == 1) {
  156. $http.post('/api/v1/mp/user/deliver/order/pay', {
  157. orderId: res.data.orderId,
  158. payType: 2
  159. }).then(ele => {
  160. if (ele.code == 0) {
  161. uni.requestPayment({
  162. timeStamp: ele.data.timeStamp,
  163. nonceStr: ele.data.nonceStr,
  164. package: ele.data.package,
  165. signType: ele.data.signType,
  166. paySign: ele.data.paySign,
  167. success() {
  168. uni.showToast({
  169. title: '支付成功',
  170. icon: 'success',
  171. duration: 2000
  172. })
  173. setTimeout(() => {
  174. uni.redirectTo({
  175. url: `/packageGoods/order/index`
  176. })
  177. }, 500)
  178. },
  179. fail() {
  180. payIng = false
  181. setTimeout(() => {
  182. uni.redirectTo({
  183. url: `/packageGoods/order/index`
  184. })
  185. }, 500)
  186. }
  187. })
  188. } else {
  189. payIng = false
  190. uni.$u.toast('支付失败!');
  191. setTimeout(() => {
  192. uni.redirectTo({
  193. url: `/packageGoods/order/index`
  194. })
  195. }, 500)
  196. }
  197. }).catch(() => {
  198. payIng = false
  199. uni.$u.toast('支付失败!');
  200. setTimeout(() => {
  201. uni.redirectTo({
  202. url: `/packageGoods/order/index`
  203. })
  204. }, 500)
  205. })
  206. } else {
  207. uni.showToast({
  208. title: '提交成功',
  209. icon: 'success',
  210. duration: 2000
  211. })
  212. setTimeout(() => {
  213. uni.redirectTo({
  214. url: `/packageGoods/order/index`
  215. })
  216. }, 500)
  217. }
  218. } else {
  219. payIng = false
  220. uni.$u.toast('提交失败!');
  221. }
  222. }).catch(() => {
  223. payIng = false
  224. uni.$u.toast('提交失败!');
  225. uni.hideLoading();
  226. })
  227. },
  228. getDetail() {
  229. uni.showLoading({
  230. title: '加载中'
  231. });
  232. $http.post('/api/v1/mp/user/deliver/order/settle', {
  233. ids: this.ids
  234. }).then(res => {
  235. uni.hideLoading();
  236. if (res.code == 0) {
  237. this.info = res.data
  238. this.addr = res.data.addr
  239. res.data.prizeList.forEach(item => {
  240. let picUrlArr = item.picUrl.split(',')
  241. item.picUrl = env.filePublic + picUrlArr[0] + '?imageView2/2/w/170'
  242. })
  243. this.list = res.data.prizeList
  244. }
  245. }).catch(() => {
  246. uni.hideLoading();
  247. })
  248. },
  249. selectArea() {
  250. this.areaShow = true
  251. },
  252. confirmArea(obj) {
  253. this.form.province = obj.province
  254. this.form.provinceId = obj.provinceId
  255. this.form.city = obj.city
  256. this.form.cityId = obj.cityId
  257. this.form.area = obj.area
  258. this.form.areaId = obj.areaId
  259. this.form.cityShow = obj.cityShow
  260. this.areaShow = false
  261. },
  262. cancel() {
  263. this.areaShow = false
  264. },
  265. toAddress() {
  266. this.toAddressShow = true
  267. uni.navigateTo({
  268. url: "/packageOperate/address/index"
  269. })
  270. },
  271. toWeixinAddress() {
  272. let _this = this
  273. uni.chooseAddress({
  274. success(res) {
  275. _this.wxAddress = res
  276. _this.getArea()
  277. }
  278. })
  279. },
  280. // 回显微信地址
  281. async getArea() {
  282. // 获取省
  283. let provinceRes = await $http.post('/api/v1/mp/area/listByPid', {
  284. pid: 0
  285. })
  286. let provinceItem = provinceRes && provinceRes.data.find((item=> item.areaName == this.wxAddress.provinceName))
  287. // 获取市
  288. let cityRes = await $http.post('/api/v1/mp/area/listByPid', {
  289. pid: provinceItem && provinceItem.areaId
  290. })
  291. let cityItem = cityRes && cityRes.data.find((item=> item.areaName == this.wxAddress.cityName))
  292. // 获取区
  293. let areaRes = await $http.post('/api/v1/mp/area/listByPid', {
  294. pid: cityItem && cityItem.areaId
  295. })
  296. let areaItem = areaRes && areaRes.data.find((item=> item.areaName == this.wxAddress.countyName))
  297. // 赋值
  298. this.form.province = provinceItem.areaName
  299. this.form.provinceId = provinceItem.areaId
  300. this.form.city = cityItem.areaName
  301. this.form.cityId = cityItem.areaId
  302. this.form.area = areaItem.areaName
  303. this.form.areaId = areaItem.areaId
  304. this.form.cityShow = `${ provinceItem.areaName }-${ cityItem.areaName }-${ areaItem.areaName }`
  305. this.form.addr = this.wxAddress.detailInfo
  306. this.form.receiver = this.wxAddress.userName
  307. this.form.mobile = this.wxAddress.telNumber
  308. },
  309. saveAddress() {
  310. let _this = this
  311. if (!_this.form.receiver) {
  312. uni.$u.toast('请输入收货人');
  313. return
  314. }
  315. if (!_this.form.mobile) {
  316. uni.$u.toast('请输入手机号码');
  317. return
  318. }
  319. const rule = /^[1][0-9][0-9]{9}$/
  320. if (!rule.test(_this.form.mobile)) {
  321. uni.$u.toast('请输入正确的手机号');
  322. return
  323. }
  324. if (!_this.form.cityShow) {
  325. uni.$u.toast('请选择所在地区');
  326. return
  327. }
  328. if (!_this.form.addr) {
  329. uni.$u.toast('请输入详细地址');
  330. return
  331. }
  332. let url = '/api/v1/mp/user/addr/create'
  333. $http.post(url, this.form).then(res => {
  334. if (res.code == 0) {
  335. uni.$u.toast('保存成功');
  336. this.getDetail()
  337. }
  338. })
  339. },
  340. },
  341. }
  342. </script>
  343. <style lang="scss" scoped>
  344. .settlement {
  345. margin: 10rpx;
  346. padding-bottom: 100rpx;
  347. &-address {
  348. background-color: #fff;
  349. padding: 0 16rpx 24rpx;
  350. margin-bottom: 20rpx;
  351. &-top {
  352. justify-content: space-between;
  353. padding: 24rpx 0;
  354. border-bottom: 1px solid rgba(236, 236, 236, 100);
  355. &__left {
  356. line-height: 40rpx;
  357. }
  358. &__right {
  359. line-height: 40rpx;
  360. color: rgba(35, 126, 212, 100);
  361. }
  362. }
  363. &-desc {
  364. &__item {
  365. line-height: 40rpx;
  366. margin-top: 16rpx;
  367. }
  368. }
  369. &-form {
  370. .save-btn {
  371. padding: 10rpx 20rpx;
  372. /deep/ button {
  373. line-height: 76rpx;
  374. font-size: 28rpx;
  375. height: 76rpx;
  376. color: #fff;
  377. background-color: $uni-bg-color;
  378. border: none;
  379. border-radius: 100rpx;
  380. }
  381. }
  382. }
  383. }
  384. &-goods {
  385. background-color: #fff;
  386. padding: 0 40rpx;
  387. margin-bottom: 20rpx;
  388. &__detail {
  389. padding: 20rpx 0;
  390. justify-content: space-between;
  391. border-bottom: 1px solid rgba(236, 236, 236, 100);
  392. &__left {
  393. display: flex;
  394. height: 170rpx;
  395. .img {
  396. image {
  397. width: 170rpx;
  398. height: 170rpx;
  399. margin-right: 20rpx;
  400. }
  401. }
  402. }
  403. &__right {
  404. flex: 1;
  405. display: flex;
  406. height: 170rpx;
  407. flex-direction: column;
  408. justify-content: space-between;
  409. align-items: flex-start;
  410. font-size: 30rpx;
  411. .title {
  412. font-weight: bold;
  413. }
  414. .sku {
  415. color: #848484;
  416. }
  417. }
  418. }
  419. &__detail:last-child {
  420. border: none;
  421. }
  422. }
  423. &-freight {
  424. background-color: #fff;
  425. justify-content: space-between;
  426. padding: 20rpx 16rpx;
  427. }
  428. }
  429. .footer-fixed {
  430. position: fixed;
  431. bottom: var(--window-bottom);
  432. left: 0;
  433. right: 0;
  434. // min-height: 120rpx;
  435. z-index: 11;
  436. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  437. background: #fff;
  438. // margin-bottom: 40rpx;
  439. // 设置ios刘海屏底部横线安全区域
  440. padding-bottom: constant(safe-area-inset-bottom);
  441. padding-bottom: env(safe-area-inset-bottom);
  442. &-color {
  443. font-size: 30rpx;
  444. color: $uni-text-color;
  445. margin: 10rpx 40rpx;
  446. }
  447. .btn {
  448. justify-content: space-between;
  449. padding: 20rpx 40rpx;
  450. &-left {
  451. .value {
  452. color: $uni-text-color;
  453. }
  454. }
  455. &-right {
  456. display: flex;
  457. align-items: center;
  458. justify-content: flex-end;
  459. .save {
  460. width: 190rpx;
  461. height: 60rpx;
  462. line-height: 60rpx;
  463. border-radius: 8rpx;
  464. text-align: center;
  465. margin-left: 40rpx;
  466. background-color: rgba(236, 112, 9, 100);
  467. color: rgba(255, 255, 255, 100);
  468. }
  469. }
  470. &-rightTwo {
  471. display: flex;
  472. align-items: center;
  473. justify-content: flex-end;
  474. .save {
  475. width: 190rpx;
  476. height: 60rpx;
  477. line-height: 60rpx;
  478. border-radius: 8rpx;
  479. text-align: center;
  480. margin-left: 40rpx;
  481. background-color: #6c6c6c;
  482. color: #ffffff;
  483. }
  484. }
  485. }
  486. }
  487. </style>