InspectionList.uvue 17 KB

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