settlement.vue 9.9 KB

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