settlement.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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. console.log(res);
  141. if (res.code == 0) {
  142. uni.navigateTo({
  143. url:`/pages/order/index?back=1`
  144. })
  145. // $http.post('/api/v1/mp/channel/mall/order/pay', {
  146. // orderId: res.msg,
  147. // payType: 2
  148. // }).then(res => {
  149. // console.log(res);
  150. // }).catch(err => {
  151. // console.log(err);
  152. // })
  153. }
  154. if (res.code == 1016) {
  155. uni.showModal({
  156. title: '提示',
  157. content: '您还未通过经销商认证,请先提交认证。',
  158. success(res) {
  159. if (res.confirm) {
  160. uni.navigateTo({
  161. url: "/pages/attestation/index"
  162. })
  163. }
  164. }
  165. })
  166. }
  167. })
  168. },
  169. getDetail() {
  170. let data = this.ids.length ? {
  171. cartIds: this.ids
  172. } : {
  173. boxId: this.boxId,
  174. orderNum: 1
  175. }
  176. $http.post('/api/v1/mp/channel/mall/order/settle', data).then(res => {
  177. console.log(res);
  178. if (res.code == 0) {
  179. this.info = res.data
  180. this.addr = res.data.addr
  181. res.data.items.forEach(item => {
  182. let picUrlArr = item.picUrl.split(',')
  183. item.picUrl = env.filePublic + picUrlArr[0]
  184. })
  185. this.list = res.data.items
  186. }
  187. console.log(this.info);
  188. })
  189. },
  190. getAddrDetail() {
  191. $http.post('/api/v1/mp/channel/mall/addr/query', {
  192. addrId: this.addrId
  193. }).then(res => {
  194. console.log(res);
  195. if (res.code == 0) {
  196. let item = res.data
  197. this.form = {
  198. ...item,
  199. cityShow: `${ item.province }-${ item.city }-${ item.area }`
  200. }
  201. }
  202. })
  203. },
  204. async getArea() {
  205. const picker = this.$refs.uPicker
  206. let provinceRes = await $http.post('/api/v1/mp/area/listByPid', {
  207. pid: 0
  208. })
  209. console.log(`省`, provinceRes);
  210. let cityRes = await $http.post('/api/v1/mp/area/listByPid', {
  211. pid: provinceRes && provinceRes.data && provinceRes.data[0].areaId
  212. })
  213. console.log(`市`, cityRes);
  214. let areaRes = await $http.post('/api/v1/mp/area/listByPid', {
  215. pid: cityRes && cityRes.data && cityRes.data[0].areaId
  216. })
  217. console.log(`区`, areaRes);
  218. picker.setColumnValues(0, provinceRes.data)
  219. picker.setColumnValues(1, cityRes.data)
  220. picker.setColumnValues(2, areaRes.data)
  221. },
  222. selectArea() {
  223. console.log(this.$refs.uPicker);
  224. this.getArea()
  225. this.show = true
  226. },
  227. async changeHandler(e) {
  228. const {
  229. columnIndex,
  230. index,
  231. value,
  232. // 微信小程序无法将picker实例传出来,只能通过ref操作
  233. picker = this.$refs.uPicker
  234. } = e
  235. console.log(columnIndex, value);
  236. if (columnIndex === 0) {
  237. let cityRes = await $http.post('/api/v1/mp/area/listByPid', {
  238. pid: value && value[0].areaId
  239. })
  240. console.log(`市`, cityRes);
  241. let areaRes = await $http.post('/api/v1/mp/area/listByPid', {
  242. pid: cityRes && cityRes.data && cityRes.data[0].areaId
  243. })
  244. console.log(`区`, areaRes);
  245. picker.setColumnValues(1, cityRes.data)
  246. picker.setColumnValues(2, areaRes.data)
  247. }
  248. if (columnIndex === 1) {
  249. let areaRes = await $http.post('/api/v1/mp/area/listByPid', {
  250. pid: value && value[1].areaId
  251. })
  252. console.log(`区`, areaRes);
  253. picker.setColumnValues(2, areaRes.data)
  254. }
  255. },
  256. // 回调参数为包含columnIndex、value、values
  257. confirm(e) {
  258. const picker = this.$refs.uPicker
  259. const {
  260. value
  261. } = e
  262. this.form.province = value[0].areaName
  263. this.form.provinceId = value[0].areaId
  264. this.form.city = value[1].areaName
  265. this.form.cityId = value[1].areaId
  266. this.form.area = value[2].areaName
  267. this.form.areaId = value[2].areaId
  268. this.form.cityShow = value.map(item => item.areaName).join('-')
  269. this.show = false
  270. picker.setColumnValues(0, [])
  271. picker.setColumnValues(1, [])
  272. picker.setColumnValues(2, [])
  273. },
  274. cancel() {
  275. this.show = false
  276. },
  277. toAddress() {
  278. this.toAddressShow = true
  279. uni.navigateTo({
  280. url: "/pages/address/index"
  281. })
  282. },
  283. saveAddress() {
  284. // receiver: '',
  285. // mobile: '',
  286. // city: '',
  287. // addr: '',
  288. // privinceId: '', // 省ID/编码
  289. // privince: '', // 省
  290. // cityId: '', // 市ID/编码
  291. // city: '', // 市
  292. // areaId: '', // 区ID/编码
  293. // area: '', // 区
  294. let _this = this
  295. if (!_this.form.receiver) {
  296. uni.$u.toast('请输入收货人');
  297. return
  298. }
  299. if (!_this.form.mobile) {
  300. uni.$u.toast('请输入手机号码');
  301. return
  302. }
  303. const rule = /^[1][0-9][0-9]{9}$/
  304. if (!rule.test(_this.form.mobile)) {
  305. uni.$u.toast('请输入正确的手机号');
  306. return
  307. }
  308. if (!_this.form.cityShow) {
  309. uni.$u.toast('请选择所在地区');
  310. return
  311. }
  312. if (!_this.form.addr) {
  313. uni.$u.toast('请输入详细地址');
  314. return
  315. }
  316. let url = '/api/v1/mp/channel/mall/addr/create'
  317. $http.post(url, this.form).then(res => {
  318. console.log(res);
  319. if (res.code == 0) {
  320. uni.$u.toast('保存成功');
  321. this.getDetail()
  322. }
  323. })
  324. },
  325. },
  326. }
  327. </script>
  328. <style lang="scss" scoped>
  329. /deep/ .u-navbar__content__title.u-navbar__content__title {
  330. color: #FFFFFF;
  331. }
  332. </style>
  333. <style lang="scss" scoped>
  334. .settlement {
  335. margin: 10rpx;
  336. padding-bottom: 100rpx;
  337. &-address {
  338. background-color: #fff;
  339. padding: 0 16rpx 24rpx;
  340. margin-bottom: 20rpx;
  341. &-top {
  342. justify-content: space-between;
  343. padding: 24rpx 0;
  344. border-bottom: 1px solid rgba(236, 236, 236, 100);
  345. &__left {
  346. line-height: 40rpx;
  347. }
  348. &__right {
  349. line-height: 40rpx;
  350. color: rgba(35, 126, 212, 100);
  351. }
  352. }
  353. &-desc {
  354. &__item {
  355. line-height: 40rpx;
  356. margin-top: 16rpx;
  357. }
  358. }
  359. &-form {
  360. .save-btn {
  361. padding: 10rpx 20rpx;
  362. /deep/ button {
  363. line-height: 76rpx;
  364. font-size: 28rpx;
  365. height: 76rpx;
  366. color: #fff;
  367. background-color: $uni-bg-color;
  368. border: none;
  369. border-radius: 100rpx;
  370. }
  371. }
  372. }
  373. }
  374. &-goods {
  375. background-color: #fff;
  376. padding: 0 16rpx;
  377. margin-bottom: 20rpx;
  378. &__detail {
  379. padding: 20rpx 0;
  380. justify-content: space-between;
  381. border-bottom: 1px solid rgba(236, 236, 236, 100);
  382. &__left {
  383. display: flex;
  384. height: 170rpx;
  385. .img {
  386. image {
  387. width: 134rpx;
  388. height: 170rpx;
  389. margin-right: 20rpx;
  390. }
  391. }
  392. .info {
  393. display: flex;
  394. flex-direction: column;
  395. justify-content: space-between;
  396. text {
  397. font-size: 24rpx;
  398. color: #9D9D9D;
  399. }
  400. text:first-child {
  401. color: rgba(16, 16, 16, 100);
  402. font-size: 28rpx;
  403. }
  404. }
  405. }
  406. &__right {
  407. display: flex;
  408. height: 170rpx;
  409. flex-direction: column;
  410. justify-content: space-between;
  411. align-items: flex-end;
  412. text:first-child {
  413. font-size: 32rpx;
  414. color: $uni-text-color;
  415. }
  416. }
  417. }
  418. &__detail:last-child {
  419. border: none;
  420. }
  421. }
  422. &-freight {
  423. background-color: #fff;
  424. justify-content: space-between;
  425. padding: 20rpx 16rpx;
  426. }
  427. }
  428. .footer-fixed {
  429. position: fixed;
  430. bottom: var(--window-bottom);
  431. left: 0;
  432. right: 0;
  433. // min-height: 120rpx;
  434. z-index: 11;
  435. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  436. background: #fff;
  437. // margin-bottom: 40rpx;
  438. // 设置ios刘海屏底部横线安全区域
  439. padding-bottom: constant(safe-area-inset-bottom);
  440. padding-bottom: env(safe-area-inset-bottom);
  441. .btn {
  442. justify-content: space-between;
  443. padding: 10rpx 40rpx;
  444. &-right {
  445. display: flex;
  446. align-items: center;
  447. justify-content: flex-end;
  448. .value {
  449. color: $uni-text-color;
  450. }
  451. .save {
  452. width: 190rpx;
  453. height: 60rpx;
  454. line-height: 60rpx;
  455. border-radius: 8rpx;
  456. text-align: center;
  457. margin-left: 40rpx;
  458. background-color: rgba(236, 112, 9, 100);
  459. color: rgba(255, 255, 255, 100);
  460. }
  461. }
  462. }
  463. }
  464. </style>