InspectionList.uvue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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, addOperateLog } 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. addOperateLog({ module: '检验任务', title: '更新检验任务', content: `更新了检验任务信息,产品码:${currentItem.prodno}, 序号为:${currentItem.sxid}`, msg: null, createuser: getCurrentUserSync()??'' })
  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. addOperateLog({ module: '检验任务', title: '更新检验任务', content: `更新了检验任务信息,产品码:${currentItem.prodno}, 序号为:${currentItem.sxid}`, msg: null, createuser: getCurrentUserSync()??'' })
  273. }
  274. }
  275. const maxNumberChange = (event : UniInputConfirmEvent) => {
  276. // 获取当前选中的报告项
  277. const currentItem = reportList.value.find(item => parseInt(item.no) === current.value);
  278. if (currentItem != null) {
  279. // 更新结果值
  280. currentItem.measuredvaluemax = event.detail.value;
  281. //更新数据库
  282. let updatedData = "measuredvaluemax='" + currentItem.measuredvaluemax + "', recorder='" + getCurrentUserSync() + "' "
  283. if (currentItem.nature == '定量') {
  284. // 初始化结果为合格
  285. currentItem.result = '合格';
  286. // 解析实测值
  287. const measuredMin = parseFloat(currentItem.measuredvalue ?? '0');
  288. const measuredMax = parseFloat(currentItem.measuredvaluemax ?? '0');
  289. // 检查下限值
  290. if (currentItem.minNum != null && currentItem.minNum != '') {
  291. const minLimit = parseFloat(currentItem.minNum);
  292. // 实测最大值和最小值都需要大于等于下限值
  293. if (measuredMin < minLimit || measuredMax < minLimit) {
  294. currentItem.result = '不合格';
  295. }
  296. }
  297. // 检查上限值
  298. if (currentItem.result === '合格' && currentItem.maxNum != null && currentItem.maxNum != '') {
  299. const maxLimit = parseFloat(currentItem.maxNum);
  300. // 实测最大值和最小值都需要小于等于上限值
  301. if (measuredMin > maxLimit || measuredMax > maxLimit) {
  302. currentItem.result = '不合格';
  303. }
  304. }
  305. // 如果上下限都为空,结果保持为合格
  306. updatedData += " ,result = '" + currentItem.result + "', recorder='" + getCurrentUserSync() + "' "
  307. }
  308. updateData('app_task_record_item', updatedData, 'sxid', currentItem.sxid.toString()).then((res : UTSJSONObject) => {
  309. let data = res?.['data'] as boolean ?? false
  310. if (data != null && data== true) {
  311. uni.showToast({
  312. title: "保存成功!",
  313. });
  314. }
  315. });
  316. addOperateLog({ module: '检验任务', title: '更新检验任务', content: `更新了检验任务信息,产品码:${currentItem.prodno}, 序号为:${currentItem.sxid}`, msg: null, createuser: getCurrentUserSync()??'' })
  317. }
  318. }
  319. const remarksChange = (event : UniInputConfirmEvent) => {
  320. // 获取当前选中的报告项
  321. const currentItem = reportList.value.find(item => parseInt(item.no) === current.value);
  322. if (currentItem != null) {
  323. // 更新结果值
  324. currentItem.memo = event.detail.value;
  325. //更新数据库
  326. let updatedData = "memo='" + currentItem.memo + "', recorder='" + getCurrentUserSync() + "' "
  327. updateData('app_task_record_item', updatedData, 'sxid', currentItem.sxid.toString()).then((res : UTSJSONObject) => {
  328. let data = res?.['data'] as boolean ?? false
  329. if (data != null && data== true) {
  330. uni.showToast({
  331. title: "保存成功!",
  332. });
  333. }
  334. });
  335. addOperateLog({ module: '检验任务', title: '更新检验任务', content: `更新了检验任务信息,产品码:${currentItem.prodno}, 序号为:${currentItem.sxid}`, msg: null, createuser: getCurrentUserSync()??'' })
  336. }
  337. }
  338. onLoad((options) => {
  339. pdid = options?.pdid ?? "1"
  340. senum = options?.senum ?? "1"
  341. // 加载初始数据(转换 senum 为数值,避免字符串类型问题)
  342. refreshRecords(getParsedValue.value(senum))
  343. });
  344. defineExpose({
  345. backPressOptions
  346. })
  347. </script>
  348. <style scoped>
  349. /* 样式部分保持不变,仅修复标签颜色冲突(tag=3时优先黄色) */
  350. .container {
  351. padding: 20px;
  352. background-color: #f5f7fa;
  353. flex: 1;
  354. box-sizing: border-box;
  355. }
  356. .banner {
  357. background: linear-gradient(135deg, #6dd5ed, #2193b0);
  358. border-radius: 12px;
  359. padding: 20px 15px;
  360. margin-bottom: 20px;
  361. box-shadow: 0 4px 8px rgba(33, 147, 176, 0.3);
  362. }
  363. .banner-title {
  364. color: white;
  365. font-size: 18px;
  366. font-weight: bold;
  367. text-align: center;
  368. }
  369. .box {
  370. width: 20px;
  371. background-color: #909193;
  372. border-radius: 7.5px;
  373. }
  374. .card-list {
  375. display: flex;
  376. flex-direction: column;
  377. }
  378. .card-list>.card {
  379. margin-bottom: 15px;
  380. }
  381. /* #ifndef APP-ANDROID */
  382. .card-list>.card:last-child {
  383. margin-bottom: 0;
  384. }
  385. /* #endif */
  386. .card {
  387. background-color: white;
  388. border-radius: 10px;
  389. padding: 15px;
  390. box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
  391. display: flex;
  392. flex-direction: column;
  393. }
  394. .card-header {
  395. display: flex;
  396. align-items: center;
  397. margin-bottom: 20rpx;
  398. }
  399. .card-icon {
  400. width: 64rpx;
  401. height: 64rpx;
  402. margin-right: 20rpx;
  403. border-radius: 12rpx;
  404. background-color: #eef5ff;
  405. padding: 10rpx;
  406. }
  407. .info-row {
  408. display: flex;
  409. flex-direction: row;
  410. font-size: 14px;
  411. color: #33475b;
  412. align-items: center;
  413. padding: 10px;
  414. }
  415. .label {
  416. font-weight: bold;
  417. color: #102a43;
  418. min-width: 75px;
  419. }
  420. .value {
  421. flex: 1;
  422. white-space: nowrap;
  423. overflow: hidden;
  424. text-overflow: ellipsis;
  425. }
  426. .divider {
  427. height: 1px;
  428. background-color: #eee;
  429. margin: 10px 0;
  430. }
  431. .card-info {
  432. font-size: 28rpx;
  433. color: #666;
  434. line-height: 1.6;
  435. display: flex;
  436. flex-direction: column;
  437. }
  438. .card-info>.card-info-item {
  439. margin-bottom: 10rpx;
  440. }
  441. /* #ifndef APP-ANDROID */
  442. .card-info>.card-info-item:last-child {
  443. margin-bottom: 0;
  444. }
  445. /* #endif */
  446. .btn-group {
  447. display: flex;
  448. justify-content: flex-end;
  449. margin-top: 20rpx;
  450. }
  451. .main-btn {
  452. font-size: 28rpx;
  453. color: white;
  454. border: none;
  455. border-radius: 100rpx;
  456. background: linear-gradient(to right, #36d1dc, #5b86e5);
  457. box-shadow: 0 6rpx 16rpx rgba(91, 134, 229, 0.3);
  458. /* #ifndef APP-ANDROID */
  459. transition: all 0.2s ease-in-out;
  460. /* #endif */
  461. }
  462. /* #ifndef APP-ANDROID */
  463. .main-btn:active {
  464. opacity: 0.9;
  465. transform: scale(0.98);
  466. }
  467. /* #endif */
  468. .empty-card {
  469. background-color: white;
  470. border-radius: 20rpx;
  471. padding: 60rpx 30rpx;
  472. box-shadow: 0 6rpx 16rpx rgba(0, 0, 0, 0.05);
  473. text-align: center;
  474. margin-top: 100rpx;
  475. }
  476. .empty-img {
  477. width: 180rpx;
  478. height: 180rpx;
  479. margin-bottom: 30rpx;
  480. opacity: 0.8;
  481. }
  482. .empty-text {
  483. font-size: 30rpx;
  484. color: #999;
  485. }
  486. .surround {
  487. border: 2rpx solid #eee;
  488. border-radius: 10rpx;
  489. min-height: 60rpx;
  490. background-color: #f5f6f7;
  491. }
  492. .selectable {
  493. /* 确保在安卓设备上文字可以正常显示为可点击状态 */
  494. user-select: text;
  495. -webkit-user-select: text;
  496. cursor: pointer;
  497. /* #ifdef APP-ANDROID */
  498. /* 安卓设备特别处理,增强可点击性 */
  499. background-color: #f8f8f8;
  500. /* #endif */
  501. }
  502. .record-card {
  503. background: #ffffff;
  504. border-radius: 20rpx;
  505. padding: 24rpx 32rpx;
  506. box-shadow: 0 8rpx 15rpx rgba(0, 43, 92, 0.1);
  507. display: flex;
  508. flex-direction: column;
  509. margin-bottom: 20rpx;
  510. margin-top: 20rpx;
  511. }
  512. /* 横向排列radio的样式 */
  513. .radio-group-horizontal {
  514. display: flex;
  515. flex-direction: row;
  516. align-items: center;
  517. }
  518. .radio-group-horizontal-rg{
  519. margin-right: 30rpx;
  520. }
  521. .flex-row {
  522. flex-direction: row;
  523. }
  524. .tag-circle {
  525. width: 60rpx;
  526. height: 60rpx;
  527. margin: 0 10rpx;
  528. display: flex;
  529. justify-content: center;
  530. align-items: center;
  531. }
  532. .circle {
  533. height: 50rpx;
  534. width: 50rpx;
  535. background-color: #004a99;
  536. text-align: center;
  537. color: #fff;
  538. line-height: 50rpx;
  539. border-radius: 50rpx;
  540. }
  541. .checked-tag {
  542. height: 60rpx;
  543. width: 60rpx;
  544. line-height: 60rpx;
  545. border: 2rpx solid #ffffff;
  546. box-shadow: 0 0 0 2rpx #007aff;
  547. position: relative;
  548. z-index: 10;
  549. }
  550. .bg-text {
  551. width: 120rpx;
  552. min-width: 100rpx;
  553. border-radius: 10rpx;
  554. text-align: center;
  555. }
  556. .bg-green {
  557. background-color: seagreen;
  558. }
  559. .bg-yellow {
  560. background-color: yellow;
  561. color: #333;
  562. /* 黄色标签加深色文字,避免看不清 */
  563. }
  564. .bg-black {
  565. background-color: #102a43;
  566. }
  567. .bg-red {
  568. background-color: red;
  569. }
  570. .btn-panel {
  571. position: relative;
  572. width: 100%;
  573. height: 90rpx;
  574. overflow: visible;
  575. }
  576. .btn {
  577. position: absolute;
  578. height: 70rpx;
  579. line-height: 70rpx;
  580. padding: 0 20rpx;
  581. top: 50%;
  582. transform: translateY(-50%);
  583. background-color: #00aaff;
  584. color: #fff;
  585. border: 0 none;
  586. border-radius: 25rpx;
  587. }
  588. .btn-first {
  589. left: 15rpx;
  590. }
  591. .btn-second {
  592. right: 15rpx;
  593. }
  594. .number-input {
  595. width: 50%;
  596. }
  597. </style>