addres.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { Cell, Icon, Tag } from 'vant';
  2. import { defineComponent, computed, PropType, reactive, onMounted } from 'vue';
  3. import styles from './address.module.less';
  4. import iconAddress from '@common/images/icon-address.png';
  5. import { useRouter } from 'vue-router';
  6. export default defineComponent({
  7. name: 'cart-address',
  8. props: {
  9. item: {
  10. type: Object as PropType<any>,
  11. default: () => ({})
  12. },
  13. isLink: {
  14. type: Boolean,
  15. default: true
  16. },
  17. setAddress: {
  18. type: Function,
  19. default: (n: any) => {}
  20. }
  21. },
  22. setup(props) {
  23. const router = useRouter();
  24. const addressInfo = computed(() => {
  25. return [
  26. props.item.provinceName,
  27. props.item.cityName,
  28. props.item.regionName,
  29. props.item.detailAddress
  30. ].join('');
  31. });
  32. const selectAddress = () => {
  33. if (!props.isLink) return;
  34. router.push('/shopAddress');
  35. };
  36. return () => (
  37. <>
  38. {props.item && props.item.phoneNumber ? (
  39. <Cell
  40. class={styles.cell}
  41. is-link={props.isLink}
  42. onClick={() => selectAddress()}
  43. titleStyle={{ marginLeft: '0' }}
  44. v-slots={{
  45. title: () => (
  46. <div>
  47. <span class={styles.userName}>{props.item.name}</span>
  48. <span class={styles.phone}>
  49. {props.item &&
  50. props.item.phoneNumber &&
  51. props.item.phoneNumber.replace(
  52. /^(\d{3})\d{4}(\d+)/,
  53. '$1****$2'
  54. )}
  55. </span>
  56. {props.item.defaultStatus && (
  57. <Tag
  58. type="primary"
  59. color="linear-gradient(90deg, #FF8633 0%, #FFB047 100%)"
  60. round
  61. style={{
  62. 'vertical-align': 'text-top',
  63. marginLeft: '10px',
  64. padding: '1px 8px'
  65. }}>
  66. 默认
  67. </Tag>
  68. )}
  69. </div>
  70. ),
  71. label: () => (
  72. <span class={styles.addressInfo}>{addressInfo.value}</span>
  73. )
  74. }}></Cell>
  75. ) : (
  76. <Cell
  77. class={styles.cell}
  78. is-link={props.isLink}
  79. onClick={() => selectAddress()}
  80. v-slots={{
  81. icon: () => <Icon name={iconAddress} size={28} />,
  82. title: () => <div class={styles.emtry}>去填写收货地址</div>
  83. }}></Cell>
  84. )}
  85. </>
  86. );
  87. }
  88. });