addressSelection.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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','change']);
  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. emits('change')
  105. }
  106. }
  107. // 收货方式切换
  108. const switchDeliveryType = (type) =>{
  109. state.value.deliveryType = type;
  110. emits('change')
  111. }
  112. </script>
  113. <style scoped lang="scss">
  114. .allAddress .font-color{
  115. color: #E93323!important
  116. }
  117. .line2{
  118. width: 504rpx;
  119. }
  120. .textR {
  121. text-align: right;
  122. }
  123. .line {
  124. width: 100%;
  125. height: 3rpx;
  126. }
  127. .line image {
  128. width: 100%;
  129. height: 100%;
  130. display: block;
  131. }
  132. .address {
  133. padding: 28rpx;
  134. background-color: #fff;
  135. box-sizing: border-box;
  136. }
  137. .address .addressCon {
  138. width: 596rpx;
  139. font-size: 26rpx;
  140. color: #666;
  141. }
  142. .address .addressCon .name {
  143. font-size: 30rpx;
  144. color: #282828;
  145. font-weight: bold;
  146. margin-bottom: 10rpx;
  147. }
  148. .address .addressCon .name .phone {
  149. margin-left: 50rpx;
  150. }
  151. .address .addressCon .default {
  152. margin-right: 12rpx;
  153. }
  154. .address .addressCon .setaddress {
  155. color: #333;
  156. font-size: 28rpx;
  157. }
  158. .address .iconfont {
  159. font-size: 35rpx;
  160. color: #707070;
  161. }
  162. .allAddress {
  163. width: 100%;
  164. background: linear-gradient(to bottom, #e93323 0%, #f5f5f5 100%);
  165. // background-image: linear-gradient(to bottom, #e93323 0%, #f5f5f5 100%);
  166. // background-image: -webkit-linear-gradient(to bottom, #e93323 0%, #f5f5f5 100%);
  167. // background-image: -moz-linear-gradient(to bottom, #e93323 0%, #f5f5f5 100%);
  168. //padding: 100rpx 30rpx 0 30rpx;
  169. padding-top: 100rpx;
  170. padding-bottom: 10rpx;
  171. }
  172. .allAddress .nav {
  173. width: 690rpx;
  174. margin: 0 auto;
  175. }
  176. .allAddress .nav .item {
  177. width: 334rpx;
  178. }
  179. .allAddress .nav .item.on {
  180. position: relative;
  181. width: 230rpx;
  182. }
  183. .allAddress .nav .item.on::before {
  184. position: absolute;
  185. bottom: 0;
  186. content: "快递配送";
  187. font-size: 28rpx;
  188. display: block;
  189. height: 0;
  190. width: 336rpx;
  191. border-width: 0 20rpx 80rpx 0;
  192. border-style: none solid solid;
  193. border-color: transparent transparent #fff;
  194. z-index: 2;
  195. border-radius: 14rpx 36rpx 0 0;
  196. text-align: center;
  197. line-height: 80rpx;
  198. }
  199. .allAddress .nav .item:nth-of-type(2).on::before {
  200. content: "到店自提";
  201. border-width: 0 0 80rpx 20rpx;
  202. border-radius: 36rpx 14rpx 0 0;
  203. }
  204. .allAddress .nav .item.on2 {
  205. position: relative;
  206. }
  207. .allAddress .nav .item.on2::before {
  208. position: absolute;
  209. bottom: 0;
  210. content: "到店自提";
  211. font-size: 28rpx;
  212. display: block;
  213. height: 0;
  214. width: 401rpx;
  215. border-width: 0 0 60rpx 60rpx;
  216. border-style: none solid solid;
  217. border-color: transparent transparent #f7c1bd;
  218. border-radius: 36rpx 14rpx 0 0;
  219. text-align: center;
  220. line-height: 60rpx;
  221. }
  222. .allAddress .nav .item:nth-of-type(1).on2::before {
  223. content: "快递配送";
  224. border-width: 0 60rpx 60rpx 0;
  225. border-radius: 14rpx 36rpx 0 0;
  226. }
  227. .allAddress .address {
  228. width: 690rpx;
  229. max-height: 180rpx;
  230. margin: 0 auto;
  231. }
  232. .allAddress .line {
  233. width: 100%;
  234. margin: 0 auto;
  235. }
  236. </style>