DownloadList.uvue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <template>
  2. <view class="container">
  3. <!-- 搜索栏 -->
  4. <view class="info-row btn-panel search-bar">
  5. <view class="search-input">
  6. <input type="text" v-model="productNo" placeholder="请输入工序码"/>
  7. </view>
  8. <view class="scan-btn" @click="scanQRCode">
  9. <uni-icons type="scan" size="32" color="#00aaff"></uni-icons>
  10. </view>
  11. </view>
  12. <!-- 按钮面板 -->
  13. <view class="info-row btn-panel">
  14. <button class="btn btn-first" @click="download">
  15. 下载数据
  16. </button>
  17. <button class="btn btn-second" @click="search">
  18. 搜索
  19. </button>
  20. </view>
  21. <!-- 列表内容 -->
  22. <!-- #ifdef APP -->
  23. <scroll-view style="flex:1">
  24. <!-- #endif -->
  25. <view class="download-card" v-for="(item, index) in downloads" :key="index" >
  26. <view @click="enterItem(item.pdid)">
  27. <view class="info-row" v-if="item.uploadFlag == 1 && (item.photoStatus + item.keyStatus + item.recordStatus)
  28. == (item.photoTotal + item.keyTotal + item.recordTotal)">
  29. <uni-icons class="my-icon" size="24" color="green" type="checkbox"></uni-icons>
  30. <text style="color: green;">已上传</text>
  31. </view>
  32. <view class="info-row">
  33. <text class="label">工序:</text>
  34. <text class="value">{{ item.gxno }}</text>
  35. </view>
  36. <view class="info-row">
  37. <text class="label">路卡号:</text>
  38. <text class="value">{{ item.cardno }}</text>
  39. </view>
  40. <view class="info-row">
  41. <text class="label">工作令:</text>
  42. <text class="value">{{ item.workorder }}</text>
  43. </view>
  44. <view class="info-row">
  45. <text class="label">产品名称:</text>
  46. <text class="value">{{ item.invname }}</text>
  47. </view>
  48. <view class="info-row">
  49. <text class="label">图号:</text>
  50. <text class="value">{{ item.graphid }}</text>
  51. </view>
  52. <view class="info-row">
  53. <text class="label">工艺编号:</text>
  54. <text class="value">{{ item.processno }}</text>
  55. </view>
  56. <view class="info-row">
  57. <text class="label">版本号:</text>
  58. <text class="value">{{ item.ver }}</text>
  59. </view>
  60. <view class="info-row">
  61. <text class="label">最近更新时间:</text>
  62. <text class="value">{{ item.lastupdatetime }}</text>
  63. </view>
  64. <view class="info-row">
  65. <text class="label">进度:</text>
  66. <text class="process-value" :class="{
  67. 'bg-green': ( item.photoStatus + item.keyStatus + item.recordStatus) == (item.photoTotal + item.keyTotal + item.recordTotal),
  68. 'bg-yellow': ( item.photoStatus + item.keyStatus + item.recordStatus) < (item.photoTotal + item.keyTotal + item.recordTotal),
  69. 'bg-black': ( item.photoStatus + item.keyStatus + item.recordStatus) == 0
  70. }"> {{ (item.photoStatus + item.keyStatus + item.recordStatus) }} / {{(item.photoTotal + item.keyTotal + item.recordTotal)}} </text>
  71. </view>
  72. <view class="info-row">
  73. <text class="label">上传时间:</text>
  74. <text class="value">{{ item.uploadtime }}</text>
  75. </view>
  76. </view>
  77. <view class="info-row">
  78. <button class="btn btn-second" @click="upload(item)">
  79. 上传数据
  80. </button>
  81. </view>
  82. </view>
  83. <!-- #ifdef APP -->
  84. </scroll-view>
  85. <!-- #endif -->
  86. </view>
  87. </template>
  88. <script setup>
  89. import { ref, reactive } from 'vue'
  90. import { getTaskInfoList } from '@/api/work';
  91. import { downloadDataFromAPI, uploadDataToAPI } from '@/utils/qcDataProcessor.uts';
  92. // 产品号输入框数据
  93. const productNo = ref('PI02297172');
  94. const backPressOptions = reactive({
  95. from: 'backbutton'
  96. } as OnBackPressOptions)
  97. onBackPress((options : OnBackPressOptions) : boolean | null => {
  98. // 使用reLaunch代替switchTab,避免多层跳转时的闪回问题
  99. // reLaunch会关闭所有页面并打开到目标页面,适合需要完全重置导航栈的场景
  100. uni.reLaunch({
  101. url: `/pages/work/index`,
  102. })
  103. // 返回true表示拦截默认返回行为
  104. return true
  105. })
  106. type Task = {
  107. pdid : number,
  108. gxpk : string,
  109. cardno : string,
  110. productcode : string,
  111. model : string,
  112. workorder : string,
  113. invname : string,
  114. graphid : string,
  115. processno : string,
  116. gxno : string,
  117. ver : string,
  118. lastupdatetime : string,
  119. photoStatus : number,
  120. keyStatus : number,
  121. recordStatus : number,
  122. photoTotal: number,
  123. keyTotal: number,
  124. recordTotal: number,
  125. uploadFlag: number,
  126. uploadtime : string,
  127. }
  128. var initDownloads = [] as Task[]
  129. var downloads = ref<Task[]>([]);
  130. const map = ref(new Map<number, string>([[1, '未执行'], [2, '执行中'], [3, '执行完'], [4, '有错误']]))
  131. // #ifdef APP-ANDROID
  132. getTaskInfoList('', null).then((res : UTSJSONObject) => {
  133. let dataList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>()
  134. if (dataList != null && dataList.length > 0) {
  135. dataList.forEach(item => {
  136. if (item != null) {
  137. let download = JSON.parse<Task>(item.toJSONString());
  138. if (download != null) {
  139. initDownloads.push(download)
  140. }
  141. }
  142. });
  143. }
  144. downloads.value = initDownloads
  145. })
  146. // #endif
  147. // #ifdef H5
  148. downloads = [{
  149. pdid: 1,
  150. workorder: "632-P-01",
  151. invname: "箱间段",
  152. productno: "1CFA1040-00#S",
  153. graphid: '',
  154. ver: '',
  155. cardno: "LK20230707070012",
  156. processno: "Pb/XXX-E11",
  157. updatetime: "2025-06-23",
  158. createtime : "2025-06-23",
  159. totalRecord : 3,
  160. statusRecordCount : 3,
  161. uploadFlag: 1,
  162. status: 3
  163. }, {
  164. pdid: 2,
  165. workorder: "712-SY-10-6",
  166. invname: "级间架",
  167. productno: "1XA1020-00A",
  168. graphid: '',
  169. ver: '',
  170. cardno: "LK20250215003",
  171. processno: "Pb/XXX-E11",
  172. createtime : "2025-06-23",
  173. updatetime: "2025-08-25",
  174. totalRecord : 4,
  175. statusRecordCount : 2,
  176. uploadFlag: 1,
  177. status: 2
  178. }, {
  179. pdid: 3,
  180. workorder: "712-SY-10-6",
  181. invname: "级间架",
  182. productno: "1XA1020-00A",
  183. graphid: '',
  184. ver: '',
  185. cardno: "LK20250215003",
  186. processno: "Pb/XXX-E11",
  187. createtime : "2025-06-23",
  188. updatetime: "2025-08-25",
  189. totalRecord : 4,
  190. statusRecordCount : 0,
  191. uploadFlag: 1,
  192. status: 1
  193. }] as Task[];
  194. // #endif
  195. const download = async (e : any) => {
  196. console.log("开始下载...")
  197. // 调用数据处理工具中的方法下载数据
  198. if(productNo.value == null || productNo.value == '') {
  199. uni.showToast({
  200. title: '请先扫描或者输入工序码',
  201. icon: 'error'
  202. });
  203. return
  204. }
  205. await downloadDataFromAPI(productNo.value, () => {
  206. // 回调函数中执行刷新,确保数据都保存好,进度条跑完
  207. uni.reLaunch({ url: '/pages/work/download/DownloadList' })
  208. }).then((res) => {
  209. // 移除这里的刷新逻辑,避免过早刷新
  210. })
  211. }
  212. const upload = async (e : Task) => {
  213. if((e.photoStatus + e.keyStatus + e.recordStatus ) != (e.photoTotal + e.keyTotal + e.recordTotal)) {
  214. uni.showToast({
  215. title: '当前任务还未完成!',
  216. icon: 'error'
  217. });
  218. return
  219. }
  220. console.log("开始上传...")
  221. uploadDataToAPI(e.gxpk, () => {
  222. uni.reLaunch({ url: '/pages/work/download/DownloadList' })
  223. }).then((res) => {
  224. // 移除这里的刷新逻辑,避免过早刷新
  225. })
  226. }
  227. const enterItem = (id : number) => {
  228. uni.navigateTo({
  229. url: `/pages/work/download/DownloadDetail?id=${id}`
  230. });
  231. }
  232. // 扫描二维码功能
  233. const scanQRCode = () => {
  234. uni.scanCode({
  235. success: (res) => {
  236. // 扫描成功,将结果填充到输入框
  237. productNo.value = res.result;
  238. console.log('扫描结果:', res.result);
  239. },
  240. fail: (err) => {
  241. console.error('扫描失败:', err);
  242. uni.showToast({
  243. title: '扫描失败,请重试',
  244. icon: 'error'
  245. });
  246. }
  247. });
  248. }
  249. const search = async () => {
  250. // 检查productNo是否为空
  251. if (productNo.value == null || productNo.value.trim() == '') {
  252. uni.showToast({
  253. title: '请输入产品号',
  254. icon: 'error'
  255. });
  256. return;
  257. }
  258. // 显示加载提示
  259. uni.showLoading({
  260. title: '搜索中...'
  261. });
  262. try {
  263. // 使用getRecordInfoList函数并传入productNo.value作为第一个参数
  264. let query = `m.gxpk like '%${productNo.value}%'`
  265. const res = await getTaskInfoList(query, null);
  266. console.log('搜索结果:', res);
  267. let dataList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>();
  268. let searchResults = [] as Task[];
  269. if (dataList != null && dataList.length > 0) {
  270. dataList.forEach(item => {
  271. if (item != null) {
  272. try {
  273. let download = JSON.parse<Task>(item.toJSONString());
  274. if (download != null) {
  275. searchResults.push(download);
  276. }
  277. } catch (e) {
  278. console.error('解析数据失败:', e);
  279. }
  280. }
  281. });
  282. }
  283. // 更新downloads数组,显示搜索结果
  284. downloads.value = searchResults;
  285. // 如果没有搜索到结果,显示提示
  286. if (searchResults.length === 0) {
  287. uni.showToast({
  288. title: '未找到相关数据',
  289. icon: 'none'
  290. });
  291. }
  292. } catch (error) {
  293. console.error('搜索失败:', error);
  294. uni.showToast({
  295. title: '搜索失败,请重试',
  296. icon: 'error'
  297. });
  298. } finally {
  299. // 隐藏加载提示
  300. uni.hideLoading();
  301. }
  302. }
  303. defineExpose({
  304. backPressOptions
  305. })
  306. </script>
  307. <style scope>
  308. .container {
  309. padding: 24rpx;
  310. background-color: #f0f4f8;
  311. flex: 1;
  312. display: flex;
  313. flex-direction: column;
  314. font-family: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif;
  315. /* #ifndef APP-ANDROID */
  316. min-height: 100vh;
  317. /* #endif */
  318. height: 120rpx;
  319. }
  320. .search-bar {
  321. background-color: #ffffff;
  322. border-radius: 10rpx;
  323. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  324. }
  325. /* 搜索输入框:占满容器剩余空间,放在按钮左侧 */
  326. .search-input {
  327. /* 清除默认输入框样式 */
  328. border: none;
  329. background: transparent;
  330. width: 70%;
  331. margin-left: 10rpx;
  332. }
  333. /* 扫描按钮:放在输入框右侧,距离最右10rpx */
  334. .scan-btn {
  335. justify-content: center;
  336. align-items: center; /* 新增:按钮内部图标垂直居中 */
  337. /* 关键:右侧10rpx边距,实现"距离最右10rpx" */
  338. margin-left: auto; /* 自动推到flex容器最右侧 */
  339. margin-right: 10rpx; /* 与容器右边缘保持10rpx间距 */
  340. }
  341. .download-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: 40rpx;
  350. margin-left: 20rpx;
  351. margin-right: 20rpx;
  352. }
  353. .download-card .view {
  354. margin-bottom: 16rpx;
  355. }
  356. /* 信息行 */
  357. .info-row {
  358. display: flex;
  359. flex-direction: row;
  360. font-size: 28rpx;
  361. color: #33475b;
  362. align-items: center;
  363. }
  364. .info-row>.label {
  365. margin-left: 10rpx;
  366. }
  367. .info-row>.value {
  368. margin-left: 10rpx;
  369. }
  370. .btn-panel {
  371. display: flex;
  372. justify-content: space-between;
  373. align-items: center;
  374. margin-left: 5rpx;
  375. margin-right: 5rpx;
  376. }
  377. .label {
  378. font-weight: bold;
  379. color: #102a43;
  380. min-width: 100rpx;
  381. }
  382. .value {
  383. flex: 1;
  384. white-space: nowrap;
  385. overflow: hidden;
  386. text-overflow: ellipsis;
  387. }
  388. .btn {
  389. align-self: flex-end;
  390. background-color: #00aaff;
  391. color: #fff;
  392. border: none;
  393. border-radius: 32rpx;
  394. padding: 2rpx 30rpx;
  395. font-size: 24rpx;
  396. font-weight: bold;
  397. /* #ifndef APP-ANDROID */
  398. transition: background-color 0.3s ease;
  399. /* #endif */
  400. margin-top: 30rpx;
  401. }
  402. .process-value {
  403. width: 120rpx;
  404. min-width: 100rpx;
  405. text-align: center;
  406. border-radius: 10rpx;
  407. }
  408. .bg-green {
  409. background-color: seagreen;
  410. }
  411. .bg-yellow {
  412. background-color: yellow;
  413. }
  414. .bg-black {
  415. background-color: #102a43;
  416. }
  417. .btn-first {
  418. margin-left: 5rpx;
  419. }
  420. .btn-second {
  421. margin-right: 5rpx;
  422. margin-left: auto;
  423. }
  424. .my-icon {
  425. margin-right: 5rpx;
  426. margin-left: auto;
  427. }
  428. </style>