snapshotSelectDialog.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <u-popup
  3. :show="visible"
  4. mode="bottom"
  5. :round="10"
  6. :closeOnClickOverlay="false"
  7. @close="handleClose"
  8. class="snapshot-select-popup"
  9. >
  10. <view class="popup-content">
  11. <!-- 头部 -->
  12. <view class="popup-header">
  13. <text class="popup-title">选择随手拍</text>
  14. <view class="close-btn" @click="handleClose">×</view>
  15. </view>
  16. <!-- 列表 -->
  17. <scroll-view class="popup-body" scroll-y @scrolltolower="loadMore">
  18. <view
  19. v-for="(item, index) in listData"
  20. :key="item.id"
  21. class="card-wrapper"
  22. >
  23. <myCard
  24. :item="item"
  25. :index="index + 1"
  26. :columns="cardColumns"
  27. :title="item.description"
  28. :showRadio="true"
  29. :radioValue="selectedId"
  30. @radioChange="onRadioChange"
  31. :showDetail="false"
  32. />
  33. </view>
  34. <view style="height: 20rpx"></view>
  35. <view v-if="loading" class="load-more">加载中...</view>
  36. <view v-if="isEnd && listData.length > 0" class="load-more"
  37. >没有更多了</view
  38. >
  39. <u-empty
  40. class="no-data"
  41. v-if="!loading && listData.length === 0"
  42. text="暂无待处理的随手拍"
  43. />
  44. </scroll-view>
  45. <!-- 底部 -->
  46. <view class="popup-footer">
  47. <view class="footer-left">
  48. <text class="selected-info" v-if="selectedRow">
  49. 已选:{{ selectedRow.description }}
  50. </text>
  51. <text class="selected-info" v-else>请选择一条记录</text>
  52. </view>
  53. <view class="footer-right">
  54. <u-button type="default" size="small" @click="handleClose"
  55. >取消</u-button
  56. >
  57. <u-button
  58. type="primary"
  59. size="small"
  60. :disabled="!selectedRow"
  61. @click="handleConfirm"
  62. >确定</u-button
  63. >
  64. </view>
  65. </view>
  66. </view>
  67. <u-toast ref="uToast" />
  68. </u-popup>
  69. </template>
  70. <script>
  71. import myCard from "@/components/myCard.vue";
  72. import { getList } from "@/api/snapshot/index.js";
  73. export default {
  74. components: { myCard },
  75. data() {
  76. return {
  77. visible: false,
  78. // 列表数据
  79. listData: [],
  80. page: 1,
  81. size: 10,
  82. isEnd: false,
  83. loading: false,
  84. // 选中
  85. selectedRow: null,
  86. selectedId: null,
  87. // 卡片列配置
  88. cardColumns: [
  89. [{ prop: "location", label: "问题位置", className: "perce100" }],
  90. [{ prop: "problemDeptName", label: "所属部门", className: "perce100" }],
  91. [
  92. { prop: "reporterName", label: "上报人", className: "perce50" },
  93. { prop: "createTime", label: "上报时间", className: "perce50" },
  94. ],
  95. ],
  96. };
  97. },
  98. methods: {
  99. // ============ 外部调用 ============
  100. open() {
  101. this.visible = true;
  102. this.resetState();
  103. this.loadData();
  104. },
  105. resetState() {
  106. this.listData = [];
  107. this.page = 1;
  108. this.isEnd = false;
  109. this.loading = false;
  110. this.selectedRow = null;
  111. this.selectedId = null;
  112. },
  113. // ============ 数据加载 ============
  114. async loadData() {
  115. if (this.loading || this.isEnd) return;
  116. this.loading = true;
  117. try {
  118. const res = await getList({
  119. pageNum: this.page,
  120. size: this.size,
  121. handleResult: 0, // 只查待处理的
  122. });
  123. const list = res.list || [];
  124. if (this.page === 1) {
  125. this.listData = list;
  126. } else {
  127. this.listData = this.listData.concat(list);
  128. }
  129. this.isEnd =
  130. list.length < this.size || this.listData.length >= res.count;
  131. this.page += 1;
  132. } catch (e) {
  133. console.error("加载随手拍失败", e);
  134. this.$refs.uToast.show({ type: "error", message: "加载失败,请重试" });
  135. } finally {
  136. this.loading = false;
  137. }
  138. },
  139. loadMore() {
  140. if (!this.isEnd && !this.loading) {
  141. this.loadData();
  142. }
  143. },
  144. // ============ 单选 ============
  145. onRadioChange(item) {
  146. this.selectedRow = item;
  147. this.selectedId = item.id;
  148. },
  149. // ============ 确认选择 ============
  150. handleConfirm() {
  151. if (!this.selectedRow) {
  152. this.$refs.uToast.show({ type: "warning", message: "请选择一条记录" });
  153. return;
  154. }
  155. const data = this.selectedRow;
  156. this.$emit("confirm", {
  157. sourceType: 4,
  158. sourceId: data.id,
  159. sourceName: "随手拍",
  160. foundUserName: data.reporterName,
  161. foundUserId: data.reporterId,
  162. foundTime: data.createTime,
  163. description: (data.location || "") + (data.description || ""),
  164. reportAttachments: data.attachment || [],
  165. });
  166. this.handleClose();
  167. },
  168. // ============ 关闭弹窗 ============
  169. handleClose() {
  170. this.visible = false;
  171. this.resetState();
  172. },
  173. },
  174. };
  175. </script>
  176. <style lang="scss" scoped>
  177. .snapshot-select-popup {
  178. /deep/ .u-popup__content {
  179. border-radius: 32rpx 32rpx 0 0;
  180. overflow: hidden;
  181. }
  182. .popup-content {
  183. height: 75vh;
  184. display: flex;
  185. flex-direction: column;
  186. background: #f5f7fb;
  187. }
  188. // ===== 头部 =====
  189. .popup-header {
  190. display: flex;
  191. justify-content: space-between;
  192. align-items: center;
  193. padding: 30rpx 32rpx;
  194. background: #fff;
  195. border-bottom: 2rpx solid #eef2f6;
  196. flex-shrink: 0;
  197. .popup-title {
  198. font-size: 36rpx;
  199. font-weight: bold;
  200. color: #1f2b3c;
  201. }
  202. .close-btn {
  203. width: 60rpx;
  204. height: 60rpx;
  205. display: flex;
  206. align-items: center;
  207. justify-content: center;
  208. font-size: 52rpx;
  209. color: #8e9aae;
  210. line-height: 1;
  211. }
  212. }
  213. // ===== 列表 =====
  214. .popup-body {
  215. flex: 1;
  216. overflow-y: auto;
  217. padding: 16rpx 24rpx;
  218. background: #f5f7fb;
  219. .card-wrapper {
  220. margin-top: 20rpx;
  221. &:first-child {
  222. margin-top: 0;
  223. }
  224. }
  225. .no-data {
  226. margin-top: 30vh;
  227. }
  228. .load-more {
  229. text-align: center;
  230. font-size: 26rpx;
  231. color: #aaa;
  232. padding: 30rpx 0 40rpx;
  233. }
  234. }
  235. // ===== 底部 =====
  236. .popup-footer {
  237. display: flex;
  238. justify-content: space-between;
  239. align-items: center;
  240. padding: 16rpx 24rpx;
  241. background: #fff;
  242. border-top: 2rpx solid #eef2f6;
  243. flex-shrink: 0;
  244. min-height: 90rpx;
  245. .footer-left {
  246. flex: 1;
  247. .selected-info {
  248. font-size: 28rpx;
  249. color: #2979ff;
  250. overflow: hidden;
  251. text-overflow: ellipsis;
  252. white-space: nowrap;
  253. display: block;
  254. max-width: 340rpx;
  255. }
  256. }
  257. .footer-right {
  258. display: flex;
  259. gap: 16rpx;
  260. flex-shrink: 0;
  261. /deep/ .u-button {
  262. border-radius: 48rpx;
  263. padding: 0 32rpx;
  264. height: 64rpx;
  265. font-size: 26rpx;
  266. }
  267. /deep/ .u-button--primary {
  268. background: #2979ff;
  269. }
  270. /deep/ .u-button--primary.u-button--disabled {
  271. background: #ccc;
  272. color: #999;
  273. }
  274. }
  275. }
  276. }
  277. </style>