settlement.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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]
  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. console.log(res);
  262. _this.wxAddress = res
  263. _this.getArea()
  264. }
  265. })
  266. },
  267. async getArea() {
  268. let provinceRes = await $http.post('/api/v1/mp/area/listByPid', {
  269. pid: 0
  270. })
  271. console.log(provinceRes);
  272. let provinceItem = provinceRes && provinceRes.data.find((item=> item.areaName == this.wxAddress.provinceName))
  273. console.log(provinceItem);
  274. return
  275. let cityRes = await $http.post('/api/v1/mp/area/listByPid', {
  276. pid: provinceRes && provinceRes.data && provinceRes.data[1].areaId
  277. })
  278. let areaRes = await $http.post('/api/v1/mp/area/listByPid', {
  279. pid: cityRes && cityRes.data && cityRes.data[0].areaId
  280. })
  281. },
  282. saveAddress() {
  283. let _this = this
  284. if (!_this.form.receiver) {
  285. uni.$u.toast('请输入收货人');
  286. return
  287. }
  288. if (!_this.form.mobile) {
  289. uni.$u.toast('请输入手机号码');
  290. return
  291. }
  292. const rule = /^[1][0-9][0-9]{9}$/
  293. if (!rule.test(_this.form.mobile)) {
  294. uni.$u.toast('请输入正确的手机号');
  295. return
  296. }
  297. if (!_this.form.cityShow) {
  298. uni.$u.toast('请选择所在地区');
  299. return
  300. }
  301. if (!_this.form.addr) {
  302. uni.$u.toast('请输入详细地址');
  303. return
  304. }
  305. let url = '/api/v1/mp/user/addr/create'
  306. $http.post(url, this.form).then(res => {
  307. if (res.code == 0) {
  308. uni.$u.toast('保存成功');
  309. this.getDetail()
  310. }
  311. })
  312. },
  313. },
  314. }
  315. </script>
  316. <style lang="scss" scoped>
  317. .settlement {
  318. margin: 10rpx;
  319. padding-bottom: 100rpx;
  320. &-address {
  321. background-color: #fff;
  322. padding: 0 16rpx 24rpx;
  323. margin-bottom: 20rpx;
  324. &-top {
  325. justify-content: space-between;
  326. padding: 24rpx 0;
  327. border-bottom: 1px solid rgba(236, 236, 236, 100);
  328. &__left {
  329. line-height: 40rpx;
  330. }
  331. &__right {
  332. line-height: 40rpx;
  333. color: rgba(35, 126, 212, 100);
  334. }
  335. }
  336. &-desc {
  337. &__item {
  338. line-height: 40rpx;
  339. margin-top: 16rpx;
  340. }
  341. }
  342. &-form {
  343. .save-btn {
  344. padding: 10rpx 20rpx;
  345. /deep/ button {
  346. line-height: 76rpx;
  347. font-size: 28rpx;
  348. height: 76rpx;
  349. color: #fff;
  350. background-color: $uni-bg-color;
  351. border: none;
  352. border-radius: 100rpx;
  353. }
  354. }
  355. }
  356. }
  357. &-goods {
  358. background-color: #fff;
  359. padding: 0 40rpx;
  360. margin-bottom: 20rpx;
  361. &__detail {
  362. padding: 20rpx 0;
  363. justify-content: space-between;
  364. border-bottom: 1px solid rgba(236, 236, 236, 100);
  365. &__left {
  366. display: flex;
  367. height: 170rpx;
  368. .img {
  369. image {
  370. width: 170rpx;
  371. height: 170rpx;
  372. margin-right: 20rpx;
  373. }
  374. }
  375. }
  376. &__right {
  377. flex: 1;
  378. display: flex;
  379. height: 170rpx;
  380. flex-direction: column;
  381. justify-content: space-between;
  382. align-items: flex-start;
  383. font-size: 30rpx;
  384. .title {
  385. font-weight: bold;
  386. }
  387. .sku {
  388. color: #848484;
  389. }
  390. }
  391. }
  392. &__detail:last-child {
  393. border: none;
  394. }
  395. }
  396. &-freight {
  397. background-color: #fff;
  398. justify-content: space-between;
  399. padding: 20rpx 16rpx;
  400. }
  401. }
  402. .footer-fixed {
  403. position: fixed;
  404. bottom: var(--window-bottom);
  405. left: 0;
  406. right: 0;
  407. // min-height: 120rpx;
  408. z-index: 11;
  409. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  410. background: #fff;
  411. // margin-bottom: 40rpx;
  412. // 设置ios刘海屏底部横线安全区域
  413. padding-bottom: constant(safe-area-inset-bottom);
  414. padding-bottom: env(safe-area-inset-bottom);
  415. .btn {
  416. justify-content: space-between;
  417. padding: 20rpx 40rpx;
  418. &-left {
  419. .value {
  420. color: $uni-text-color;
  421. }
  422. }
  423. &-right {
  424. display: flex;
  425. align-items: center;
  426. justify-content: flex-end;
  427. .save {
  428. width: 190rpx;
  429. height: 60rpx;
  430. line-height: 60rpx;
  431. border-radius: 8rpx;
  432. text-align: center;
  433. margin-left: 40rpx;
  434. background-color: rgba(236, 112, 9, 100);
  435. color: rgba(255, 255, 255, 100);
  436. }
  437. }
  438. }
  439. }
  440. </style>