settlement.vue 10 KB

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