settlement.vue 12 KB

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