addressSelection.vue 6.8 KB

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