InspectionList.uvue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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" :step="0.1" :min="0.5" 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" :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" :min="0"></uni-number-box>
  70. </view>
  71. </view>
  72. <view class="info-row">
  73. <text class="label">结论</text>
  74. <view class="value">
  75. <!-- <picker @change="bindPickerChange" :value="index" :range="array" v-if="item.nature == '定性'">
  76. <view class="uni-input">{{array[index]}}</view>
  77. </picker> -->
  78. <input v-model="item.result" class="surround uni-input" v-if="item.nature != '定性'"></input>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. <!-- 空状态 -->
  84. <view v-else class="empty-card">
  85. <image src="/static/image/empty.png" class="empty-img" />
  86. <text class="empty-text">暂无检查检验记录</text>
  87. </view>
  88. <view class="info-row btn-panel">
  89. <button class="btn btn-first" @click="tabsClick(current-1)" v-if="current > 1">
  90. 前一项
  91. </button>
  92. <button class="btn btn-second" @click="tabsClick(current+1)" v-if="current < maxcount">
  93. 下一项
  94. </button>
  95. </view>
  96. <!-- #ifdef APP -->
  97. </scroll-view>
  98. <!-- #endif -->
  99. </template>
  100. <script setup>
  101. import { ref, computed } from 'vue' // 1. 引入 computed(计算属性核心)
  102. import { getJoinList, QcRecord, recordStatusDict, updateData } from '@/api/work';
  103. // 存储页面参数
  104. let pdid = "";
  105. let senum = "";
  106. // 检查项目最大数量(改为 ref 响应式,避免值变化不更新)
  107. const maxcount = ref(5)
  108. const current = ref(1)
  109. const reportList = ref<QcRecord[]>([])
  110. const initRecords = ref<QcRecord[]>([])
  111. const currentMinNum = ref(0);
  112. const currentMaxNum = ref(0);
  113. const currentMeasuredValue = ref(0);
  114. const currentMeasuredMaxValue = ref(0);
  115. const getParsedValue = computed(() => {
  116. return (value : string | number) => {
  117. if (typeof value === 'number') {
  118. return value;
  119. }
  120. if (typeof value === 'string') {
  121. const num = parseFloat(value);
  122. return isNaN(num) ? 0 : num;
  123. }
  124. return 0;
  125. }
  126. });
  127. const updateCurrentValues = (currentItem : QcRecord) => {
  128. currentMinNum.value = getParsedValue.value(currentItem.minNum);
  129. currentMaxNum.value = getParsedValue.value(currentItem.maxNum);
  130. currentMeasuredValue.value = getParsedValue.value(currentItem.measuredvalue);
  131. currentMeasuredMaxValue.value = getParsedValue.value(currentItem.measuredvaluemax);
  132. };
  133. // 4. 切换标签时更新 reportList(使用响应式的 initRecords)
  134. const tabsClick = (obj : number) => {
  135. current.value = obj;
  136. const filtered = initRecords.value.filter(item =>
  137. getParsedValue.value(item.no) === current.value
  138. );
  139. reportList.value = filtered;
  140. if (filtered.length > 0) {
  141. updateCurrentValues(filtered[0]); // 手动更新数值
  142. }
  143. }
  144. const refreshRecords = (index : number) => {
  145. // 清空现有数据(响应式数组需操作 .value)
  146. initRecords.value = [];
  147. // #ifdef APP-ANDROID
  148. getJoinList(
  149. 'app_task_record as r',
  150. 'app_task_record_item as i',
  151. 'r.*,i.*',
  152. 'r.sxid=i.psxid',
  153. 'pdid',
  154. pdid,
  155. null
  156. ).then((res : UTSJSONObject) => {
  157. const dataList = res?.['data'] as UTSJSONObject[] ?? []
  158. if (dataList.length > 0) {
  159. dataList.forEach(item => {
  160. if (item != null) {
  161. const record = JSON.parse<QcRecord>(item.toJSONString());
  162. if (record != null) {
  163. initRecords.value.push(record)
  164. // 计算 maxcount 时使用数值转换,避免字符串干扰
  165. const noValue = getParsedValue.value(record.no)
  166. if (noValue > maxcount.value) {
  167. maxcount.value = noValue;
  168. }
  169. }
  170. }
  171. });
  172. }
  173. // 对initRecords按照no字段进行升序排序
  174. if (initRecords.value.length > 0) {
  175. initRecords.value.sort((a, b) => {
  176. const noA = getParsedValue.value(a.no);
  177. const noB = getParsedValue.value(b.no);
  178. return noA - noB;
  179. });
  180. current.value = index > 0 ? index : getParsedValue.value(initRecords.value[0].no);
  181. const filtered = initRecords.value.filter(item =>
  182. getParsedValue.value(item.no) === current.value
  183. );
  184. reportList.value = filtered;
  185. if (filtered.length > 0) {
  186. updateCurrentValues(filtered[0]); // 初始化数值
  187. }
  188. }
  189. });
  190. // #endif
  191. }
  192. onLoad((options) => {
  193. pdid = options?.pdid ?? "1"
  194. senum = options?.senum ?? "1"
  195. // 加载初始数据(转换 senum 为数值,避免字符串类型问题)
  196. refreshRecords(getParsedValue.value(senum))
  197. });
  198. </script>
  199. <style scoped>
  200. /* 样式部分保持不变,仅修复标签颜色冲突(tag=3时优先黄色) */
  201. .container {
  202. padding: 20px;
  203. background-color: #f5f7fa;
  204. flex: 1;
  205. box-sizing: border-box;
  206. }
  207. .banner {
  208. background: linear-gradient(135deg, #6dd5ed, #2193b0);
  209. border-radius: 12px;
  210. padding: 20px 15px;
  211. margin-bottom: 20px;
  212. box-shadow: 0 4px 8px rgba(33, 147, 176, 0.3);
  213. }
  214. .banner-title {
  215. color: white;
  216. font-size: 18px;
  217. font-weight: bold;
  218. text-align: center;
  219. }
  220. .box {
  221. width: 20px;
  222. background-color: #909193;
  223. border-radius: 7.5px;
  224. }
  225. .card-list {
  226. display: flex;
  227. flex-direction: column;
  228. }
  229. .card-list>.card {
  230. margin-bottom: 15px;
  231. }
  232. /* #ifndef APP-ANDROID */
  233. .card-list>.card:last-child {
  234. margin-bottom: 0;
  235. }
  236. /* #endif */
  237. .card {
  238. background-color: white;
  239. border-radius: 10px;
  240. padding: 15px;
  241. box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
  242. display: flex;
  243. flex-direction: column;
  244. }
  245. .card-header {
  246. display: flex;
  247. align-items: center;
  248. margin-bottom: 20rpx;
  249. }
  250. .card-icon {
  251. width: 64rpx;
  252. height: 64rpx;
  253. margin-right: 20rpx;
  254. border-radius: 12rpx;
  255. background-color: #eef5ff;
  256. padding: 10rpx;
  257. }
  258. .info-row {
  259. display: flex;
  260. flex-direction: row;
  261. font-size: 14px;
  262. color: #33475b;
  263. align-items: center;
  264. padding: 10px;
  265. }
  266. .label {
  267. font-weight: bold;
  268. color: #102a43;
  269. min-width: 75px;
  270. }
  271. .value {
  272. flex: 1;
  273. white-space: nowrap;
  274. overflow: hidden;
  275. text-overflow: ellipsis;
  276. }
  277. .divider {
  278. height: 1px;
  279. background-color: #eee;
  280. margin: 10px 0;
  281. }
  282. .card-info {
  283. font-size: 28rpx;
  284. color: #666;
  285. line-height: 1.6;
  286. display: flex;
  287. flex-direction: column;
  288. }
  289. .card-info>.card-info-item {
  290. margin-bottom: 10rpx;
  291. }
  292. /* #ifndef APP-ANDROID */
  293. .card-info>.card-info-item:last-child {
  294. margin-bottom: 0;
  295. }
  296. /* #endif */
  297. .btn-group {
  298. display: flex;
  299. justify-content: flex-end;
  300. margin-top: 20rpx;
  301. }
  302. .main-btn {
  303. font-size: 28rpx;
  304. color: white;
  305. border: none;
  306. border-radius: 100rpx;
  307. background: linear-gradient(to right, #36d1dc, #5b86e5);
  308. box-shadow: 0 6rpx 16rpx rgba(91, 134, 229, 0.3);
  309. /* #ifndef APP-ANDROID */
  310. transition: all 0.2s ease-in-out;
  311. /* #endif */
  312. }
  313. /* #ifndef APP-ANDROID */
  314. .main-btn:active {
  315. opacity: 0.9;
  316. transform: scale(0.98);
  317. }
  318. /* #endif */
  319. .empty-card {
  320. background-color: white;
  321. border-radius: 20rpx;
  322. padding: 60rpx 30rpx;
  323. box-shadow: 0 6rpx 16rpx rgba(0, 0, 0, 0.05);
  324. text-align: center;
  325. margin-top: 100rpx;
  326. }
  327. .empty-img {
  328. width: 180rpx;
  329. height: 180rpx;
  330. margin-bottom: 30rpx;
  331. opacity: 0.8;
  332. }
  333. .empty-text {
  334. font-size: 30rpx;
  335. color: #999;
  336. }
  337. .surround {
  338. border: 1px solid silver;
  339. border-radius: 10rpx;
  340. }
  341. .record-card {
  342. background: #ffffff;
  343. border-radius: 20rpx;
  344. padding: 24rpx 32rpx;
  345. box-shadow: 0 8rpx 15rpx rgba(0, 43, 92, 0.1);
  346. display: flex;
  347. flex-direction: column;
  348. margin-bottom: 20rpx;
  349. margin-top: 20rpx;
  350. }
  351. .flex-row {
  352. flex-direction: row;
  353. }
  354. .tag-circle {
  355. width: 60rpx;
  356. height: 60rpx;
  357. margin: 0 10rpx;
  358. display: flex;
  359. justify-content: center;
  360. align-items: center;
  361. }
  362. .circle {
  363. height: 50rpx;
  364. width: 50rpx;
  365. background-color: #004a99;
  366. text-align: center;
  367. color: #fff;
  368. line-height: 50rpx;
  369. border-radius: 50rpx;
  370. }
  371. .checked-tag {
  372. height: 60rpx;
  373. width: 60rpx;
  374. line-height: 60rpx;
  375. border: 2rpx solid #ffffff;
  376. box-shadow: 0 0 0 2rpx #007aff;
  377. position: relative;
  378. z-index: 10;
  379. }
  380. .bg-green {
  381. background-color: seagreen;
  382. }
  383. .bg-yellow {
  384. background-color: yellow;
  385. color: #333;
  386. /* 黄色标签加深色文字,避免看不清 */
  387. }
  388. .bg-black {
  389. background-color: #102a43;
  390. }
  391. .bg-red {
  392. background-color: red;
  393. }
  394. .btn-panel {
  395. position: relative;
  396. width: 100%;
  397. height: 90rpx;
  398. overflow: visible;
  399. }
  400. .btn {
  401. position: absolute;
  402. height: 70rpx;
  403. line-height: 70rpx;
  404. padding: 0 20rpx;
  405. top: 50%;
  406. transform: translateY(-50%);
  407. background-color: #00aaff;
  408. color: #fff;
  409. border: 0 none;
  410. border-radius: 25rpx;
  411. }
  412. .btn-first {
  413. left: 15rpx;
  414. }
  415. .btn-second {
  416. right: 15rpx;
  417. }
  418. </style>