settlement.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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. <!-- 选择地址、获取微信地址 -->
  7. <view class="flex settlement-address-top" v-if="info.addr !== null">
  8. <view class="settlement-address-top__left">配送地址</view>
  9. <view class="flex settlement-address-top__right" @click="toAddress">
  10. <view class="">更改地址</view>
  11. <u-icon name="arrow-right" size="18" color="#237ED4 100%"></u-icon>
  12. </view>
  13. </view>
  14. <view class="flex settlement-address-top" v-else>
  15. <view class="settlement-address-top__left">配送地址</view>
  16. <view class="flex settlement-address-top__right" @click="toWeixinAddress">
  17. <view class="">微信地址</view>
  18. <u-icon name="arrow-right" size="18" color="#237ED4 100%"></u-icon>
  19. </view>
  20. </view>
  21. <!-- 收货人、地址 -->
  22. <view class="settlement-address-desc" v-if="info.addr !== null">
  23. <view class="settlement-address-desc__item">{{ addr.receiver || '-' }}<text>{{ addr.mobile || '-' }}</text></view>
  24. <view class="settlement-address-desc__item">
  25. {{ `${ addr.province || '-' } ${ addr.city || '-' } ${ addr.area || '-' }` }} {{ addr.addr || '-' }}</view>
  26. </view>
  27. <!-- 地址form -->
  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. <!-- 商品 -->
  55. <view class="settlement-goods">
  56. <view class="settlement-goods-item" v-for="(item, index) in list" :key="index">
  57. <image :src="item.picUrl" mode="aspectFit"></image>
  58. <view class="info">
  59. <view class="info-title ells">{{ item.title }}</view>
  60. <view class="info-num flex">
  61. <view class="info-num-sku ells-one">规格:{{ item.properties || '-' }}</view>
  62. <view class="info-num-goods">数量:{{ item.goodsNum }}</view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. <view class="settlement-freight flex">
  68. <text>留言</text>
  69. <u-input v-model="info.memo" placeholder="请输入留言" clearable inputAlign="right" border="none" />
  70. </view>
  71. <view class="settlement-freight flex">
  72. <text>运费</text>
  73. <text>¥{{ $numberFormat(info.freightAmt) }}</text>
  74. </view>
  75. </view>
  76. <view class="footer-fixed">
  77. <view class="content">
  78. <view class="content-not flex" v-if="info.freightType == 2">
  79. <icon type="warn" style="vertical-align: bottom; margin-right: 20rpx; " size="20"/>
  80. <text>当前收货地址暂不支持发货</text>
  81. </view>
  82. <view class="content-btn flex">
  83. <view class="content-btn-left">
  84. <view class="money">
  85. <text>合计:</text>
  86. <text class="value">¥{{ $numberFormat(info.payAmt) }}</text>
  87. </view>
  88. </view>
  89. <view class="content-btn-right">
  90. <text class="save not" v-if="info.freightType == 2">提交</text>
  91. <text class="save" @click="save" v-else>提交</text>
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. <area-picker :area-show="areaShow" @cancel="cancel" @confirmArea="confirmArea" />
  97. </view>
  98. </template>
  99. <script>
  100. import env from '../../config/env.js'
  101. import $http from '@/utils/request.js'
  102. import AreaPicker from '../../components/area-picker/area-picker.vue'
  103. export default {
  104. components: {
  105. AreaPicker
  106. },
  107. data() {
  108. return {
  109. ids: [],
  110. info: {},
  111. addr: {},
  112. list: [],
  113. loading: false,
  114. addrId: '',
  115. form: {
  116. receiver: '',
  117. mobile: '',
  118. name: '',
  119. cityShow: '',
  120. addr: '',
  121. provinceId: '', // 省ID/编码
  122. province: '', // 省
  123. cityId: '', // 市ID/编码
  124. city: '', // 市
  125. areaId: '', // 区ID/编码
  126. area: '', // 区
  127. },
  128. areaShow: false,
  129. toAddressShow: false,
  130. wxAddress: {}
  131. }
  132. },
  133. onLoad(opthios) {
  134. if (opthios.ids) {
  135. this.ids = JSON.parse(opthios.ids)
  136. this.getDetail()
  137. }
  138. },
  139. onShow() {
  140. if (this.toAddressShow) {
  141. this.getDetail()
  142. }
  143. },
  144. methods: {
  145. save() {
  146. if (this.info.addr == null) {
  147. uni.$u.toast('请先保存配送地址');
  148. return
  149. }
  150. let _this = this
  151. let payIng = false
  152. if (payIng) return
  153. uni.showLoading({
  154. title: '加载中'
  155. });
  156. $http.post('/api/v1/mp/user/deliver/order/submit', {memo:this.info.memo}).then(res => {
  157. payIng = true
  158. uni.hideLoading();
  159. if (res.code == 0) {
  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: 34rpx;
  351. padding-bottom: 100rpx;
  352. &-address {
  353. background-color: #fff;
  354. padding: 34rpx;
  355. margin-bottom: 34rpx;
  356. border-radius: 22rpx;
  357. // 选择地址、获取微信地址
  358. &-top {
  359. justify-content: space-between;
  360. padding: 0 0 34rpx;
  361. border-bottom: 1px solid rgba(236, 236, 236, 100);
  362. &__left {
  363. line-height: 40rpx;
  364. }
  365. &__right {
  366. line-height: 40rpx;
  367. color: rgba(35, 126, 212, 100);
  368. }
  369. }
  370. // 收货人、地址
  371. &-desc {
  372. margin-top: 34rpx;
  373. &__item {
  374. line-height: 28rpx;
  375. margin-bottom: 20rpx;
  376. text {
  377. padding-left: 8rpx;
  378. font-size: 24rpx;
  379. color: #666;
  380. }
  381. }
  382. &__item:last-child {
  383. margin-bottom: 0;
  384. color: #999;
  385. }
  386. }
  387. // 地址form
  388. &-form {
  389. .save-btn {
  390. padding: 10rpx 20rpx;
  391. /deep/ button {
  392. line-height: 76rpx;
  393. font-size: 28rpx;
  394. height: 76rpx;
  395. color: #fff;
  396. background-color: $uni-bg-color;
  397. border: none;
  398. border-radius: 100rpx;
  399. }
  400. }
  401. }
  402. }
  403. // 商品
  404. &-goods {
  405. // 商品列表
  406. &-item{
  407. display: flex;
  408. padding: 34rpx 32rpx 34rpx 22rpx;
  409. box-shadow: 0px 0px 8px 0px rgba(26, 35, 113, 0.08);
  410. background-color: #fff;
  411. border-radius: 22rpx;
  412. margin-bottom: 34rpx;
  413. image {
  414. width: 176rpx;
  415. height: 176rpx;
  416. border-radius: 12rpx;
  417. margin-right: 22rpx;
  418. }
  419. .info {
  420. display: flex;
  421. flex-direction: column;
  422. justify-content: space-between;
  423. flex: 1;
  424. padding: 8rpx 0;
  425. &-title {
  426. font-size: 30rpx;
  427. font-weight: bold;
  428. line-height: 40rpx;
  429. }
  430. &-num {
  431. justify-content: space-between;
  432. &-sku {
  433. flex: 1;
  434. color: #666666;
  435. font-size: 26rpx;
  436. }
  437. &-goods {
  438. color: #666666;
  439. font-size: 26rpx;
  440. }
  441. }
  442. }
  443. }
  444. }
  445. // 留言、运费
  446. &-freight {
  447. font-size: 30rpx;
  448. margin-bottom: 34rpx;
  449. background-color: #fff;
  450. justify-content: space-between;
  451. padding: 34rpx;
  452. border-radius: 22rpx;
  453. }
  454. }
  455. .footer-fixed {
  456. position: fixed;
  457. bottom: var(--window-bottom);
  458. left: 0;
  459. right: 0;
  460. z-index: 11;
  461. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  462. background: #fff;
  463. // 设置ios刘海屏底部横线安全区域
  464. padding-bottom: constant(safe-area-inset-bottom);
  465. padding-bottom: env(safe-area-inset-bottom);
  466. .content {
  467. padding: 20rpx 40rpx;
  468. font-size: 30rpx;
  469. // 不发货提示
  470. &-not {
  471. justify-content: flex-start;
  472. font-size: 30rpx;
  473. color: #FF4208;
  474. margin: 0 0 30rpx;
  475. }
  476. // 提交按钮
  477. &-btn {
  478. justify-content: space-between;
  479. &-left {
  480. .value {
  481. color: #FF4208;
  482. }
  483. }
  484. &-right {
  485. display: flex;
  486. align-items: center;
  487. justify-content: flex-end;
  488. .save {
  489. width: 210rpx;
  490. height: 82rpx;
  491. line-height: 82rpx;
  492. background: #F9822C;
  493. border-radius: 40rpx;
  494. text-align: center;
  495. color: #fff;
  496. }
  497. .not {
  498. background-color: #6c6c6c;
  499. }
  500. }
  501. }
  502. }
  503. }
  504. </style>