settlement.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <template>
  2. <view>
  3. <u-navbar title="结算" :border="true" :placeholder="true" :autoBack="true" leftIconColor="#fff"
  4. bgColor="#E96737" />
  5. <view class="settlement">
  6. <view class="settlement-address">
  7. <view class="flex settlement-address-top">
  8. <view class="settlement-address-top__left">配送地址</view>
  9. <view class="flex settlement-address-top__right" @click="toAddress">
  10. <view class="">更改地址</view>
  11. <u-icon name="arrow-right" size="18" color="#237ED4 100%"></u-icon>
  12. </view>
  13. </view>
  14. <view class="settlement-address-desc" v-if="info.addr !== null">
  15. <view class="settlement-address-desc__item">{{ `${ addr.province }-${ addr.city }-${ addr.area }` }}
  16. {{ addr.addr }}
  17. </view>
  18. <view class="settlement-address-desc__item">{{ addr.receiver }} {{ addr.mobile }}</view>
  19. </view>
  20. <view class="settlement-address-form" v-else>
  21. <view class="address-add">
  22. <u--form labelPosition="left" ref="form" labelWidth="90">
  23. <u-form-item label="收货人:" borderBottom required>
  24. <u--input v-model="form.receiver" border="none" placeholder="请输入收货人"></u--input>
  25. </u-form-item>
  26. <u-form-item label="手机号码:" borderBottom required>
  27. <u--input v-model="form.mobile" border="none" placeholder="请输入手机号码"></u--input>
  28. </u-form-item>
  29. <u-form-item label="所在地区:" borderBottom required @click="selectArea">
  30. <u--input v-model="form.cityShow" border="none" disabled disabledColor="#ffffff"
  31. placeholder="请选择地区">
  32. </u--input>
  33. <u-icon slot="right" name="arrow-right"></u-icon>
  34. </u-form-item>
  35. <u-form-item label="详细地址:" :borderBottom="false" required>
  36. <u--textarea v-model="form.addr" placeholder="请输入详细地址"></u--textarea>
  37. </u-form-item>
  38. </u--form>
  39. </view>
  40. <!-- 操作按钮 -->
  41. <view class="save-btn">
  42. <button :loading="loading" type="default" @click="saveAddress">保存并使用</button>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="settlement-goods">
  47. <view class="flex settlement-goods__detail" v-for="(item, index) in list" :key="index">
  48. <view class="settlement-goods__detail__left">
  49. <view class="img">
  50. <image class="img" :src="item.picUrl" mode="aspectFill">
  51. </image>
  52. </view>
  53. <view class="info">
  54. <text>{{ item.title }}</text>
  55. <text>面值:{{ $numberFormat(item.facePrice) }}元</text>
  56. <text>规格:{{ item.pkgUnit }}张/包 </text>
  57. </view>
  58. </view>
  59. <view class="settlement-goods__detail__right">
  60. <text>¥{{ $numberFormat(item.pkgSalePrice) }}</text>
  61. <text>x {{ item.orderNum }}</text>
  62. </view>
  63. </view>
  64. </view>
  65. <view class="flex settlement-freight">
  66. <text>运费</text>
  67. <text>¥{{ $numberFormat(info.freightAmt) }}</text>
  68. </view>
  69. </view>
  70. <view class="footer-fixed">
  71. <view class="flex btn">
  72. <view class="btn-left">共计 {{ info.pkgNum }} 包</view>
  73. <view class="btn-right">
  74. <view class="money">
  75. <text>共计:</text>
  76. <text>¥{{ $numberFormat(info.payAmt) }}</text>
  77. </view>
  78. <text class="save" @click="save">提交</text>
  79. </view>
  80. </view>
  81. </view>
  82. <u-picker ref="uPicker" :show="show" :columns="columns" @change="changeHandler" @confirm="confirm"
  83. @cancel="cancel" keyName="areaName"></u-picker>
  84. </view>
  85. </template>
  86. <script>
  87. import env from '../../config/env.js'
  88. import $http from '@/utils/request.js'
  89. export default {
  90. data() {
  91. return {
  92. ids: [],
  93. info: {},
  94. addr: {},
  95. list: [],
  96. loading: false,
  97. addrId: '',
  98. form: {
  99. receiver: '',
  100. mobile: '',
  101. name: '',
  102. cityShow: '',
  103. addr: '',
  104. provinceId: '', // 省ID/编码
  105. province: '', // 省
  106. cityId: '', // 市ID/编码
  107. city: '', // 市
  108. areaId: '', // 区ID/编码
  109. area: '', // 区
  110. },
  111. show: false,
  112. columns: [
  113. [],
  114. [],
  115. []
  116. ],
  117. toAddressShow: false,
  118. }
  119. },
  120. onLoad(opthios) {
  121. if (opthios.ids) {
  122. this.ids = JSON.parse(opthios.ids)
  123. this.getDetail()
  124. }
  125. if(opthios.boxId) {
  126. this.boxId = opthios.boxId
  127. this.getDetail()
  128. }
  129. },
  130. onShow() {
  131. if (this.toAddressShow) {
  132. this.getDetail()
  133. }
  134. },
  135. methods: {
  136. save() {
  137. $http.post('/api/v1/mp/channel/mall/order/submit', {
  138. memo: ""
  139. }).then(res => {
  140. if (res.code == 0) {
  141. uni.navigateTo({
  142. url:`/pages/order/index?back=1`
  143. })
  144. }
  145. if (res.code == 1016) {
  146. uni.showModal({
  147. title: '提示',
  148. content: '您还未通过经销商认证,请先提交认证。',
  149. success(res) {
  150. if (res.confirm) {
  151. uni.navigateTo({
  152. url: "/pages/attestation/index"
  153. })
  154. }
  155. }
  156. })
  157. }
  158. })
  159. },
  160. getDetail() {
  161. let data = this.ids.length ? {
  162. cartIds: this.ids
  163. } : {
  164. boxId: this.boxId,
  165. orderNum: 1
  166. }
  167. $http.post('/api/v1/mp/channel/mall/order/settle', data).then(res => {
  168. if (res.code == 0) {
  169. this.info = res.data
  170. this.addr = res.data.addr
  171. res.data.items.forEach(item => {
  172. let picUrlArr = item.picUrl.split(',')
  173. item.picUrl = env.filePublic + picUrlArr[0]
  174. })
  175. this.list = res.data.items
  176. }
  177. })
  178. },
  179. getAddrDetail() {
  180. $http.post('/api/v1/mp/channel/mall/addr/query', {
  181. addrId: this.addrId
  182. }).then(res => {
  183. if (res.code == 0) {
  184. let item = res.data
  185. this.form = {
  186. ...item,
  187. cityShow: `${ item.province }-${ item.city }-${ item.area }`
  188. }
  189. }
  190. })
  191. },
  192. async getArea() {
  193. const picker = this.$refs.uPicker
  194. let provinceRes = await $http.post('/api/v1/mp/area/listByPid', {
  195. pid: 0
  196. })
  197. let cityRes = await $http.post('/api/v1/mp/area/listByPid', {
  198. pid: provinceRes && provinceRes.data && provinceRes.data[0].areaId
  199. })
  200. let areaRes = await $http.post('/api/v1/mp/area/listByPid', {
  201. pid: cityRes && cityRes.data && cityRes.data[0].areaId
  202. })
  203. picker.setColumnValues(0, provinceRes.data)
  204. picker.setColumnValues(1, cityRes.data)
  205. picker.setColumnValues(2, areaRes.data)
  206. },
  207. selectArea() {
  208. this.getArea()
  209. this.show = true
  210. },
  211. async changeHandler(e) {
  212. const {
  213. columnIndex,
  214. index,
  215. value,
  216. // 微信小程序无法将picker实例传出来,只能通过ref操作
  217. picker = this.$refs.uPicker
  218. } = e
  219. if (columnIndex === 0) {
  220. let cityRes = await $http.post('/api/v1/mp/area/listByPid', {
  221. pid: value && value[0].areaId
  222. })
  223. let areaRes = await $http.post('/api/v1/mp/area/listByPid', {
  224. pid: cityRes && cityRes.data && cityRes.data[0].areaId
  225. })
  226. picker.setColumnValues(1, cityRes.data)
  227. picker.setColumnValues(2, areaRes.data)
  228. }
  229. if (columnIndex === 1) {
  230. let areaRes = await $http.post('/api/v1/mp/area/listByPid', {
  231. pid: value && value[1].areaId
  232. })
  233. picker.setColumnValues(2, areaRes.data)
  234. }
  235. },
  236. // 回调参数为包含columnIndex、value、values
  237. confirm(e) {
  238. const picker = this.$refs.uPicker
  239. const {
  240. value
  241. } = e
  242. this.form.province = value[0].areaName
  243. this.form.provinceId = value[0].areaId
  244. this.form.city = value[1].areaName
  245. this.form.cityId = value[1].areaId
  246. this.form.area = value[2].areaName
  247. this.form.areaId = value[2].areaId
  248. this.form.cityShow = value.map(item => item.areaName).join('-')
  249. this.show = false
  250. picker.setColumnValues(0, [])
  251. picker.setColumnValues(1, [])
  252. picker.setColumnValues(2, [])
  253. },
  254. cancel() {
  255. this.show = false
  256. },
  257. toAddress() {
  258. this.toAddressShow = true
  259. uni.navigateTo({
  260. url: "/pages/address/index"
  261. })
  262. },
  263. saveAddress() {
  264. // receiver: '',
  265. // mobile: '',
  266. // city: '',
  267. // addr: '',
  268. // privinceId: '', // 省ID/编码
  269. // privince: '', // 省
  270. // cityId: '', // 市ID/编码
  271. // city: '', // 市
  272. // areaId: '', // 区ID/编码
  273. // area: '', // 区
  274. let _this = this
  275. if (!_this.form.receiver) {
  276. uni.$u.toast('请输入收货人');
  277. return
  278. }
  279. if (!_this.form.mobile) {
  280. uni.$u.toast('请输入手机号码');
  281. return
  282. }
  283. const rule = /^[1][0-9][0-9]{9}$/
  284. if (!rule.test(_this.form.mobile)) {
  285. uni.$u.toast('请输入正确的手机号');
  286. return
  287. }
  288. if (!_this.form.cityShow) {
  289. uni.$u.toast('请选择所在地区');
  290. return
  291. }
  292. if (!_this.form.addr) {
  293. uni.$u.toast('请输入详细地址');
  294. return
  295. }
  296. let url = '/api/v1/mp/channel/mall/addr/create'
  297. $http.post(url, this.form).then(res => {
  298. if (res.code == 0) {
  299. uni.$u.toast('保存成功');
  300. this.getDetail()
  301. }
  302. })
  303. },
  304. },
  305. }
  306. </script>
  307. <style lang="scss" scoped>
  308. /deep/ .u-navbar__content__title.u-navbar__content__title {
  309. color: #FFFFFF;
  310. }
  311. </style>
  312. <style lang="scss" scoped>
  313. .settlement {
  314. margin: 10rpx;
  315. padding-bottom: 100rpx;
  316. &-address {
  317. background-color: #fff;
  318. padding: 0 16rpx 24rpx;
  319. margin-bottom: 20rpx;
  320. &-top {
  321. justify-content: space-between;
  322. padding: 24rpx 0;
  323. border-bottom: 1px solid rgba(236, 236, 236, 100);
  324. &__left {
  325. line-height: 40rpx;
  326. }
  327. &__right {
  328. line-height: 40rpx;
  329. color: rgba(35, 126, 212, 100);
  330. }
  331. }
  332. &-desc {
  333. &__item {
  334. line-height: 40rpx;
  335. margin-top: 16rpx;
  336. }
  337. }
  338. &-form {
  339. .save-btn {
  340. padding: 10rpx 20rpx;
  341. /deep/ button {
  342. line-height: 76rpx;
  343. font-size: 28rpx;
  344. height: 76rpx;
  345. color: #fff;
  346. background-color: $uni-bg-color;
  347. border: none;
  348. border-radius: 100rpx;
  349. }
  350. }
  351. }
  352. }
  353. &-goods {
  354. background-color: #fff;
  355. padding: 0 16rpx;
  356. margin-bottom: 20rpx;
  357. &__detail {
  358. padding: 20rpx 0;
  359. justify-content: space-between;
  360. border-bottom: 1px solid rgba(236, 236, 236, 100);
  361. &__left {
  362. display: flex;
  363. height: 170rpx;
  364. .img {
  365. image {
  366. width: 134rpx;
  367. height: 170rpx;
  368. margin-right: 20rpx;
  369. }
  370. }
  371. .info {
  372. display: flex;
  373. flex-direction: column;
  374. justify-content: space-between;
  375. text {
  376. font-size: 24rpx;
  377. color: #9D9D9D;
  378. }
  379. text:first-child {
  380. color: rgba(16, 16, 16, 100);
  381. font-size: 28rpx;
  382. }
  383. }
  384. }
  385. &__right {
  386. display: flex;
  387. height: 170rpx;
  388. flex-direction: column;
  389. justify-content: space-between;
  390. align-items: flex-end;
  391. text:first-child {
  392. font-size: 32rpx;
  393. color: $uni-text-color;
  394. }
  395. }
  396. }
  397. &__detail:last-child {
  398. border: none;
  399. }
  400. }
  401. &-freight {
  402. background-color: #fff;
  403. justify-content: space-between;
  404. padding: 20rpx 16rpx;
  405. }
  406. }
  407. .footer-fixed {
  408. position: fixed;
  409. bottom: var(--window-bottom);
  410. left: 0;
  411. right: 0;
  412. // min-height: 120rpx;
  413. z-index: 11;
  414. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  415. background: #fff;
  416. // margin-bottom: 40rpx;
  417. // 设置ios刘海屏底部横线安全区域
  418. padding-bottom: constant(safe-area-inset-bottom);
  419. padding-bottom: env(safe-area-inset-bottom);
  420. .btn {
  421. justify-content: space-between;
  422. padding: 10rpx 40rpx;
  423. &-right {
  424. display: flex;
  425. align-items: center;
  426. justify-content: flex-end;
  427. .value {
  428. color: $uni-text-color;
  429. }
  430. .save {
  431. width: 190rpx;
  432. height: 60rpx;
  433. line-height: 60rpx;
  434. border-radius: 8rpx;
  435. text-align: center;
  436. margin-left: 40rpx;
  437. background-color: rgba(236, 112, 9, 100);
  438. color: rgba(255, 255, 255, 100);
  439. }
  440. }
  441. }
  442. }
  443. </style>