InspectionList.uvue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. <template>
  2. <view class="record-card flex-row">
  3. <view class="tag-circle" v-for="(item, index) in initRecords" :key="index" @click="tabsClick(parseInt(item.no))"
  4. :class="{'checked-tag' : parseInt(item.no) == current}">
  5. <text class="circle" :class="{
  6. 'bg-green': item.result == '合格',
  7. 'bg-red': item.result == '不合格',
  8. 'bg-black': item.result != '不合格' && item.result != '合格'
  9. }">{{item.no}}</text>
  10. </view>
  11. </view>
  12. <!-- #ifdef APP -->
  13. <scroll-view style="flex:1">
  14. <!-- #endif -->
  15. <view v-if="reportList.length" class="card-list">
  16. <!-- 注意:v-for 遍历 reportList 时,item 是响应式的,但内部字段需通过计算属性转换 -->
  17. <view class="card" v-for="item in reportList" :key="item.no" v-show="current == parseInt(item.no)">
  18. <!-- 序号:绑定计算属性 parsedMinNum(对应 item.minNum) -->
  19. <view class="info-row">
  20. <text class="label">序号</text>
  21. <view class="value">
  22. {{getParsedValue(item.no)}}
  23. </view>
  24. </view>
  25. <view class="info-row">
  26. <text class="label">产品码</text>
  27. <view class="value">
  28. {{item.prodno}}
  29. </view>
  30. </view>
  31. <view class="info-row">
  32. <text class="label">检测项目</text>
  33. <view class="value">
  34. {{item.invname}}
  35. </view>
  36. </view>
  37. <view class="info-row">
  38. <text class="label">性质</text>
  39. <view class="value">
  40. {{item.nature}}
  41. </view>
  42. </view>
  43. <!-- 上限要求:绑定计算属性 parsedMinNum -->
  44. <view class="info-row">
  45. <text class="label">上限要求</text>
  46. <view class="value">
  47. {{item.maxNum}}
  48. </view>
  49. </view>
  50. <!-- 下限要求:绑定计算属性 parsedMaxNum(对应 item.maxNum) -->
  51. <view class="info-row">
  52. <text class="label">下限要求</text>
  53. <view class="value">
  54. {{item.minNum}}
  55. </view>
  56. </view>
  57. <view class="divider"></view>
  58. <!-- 实测值小:绑定计算属性 parsedMeasuredValue(对应 item.measuredvalue) -->
  59. <view class="info-row">
  60. <text class="label">实测值小</text>
  61. <view class="value">
  62. <input type="digit" class="surround uni-input number-input" v-model="item.measuredvalue" @confirm="minNumberChange"></input>
  63. </view>
  64. </view>
  65. <!-- 实测值大:绑定计算属性 parsedMeasuredMaxValue(对应 item.measuredvaluemax) -->
  66. <view class="info-row">
  67. <text class="label">实测值大</text>
  68. <view class="value">
  69. <input type="digit" class="surround uni-input number-input" v-model="item.measuredvaluemax" @confirm="maxNumberChange"></input>
  70. </view>
  71. </view>
  72. <view class="info-row">
  73. <text class="label">结论</text>
  74. <view class="value">
  75. <radio-group class="radio-group-horizontal" @change="resultChange">
  76. <radio class="radio-group-horizontal-rg" value="合格" :checked="item.result == '合格'" :disabled="item.nature == '定量'">合格</radio>
  77. <radio class="radio-group-horizontal-rg" value="不合格" :checked="item.result == '不合格'" :disabled="item.nature == '定量'">不合格</radio>
  78. </radio-group>
  79. </view>
  80. </view>
  81. <view class="info-row">
  82. <text class="label">备注</text>
  83. <view class="value">
  84. <input v-model="item.memo" class="surround uni-input" @confirm="remarksChange"></input>
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. <!-- 空状态 -->
  90. <view v-else class="empty-card">
  91. <image src="/static/image/empty.png" class="empty-img" />
  92. <text class="empty-text">暂无检查检验记录</text>
  93. </view>
  94. <view class="info-row btn-panel">
  95. <button class="btn btn-first" @click="tabsClick(current-1)" v-if="current > 1">
  96. 前一项
  97. </button>
  98. <button class="btn btn-second" @click="tabsClick(current+1)" v-if="current < maxcount">
  99. 下一项
  100. </button>
  101. </view>
  102. <!-- #ifdef APP -->
  103. </scroll-view>
  104. <!-- #endif -->
  105. </template>
  106. <script setup>
  107. import { ref, computed } from 'vue' // 1. 引入 computed(计算属性核心)
  108. import { getJoinList, QcRecord, recordStatusDict, updateData } from '@/api/work';
  109. // 存储页面参数
  110. let pdid = "";
  111. let senum = "";
  112. // 检查项目最大数量(改为 ref 响应式,避免值变化不更新)
  113. const maxcount = ref(5)
  114. const current = ref(1)
  115. const reportList = ref<QcRecord[]>([])
  116. const initRecords = ref<QcRecord[]>([])
  117. // 下拉框选项数组 - 定性分析选项
  118. const array = ref(['合格', '不合格']);
  119. //自定义返回行为,覆盖系统默认返回按钮
  120. const backPressOptions = reactive({
  121. from: 'backbutton'
  122. } as OnBackPressOptions)
  123. onBackPress((options : OnBackPressOptions) : boolean | null => {
  124. uni.navigateTo({
  125. url: `/pages/work/download/DownloadDetail?id=${pdid}`,
  126. // 修改动画方向为从左到右退回
  127. animationType: 'slide-in-left', // 使用从左到右滑出的动画效果
  128. animationDuration: 300 // 动画持续时间,单位ms
  129. })
  130. // 返回true表示拦截默认返回行为
  131. return true
  132. })
  133. const getParsedValue = computed(() => {
  134. return (value : string | number) => {
  135. if (typeof value === 'number') {
  136. return value;
  137. }
  138. if (typeof value === 'string') {
  139. const num = parseFloat(value);
  140. return isNaN(num) ? 0 : num;
  141. }
  142. return 0;
  143. }
  144. });
  145. // 4. 切换标签时更新 reportList(使用响应式的 initRecords)
  146. const tabsClick = (obj : number) => {
  147. current.value = obj;
  148. const filtered = initRecords.value.filter(item =>
  149. getParsedValue.value(item.no) === current.value
  150. );
  151. reportList.value = filtered;
  152. }
  153. const refreshRecords = (index : number) => {
  154. // 清空现有数据(响应式数组需操作 .value)
  155. initRecords.value = [];
  156. // #ifdef APP-ANDROID
  157. getJoinList(
  158. 'app_task_record as r',
  159. 'app_task_record_item as i',
  160. 'r.*,i.*',
  161. 'r.sxid=i.psxid',
  162. 'pdid',
  163. pdid,
  164. null
  165. ).then((res : UTSJSONObject) => {
  166. const dataList = res?.['data'] as UTSJSONObject[] ?? []
  167. if (dataList.length > 0) {
  168. dataList.forEach(item => {
  169. if (item != null) {
  170. const record = JSON.parse<QcRecord>(item.toJSONString());
  171. if (record != null) {
  172. initRecords.value.push(record)
  173. // 计算 maxcount 时使用数值转换,避免字符串干扰
  174. const noValue = getParsedValue.value(record.no)
  175. if (noValue > maxcount.value) {
  176. maxcount.value = noValue;
  177. }
  178. }
  179. }
  180. });
  181. }
  182. // 对initRecords按照no字段进行升序排序
  183. if (initRecords.value.length > 0) {
  184. initRecords.value.sort((a, b) => {
  185. const noA = getParsedValue.value(a.no);
  186. const noB = getParsedValue.value(b.no);
  187. return noA - noB;
  188. });
  189. current.value = index > 0 ? index : getParsedValue.value(initRecords.value[0].no);
  190. const filtered = initRecords.value.filter(item =>
  191. getParsedValue.value(item.no) === current.value
  192. );
  193. reportList.value = filtered;
  194. }
  195. });
  196. // #endif
  197. }
  198. const resultChange = (event : UniRadioGroupChangeEvent) => {
  199. // 获取当前选中的报告项
  200. const currentItem = reportList.value.find(item => parseInt(item.no) === current.value);
  201. if (currentItem != null) {
  202. // 如果是定量性质,则不允许修改
  203. if (currentItem.memo == '定量') {
  204. uni.showToast({
  205. title: "定量项目不可修改结论",
  206. icon: 'error',
  207. duration: 2000
  208. });
  209. return;
  210. }
  211. // 更新结果值
  212. currentItem.result = event.detail.value;
  213. //更新数据库
  214. let updatedData = "result='" + currentItem.result + "'"
  215. updateData('app_task_record_item', updatedData, 'sxid', currentItem.sxid.toString()).then((res : UTSJSONObject) => {
  216. let data = res?.['data'] as boolean ?? false
  217. if (data != null && data== true) {
  218. uni.showToast({
  219. title: "保存成功!",
  220. });
  221. }
  222. });
  223. }
  224. }
  225. const minNumberChange = (event : UniInputConfirmEvent) => {
  226. // 获取当前选中的报告项
  227. const currentItem = reportList.value.find(item => parseInt(item.no) === current.value);
  228. if (currentItem != null) {
  229. // 更新结果值
  230. currentItem.measuredvalue = event.detail.value;
  231. let updatedData = "measuredvalue='" + currentItem.measuredvalue + "'"
  232. if (currentItem.nature == '定量') {
  233. let minValue = parseFloat(currentItem.minNum ?? '0');
  234. let maxValue = parseFloat(currentItem.maxNum ?? '0');
  235. let currenMinValue = parseFloat(currentItem.measuredvalue ?? '0');
  236. let currenMaxValue = parseFloat(currentItem.measuredvaluemax ?? '0');
  237. if (currenMinValue > maxValue || currenMinValue < minValue|| currenMaxValue > maxValue || currenMaxValue < minValue) {
  238. currentItem.result = '不合格'
  239. } else {
  240. currentItem.result = '合格'
  241. }
  242. updatedData += " ,result = '" + currentItem.result + "'"
  243. }
  244. //更新数据库
  245. updateData('app_task_record_item', updatedData, 'sxid', currentItem.sxid.toString()).then((res : UTSJSONObject) => {
  246. let data = res?.['data'] as boolean ?? false
  247. if (data != null && data== true) {
  248. uni.showToast({
  249. title: "保存成功!",
  250. });
  251. }
  252. });
  253. }
  254. }
  255. const maxNumberChange = (event : UniInputConfirmEvent) => {
  256. // 获取当前选中的报告项
  257. const currentItem = reportList.value.find(item => parseInt(item.no) === current.value);
  258. if (currentItem != null) {
  259. // 更新结果值
  260. currentItem.measuredvaluemax = event.detail.value;
  261. //更新数据库
  262. let updatedData = "measuredvaluemax='" + currentItem.measuredvaluemax + "'"
  263. if (currentItem.nature == '定量') {
  264. let minValue = parseFloat(currentItem.minNum ?? '0');
  265. let maxValue = parseFloat(currentItem.maxNum ?? '0');
  266. let currenMinValue = parseFloat(currentItem.measuredvalue ?? '0');
  267. let currenMaxValue = parseFloat(currentItem.measuredvaluemax ?? '0');
  268. if (currenMinValue > maxValue || currenMinValue < minValue|| currenMaxValue > maxValue || currenMaxValue < minValue) {
  269. currentItem.result = '不合格'
  270. } else {
  271. currentItem.result = '合格'
  272. }
  273. updatedData += " ,result = '" + currentItem.result + "'"
  274. }
  275. updateData('app_task_record_item', updatedData, 'sxid', currentItem.sxid.toString()).then((res : UTSJSONObject) => {
  276. let data = res?.['data'] as boolean ?? false
  277. if (data != null && data== true) {
  278. uni.showToast({
  279. title: "保存成功!",
  280. });
  281. }
  282. });
  283. }
  284. }
  285. const remarksChange = (event : UniInputConfirmEvent) => {
  286. // 获取当前选中的报告项
  287. const currentItem = reportList.value.find(item => parseInt(item.no) === current.value);
  288. if (currentItem != null) {
  289. // 更新结果值
  290. currentItem.memo = event.detail.value;
  291. //更新数据库
  292. let updatedData = "memo='" + currentItem.memo + "'"
  293. updateData('app_task_record_item', updatedData, 'sxid', currentItem.sxid.toString()).then((res : UTSJSONObject) => {
  294. let data = res?.['data'] as boolean ?? false
  295. if (data != null && data== true) {
  296. uni.showToast({
  297. title: "保存成功!",
  298. });
  299. }
  300. });
  301. }
  302. }
  303. onLoad((options) => {
  304. pdid = options?.pdid ?? "1"
  305. senum = options?.senum ?? "1"
  306. // 加载初始数据(转换 senum 为数值,避免字符串类型问题)
  307. refreshRecords(getParsedValue.value(senum))
  308. });
  309. defineExpose({
  310. backPressOptions
  311. })
  312. </script>
  313. <style scoped>
  314. /* 样式部分保持不变,仅修复标签颜色冲突(tag=3时优先黄色) */
  315. .container {
  316. padding: 20px;
  317. background-color: #f5f7fa;
  318. flex: 1;
  319. box-sizing: border-box;
  320. }
  321. .banner {
  322. background: linear-gradient(135deg, #6dd5ed, #2193b0);
  323. border-radius: 12px;
  324. padding: 20px 15px;
  325. margin-bottom: 20px;
  326. box-shadow: 0 4px 8px rgba(33, 147, 176, 0.3);
  327. }
  328. .banner-title {
  329. color: white;
  330. font-size: 18px;
  331. font-weight: bold;
  332. text-align: center;
  333. }
  334. .box {
  335. width: 20px;
  336. background-color: #909193;
  337. border-radius: 7.5px;
  338. }
  339. .card-list {
  340. display: flex;
  341. flex-direction: column;
  342. }
  343. .card-list>.card {
  344. margin-bottom: 15px;
  345. }
  346. /* #ifndef APP-ANDROID */
  347. .card-list>.card:last-child {
  348. margin-bottom: 0;
  349. }
  350. /* #endif */
  351. .card {
  352. background-color: white;
  353. border-radius: 10px;
  354. padding: 15px;
  355. box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
  356. display: flex;
  357. flex-direction: column;
  358. }
  359. .card-header {
  360. display: flex;
  361. align-items: center;
  362. margin-bottom: 20rpx;
  363. }
  364. .card-icon {
  365. width: 64rpx;
  366. height: 64rpx;
  367. margin-right: 20rpx;
  368. border-radius: 12rpx;
  369. background-color: #eef5ff;
  370. padding: 10rpx;
  371. }
  372. .info-row {
  373. display: flex;
  374. flex-direction: row;
  375. font-size: 14px;
  376. color: #33475b;
  377. align-items: center;
  378. padding: 10px;
  379. }
  380. .label {
  381. font-weight: bold;
  382. color: #102a43;
  383. min-width: 75px;
  384. }
  385. .value {
  386. flex: 1;
  387. white-space: nowrap;
  388. overflow: hidden;
  389. text-overflow: ellipsis;
  390. }
  391. .divider {
  392. height: 1px;
  393. background-color: #eee;
  394. margin: 10px 0;
  395. }
  396. .card-info {
  397. font-size: 28rpx;
  398. color: #666;
  399. line-height: 1.6;
  400. display: flex;
  401. flex-direction: column;
  402. }
  403. .card-info>.card-info-item {
  404. margin-bottom: 10rpx;
  405. }
  406. /* #ifndef APP-ANDROID */
  407. .card-info>.card-info-item:last-child {
  408. margin-bottom: 0;
  409. }
  410. /* #endif */
  411. .btn-group {
  412. display: flex;
  413. justify-content: flex-end;
  414. margin-top: 20rpx;
  415. }
  416. .main-btn {
  417. font-size: 28rpx;
  418. color: white;
  419. border: none;
  420. border-radius: 100rpx;
  421. background: linear-gradient(to right, #36d1dc, #5b86e5);
  422. box-shadow: 0 6rpx 16rpx rgba(91, 134, 229, 0.3);
  423. /* #ifndef APP-ANDROID */
  424. transition: all 0.2s ease-in-out;
  425. /* #endif */
  426. }
  427. /* #ifndef APP-ANDROID */
  428. .main-btn:active {
  429. opacity: 0.9;
  430. transform: scale(0.98);
  431. }
  432. /* #endif */
  433. .empty-card {
  434. background-color: white;
  435. border-radius: 20rpx;
  436. padding: 60rpx 30rpx;
  437. box-shadow: 0 6rpx 16rpx rgba(0, 0, 0, 0.05);
  438. text-align: center;
  439. margin-top: 100rpx;
  440. }
  441. .empty-img {
  442. width: 180rpx;
  443. height: 180rpx;
  444. margin-bottom: 30rpx;
  445. opacity: 0.8;
  446. }
  447. .empty-text {
  448. font-size: 30rpx;
  449. color: #999;
  450. }
  451. .surround {
  452. border: 1px solid silver;
  453. border-radius: 10rpx;
  454. min-height: 60rpx;
  455. }
  456. .selectable {
  457. /* 确保在安卓设备上文字可以正常显示为可点击状态 */
  458. user-select: text;
  459. -webkit-user-select: text;
  460. cursor: pointer;
  461. /* #ifdef APP-ANDROID */
  462. /* 安卓设备特别处理,增强可点击性 */
  463. background-color: #f8f8f8;
  464. /* #endif */
  465. }
  466. .record-card {
  467. background: #ffffff;
  468. border-radius: 20rpx;
  469. padding: 24rpx 32rpx;
  470. box-shadow: 0 8rpx 15rpx rgba(0, 43, 92, 0.1);
  471. display: flex;
  472. flex-direction: column;
  473. margin-bottom: 20rpx;
  474. margin-top: 20rpx;
  475. }
  476. /* 横向排列radio的样式 */
  477. .radio-group-horizontal {
  478. display: flex;
  479. flex-direction: row;
  480. align-items: center;
  481. }
  482. .radio-group-horizontal-rg{
  483. margin-right: 30rpx;
  484. }
  485. .flex-row {
  486. flex-direction: row;
  487. }
  488. .tag-circle {
  489. width: 60rpx;
  490. height: 60rpx;
  491. margin: 0 10rpx;
  492. display: flex;
  493. justify-content: center;
  494. align-items: center;
  495. }
  496. .circle {
  497. height: 50rpx;
  498. width: 50rpx;
  499. background-color: #004a99;
  500. text-align: center;
  501. color: #fff;
  502. line-height: 50rpx;
  503. border-radius: 50rpx;
  504. }
  505. .checked-tag {
  506. height: 60rpx;
  507. width: 60rpx;
  508. line-height: 60rpx;
  509. border: 2rpx solid #ffffff;
  510. box-shadow: 0 0 0 2rpx #007aff;
  511. position: relative;
  512. z-index: 10;
  513. }
  514. .bg-green {
  515. background-color: seagreen;
  516. }
  517. .bg-yellow {
  518. background-color: yellow;
  519. color: #333;
  520. /* 黄色标签加深色文字,避免看不清 */
  521. }
  522. .bg-black {
  523. background-color: #102a43;
  524. }
  525. .bg-red {
  526. background-color: red;
  527. }
  528. .btn-panel {
  529. position: relative;
  530. width: 100%;
  531. height: 90rpx;
  532. overflow: visible;
  533. }
  534. .btn {
  535. position: absolute;
  536. height: 70rpx;
  537. line-height: 70rpx;
  538. padding: 0 20rpx;
  539. top: 50%;
  540. transform: translateY(-50%);
  541. background-color: #00aaff;
  542. color: #fff;
  543. border: 0 none;
  544. border-radius: 25rpx;
  545. }
  546. .btn-first {
  547. left: 15rpx;
  548. }
  549. .btn-second {
  550. right: 15rpx;
  551. }
  552. .number-input {
  553. width: 50%;
  554. }
  555. </style>