addressSelection.vue 6.8 KB

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