settlement.vue 10 KB

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