PhotoRecord.uvue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. <template>
  2. <scroll-view class="tag-scroll-container" scroll-x="true">
  3. <view class="record-card2 flex-row">
  4. <view class="tag-circle" v-for="(item, index) in initRecords" :key="index" @click="tabsClick(item.senum)"
  5. :class="{'checked-tag' : item.senum == current}">
  6. <text class="circle" :class="{
  7. 'bg-green': item.photourlSpl.length > 0,
  8. 'bg-black': item.photourlSpl.length == 0
  9. }">{{item.senum}}</text>
  10. </view>
  11. </view>
  12. </scroll-view>
  13. <!-- #ifdef APP -->
  14. <scroll-view style="flex:1">
  15. <!-- #endif -->
  16. <view class="record-card" v-for="(item, index) in records" :key="index"
  17. v-show="current == item.senum as number">
  18. <view class="header-row">
  19. <text class="label">序号:</text>
  20. <text class="value">{{ item.senum }}</text>
  21. <text class="status">{{ item.imgname.length > 0 ? '已拍照' : '未拍照'}}</text>
  22. </view>
  23. <view class="info-row">
  24. <text class="label">产品码:</text>
  25. <text class="value">{{ item.prodno }}</text>
  26. </view>
  27. <view class="info-row">
  28. <text class="label">拍照点:</text>
  29. <text class="value">{{ item.processStep }}</text>
  30. </view>
  31. <view class="info-row">
  32. <text class="label">拍照位置:</text>
  33. <text class="value">{{ item.photographpoint }}</text>
  34. </view>
  35. <view class="info-row">
  36. <text class="label">描述:</text>
  37. <text class="value">{{ item.photographdescription }}</text>
  38. </view>
  39. <button class="cancel-btn" @click="cancel(item.sxid)" v-if="canEdit">
  40. 拍照
  41. </button>
  42. <view class="tag-banner" style="" v-if="item.imgname.length > 0">
  43. <view class="tag-banner" v-for="(tag,index) in item.imgname" :key="index" >
  44. <text class="img-banner" v-if="item.imgname.length > 0 && closeTags[index]"
  45. @click="closeTag(index)">{{tag}}</text>
  46. </view>
  47. </view>
  48. <view class="my-page">
  49. <swiper class="swiper-box my-swiper" :current="0" :indicator-dots="true" v-if="item.photourlSpl.length>0" :key="'photo-'+item.sxid">
  50. <swiper-item v-for="(url, index) in item.photourlSpl" :key="index" @tap="preview(uni.env.USER_DATA_PATH+url)">
  51. <view class="swiper-item ">
  52. <image class="my-image" :src="uni.env.USER_DATA_PATH+url" mode="aspectFill" />
  53. </view>
  54. <view v-if="item.imgname.length>0">
  55. <text class="demo-view-label">{{ item.imgname?.[index] ?? ''}}</text>
  56. </view>
  57. </swiper-item>
  58. </swiper>
  59. <view v-if="item.exampleurlSpl.length>0"><text class="info-tips">—— 以下为示例图像 ——</text></view>
  60. <swiper class="swiper-box my-swiper mg-top" :current="0" :indicator-dots="true"
  61. v-if="item.exampleurlSpl.length>0" :key="'example-'+item.sxid">
  62. <swiper-item v-for="(url, index) in item.exampleurlSpl" :key="index" @tap="preview(url)">
  63. <view class="swiper-item ">
  64. <image class="my-image" :src="url" mode="aspectFill" />
  65. </view>
  66. </swiper-item>
  67. </swiper>
  68. </view>
  69. </view>
  70. <view class="info-row btn-panel">
  71. <button class="btn btn-first" @click="tabsClick(current-1)" v-if="current > 1">
  72. 前一项
  73. </button>
  74. <button class="btn btn-second" @click="tabsClick(current+1)" v-if="current < maxcount">
  75. 下一项
  76. </button>
  77. </view>
  78. <!-- #ifdef APP -->
  79. </scroll-view>
  80. <!-- #endif -->
  81. </template>
  82. <script setup>
  83. import {
  84. ref
  85. } from 'vue'
  86. import { getListByOrder, TaskPhoto, recordStatusDict, updateData } from '@/api/work';
  87. // 存储页面参数
  88. let photoitem = "";
  89. let pid = "";
  90. let senum = "";
  91. //自定义返回行为,覆盖系统默认返回按钮
  92. const backPressOptions = reactive({
  93. from: 'backbutton'
  94. } as OnBackPressOptions)
  95. onBackPress((options : OnBackPressOptions) : boolean | null => {
  96. uni.navigateTo({
  97. url: `/pages/work/download/DownloadDetail?id=${pid}`,
  98. // 修改动画方向为从左到右退回
  99. animationType: 'slide-in-left', // 使用从左到右滑出的动画效果
  100. animationDuration: 300 // 动画持续时间,单位ms
  101. })
  102. // 返回true表示拦截默认返回行为
  103. return true
  104. })
  105. //检查项目最大数量
  106. var maxcount = 5
  107. var current = ref(1)
  108. var records = ref<TaskPhoto[]>([]);
  109. const closeTags = ref<boolean[]>([]);
  110. var initRecords = [] as TaskPhoto[]
  111. let canEdit = ref<boolean>(true);
  112. // 定义数据刷新函数
  113. const refreshRecords = (index : number) => {
  114. // 清空现有数据
  115. initRecords = [];
  116. closeTags.value = [];
  117. // #ifdef APP-ANDROID
  118. getListByOrder('app_task_photo', 'pdid', pid, ' order by sxid desc', null).then((res : UTSJSONObject) => {
  119. let dataList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>()
  120. if (dataList != null && dataList.length > 0) {
  121. let index = 1
  122. dataList.forEach(item => {
  123. if (item != null) {
  124. const imgnameStr = item?.['imgname'] as string ?? ''
  125. const photourlStr = item?.['photourl'] as string ?? ''
  126. const exampleurlStr = item?.['exampleurl'] as string ?? ''
  127. const uploadFlag = parseInt(item?.['uploadFlag'] as string ?? '0')
  128. if(uploadFlag == 1) {
  129. //已经上传过不允许编辑
  130. canEdit.value = false;
  131. }
  132. const imgnameArr = imgnameStr.indexOf(",") > -1 ? imgnameStr.split(",") : (imgnameStr != '' ? [imgnameStr] : [])
  133. const photourlArr = photourlStr.indexOf(",") > -1 ? photourlStr.split(",") : (photourlStr != '' ? [photourlStr] : [])
  134. const exampleurlArr = exampleurlStr.indexOf(",") > -1 ? exampleurlStr.split(",") : (exampleurlStr != '' ? [exampleurlStr] : [])
  135. item['imgname'] = imgnameArr
  136. item['photourlSpl'] = photourlArr
  137. item['exampleurlSpl'] = exampleurlArr
  138. item['senum'] = index
  139. let record = JSON.parse<TaskPhoto>(item.toJSONString());
  140. if (record != null) {
  141. initRecords.push(record)
  142. // 为每个图片初始化closeTags值为true,表示默认显示
  143. if (record.imgname != null && record.imgname.length > 0) {
  144. for (let i = 0; i < record.imgname.length; i++) {
  145. closeTags.value.push(true);
  146. }
  147. }
  148. index++
  149. }
  150. }
  151. });
  152. maxcount = index-1;
  153. }
  154. if (initRecords.length > 0) {
  155. if (index > 0) {
  156. current.value = index
  157. } else {
  158. current.value = initRecords[0].senum
  159. }
  160. records.value = initRecords.filter(item => item['senum'] == current.value)
  161. console.log(records)
  162. }
  163. });
  164. // #endif
  165. }
  166. onLoad((options) => {
  167. photoitem = options?.photoitem ?? ""
  168. pid = options?.pdid ?? "1"
  169. senum = options?.senum ?? "1"
  170. // 加载初始数据
  171. refreshRecords(parseInt(senum));
  172. });
  173. const tabsClick = (obj : number) => {
  174. current.value = obj
  175. records.value = initRecords.filter(item => item['senum'] == current.value)
  176. }
  177. const closeTag = (index : number) => {
  178. if (!canEdit.value) {
  179. uni.showToast({
  180. title: "已上传的图片无法删除",
  181. icon: "error"
  182. })
  183. return
  184. }
  185. let record = records.value[0]
  186. uni.showModal({
  187. title: '系统提示',
  188. content: '确认是否删除图片',
  189. cancelText: '取消',
  190. confirmText: '确定',
  191. success: function (res) {
  192. if (res.confirm) {
  193. closeTags.value[index] = false
  194. let imgname = record.imgname.filter((img, i) => i != index)
  195. let urlpdt = record.photourlSpl.filter((url, i) => i != index)
  196. let updatedData = ''
  197. if (imgname.length != urlpdt.length) {
  198. uni.showToast({
  199. title: '图片数据不正确',
  200. icon: 'error',
  201. duration: 2000
  202. });
  203. return;
  204. }
  205. if (imgname.length == 0 && urlpdt.length == 0) {
  206. updatedData = "imgname='',photourl=''"
  207. } else if (imgname.length == 1 && urlpdt.length == 1) {
  208. updatedData = "imgname='" + imgname[0] + "',photourl='" + urlpdt[0] + "'"
  209. } else {
  210. updatedData = "imgname='" + imgname.join(",") + "',photourl='" + urlpdt.join(",") + "'"
  211. }
  212. updateData('app_task_photo', updatedData, 'sxid', record.sxid.toString()).then((res : UTSJSONObject) => {
  213. let dataRes = res?.['data'] as boolean ?? false
  214. if (dataRes) {
  215. uni.showToast({
  216. title: "删除成功!",
  217. });
  218. // 刷新页面数据
  219. refreshRecords(record.senum);
  220. }
  221. });
  222. }
  223. }
  224. })
  225. }
  226. const preview = (imageUrl : string) => {
  227. uni.previewImage({
  228. urls: [imageUrl], // 需要预览的图片链接列表
  229. current: 0, // 当前显示图片的索引
  230. indicator: 'number', // 图片指示器样式
  231. loop: false // 是否可循环预览
  232. });
  233. }
  234. const cancel = (id : number) => {
  235. uni.navigateTo({
  236. url: `/pages/work/download/TaskCamera?id=${id}&num=${current.value}`
  237. })
  238. }
  239. defineExpose({
  240. backPressOptions
  241. })
  242. </script>
  243. <style scoped>
  244. .container {
  245. padding: 24rpx;
  246. background-color: #f0f4f8;
  247. flex: 1;
  248. display: flex;
  249. flex-direction: column;
  250. font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif;
  251. /* #ifndef APP-ANDROID */
  252. min-height: 100vh;
  253. /* #endif */
  254. }
  255. .banner {
  256. background: linear-gradient(135deg, #6dd5ed, #2193b0);
  257. border-radius: 24rpx;
  258. padding: 40rpx 30rpx;
  259. margin-bottom: 40rpx;
  260. box-shadow: 0 8rpx 16rpx rgba(33, 147, 176, 0.3);
  261. }
  262. .banner-title {
  263. color: white;
  264. font-size: 36rpx;
  265. font-weight: bold;
  266. text-align: center;
  267. }
  268. /* 卡片整体 */
  269. .record-card {
  270. background: #ffffff;
  271. border-radius: 20rpx;
  272. padding: 24rpx 32rpx;
  273. box-shadow: 0 8rpx 15rpx rgba(0, 43, 92, 0.1);
  274. display: flex;
  275. flex-direction: column;
  276. margin-bottom: 15rpx;
  277. margin-top: 10rpx;
  278. }
  279. /* 卡片整体 */
  280. .record-card2 {
  281. background: #ffffff;
  282. border-radius: 20rpx;
  283. padding: 24rpx 32rpx;
  284. display: flex;
  285. flex-direction: column;
  286. margin-bottom: 20rpx;
  287. margin-top: 20rpx;
  288. }
  289. /* 头部:科室 和 状态 */
  290. .header-row {
  291. display: flex;
  292. flex-direction: row;
  293. justify-content: space-between;
  294. align-items: center;
  295. }
  296. .department {
  297. font-size: 32rpx;
  298. font-weight: 700;
  299. color: #004a99;
  300. }
  301. .status {
  302. font-size: 28rpx;
  303. color: #1890ff;
  304. padding: 6rpx 18rpx;
  305. border-radius: 16rpx;
  306. background-color: #e6f7ff;
  307. }
  308. .status-cancelled {
  309. color: #ff4d4f;
  310. background-color: #fff1f0;
  311. }
  312. /* 信息行 */
  313. .info-row {
  314. display: flex;
  315. flex-direction: row;
  316. font-size: 28rpx;
  317. color: #33475b;
  318. align-items: center;
  319. }
  320. .label {
  321. color: #102a43;
  322. min-width: 100rpx;
  323. width: 180rpx;
  324. line-height: 1.5;
  325. }
  326. .value {
  327. flex: 1;
  328. word-break: break-all;
  329. word-wrap: break-word;
  330. }
  331. .fee {
  332. color: #fa541c;
  333. font-weight: 700;
  334. }
  335. /* 取消按钮 */
  336. .cancel-btn {
  337. align-self: flex-end;
  338. background-color: #ff4d4f;
  339. color: #fff;
  340. border: none;
  341. border-radius: 32rpx;
  342. padding: 5rpx 30rpx;
  343. font-size: 28rpx;
  344. font-weight: 700;
  345. margin-top: 20rpx;
  346. }
  347. .cancel-btn:hover {
  348. background-color: #d9363e;
  349. }
  350. .cancel-btn:active {
  351. background-color: #a93232;
  352. }
  353. .swiper {
  354. height: 300rpx;
  355. margin: 20rpx 0;
  356. }
  357. .swiper-box {
  358. height: 500rpx;
  359. }
  360. .swiper-item {
  361. /* #ifndef APP-NVUE */
  362. display: flex;
  363. /* #endif */
  364. flex-direction: column;
  365. justify-content: center;
  366. align-items: center;
  367. color: #fff;
  368. height: 500rpx;
  369. line-height: 300rpx;
  370. }
  371. .my-page {
  372. display: flex;
  373. flex-direction: column;
  374. box-sizing: border-box;
  375. background-color: #fff;
  376. /* #ifndef APP-ANDROID */
  377. min-height: 100%;
  378. /* #endif */
  379. height: 100%;
  380. }
  381. .flex-row {
  382. flex-direction: row;
  383. flex-wrap: nowrap;
  384. width: auto;
  385. min-width: 100%;
  386. /* 确保容器宽度至少为屏幕宽度 */
  387. }
  388. .demo-view-label {
  389. text-align: center;
  390. color: #102a43;
  391. line-height: 1.5;
  392. margin-top: 5rpx;
  393. }
  394. .tag-circle {
  395. width: 60rpx;
  396. height: 60rpx;
  397. margin: 0 10rpx;
  398. display: flex;
  399. justify-content: center;
  400. align-items: center;
  401. flex-shrink: 0;
  402. }
  403. .circle {
  404. height: 50rpx;
  405. width: 50rpx;
  406. background-color: #004a99;
  407. text-align: center;
  408. color: #fff;
  409. line-height: 50rpx;
  410. border-radius: 50rpx;
  411. }
  412. .checked-tag {
  413. height: 60rpx;
  414. width: 60rpx;
  415. line-height: 60rpx;
  416. border: 2rpx solid #ffffff;
  417. box-shadow: 0 0 0 2rpx #007aff;
  418. position: relative;
  419. z-index: 10;
  420. }
  421. .bg-green {
  422. background-color: seagreen;
  423. }
  424. .bg-yellow {
  425. background-color: yellow;
  426. }
  427. .bg-black {
  428. background-color: #102a43;
  429. }
  430. .bg-red {
  431. background-color: red;
  432. }
  433. .btn-panel {
  434. position: relative;
  435. width: 100%;
  436. height: 90rpx;
  437. overflow: visible;
  438. }
  439. .btn {
  440. position: absolute;
  441. height: 70rpx;
  442. line-height: 70rpx;
  443. padding: 0 20rpx;
  444. top: 50%;
  445. transform: translateY(-50%);
  446. background-color: #00aaff;
  447. color: #fff;
  448. border: 0 none;
  449. border-radius: 25rpx;
  450. }
  451. .btn-first {
  452. left: 15rpx;
  453. }
  454. .btn-second {
  455. right: 15rpx;
  456. }
  457. /* 安卓兼容的滚动容器样式 */
  458. .tag-scroll-container {
  459. width: 100%;
  460. overflow-x: auto;
  461. overflow-y: hidden;
  462. -webkit-overflow-scrolling: touch;
  463. box-sizing: border-box;
  464. padding: 10rpx 15rpx;
  465. white-space: nowrap;
  466. display: flex;
  467. flex-direction: row;
  468. }
  469. .tag-scroll-container::-webkit-scrollbar-thumb {
  470. background-color: rgba(0, 0, 0, 0.2) !important;
  471. border-radius: 3rpx !important;
  472. }
  473. .img-banner {
  474. height: 50rpx;
  475. width: 100%;
  476. background-color: #004a99;
  477. text-align: center;
  478. color: #fff;
  479. line-height: 50rpx;
  480. border-radius: 10rpx;
  481. margin-left: 2rpx;
  482. font-size: 12px;
  483. padding: 0 10rpx;
  484. }
  485. .tag-banner {
  486. flex-direction: column;
  487. flex-wrap: wrap;
  488. margin: 4px 0;
  489. font-size: 12px;
  490. }
  491. .mg-top {
  492. margin-top: 20rpx;
  493. }
  494. .info-tips {
  495. text-align: center;
  496. color: #999;
  497. font-size: 20rpx;
  498. margin-top: 20rpx;
  499. }
  500. </style>