addressSelection.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <!-- 下单界面,收货地址 or 自提门店的选择组件 -->
  2. <template>
  3. <view class="allAddress" :style="state.isPickUp ? '':'padding-top:10rpx;'">
  4. <view class="nav flex flex-wrap">
  5. <view class="item font-color" :class="state.deliveryType === 1 ? 'on' : 'on2'"
  6. @tap="switchDeliveryType(1)" v-if='state.isPickUp' />
  7. <view class="item font-color" :class="state.deliveryType === 2 ? 'on' : 'on2'"
  8. @tap="switchDeliveryType(2)" v-if='state.isPickUp' />
  9. </view>
  10. <!-- 情况一:收货地址的选择 -->
  11. <view class='address flex flex-wrap flex-center ss-row-between' @tap='onSelectAddress' v-if='state.deliveryType === 1'
  12. :style="state.isPickUp ? '':'border-top-left-radius: 14rpx;border-top-right-radius: 14rpx;'">
  13. <view class='addressCon' v-if="state.addressInfo.name">
  14. <view class='name'>{{ state.addressInfo.name }}
  15. <text class='phone'>{{ state.addressInfo.mobile }}</text>
  16. </view>
  17. <view class="flex flex-wrap">
  18. <text class='default font-color' v-if="state.addressInfo.defaultStatus">[默认]</text>
  19. <text class="line2">{{ state.addressInfo.areaName }} {{ state.addressInfo.detailAddress }}</text>
  20. </view>
  21. </view>
  22. <view class='addressCon' v-else>
  23. <view class='setaddress'>设置收货地址</view>
  24. </view>
  25. <view class='iconfont'>
  26. <view class="ss-rest-button">
  27. <text class="_icon-forward" />
  28. </view>
  29. </view>
  30. </view>
  31. <!-- 情况二:门店的选择 -->
  32. <view class='address flex flex-wrap flex-center ss-row-between' v-else @tap="onSelectAddress">
  33. <view class='addressCon' v-if="state.pickUpInfo.name">
  34. <view class='name'>{{ state.pickUpInfo.name }}
  35. <text class='phone'>{{ state.pickUpInfo.phone }}</text>
  36. </view>
  37. <view class="line1"> {{ state.pickUpInfo.areaName }}{{ ', ' + state.pickUpInfo.detailAddress }}
  38. </view>
  39. </view>
  40. <view class='addressCon' v-else>
  41. <view class='setaddress'>选择自提门店</view>
  42. </view>
  43. <view class='iconfont'>
  44. <view class="ss-rest-button">
  45. <text class="_icon-forward" />
  46. </view>
  47. </view>
  48. </view>
  49. <view class='line'>
  50. <image :src="sheep.$url.static('/static/images/line.png', 'local')" />
  51. </view>
  52. </view>
  53. </template>
  54. <script setup>
  55. import { computed } from 'vue';
  56. import sheep from '@/sheep';
  57. import { isEmpty } from 'lodash-es';
  58. const props = defineProps({
  59. modelValue: {
  60. type: Object,
  61. default() {},
  62. }
  63. });
  64. const emits = defineEmits(['update:modelValue']);
  65. // computed 解决父子组件双向数据同步
  66. const state = computed({
  67. get(){
  68. return new Proxy(props.modelValue, {
  69. set(obj, name, val) {
  70. emits('update:modelValue', {
  71. ...obj,
  72. [name]: val,
  73. });
  74. return true;
  75. }
  76. })
  77. },
  78. set(val){
  79. emits('update:modelValue', val);
  80. }
  81. })
  82. // 选择地址
  83. function onSelectAddress() {
  84. let emitName = 'SELECT_ADDRESS'
  85. let addressPage = '/pages/user/address/list?type=select';
  86. if (state.value.deliveryType === 2){
  87. emitName = 'SELECT_PICK_UP_INFO'
  88. addressPage = '/pages/user/goods_details_store/index'
  89. }
  90. uni.$once(emitName, (e) => {
  91. changeConsignee(e.addressInfo);
  92. });
  93. sheep.$router.go(addressPage);
  94. }
  95. // 更改收货人地址&计算订单信息
  96. async function changeConsignee(addressInfo = {}) {
  97. if (!isEmpty(addressInfo)) {
  98. if (state.value.deliveryType === 1){
  99. state.value.addressInfo = addressInfo;
  100. }
  101. if (state.value.deliveryType === 2){
  102. state.value.pickUpInfo = addressInfo;
  103. }
  104. }
  105. }
  106. // 收货方式切换
  107. const switchDeliveryType = (type) =>{
  108. state.value.deliveryType = type;
  109. }
  110. </script>
  111. <style scoped lang="scss">
  112. .allAddress .font-color{
  113. color: #E93323!important
  114. }
  115. .line2{
  116. width: 504rpx;
  117. }
  118. .textR {
  119. text-align: right;
  120. }
  121. .line {
  122. width: 100%;
  123. height: 3rpx;
  124. }
  125. .line image {
  126. width: 100%;
  127. height: 100%;
  128. display: block;
  129. }
  130. .address {
  131. padding: 28rpx;
  132. background-color: #fff;
  133. box-sizing: border-box;
  134. }
  135. .address .addressCon {
  136. width: 596rpx;
  137. font-size: 26rpx;
  138. color: #666;
  139. }
  140. .address .addressCon .name {
  141. font-size: 30rpx;
  142. color: #282828;
  143. font-weight: bold;
  144. margin-bottom: 10rpx;
  145. }
  146. .address .addressCon .name .phone {
  147. margin-left: 50rpx;
  148. }
  149. .address .addressCon .default {
  150. margin-right: 12rpx;
  151. }
  152. .address .addressCon .setaddress {
  153. color: #333;
  154. font-size: 28rpx;
  155. }
  156. .address .iconfont {
  157. font-size: 35rpx;
  158. color: #707070;
  159. }
  160. .allAddress {
  161. width: 100%;
  162. background: linear-gradient(to bottom, #e93323 0%, #f5f5f5 100%);
  163. // background-image: linear-gradient(to bottom, #e93323 0%, #f5f5f5 100%);
  164. // background-image: -webkit-linear-gradient(to bottom, #e93323 0%, #f5f5f5 100%);
  165. // background-image: -moz-linear-gradient(to bottom, #e93323 0%, #f5f5f5 100%);
  166. //padding: 100rpx 30rpx 0 30rpx;
  167. padding-top: 100rpx;
  168. padding-bottom: 10rpx;
  169. }
  170. .allAddress .nav {
  171. width: 690rpx;
  172. margin: 0 auto;
  173. }
  174. .allAddress .nav .item {
  175. width: 334rpx;
  176. }
  177. .allAddress .nav .item.on {
  178. position: relative;
  179. width: 230rpx;
  180. }
  181. .allAddress .nav .item.on::before {
  182. position: absolute;
  183. bottom: 0;
  184. content: "快递配送";
  185. font-size: 28rpx;
  186. display: block;
  187. height: 0;
  188. width: 336rpx;
  189. border-width: 0 20rpx 80rpx 0;
  190. border-style: none solid solid;
  191. border-color: transparent transparent #fff;
  192. z-index: 2;
  193. border-radius: 14rpx 36rpx 0 0;
  194. text-align: center;
  195. line-height: 80rpx;
  196. }
  197. .allAddress .nav .item:nth-of-type(2).on::before {
  198. content: "到店自提";
  199. border-width: 0 0 80rpx 20rpx;
  200. border-radius: 36rpx 14rpx 0 0;
  201. }
  202. .allAddress .nav .item.on2 {
  203. position: relative;
  204. }
  205. .allAddress .nav .item.on2::before {
  206. position: absolute;
  207. bottom: 0;
  208. content: "到店自提";
  209. font-size: 28rpx;
  210. display: block;
  211. height: 0;
  212. width: 401rpx;
  213. border-width: 0 0 60rpx 60rpx;
  214. border-style: none solid solid;
  215. border-color: transparent transparent #f7c1bd;
  216. border-radius: 36rpx 14rpx 0 0;
  217. text-align: center;
  218. line-height: 60rpx;
  219. }
  220. .allAddress .nav .item:nth-of-type(1).on2::before {
  221. content: "快递配送";
  222. border-width: 0 60rpx 60rpx 0;
  223. border-radius: 14rpx 36rpx 0 0;
  224. }
  225. .allAddress .address {
  226. width: 690rpx;
  227. max-height: 180rpx;
  228. margin: 0 auto;
  229. }
  230. .allAddress .line {
  231. width: 100%;
  232. margin: 0 auto;
  233. }
  234. </style>