settlement.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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="settlement-address-desc" v-if="info.addr !== null">
  14. <view class="settlement-address-desc__item">{{ `${ addr.province || '-' }-${ addr.city || '-' }-${ addr.area || '-' }` }}
  15. {{ addr.addr || '-' }}
  16. </view>
  17. <view class="settlement-address-desc__item">{{ addr.receiver || '-' }} {{ addr.mobile || '-' }}</view>
  18. </view>
  19. <view class="settlement-address-form" v-else>
  20. <view class="address-add">
  21. <u--form labelPosition="left" ref="form" labelWidth="90">
  22. <u-form-item label="收货人:" borderBottom required>
  23. <u--input v-model="form.receiver" border="none" placeholder="请输入收货人"></u--input>
  24. </u-form-item>
  25. <u-form-item label="手机号码:" borderBottom required>
  26. <u--input v-model="form.mobile" border="none" placeholder="请输入手机号码"></u--input>
  27. </u-form-item>
  28. <u-form-item label="所在地区:" borderBottom required @click="selectArea">
  29. <u--input v-model="form.cityShow" border="none" disabled disabledColor="#ffffff"
  30. placeholder="请选择地区">
  31. </u--input>
  32. <u-icon slot="right" name="arrow-right"></u-icon>
  33. </u-form-item>
  34. <u-form-item label="详细地址:" :borderBottom="false" required>
  35. <u--textarea v-model="form.addr" placeholder="请输入详细地址"></u--textarea>
  36. </u-form-item>
  37. </u--form>
  38. </view>
  39. <!-- 操作按钮 -->
  40. <view class="save-btn">
  41. <button :loading="loading" type="default" @click="saveAddress">保存并使用</button>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="settlement-goods">
  46. <view class="flex settlement-goods__detail" v-for="(item, index) in list" :key="index">
  47. <view class="settlement-goods__detail__left">
  48. <view class="img">
  49. <image class="img" :src="item.picUrl" mode="aspectFill">
  50. </image>
  51. </view>
  52. </view>
  53. <view class="settlement-goods__detail__right">
  54. <view class="ells title">{{ item.title }}</view>
  55. <view class="sku" v-if="item.properties">规格:{{ item.properties }}</view>
  56. <view class="">数量:{{ item.goodsNum }}</view>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="flex settlement-freight">
  61. <text>运费</text>
  62. <text>¥{{ $numberFormat(info.freightAmt) }}</text>
  63. </view>
  64. </view>
  65. <view class="footer-fixed">
  66. <view class="flex btn">
  67. <view class="btn-left">
  68. <view class="money">
  69. <text>合计:</text>
  70. <text class="value">¥{{ $numberFormat(info.payAmt) }}</text>
  71. </view>
  72. </view>
  73. <view class="btn-right">
  74. <text class="save" @click="save">提交</text>
  75. </view>
  76. </view>
  77. </view>
  78. <area-picker :area-show="areaShow" @cancel="cancel" @confirmArea="confirmArea" />
  79. </view>
  80. </template>
  81. <script>
  82. import env from '../../config/env.js'
  83. import $http from '@/utils/request.js'
  84. import AreaPicker from '../../components/area-picker/area-picker.vue'
  85. export default {
  86. components: {
  87. AreaPicker
  88. },
  89. data() {
  90. return {
  91. ids: [],
  92. info: {},
  93. addr: {},
  94. list: [],
  95. loading: false,
  96. addrId: '',
  97. form: {
  98. receiver: '',
  99. mobile: '',
  100. name: '',
  101. cityShow: '',
  102. addr: '',
  103. provinceId: '', // 省ID/编码
  104. province: '', // 省
  105. cityId: '', // 市ID/编码
  106. city: '', // 市
  107. areaId: '', // 区ID/编码
  108. area: '', // 区
  109. },
  110. areaShow: false,
  111. toAddressShow: false,
  112. }
  113. },
  114. onLoad(opthios) {
  115. if (opthios.ids) {
  116. this.ids = JSON.parse(opthios.ids)
  117. this.getDetail()
  118. }
  119. },
  120. onShow() {
  121. if (this.toAddressShow) {
  122. this.getDetail()
  123. }
  124. },
  125. methods: {
  126. save() {
  127. if(this.info.addr == null){
  128. uni.$u.toast('请先保存配送地址');
  129. return
  130. }
  131. let _this = this
  132. let payIng = false
  133. if (payIng) return
  134. uni.showLoading({
  135. title: '加载中'
  136. });
  137. $http.post('/api/v1/mp/user/deliver/order/submit', {}).then(res => {
  138. payIng = true
  139. uni.hideLoading();
  140. if (res.code == 0) {
  141. if (res.data.needPay == 1) {
  142. $http.post('/api/v1/mp/user/deliver/order/pay', {
  143. orderId: res.data.orderId,
  144. payType: 2
  145. }).then(ele => {
  146. if (ele.code == 0) {
  147. uni.requestPayment({
  148. timeStamp: ele.data.timeStamp,
  149. nonceStr: ele.data.nonceStr,
  150. package: ele.data.package,
  151. signType: ele.data.signType,
  152. paySign: ele.data.paySign,
  153. success() {
  154. uni.showToast({
  155. title: '支付成功',
  156. icon: 'success',
  157. duration: 2000
  158. })
  159. setTimeout(() => {
  160. uni.redirectTo({
  161. url: `/pages/order/index`
  162. })
  163. }, 500)
  164. },
  165. fail() {
  166. payIng = false
  167. setTimeout(() => {
  168. uni.redirectTo({
  169. url: `/pages/order/index`
  170. })
  171. }, 500)
  172. }
  173. })
  174. } else {
  175. payIng = false
  176. uni.$u.toast('支付失败!');
  177. }
  178. }).catch(() => {
  179. payIng = false
  180. uni.$u.toast('支付失败!');
  181. })
  182. } else {
  183. uni.showToast({
  184. title: '提交成功',
  185. icon: 'success',
  186. duration: 2000
  187. })
  188. setTimeout(() => {
  189. uni.redirectTo({
  190. url: `/pages/order/index`
  191. })
  192. }, 500)
  193. }
  194. } else {
  195. payIng = false
  196. uni.$u.toast('提交失败!');
  197. }
  198. }).catch(() => {
  199. payIng = false
  200. uni.$u.toast('提交失败!');
  201. uni.hideLoading();
  202. })
  203. },
  204. getDetail() {
  205. uni.showLoading({
  206. title: '加载中'
  207. });
  208. $http.post('/api/v1/mp/user/deliver/order/settle', {
  209. ids: this.ids
  210. }).then(res => {
  211. uni.hideLoading();
  212. if (res.code == 0) {
  213. this.info = res.data
  214. this.addr = res.data.addr
  215. res.data.prizeList.forEach(item => {
  216. let picUrlArr = item.picUrl.split(',')
  217. item.picUrl = env.filePublic + picUrlArr[0]
  218. })
  219. this.list = res.data.prizeList
  220. }
  221. }).catch(() => {
  222. uni.hideLoading();
  223. })
  224. },
  225. selectArea() {
  226. this.areaShow = true
  227. },
  228. confirmArea(obj) {
  229. // console.log(obj);
  230. this.form.province = obj.province
  231. this.form.provinceId = obj.provinceId
  232. this.form.city = obj.city
  233. this.form.cityId = obj.cityId
  234. this.form.area = obj.area
  235. this.form.areaId = obj.areaId
  236. this.form.cityShow = obj.cityShow
  237. this.areaShow = false
  238. },
  239. cancel() {
  240. this.areaShow = false
  241. },
  242. toAddress() {
  243. this.toAddressShow = true
  244. uni.navigateTo({
  245. url: "/pages/address/index"
  246. })
  247. },
  248. saveAddress() {
  249. let _this = this
  250. if (!_this.form.receiver) {
  251. uni.$u.toast('请输入收货人');
  252. return
  253. }
  254. if (!_this.form.mobile) {
  255. uni.$u.toast('请输入手机号码');
  256. return
  257. }
  258. const rule = /^[1][0-9][0-9]{9}$/
  259. if (!rule.test(_this.form.mobile)) {
  260. uni.$u.toast('请输入正确的手机号');
  261. return
  262. }
  263. if (!_this.form.cityShow) {
  264. uni.$u.toast('请选择所在地区');
  265. return
  266. }
  267. if (!_this.form.addr) {
  268. uni.$u.toast('请输入详细地址');
  269. return
  270. }
  271. let url = '/api/v1/mp/user/addr/create'
  272. $http.post(url, this.form).then(res => {
  273. if (res.code == 0) {
  274. uni.$u.toast('保存成功');
  275. this.getDetail()
  276. }
  277. })
  278. },
  279. },
  280. }
  281. </script>
  282. <style lang="scss" scoped>
  283. .settlement {
  284. margin: 10rpx;
  285. padding-bottom: 100rpx;
  286. &-address {
  287. background-color: #fff;
  288. padding: 0 16rpx 24rpx;
  289. margin-bottom: 20rpx;
  290. &-top {
  291. justify-content: space-between;
  292. padding: 24rpx 0;
  293. border-bottom: 1px solid rgba(236, 236, 236, 100);
  294. &__left {
  295. line-height: 40rpx;
  296. }
  297. &__right {
  298. line-height: 40rpx;
  299. color: rgba(35, 126, 212, 100);
  300. }
  301. }
  302. &-desc {
  303. &__item {
  304. line-height: 40rpx;
  305. margin-top: 16rpx;
  306. }
  307. }
  308. &-form {
  309. .save-btn {
  310. padding: 10rpx 20rpx;
  311. /deep/ button {
  312. line-height: 76rpx;
  313. font-size: 28rpx;
  314. height: 76rpx;
  315. color: #fff;
  316. background-color: $uni-bg-color;
  317. border: none;
  318. border-radius: 100rpx;
  319. }
  320. }
  321. }
  322. }
  323. &-goods {
  324. background-color: #fff;
  325. padding: 0 40rpx;
  326. margin-bottom: 20rpx;
  327. &__detail {
  328. padding: 20rpx 0;
  329. justify-content: space-between;
  330. border-bottom: 1px solid rgba(236, 236, 236, 100);
  331. &__left {
  332. display: flex;
  333. height: 170rpx;
  334. .img {
  335. image {
  336. width: 170rpx;
  337. height: 170rpx;
  338. margin-right: 20rpx;
  339. }
  340. }
  341. }
  342. &__right {
  343. flex: 1;
  344. display: flex;
  345. height: 170rpx;
  346. flex-direction: column;
  347. justify-content: space-between;
  348. align-items: flex-start;
  349. font-size: 30rpx;
  350. .title{
  351. font-weight: bold;
  352. }
  353. .sku {
  354. color: #848484;
  355. }
  356. }
  357. }
  358. &__detail:last-child {
  359. border: none;
  360. }
  361. }
  362. &-freight {
  363. background-color: #fff;
  364. justify-content: space-between;
  365. padding: 20rpx 16rpx;
  366. }
  367. }
  368. .footer-fixed {
  369. position: fixed;
  370. bottom: var(--window-bottom);
  371. left: 0;
  372. right: 0;
  373. // min-height: 120rpx;
  374. z-index: 11;
  375. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  376. background: #fff;
  377. // margin-bottom: 40rpx;
  378. // 设置ios刘海屏底部横线安全区域
  379. padding-bottom: constant(safe-area-inset-bottom);
  380. padding-bottom: env(safe-area-inset-bottom);
  381. .btn {
  382. justify-content: space-between;
  383. padding: 10rpx 40rpx;
  384. &-left {
  385. .value {
  386. color: $uni-text-color;
  387. }
  388. }
  389. &-right {
  390. display: flex;
  391. align-items: center;
  392. justify-content: flex-end;
  393. .save {
  394. width: 190rpx;
  395. height: 60rpx;
  396. line-height: 60rpx;
  397. border-radius: 8rpx;
  398. text-align: center;
  399. margin-left: 40rpx;
  400. background-color: rgba(236, 112, 9, 100);
  401. color: rgba(255, 255, 255, 100);
  402. }
  403. }
  404. }
  405. }
  406. </style>