settlement.vue 13 KB

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