index.taro.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <div class="nut-addresslist">
  3. <general-shell
  4. v-if="!longPressEdition && !swipeEdition"
  5. v-for="(item, index) of dataArray"
  6. :key="'general' + index"
  7. :item="item"
  8. @handleDelIcon="clickDelIcon"
  9. @handleEditIcon="clickEditIcon"
  10. @handleItemContent="clickContentItem"
  11. @handelSwipeDel="clickSwipeDel"
  12. >
  13. </general-shell>
  14. <long-press-shell
  15. v-if="longPressEdition && !swipeEdition"
  16. v-for="(item, index) of dataArray"
  17. :key="'longpress' + index"
  18. :item="item"
  19. @handleDelIcon="clickDelIcon"
  20. @handleEditIcon="clickEditIcon"
  21. @handleItemContent="clickContentItem"
  22. @handleCopy="clickLongCopy"
  23. @handleSet="clickLongSet"
  24. @handleDel="clickLongDel"
  25. >
  26. <template v-slot:contentInfo>
  27. <slot name="iteminfos"></slot>
  28. </template>
  29. <template v-slot:contentIcons>
  30. <slot name="itemicon"></slot>
  31. </template>
  32. <template v-slot:contentAddrs>
  33. <slot name="itemaddr"></slot>
  34. </template>
  35. <template v-slot:longpressAll>
  36. <slot name="longpressbtns"></slot>
  37. </template>
  38. </long-press-shell>
  39. <swipe-shell
  40. v-if="!longPressEdition && swipeEdition"
  41. v-for="(item, index) of dataArray"
  42. :key="'swipe' + index"
  43. :item="item"
  44. @handleDelIcon="clickDelIcon"
  45. @handleEditIcon="clickEditIcon"
  46. @handleItemContent="clickContentItem"
  47. @handelSwipeDel="clickSwipeDel"
  48. >
  49. <template v-slot:contentInfo>
  50. <slot name="iteminfos"></slot>
  51. </template>
  52. <template v-slot:contentIcons>
  53. <slot name="itemicon"></slot>
  54. </template>
  55. <template v-slot:contentAddrs>
  56. <slot name="itemaddr"></slot>
  57. </template>
  58. <template v-slot:swiperightbtn>
  59. <slot name="swiperight"></slot>
  60. </template>
  61. </swipe-shell>
  62. <div class="nut-addresslist__bottom" v-if="showBottomButton" @click="addAddress">
  63. <nut-button block type="danger">{{ translate('addAddress') }}</nut-button>
  64. </div>
  65. </div>
  66. </template>
  67. <script lang="ts">
  68. import { toRefs, reactive, onMounted, ref, watch } from 'vue';
  69. import { createComponent } from '@/packages/utils/create';
  70. const { componentName, create, translate } = createComponent('addresslist');
  71. import LongPressShell from './components/LongPressShell.vue';
  72. import SwipeShell from './components/SwipeShell.vue';
  73. import GeneralShell from './components/GeneralShell.vue';
  74. import { floatData } from '@/packages/utils/util';
  75. export default create({
  76. props: {
  77. data: {
  78. type: Array,
  79. default: []
  80. },
  81. longPressEdition: {
  82. type: Boolean,
  83. default: false
  84. },
  85. swipeEdition: {
  86. type: Boolean,
  87. default: false
  88. },
  89. showBottomButton: {
  90. type: Boolean,
  91. default: true
  92. },
  93. dataMapOptions: {
  94. type: Object,
  95. default: {}
  96. }
  97. },
  98. components: {
  99. LongPressShell,
  100. SwipeShell,
  101. GeneralShell
  102. },
  103. emits: [
  104. 'handelDelIcon',
  105. 'handelEditIcon',
  106. 'handelItem',
  107. 'longPressCopyClick',
  108. 'longPressSetClick',
  109. 'longPressDelClick',
  110. 'swipeDelClick',
  111. 'addAddressClick'
  112. ],
  113. setup(props, { emit }) {
  114. const dataArray = ref([]);
  115. const dataInfo = reactive({
  116. id: 2,
  117. addressName: '姓名',
  118. phone: '123****4567',
  119. defaultAddress: false,
  120. fullAddress: '北京市通州区测试测试测试测试测试测试测试测试测试'
  121. });
  122. //磨平参数差异
  123. const trowelData = () => {
  124. if (Object.keys(props.dataMapOptions).length > 0 && props.data.length > 0) {
  125. dataArray.value = props.data.map((item, index) => {
  126. return floatData(dataInfo, item, props.dataMapOptions);
  127. });
  128. }
  129. };
  130. // 监听props.data的变更重新渲染列表
  131. watch(
  132. () => props.data,
  133. () => trowelData(),
  134. { deep: true }
  135. );
  136. const clickDelIcon = (event, item) => {
  137. emit('handelDelIcon', event, item);
  138. event.stopPropagation();
  139. };
  140. const clickEditIcon = (event, item) => {
  141. emit('handelEditIcon', event, item);
  142. event.stopPropagation();
  143. };
  144. const clickContentItem = (event, item) => {
  145. emit('handelItem', event, item);
  146. event.stopPropagation();
  147. };
  148. const clickLongCopy = (event, item) => {
  149. emit('longPressCopyClick', event, item);
  150. event.stopPropagation();
  151. };
  152. const clickLongSet = (event, item) => {
  153. emit('longPressSetClick', event, item);
  154. event.stopPropagation();
  155. };
  156. const clickLongDel = (event, item) => {
  157. emit('longPressDelClick', event, item);
  158. event.stopPropagation();
  159. };
  160. const clickSwipeDel = (event, item) => {
  161. emit('swipeDelClick', event, item);
  162. event.stopPropagation();
  163. };
  164. const addAddress = (event) => {
  165. emit('addAddressClick', event);
  166. event.stopPropagation();
  167. };
  168. onMounted(() => {
  169. trowelData();
  170. });
  171. return {
  172. clickDelIcon,
  173. clickEditIcon,
  174. clickContentItem,
  175. clickLongCopy,
  176. clickLongSet,
  177. clickLongDel,
  178. clickSwipeDel,
  179. addAddress,
  180. dataArray,
  181. translate
  182. };
  183. }
  184. });
  185. </script>