PhotoRecord.uvue 13 KB

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