settlement.vue 13 KB

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