settlement.vue 9.8 KB

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