InspectionList.uvue 17 KB

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