InspectionList.uvue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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" v-if="item.nature == '定性'">
  76. <radio class="radio-group-horizontal-rg" value="合格" :checked="item.result == '合格'">合格</radio>
  77. <radio class="radio-group-horizontal-rg" value="不合格" :checked="item.result == '不合格'">不合格</radio>
  78. </radio-group>
  79. <input v-model="item.result" class="surround uni-input" v-if="item.nature != '定性'"></input>
  80. </view>
  81. </view>
  82. <view class="info-row">
  83. <text class="label">备注</text>
  84. <view class="value">
  85. <input v-model="item.memo" class="surround uni-input" @confirm="remarksChange"></input>
  86. </view>
  87. </view>
  88. </view>
  89. </view>
  90. <!-- 空状态 -->
  91. <view v-else class="empty-card">
  92. <image src="/static/image/empty.png" class="empty-img" />
  93. <text class="empty-text">暂无检查检验记录</text>
  94. </view>
  95. <view class="info-row btn-panel">
  96. <button class="btn btn-first" @click="tabsClick(current-1)" v-if="current > 1">
  97. 前一项
  98. </button>
  99. <button class="btn btn-second" @click="tabsClick(current+1)" v-if="current < maxcount">
  100. 下一项
  101. </button>
  102. </view>
  103. <!-- #ifdef APP -->
  104. </scroll-view>
  105. <!-- #endif -->
  106. </template>
  107. <script setup>
  108. import { ref, computed } from 'vue' // 1. 引入 computed(计算属性核心)
  109. import { getJoinList, QcRecord, recordStatusDict, updateData } from '@/api/work';
  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. const getParsedValue = computed(() => {
  121. return (value : string | number) => {
  122. if (typeof value === 'number') {
  123. return value;
  124. }
  125. if (typeof value === 'string') {
  126. const num = parseFloat(value);
  127. return isNaN(num) ? 0 : num;
  128. }
  129. return 0;
  130. }
  131. });
  132. // 处理picker组件的点击事件,确保在安卓设备上可以正常触发
  133. const handlePickerClick = (e: any) => {
  134. // 这里可以添加一些处理逻辑,确保在安卓设备上可以正常打开picker
  135. console.log('Picker clicked');
  136. };
  137. // 4. 切换标签时更新 reportList(使用响应式的 initRecords)
  138. const tabsClick = (obj : number) => {
  139. current.value = obj;
  140. const filtered = initRecords.value.filter(item =>
  141. getParsedValue.value(item.no) === current.value
  142. );
  143. reportList.value = filtered;
  144. }
  145. const refreshRecords = (index : number) => {
  146. // 清空现有数据(响应式数组需操作 .value)
  147. initRecords.value = [];
  148. // #ifdef APP-ANDROID
  149. getJoinList(
  150. 'app_task_record as r',
  151. 'app_task_record_item as i',
  152. 'r.*,i.*',
  153. 'r.sxid=i.psxid',
  154. 'pdid',
  155. pdid,
  156. null
  157. ).then((res : UTSJSONObject) => {
  158. const dataList = res?.['data'] as UTSJSONObject[] ?? []
  159. if (dataList.length > 0) {
  160. dataList.forEach(item => {
  161. if (item != null) {
  162. const record = JSON.parse<QcRecord>(item.toJSONString());
  163. if (record != null) {
  164. initRecords.value.push(record)
  165. // 计算 maxcount 时使用数值转换,避免字符串干扰
  166. const noValue = getParsedValue.value(record.no)
  167. if (noValue > maxcount.value) {
  168. maxcount.value = noValue;
  169. }
  170. }
  171. }
  172. });
  173. }
  174. // 对initRecords按照no字段进行升序排序
  175. if (initRecords.value.length > 0) {
  176. initRecords.value.sort((a, b) => {
  177. const noA = getParsedValue.value(a.no);
  178. const noB = getParsedValue.value(b.no);
  179. return noA - noB;
  180. });
  181. current.value = index > 0 ? index : getParsedValue.value(initRecords.value[0].no);
  182. const filtered = initRecords.value.filter(item =>
  183. getParsedValue.value(item.no) === current.value
  184. );
  185. reportList.value = filtered;
  186. }
  187. });
  188. // #endif
  189. }
  190. const resultChange = (event : UniRadioGroupChangeEvent) => {
  191. // 获取当前选中的报告项
  192. const currentItem = reportList.value.find(item => parseInt(item.no) === current.value);
  193. if (currentItem != null) {
  194. // 更新结果值
  195. currentItem.result = event.detail.value;
  196. //更新数据库
  197. let updatedData = "result='" + currentItem.result + "'"
  198. updateData('app_task_record_item', updatedData, 'sxid', currentItem.sxid.toString()).then((res : UTSJSONObject) => {
  199. let data = res?.['data'] as boolean ?? false
  200. if (data != null && data== true) {
  201. uni.showToast({
  202. title: "保存成功!",
  203. });
  204. }
  205. });
  206. }
  207. }
  208. const minNumberChange = (event : UniInputConfirmEvent) => {
  209. // 获取当前选中的报告项
  210. const currentItem = reportList.value.find(item => parseInt(item.no) === current.value);
  211. if (currentItem != null) {
  212. // 更新结果值
  213. currentItem.measuredvalue = event.detail.value;
  214. //更新数据库
  215. let updatedData = "measuredvalue='" + currentItem.measuredvalue + "'"
  216. updateData('app_task_record_item', updatedData, 'sxid', currentItem.sxid.toString()).then((res : UTSJSONObject) => {
  217. let data = res?.['data'] as boolean ?? false
  218. if (data != null && data== true) {
  219. uni.showToast({
  220. title: "保存成功!",
  221. });
  222. }
  223. });
  224. }
  225. }
  226. const maxNumberChange = (event : UniInputConfirmEvent) => {
  227. // 获取当前选中的报告项
  228. const currentItem = reportList.value.find(item => parseInt(item.no) === current.value);
  229. if (currentItem != null) {
  230. // 更新结果值
  231. currentItem.measuredvaluemax = event.detail.value;
  232. //更新数据库
  233. let updatedData = "measuredvaluemax='" + currentItem.measuredvaluemax + "'"
  234. updateData('app_task_record_item', updatedData, 'sxid', currentItem.sxid.toString()).then((res : UTSJSONObject) => {
  235. let data = res?.['data'] as boolean ?? false
  236. if (data != null && data== true) {
  237. uni.showToast({
  238. title: "保存成功!",
  239. });
  240. }
  241. });
  242. }
  243. }
  244. const remarksChange = (event : UniInputConfirmEvent) => {
  245. // 获取当前选中的报告项
  246. const currentItem = reportList.value.find(item => parseInt(item.no) === current.value);
  247. if (currentItem != null) {
  248. // 更新结果值
  249. currentItem.memo = event.detail.value;
  250. //更新数据库
  251. let updatedData = "memo='" + currentItem.memo + "'"
  252. updateData('app_task_record_item', updatedData, 'sxid', currentItem.sxid.toString()).then((res : UTSJSONObject) => {
  253. let data = res?.['data'] as boolean ?? false
  254. if (data != null && data== true) {
  255. uni.showToast({
  256. title: "保存成功!",
  257. });
  258. }
  259. });
  260. }
  261. }
  262. onLoad((options) => {
  263. pdid = options?.pdid ?? "1"
  264. senum = options?.senum ?? "1"
  265. // 加载初始数据(转换 senum 为数值,避免字符串类型问题)
  266. refreshRecords(getParsedValue.value(senum))
  267. });
  268. </script>
  269. <style scoped>
  270. /* 样式部分保持不变,仅修复标签颜色冲突(tag=3时优先黄色) */
  271. .container {
  272. padding: 20px;
  273. background-color: #f5f7fa;
  274. flex: 1;
  275. box-sizing: border-box;
  276. }
  277. .banner {
  278. background: linear-gradient(135deg, #6dd5ed, #2193b0);
  279. border-radius: 12px;
  280. padding: 20px 15px;
  281. margin-bottom: 20px;
  282. box-shadow: 0 4px 8px rgba(33, 147, 176, 0.3);
  283. }
  284. .banner-title {
  285. color: white;
  286. font-size: 18px;
  287. font-weight: bold;
  288. text-align: center;
  289. }
  290. .box {
  291. width: 20px;
  292. background-color: #909193;
  293. border-radius: 7.5px;
  294. }
  295. .card-list {
  296. display: flex;
  297. flex-direction: column;
  298. }
  299. .card-list>.card {
  300. margin-bottom: 15px;
  301. }
  302. /* #ifndef APP-ANDROID */
  303. .card-list>.card:last-child {
  304. margin-bottom: 0;
  305. }
  306. /* #endif */
  307. .card {
  308. background-color: white;
  309. border-radius: 10px;
  310. padding: 15px;
  311. box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
  312. display: flex;
  313. flex-direction: column;
  314. }
  315. .card-header {
  316. display: flex;
  317. align-items: center;
  318. margin-bottom: 20rpx;
  319. }
  320. .card-icon {
  321. width: 64rpx;
  322. height: 64rpx;
  323. margin-right: 20rpx;
  324. border-radius: 12rpx;
  325. background-color: #eef5ff;
  326. padding: 10rpx;
  327. }
  328. .info-row {
  329. display: flex;
  330. flex-direction: row;
  331. font-size: 14px;
  332. color: #33475b;
  333. align-items: center;
  334. padding: 10px;
  335. }
  336. .label {
  337. font-weight: bold;
  338. color: #102a43;
  339. min-width: 75px;
  340. }
  341. .value {
  342. flex: 1;
  343. white-space: nowrap;
  344. overflow: hidden;
  345. text-overflow: ellipsis;
  346. }
  347. .divider {
  348. height: 1px;
  349. background-color: #eee;
  350. margin: 10px 0;
  351. }
  352. .card-info {
  353. font-size: 28rpx;
  354. color: #666;
  355. line-height: 1.6;
  356. display: flex;
  357. flex-direction: column;
  358. }
  359. .card-info>.card-info-item {
  360. margin-bottom: 10rpx;
  361. }
  362. /* #ifndef APP-ANDROID */
  363. .card-info>.card-info-item:last-child {
  364. margin-bottom: 0;
  365. }
  366. /* #endif */
  367. .btn-group {
  368. display: flex;
  369. justify-content: flex-end;
  370. margin-top: 20rpx;
  371. }
  372. .main-btn {
  373. font-size: 28rpx;
  374. color: white;
  375. border: none;
  376. border-radius: 100rpx;
  377. background: linear-gradient(to right, #36d1dc, #5b86e5);
  378. box-shadow: 0 6rpx 16rpx rgba(91, 134, 229, 0.3);
  379. /* #ifndef APP-ANDROID */
  380. transition: all 0.2s ease-in-out;
  381. /* #endif */
  382. }
  383. /* #ifndef APP-ANDROID */
  384. .main-btn:active {
  385. opacity: 0.9;
  386. transform: scale(0.98);
  387. }
  388. /* #endif */
  389. .empty-card {
  390. background-color: white;
  391. border-radius: 20rpx;
  392. padding: 60rpx 30rpx;
  393. box-shadow: 0 6rpx 16rpx rgba(0, 0, 0, 0.05);
  394. text-align: center;
  395. margin-top: 100rpx;
  396. }
  397. .empty-img {
  398. width: 180rpx;
  399. height: 180rpx;
  400. margin-bottom: 30rpx;
  401. opacity: 0.8;
  402. }
  403. .empty-text {
  404. font-size: 30rpx;
  405. color: #999;
  406. }
  407. .surround {
  408. border: 1px solid silver;
  409. border-radius: 10rpx;
  410. min-height: 60rpx;
  411. }
  412. .selectable {
  413. /* 确保在安卓设备上文字可以正常显示为可点击状态 */
  414. user-select: text;
  415. -webkit-user-select: text;
  416. cursor: pointer;
  417. /* #ifdef APP-ANDROID */
  418. /* 安卓设备特别处理,增强可点击性 */
  419. background-color: #f8f8f8;
  420. /* #endif */
  421. }
  422. .record-card {
  423. background: #ffffff;
  424. border-radius: 20rpx;
  425. padding: 24rpx 32rpx;
  426. box-shadow: 0 8rpx 15rpx rgba(0, 43, 92, 0.1);
  427. display: flex;
  428. flex-direction: column;
  429. margin-bottom: 20rpx;
  430. margin-top: 20rpx;
  431. }
  432. /* 横向排列radio的样式 */
  433. .radio-group-horizontal {
  434. display: flex;
  435. flex-direction: row;
  436. align-items: center;
  437. }
  438. .radio-group-horizontal-rg{
  439. margin-right: 30rpx;
  440. }
  441. .flex-row {
  442. flex-direction: row;
  443. }
  444. .tag-circle {
  445. width: 60rpx;
  446. height: 60rpx;
  447. margin: 0 10rpx;
  448. display: flex;
  449. justify-content: center;
  450. align-items: center;
  451. }
  452. .circle {
  453. height: 50rpx;
  454. width: 50rpx;
  455. background-color: #004a99;
  456. text-align: center;
  457. color: #fff;
  458. line-height: 50rpx;
  459. border-radius: 50rpx;
  460. }
  461. .checked-tag {
  462. height: 60rpx;
  463. width: 60rpx;
  464. line-height: 60rpx;
  465. border: 2rpx solid #ffffff;
  466. box-shadow: 0 0 0 2rpx #007aff;
  467. position: relative;
  468. z-index: 10;
  469. }
  470. .bg-green {
  471. background-color: seagreen;
  472. }
  473. .bg-yellow {
  474. background-color: yellow;
  475. color: #333;
  476. /* 黄色标签加深色文字,避免看不清 */
  477. }
  478. .bg-black {
  479. background-color: #102a43;
  480. }
  481. .bg-red {
  482. background-color: red;
  483. }
  484. .btn-panel {
  485. position: relative;
  486. width: 100%;
  487. height: 90rpx;
  488. overflow: visible;
  489. }
  490. .btn {
  491. position: absolute;
  492. height: 70rpx;
  493. line-height: 70rpx;
  494. padding: 0 20rpx;
  495. top: 50%;
  496. transform: translateY(-50%);
  497. background-color: #00aaff;
  498. color: #fff;
  499. border: 0 none;
  500. border-radius: 25rpx;
  501. }
  502. .btn-first {
  503. left: 15rpx;
  504. }
  505. .btn-second {
  506. right: 15rpx;
  507. }
  508. .number-input {
  509. width: 50%;
  510. }
  511. </style>