index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <view class="container">
  3. <uni-card class="addUser">
  4. <uni-list :border="false">
  5. <uni-list-item :showExtraIcon="true" :extra-icon="extraIcon" title="添加成员" clickable @click="onClick"></uni-list-item>
  6. </uni-list>
  7. </uni-card>
  8. <uni-list :border="true">
  9. <view :id="item && item.residentId" class="delBox" @touchstart="touchStart" @touchend="touchEnd" v-for="(item, index) in list" :key="index" >
  10. <uni-list-chat :class="{ left: isId == item.residentId }" class="item" :avatar="item.avatar || '/static/user1.png'" :title="item.name" :note="item.phone" badge-positon="left">
  11. <view class="chat-custom-right">
  12. <text class="chat-custom-text">{{ item && item.status == 0 ? '未检' : '已检' }}</text>
  13. <!-- 需要使用 uni-icons 请自行引入 -->
  14. <!-- <uni-icons type="upload" color="#999" size="18"></uni-icons> -->
  15. <button type="primary" size="mini" :disabled="item && item.status == 1" @click="filing(item)">报备</button>
  16. </view>
  17. </uni-list-chat>
  18. <uni-icons @click="userbtn(item)" color="#fff" class="del compose" type="compose" size="28"></uni-icons>
  19. <uni-icons :class="{ left: isId !== item.residentId }" @click="delbtn(item)" color="#fff" class="del" type="trash-filled" size="28"></uni-icons>
  20. </view>
  21. </uni-list>
  22. </view>
  23. </template>
  24. <script>
  25. import requestFamily from '../../api/family.js';
  26. export default {
  27. data() {
  28. return {
  29. isId: '',
  30. startX: 0,
  31. extraIcon: {
  32. color: '#ff8319',
  33. size: '20',
  34. type: 'plusempty'
  35. },
  36. list: [],
  37. natTaskId: '',
  38. }
  39. },
  40. async mounted() {
  41. const task = await requestFamily.runningTask();
  42. if (task.code == 200) {
  43. this.natTaskId = task.data[0].natTaskId;
  44. this.query();
  45. }
  46. },
  47. onShow() {
  48. this.isId = '';
  49. },
  50. methods: {
  51. async query() {
  52. const { userId } = uni.getStorageSync('userinfo');
  53. const familyInfo = await requestFamily.getFamilyInfo({ userId });
  54. if (familyInfo.code == 200) {
  55. const membersStatus = await requestFamily.membersStatus({ userId, natTaskId: this.natTaskId });
  56. familyInfo.rows = familyInfo.rows.map(e => {
  57. const resident = membersStatus.data.find(j => j.residentId == e.residentId);
  58. return { ...e, status: resident?.status || 0 };
  59. })
  60. this.list = familyInfo.rows;
  61. }
  62. },
  63. // 滑动开始
  64. touchStart(e) {
  65. if (e.touches.length == 1) {
  66. //设置触摸起始点水平方向位置
  67. this.startX=e.touches[0].clientX;
  68. }
  69. },
  70. // 滑动结束
  71. touchEnd(e) {
  72. if (e.changedTouches.length == 1) {
  73. //手指移动结束后水平位置
  74. var endX = e.changedTouches[0].clientX;
  75. let diff = endX - this.startX;
  76. if(Math.abs(diff) > 20){
  77. if(diff < 0) {
  78. this.isId = e.currentTarget.id;
  79. }else{
  80. this.isId = '';
  81. }
  82. }
  83. }
  84. },
  85. // 报备
  86. async filing(e) {
  87. const res = await requestFamily.filing({ residentId: e.residentId, natTaskId: this.natTaskId });
  88. if (res.code == 200) {
  89. this.query();
  90. uni.showToast({
  91. title: '报备成功',
  92. duration: 2000,
  93. });
  94. }
  95. },
  96. // 删除
  97. async delbtn(e) {
  98. const res = await requestFamily.familyInfo({ ...e, reqType: '2' });
  99. if (res.code == 200) {
  100. this.isId = '';
  101. uni.showToast({
  102. title: '已提交审核',
  103. duration: 2000,
  104. });
  105. }
  106. },
  107. onClick() {
  108. uni.navigateTo({
  109. url: '/pages/user/familyInfo'
  110. })
  111. },
  112. userbtn(e) {
  113. console.log(e);
  114. uni.navigateTo({
  115. url: `/pages/user/familyInfo?residentId=${e.residentId}`
  116. })
  117. }
  118. }
  119. }
  120. </script>
  121. <style>
  122. .container {
  123. width: 100%;
  124. }
  125. .addUser {
  126. display: block;
  127. /* width: 90%; */
  128. margin: 5px auto;
  129. }
  130. .chat-custom-text {
  131. font-size: 12px;
  132. color: #999;
  133. width: 100%;
  134. text-align: center;
  135. display: block;
  136. }
  137. .addUser .uni-list-item__container {
  138. flex: none;
  139. margin: 0 auto;
  140. }
  141. .addUser .uni-list-item__content-title {
  142. color: #ff8319;
  143. }
  144. .delBox {
  145. display: flex;
  146. width: 100%;
  147. overflow: hidden;
  148. }
  149. .item {
  150. width: 100%;
  151. }
  152. .del {
  153. display: block;
  154. width: 50px;
  155. background: red;
  156. }
  157. .right {
  158. margin-right: -100px;
  159. }
  160. .uni-icons {
  161. display: block;
  162. width: 100%;
  163. text-align: center;
  164. line-height: 2.3em;
  165. }
  166. .left {
  167. margin-left: -100px;
  168. }
  169. .compose {
  170. background: #1aad19;
  171. }
  172. </style>