InspectionList.uvue 13 KB

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