InspectionList.uvue 17 KB

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