settlement.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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: `/pages/order/index`
  176. })
  177. }, 500)
  178. },
  179. fail() {
  180. payIng = false
  181. setTimeout(() => {
  182. uni.redirectTo({
  183. url: `/pages/order/index`
  184. })
  185. }, 500)
  186. }
  187. })
  188. } else {
  189. payIng = false
  190. uni.$u.toast('支付失败!');
  191. }
  192. }).catch(() => {
  193. payIng = false
  194. uni.$u.toast('支付失败!');
  195. })
  196. } else {
  197. uni.showToast({
  198. title: '提交成功',
  199. icon: 'success',
  200. duration: 2000
  201. })
  202. setTimeout(() => {
  203. uni.redirectTo({
  204. url: `/pages/order/index`
  205. })
  206. }, 500)
  207. }
  208. } else {
  209. payIng = false
  210. uni.$u.toast('提交失败!');
  211. }
  212. }).catch(() => {
  213. payIng = false
  214. uni.$u.toast('提交失败!');
  215. uni.hideLoading();
  216. })
  217. },
  218. getDetail() {
  219. uni.showLoading({
  220. title: '加载中'
  221. });
  222. $http.post('/api/v1/mp/user/deliver/order/settle', {
  223. ids: this.ids
  224. }).then(res => {
  225. uni.hideLoading();
  226. if (res.code == 0) {
  227. this.info = res.data
  228. this.addr = res.data.addr
  229. res.data.prizeList.forEach(item => {
  230. let picUrlArr = item.picUrl.split(',')
  231. item.picUrl = env.filePublic + picUrlArr[0] + '?imageView2/2/w/170'
  232. })
  233. this.list = res.data.prizeList
  234. }
  235. }).catch(() => {
  236. uni.hideLoading();
  237. })
  238. },
  239. selectArea() {
  240. this.areaShow = true
  241. },
  242. confirmArea(obj) {
  243. this.form.province = obj.province
  244. this.form.provinceId = obj.provinceId
  245. this.form.city = obj.city
  246. this.form.cityId = obj.cityId
  247. this.form.area = obj.area
  248. this.form.areaId = obj.areaId
  249. this.form.cityShow = obj.cityShow
  250. this.areaShow = false
  251. },
  252. cancel() {
  253. this.areaShow = false
  254. },
  255. toAddress() {
  256. this.toAddressShow = true
  257. uni.navigateTo({
  258. url: "/pages/address/index"
  259. })
  260. },
  261. toWeixinAddress() {
  262. let _this = this
  263. uni.chooseAddress({
  264. success(res) {
  265. _this.wxAddress = res
  266. _this.getArea()
  267. }
  268. })
  269. },
  270. // 回显微信地址
  271. async getArea() {
  272. // 获取省
  273. let provinceRes = await $http.post('/api/v1/mp/area/listByPid', {
  274. pid: 0
  275. })
  276. let provinceItem = provinceRes && provinceRes.data.find((item=> item.areaName == this.wxAddress.provinceName))
  277. // 获取市
  278. let cityRes = await $http.post('/api/v1/mp/area/listByPid', {
  279. pid: provinceItem && provinceItem.areaId
  280. })
  281. let cityItem = cityRes && cityRes.data.find((item=> item.areaName == this.wxAddress.cityName))
  282. // 获取区
  283. let areaRes = await $http.post('/api/v1/mp/area/listByPid', {
  284. pid: cityItem && cityItem.areaId
  285. })
  286. let areaItem = areaRes && areaRes.data.find((item=> item.areaName == this.wxAddress.countyName))
  287. // 赋值
  288. this.form.province = provinceItem.areaName
  289. this.form.provinceId = provinceItem.areaId
  290. this.form.city = cityItem.areaName
  291. this.form.cityId = cityItem.areaId
  292. this.form.area = areaItem.areaName
  293. this.form.areaId = areaItem.areaId
  294. this.form.cityShow = `${ provinceItem.areaName }-${ cityItem.areaName }-${ areaItem.areaName }`
  295. this.form.addr = this.wxAddress.detailInfo
  296. this.form.receiver = this.wxAddress.userName
  297. this.form.mobile = this.wxAddress.telNumber
  298. },
  299. saveAddress() {
  300. let _this = this
  301. if (!_this.form.receiver) {
  302. uni.$u.toast('请输入收货人');
  303. return
  304. }
  305. if (!_this.form.mobile) {
  306. uni.$u.toast('请输入手机号码');
  307. return
  308. }
  309. const rule = /^[1][0-9][0-9]{9}$/
  310. if (!rule.test(_this.form.mobile)) {
  311. uni.$u.toast('请输入正确的手机号');
  312. return
  313. }
  314. if (!_this.form.cityShow) {
  315. uni.$u.toast('请选择所在地区');
  316. return
  317. }
  318. if (!_this.form.addr) {
  319. uni.$u.toast('请输入详细地址');
  320. return
  321. }
  322. let url = '/api/v1/mp/user/addr/create'
  323. $http.post(url, this.form).then(res => {
  324. if (res.code == 0) {
  325. uni.$u.toast('保存成功');
  326. this.getDetail()
  327. }
  328. })
  329. },
  330. },
  331. }
  332. </script>
  333. <style lang="scss" scoped>
  334. .settlement {
  335. margin: 10rpx;
  336. padding-bottom: 100rpx;
  337. &-address {
  338. background-color: #fff;
  339. padding: 0 16rpx 24rpx;
  340. margin-bottom: 20rpx;
  341. &-top {
  342. justify-content: space-between;
  343. padding: 24rpx 0;
  344. border-bottom: 1px solid rgba(236, 236, 236, 100);
  345. &__left {
  346. line-height: 40rpx;
  347. }
  348. &__right {
  349. line-height: 40rpx;
  350. color: rgba(35, 126, 212, 100);
  351. }
  352. }
  353. &-desc {
  354. &__item {
  355. line-height: 40rpx;
  356. margin-top: 16rpx;
  357. }
  358. }
  359. &-form {
  360. .save-btn {
  361. padding: 10rpx 20rpx;
  362. /deep/ button {
  363. line-height: 76rpx;
  364. font-size: 28rpx;
  365. height: 76rpx;
  366. color: #fff;
  367. background-color: $uni-bg-color;
  368. border: none;
  369. border-radius: 100rpx;
  370. }
  371. }
  372. }
  373. }
  374. &-goods {
  375. background-color: #fff;
  376. padding: 0 40rpx;
  377. margin-bottom: 20rpx;
  378. &__detail {
  379. padding: 20rpx 0;
  380. justify-content: space-between;
  381. border-bottom: 1px solid rgba(236, 236, 236, 100);
  382. &__left {
  383. display: flex;
  384. height: 170rpx;
  385. .img {
  386. image {
  387. width: 170rpx;
  388. height: 170rpx;
  389. margin-right: 20rpx;
  390. }
  391. }
  392. }
  393. &__right {
  394. flex: 1;
  395. display: flex;
  396. height: 170rpx;
  397. flex-direction: column;
  398. justify-content: space-between;
  399. align-items: flex-start;
  400. font-size: 30rpx;
  401. .title {
  402. font-weight: bold;
  403. }
  404. .sku {
  405. color: #848484;
  406. }
  407. }
  408. }
  409. &__detail:last-child {
  410. border: none;
  411. }
  412. }
  413. &-freight {
  414. background-color: #fff;
  415. justify-content: space-between;
  416. padding: 20rpx 16rpx;
  417. }
  418. }
  419. .footer-fixed {
  420. position: fixed;
  421. bottom: var(--window-bottom);
  422. left: 0;
  423. right: 0;
  424. // min-height: 120rpx;
  425. z-index: 11;
  426. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  427. background: #fff;
  428. // margin-bottom: 40rpx;
  429. // 设置ios刘海屏底部横线安全区域
  430. padding-bottom: constant(safe-area-inset-bottom);
  431. padding-bottom: env(safe-area-inset-bottom);
  432. &-color {
  433. font-size: 30rpx;
  434. color: $uni-text-color;
  435. margin: 10rpx 40rpx;
  436. }
  437. .btn {
  438. justify-content: space-between;
  439. padding: 20rpx 40rpx;
  440. &-left {
  441. .value {
  442. color: $uni-text-color;
  443. }
  444. }
  445. &-right {
  446. display: flex;
  447. align-items: center;
  448. justify-content: flex-end;
  449. .save {
  450. width: 190rpx;
  451. height: 60rpx;
  452. line-height: 60rpx;
  453. border-radius: 8rpx;
  454. text-align: center;
  455. margin-left: 40rpx;
  456. background-color: rgba(236, 112, 9, 100);
  457. color: rgba(255, 255, 255, 100);
  458. }
  459. }
  460. &-rightTwo {
  461. display: flex;
  462. align-items: center;
  463. justify-content: flex-end;
  464. .save {
  465. width: 190rpx;
  466. height: 60rpx;
  467. line-height: 60rpx;
  468. border-radius: 8rpx;
  469. text-align: center;
  470. margin-left: 40rpx;
  471. background-color: #6c6c6c;
  472. color: #ffffff;
  473. }
  474. }
  475. }
  476. }
  477. </style>