PassengerList.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <view class="boxs">
  3. <!-- 外层容器 -->
  4. <view class="flex align-center padding-tb-sm" v-for="(item, index) in selectdata" :key="index">
  5. <!-- 显示头像 -->
  6. <view>
  7. <image v-if="globalImages" :src="globalImages + 'images/order/chengcheren.png'" style="width: 80rpx;height: 80rpx;" mode=""></image>
  8. </view>
  9. <!-- 显示姓名和关系、电话 -->
  10. <view style="margin-left: 30rpx; line-height: 40rpx;">
  11. <view>{{ item.name }}</view>
  12. <view style="color: #999;">{{ item.idCard }}</view>
  13. </view>
  14. <!-- 编辑图标 -->
  15. <view style="position: absolute; right: 130rpx;" @tap="handleEdit(item)">
  16. <image v-if="globalImages" :src="globalImages + 'images/order/xiugai.png'" style="width: 36rpx;height: 36rpx;" mode="">
  17. </image>
  18. </view>
  19. <!-- 删除图标 -->
  20. <view style="position: absolute; right: 60rpx;" @tap="handleDelete(item.id, index)">
  21. <image v-if="globalImages" :src="globalImages + 'images/order/shanchu.png'" style="width: 36rpx;height: 36rpx;" mode="">
  22. </image>
  23. </view>
  24. </view>
  25. <!-- 底部操作栏 -->
  26. <view class="footer">
  27. <button class="submit-btn" @click="goNav('/my/classes/adddetailsList?type=add')">+ 新增乘车人</button>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import { waitForGlobalImages } from '@/utils/globalImageLoader'
  33. export default {
  34. data() {
  35. return {
  36. selectdata: [],
  37. globalImages: ''
  38. }
  39. },
  40. onLoad(options) {
  41. waitForGlobalImages().then((path) => {
  42. console.log('✅ 全局图片路径:', path)
  43. this.globalImages = path
  44. })
  45. this.fetchPassengerList(); // 初始化加载一次
  46. uni.$on('refreshPassengerList', () => {
  47. this.fetchPassengerList(); // 被添加页通知时刷新
  48. });
  49. },
  50. onUnload() {
  51. uni.$off('refreshPassengerList'); // 销毁监听,避免重复绑定
  52. },
  53. methods: {
  54. fetchPassengerList() {
  55. this.$Request.getT('/app/passenger/selectList').then(res => {
  56. if (res.code === 0) {
  57. this.selectdata = res.data;
  58. }
  59. });
  60. },
  61. handleEdit(contact) {
  62. const token = this.$queue.getData("token");
  63. if (token) {
  64. uni.navigateTo({
  65. url: `/my/classes/adddetailsList?type=edit&data=${encodeURIComponent(JSON.stringify(contact))}`
  66. });
  67. }
  68. },
  69. handleDelete(ids, index) {
  70. uni.showModal({
  71. title: '确认删除',
  72. content: '是否删除该乘车人?',
  73. success: (res) => {
  74. if (res.confirm) {
  75. let data = {
  76. id: ids
  77. }
  78. this.$Request.postT('/app/passenger/delete', data)
  79. .then(res => {
  80. if (res.code === 0) {
  81. uni.showToast({ title: '删除成功', icon: 'success' });
  82. this.fetchPassengerList()
  83. } else {
  84. uni.showToast({ title: res.msg || '删除失败', icon: 'none' });
  85. }
  86. })
  87. .catch(err => {
  88. console.error('删除失败:', err);
  89. uni.showToast({ title: '网络错误', icon: 'none' });
  90. });
  91. }
  92. }
  93. });
  94. },
  95. goNav(url) {
  96. // #ifdef MP-WEIXIN
  97. if (uni.getStorageSync('sendorderMsg')) {
  98. uni.requestSubscribeMessage({
  99. tmplIds: this.arr,
  100. success(re) {
  101. // console.log(re,'**********')
  102. var datas = JSON.stringify(re);
  103. if (datas.indexOf("accept") != -1) {
  104. console.log(re)
  105. }
  106. },
  107. fail: (res) => {
  108. console.log(res)
  109. }
  110. })
  111. }
  112. // #endif
  113. let token = this.$queue.getData("token");
  114. if (token) {
  115. uni.navigateTo({
  116. url: url
  117. })
  118. } else {
  119. this.bindlogin();
  120. }
  121. }
  122. }
  123. }
  124. </script>
  125. <style scoped>
  126. .boxs {
  127. background: #FFFFFF;
  128. border-radius: 24rpx;
  129. margin: 30rpx;
  130. padding: 30rpx;
  131. }
  132. .footer {
  133. position: fixed;
  134. bottom: 0;
  135. left: 0;
  136. right: 0;
  137. background: #fff;
  138. padding: 20rpx 30rpx;
  139. box-shadow: 0 -4rpx 10rpx rgba(0, 0, 0, 0.05);
  140. }
  141. .submit-btn {
  142. background: #fe6b01;
  143. color: #fff;
  144. border-radius: 50rpx;
  145. font-size: 32rpx;
  146. height: 80rpx;
  147. line-height: 80rpx;
  148. }
  149. </style>