form.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. <template>
  2. <view class="page-container uni-column">
  3. <view class="carrier-info uni-column">
  4. <view class="carrier-code uni-row">
  5. <text>箱号</text>
  6. <text style="margin-left: 24rpx;">{{processInspecion.lot.allCarrierName}}</text>
  7. </view>
  8. <view class="info-row uni-row">
  9. <view class="label">图号</view>
  10. <view class="value">{{ processInspecion.lot.drawingNumber }}</view>
  11. </view>
  12. <view class="info-row uni-row">
  13. <view class="label">批次号</view>
  14. <view class="value">{{ processInspecion.lot.lotCode }}</view>
  15. </view>
  16. <view class="info-row uni-row">
  17. <view class="label">工艺版本</view>
  18. <view class="value">{{ processInspecion.lot.technologyVersion }}</view>
  19. </view>
  20. <view class="info-row uni-row">
  21. <view class="label">产品描述</view>
  22. <view class="value">{{processInspecion.lot. productDescription }}</view>
  23. </view>
  24. <view class="info-row uni-row">
  25. <view class="label">当前工序</view>
  26. <view class="value">{{ processInspecion.lot.processAlias }}</view>
  27. </view>
  28. <view class="info-row uni-row">
  29. <view class="label">投产数量</view>
  30. <view class="value">{{ processInspecion.lot.pudName }}</view>
  31. </view>
  32. </view>
  33. <!-- 废品信息 -->
  34. <view class="title unfit-title uni-row">
  35. <text>废品信息</text>
  36. <view class="add-btn" @click="handleAddWaste">添加</view>
  37. </view>
  38. <view class="unfit-container">
  39. <view class="unfit-item-container uni-column" v-for="(item, index) in unfitInfos" :key="index">
  40. <!-- 暂时注释,后续会使用 -->
  41. <!-- <view class="title uni-row">
  42. <text>检查项-{{ item.title }}</text>
  43. <uni-icons type="trash" size="24" color="#fc6565" @click="handleDelWaste(index)" />
  44. </view> -->
  45. <!-- <view class="standard">检查标准:{{ item.standard }}</view> -->
  46. <view class="resu uni-row">
  47. <view class="label">检查标准</view>
  48. <input v-model="item.checkStandard" placeholder="请输入检查标准" />
  49. <uni-icons type="trash" size="24" style="margin-left: 55rpx;" color="#fc6565"
  50. @click="handleDelWaste(index)" />
  51. </view>
  52. <view class="result uni-row">
  53. <view class="label">检查结果</view>
  54. <input v-model="item.checkResult" placeholder="请输入检查结果" />
  55. <view class="label" style="text-align: right; padding-right: 16rpx;">数量
  56. </view>
  57. <input class="number" type="number" @blur="rejectNumberChange" v-model="item.rejectNum"
  58. placeholder="" />
  59. </view>
  60. </view>
  61. </view>
  62. <!-- 咨询部分 -->
  63. <view class="title">咨询</view>
  64. <view class="consultation-container uni-column">
  65. <view class="consultation-item-container" v-for="(item, index) in consultations" :key="index">
  66. <view class="question uni-column">
  67. <view class="label uni-row">
  68. <text>问题描述</text>
  69. <text :style="selectType(item)">{{item.consultDepartment == 0?'技术':'品管'}} {{ selectText(item) }}</text>
  70. </view>
  71. <view class="content">{{ item.content }}</view>
  72. </view>
  73. <!-- 不需要暂时注释 -->
  74. <!-- <view v-if="item.answer !== ''" class="answer"
  75. style="margin-top: 24rpx; padding-top: 24rpx; border-top: 1px dotted #aaaaaa;">
  76. <view class="label">回复</view>
  77. <view class="content">{{ item.answer }}</view>
  78. </view> -->
  79. </view>
  80. </view>
  81. <!-- 报工部分 -->
  82. <view class="daywork-container">
  83. <!-- 此处后续要加上条件限制,当状态为合格或不合格的时候不能修改状态,需要有权限的人来进行修改 -->
  84. <view class="result uni-row">
  85. <view class="label">检测量</view>
  86. <input type="number" v-model="processInspecion.examiningNum" placeholder="请输入检测量" />
  87. <view class="label" style="text-align: right; padding-right: 24rpx">废品量</view>
  88. <input type="number" v-model="processInspecion.rejectNum" placeholder="请输入废品量" />
  89. </view>
  90. <view class="result uni-row">
  91. <view class="label" style="margin-top: 20rpx; margin-right: 10rpx;">序检状态</view>
  92. <uni-data-checkbox style="margin-top: 20rpx;" v-model="processInspecion.status"
  93. :localdata="range"></uni-data-checkbox>
  94. <!-- @change="change" -->
  95. </view>
  96. <view class="remark uni-row">
  97. <view class="label">备注</view>
  98. <textarea v-model="processInspecion.remark" />
  99. </view>
  100. <view class="btns-container uni-row">
  101. <view class="finished-btn" @click="endWork">结束报工</view>
  102. <view class="question-btn uni-column" @click.stop="handleAddConsultation">
  103. <uni-icons type="headphones" size="24" />
  104. <text>咨询</text>
  105. </view>
  106. </view>
  107. </view>
  108. </view>
  109. </template>
  110. <script setup>
  111. import {
  112. ref,
  113. onMounted,
  114. getCurrentInstance
  115. } from 'vue'
  116. import {
  117. onLoad,
  118. onReady,
  119. onUnload,
  120. onShow
  121. } from '@dcloudio/uni-app'
  122. import {
  123. store
  124. } from '@/store/index.js'
  125. import {
  126. saveProcessInspecion,
  127. selectInspecion
  128. } from '@/api/business/processInspection.js'
  129. const lot = ref({})
  130. const isEventTriggered = ref(false); // 创建一个标志位
  131. const unfitInfos = ref([]) //废品信息
  132. const consultations = ref([]) //咨询信息
  133. // 创建一个引用来存储最后一次请求的时间戳
  134. const lastRequestTimestamp = ref(0);
  135. const processInspecion = ref({
  136. remark: "",
  137. rejectNum: 0,
  138. examiningNum: 0,
  139. status: 0,
  140. })
  141. const consul = [{
  142. value: 0,
  143. text: "待确认",
  144. type: "color: #fcab53"
  145. }, {
  146. value: 2,
  147. text: "合格",
  148. type: "color: #55ff7f"
  149. }, {
  150. value: 1,
  151. text: "不合格",
  152. type: "color: #ff0c2c"
  153. }]
  154. const range = [{
  155. value: 0,
  156. text: "待确认",
  157. type: "color: #fcab53"
  158. }, {
  159. value: 1,
  160. text: "合格",
  161. type: "color: #55ff7f"
  162. }, {
  163. value: 2,
  164. text: "不合格",
  165. type: "color: #ff0c2c"
  166. }]
  167. /***************************** 页面生命周期函数 *****************************/
  168. onMounted(() => {
  169. const instance = getCurrentInstance().proxy
  170. const eventChannel = instance.getOpenerEventChannel();
  171. eventChannel.on('processInspectionFrom', function(data) {
  172. console.log('acceptDataFromOpenerPage', data)
  173. if (data && data.data) {
  174. processInspecion.value.lot = data.data;
  175. }
  176. })
  177. })
  178. onShow(() => {
  179. if (store.processInspection != null) {
  180. uni.showLoading({
  181. title: '加载中'
  182. });
  183. processInspecion.value = store.processInspection
  184. selectInspecion(processInspecion.value).then(res => {
  185. if (res.code == 200) {
  186. processInspecion.value = res.data;
  187. unfitInfos.value = res.data.dayworkItemRejects;
  188. consultations.value = res.data.dayworkItemConsults;
  189. console.log("res", res);
  190. uni.hideLoading();
  191. // getInspecion();
  192. } else {
  193. uni.showToast({
  194. icon: 'none',
  195. title: res.msg,
  196. duration: 2000
  197. })
  198. }
  199. });
  200. }
  201. })
  202. /***************************** 定义了一些方法 *****************************/
  203. //咨询文本
  204. function selectText(item) {
  205. for (var i = 0; i < consul.length; i++) {
  206. if (item.status == consul[i].value) {
  207. return consul[i].text
  208. }
  209. }
  210. }
  211. const rejectNumberChange = () => {
  212. let sumReject = 0
  213. unfitInfos.value.forEach(v => {
  214. sumReject += Number(v.rejectNum)
  215. })
  216. processInspecion.value.rejectNum = sumReject
  217. console.log(processInspecion.value)
  218. }
  219. //查询咨询列表
  220. function getInspecion() {
  221. processInspecion.value = store.processInspection
  222. selectInspecion(processInspecion.value).then(res => {
  223. console.log("咨询", res);
  224. if (res.code == 200) {
  225. console.log("res", res);
  226. } else {
  227. uni.showToast({
  228. icon: 'none',
  229. title: res.msg,
  230. duration: 2000
  231. })
  232. }
  233. });
  234. }
  235. //结束报工按钮
  236. function endWork() {
  237. let unf = unfitInfos.value;
  238. for (var i = 0; i < unfitInfos.value.length; i++) {
  239. if (!unf[i].checkStandard && !unf[i].checkResult && !unf[i].rejectNum) {
  240. uni.showToast({
  241. icon: 'none',
  242. title: "废品信息不能为空",
  243. duration: 2000
  244. })
  245. return;
  246. }
  247. }
  248. let sumReject = 0
  249. unfitInfos.value.forEach(v => {
  250. sumReject += Number(v.rejectNum)
  251. })
  252. if (processInspecion.value.rejectNum != sumReject) {
  253. uni.showToast({
  254. icon: 'none',
  255. title: "废品量与废品信息不一致",
  256. duration: 2000
  257. })
  258. return;
  259. }
  260. save();
  261. }
  262. function save() {
  263. const currentTime = Date.now();
  264. // 检查是否已经过去了 2 秒
  265. if (currentTime - lastRequestTimestamp.value < 2000) {
  266. // 如果在 2 秒 内已经点击,那么不执行
  267. uni.showToast({
  268. icon: 'none',
  269. title: `请勿重复点击`,
  270. duration: 2000
  271. })
  272. return;
  273. }
  274. let pages = getCurrentPages();
  275. processInspecion.value.dayworkItemConsults = consultations.value;
  276. processInspecion.value.dayworkItemRejects = unfitInfos.value;
  277. processInspecion.value.user = store.userInfo;
  278. saveProcessInspecion(processInspecion.value).then(res => {
  279. if (res.code == 200) {
  280. let index = 0;
  281. for (let i = 0; i < pages.length; i++) {
  282. if (pages[i].$page.fullPath == "/pages/processInspection/index") {
  283. index = pages.length - i - 1;
  284. }
  285. }
  286. console.log("index", index);
  287. uni.navigateBack({
  288. delta: index
  289. });
  290. } else {
  291. uni.showToast({
  292. icon: 'none',
  293. title: res.msg,
  294. duration: 2000
  295. })
  296. }
  297. });
  298. }
  299. //咨询样式
  300. function selectType(item) {
  301. for (var i = 0; i < consul.length; i++) {
  302. if (item.status == consul[i].value) {
  303. return consul[i].type
  304. }
  305. }
  306. }
  307. const addWasteInfo = (data) => {
  308. const info = {
  309. title: data.title,
  310. checkStandard: data.standard
  311. }
  312. unfitInfos.value.push(info)
  313. }
  314. const addConsultation = (data) => {
  315. let info = data
  316. info.forEach(item =>{
  317. item.status = 0
  318. })
  319. consultations.value = info
  320. isEventTriggered.value = true; // 更新标志位状态
  321. }
  322. /***************************** 定义了一些事件 *****************************/
  323. // 添加不合格信息
  324. const handleAddWaste = () => {
  325. let info = {}
  326. unfitInfos.value.push(info)
  327. // 监听事件,暂时不用,后续会使用
  328. // uni.$once('addWasteInfoEvent', (data) => {
  329. // addWasteInfo(data)
  330. // })
  331. // uni.navigateTo({
  332. // url: "/pages/processInspection/options"
  333. // })
  334. }
  335. // 删除不合格信息
  336. const handleDelWaste = (index) => {
  337. uni.showModal({
  338. title: '提示',
  339. content: '确定删除该项?',
  340. success: function(res) {
  341. if (res.confirm) {
  342. unfitInfos.value.splice(index, 1)
  343. } else if (res.cancel) {
  344. return
  345. }
  346. }
  347. })
  348. }
  349. // 咨询
  350. const handleAddConsultation = () => {
  351. isEventTriggered.value = false;
  352. // 监听事件
  353. uni.$once('addWasteConsultationEvent', (data) => {
  354. if (!isEventTriggered.value) {
  355. // 如果事件尚未触发,则执行事件触发逻辑
  356. addConsultation(data)
  357. }
  358. })
  359. uni.navigateTo({
  360. url: "/pages/processInspection/consultation",
  361. success: (res) => {
  362. // 通过eventChannel向被打开页面传送数据
  363. res.eventChannel.emit("processInspectionConsultation", {
  364. data: processInspecion.value.lot
  365. })
  366. }
  367. })
  368. }
  369. </script>
  370. <style lang="scss">
  371. .page-container {
  372. height: 100%;
  373. background-color: #ececec;
  374. font-size: 28rpx;
  375. >.title {
  376. font-weight: 700;
  377. margin: 24rpx 16rpx;
  378. }
  379. }
  380. .carrier-info {
  381. margin: 32rpx 16rpx 0 16rpx;
  382. padding: 24rpx;
  383. background-color: #ffffff;
  384. border-radius: 8rpx;
  385. .carrier-code {
  386. font-size: 32rpx;
  387. font-weight: 700;
  388. }
  389. .info-row {
  390. margin-top: 16rpx;
  391. color: #767676;
  392. .label {
  393. width: 160rpx;
  394. }
  395. .value {
  396. flex: 1;
  397. textarea {
  398. flex: 1;
  399. border: 1px solid #888888;
  400. box-sizing: border-box;
  401. padding: 16rpx;
  402. }
  403. }
  404. }
  405. }
  406. .unfit-title {
  407. margin-bottom: 24rpx;
  408. justify-content: space-between;
  409. align-items: center;
  410. text {
  411. font-size: 28rpx;
  412. font-weight: 700;
  413. }
  414. .add-btn {
  415. padding: 12rpx 32rpx;
  416. background-color: #a4adb3;
  417. color: #ffffff;
  418. border-radius: 12rpx;
  419. font-size: 24rpx;
  420. }
  421. }
  422. .unfit-container {
  423. padding: 24rpx;
  424. margin: 0 16rpx;
  425. background-color: #ffffff;
  426. border-radius: 12rpx;
  427. .unfit-item-container {
  428. position: relative;
  429. >* {
  430. margin-bottom: 24rpx;
  431. }
  432. .title {
  433. font-weight: 700;
  434. justify-content: space-between;
  435. align-items: center;
  436. image {
  437. width: 40rpx;
  438. height: 40rpx;
  439. }
  440. }
  441. .standard {}
  442. .resu {
  443. width: 100%;
  444. align-items: center;
  445. input {
  446. margin-left: 20rpx;
  447. width: 200rpx;
  448. height: 56rpx;
  449. flex: 1;
  450. border: 1px solid #9f9f9f;
  451. font-size: 28rpx;
  452. }
  453. }
  454. .result {
  455. align-items: center;
  456. border-bottom: 1px solid #9f9f9f;
  457. padding-bottom: 32rpx;
  458. .label {
  459. flex: 1;
  460. }
  461. input {
  462. width: 280rpx;
  463. height: 56rpx;
  464. border: 1px solid #9f9f9f;
  465. font-size: 28rpx;
  466. &.number {
  467. width: 104rpx;
  468. text-align: center;
  469. }
  470. }
  471. }
  472. }
  473. .unfit-item-container:last-child {
  474. .result {
  475. border-bottom: none;
  476. padding-bottom: 0;
  477. }
  478. }
  479. }
  480. .consultation-container {
  481. margin: 0 16rpx;
  482. padding: 24rpx;
  483. background-color: #ffffff;
  484. border-radius: 8rpx;
  485. .consultation-item-container {
  486. margin-bottom: 24rpx;
  487. border-bottom: 2px solid #888888;
  488. padding-bottom: 24rpx;
  489. }
  490. .consultation-item-container:last-child {
  491. margin-bottom: 0;
  492. border-bottom: 0;
  493. padding-bottom: 0;
  494. }
  495. .question,
  496. .answer {
  497. .label {
  498. justify-content: space-between;
  499. margin-bottom: 16rpx;
  500. font-weight: 700;
  501. }
  502. .content {
  503. line-height: 40rpx;
  504. }
  505. }
  506. .answer {
  507. margin-top: 24rpx;
  508. }
  509. }
  510. .daywork-container {
  511. margin-top: 24rpx;
  512. padding: 24rpx;
  513. background-color: #ffffff;
  514. border: 1px solid #bcbcbc;
  515. .result {
  516. align-items: center;
  517. .label {
  518. width: 112rpx;
  519. }
  520. input {
  521. flex: 1;
  522. height: 56rpx;
  523. border: 1px solid #9f9f9f;
  524. font-size: 28rpx;
  525. text-align: center;
  526. }
  527. }
  528. .remark {
  529. margin-top: 24rpx;
  530. .label {
  531. width: 112rpx;
  532. }
  533. textarea {
  534. flex: 1;
  535. border: 1px solid #9f9f9f;
  536. height: 168rpx;
  537. }
  538. }
  539. .btns-container {
  540. margin-top: 24rpx;
  541. .finished-btn {
  542. display: flex;
  543. flex: 1;
  544. height: 80rpx;
  545. background-color: #fc6565;
  546. color: #ffffff;
  547. text-align: center;
  548. justify-content: center;
  549. align-items: center;
  550. border-radius: 8rpx;
  551. }
  552. .question-btn {
  553. width: 80rpx;
  554. align-items: flex-end;
  555. image {
  556. width: 48rpx;
  557. height: 48rpx;
  558. }
  559. text {
  560. font-size: 24rpx;
  561. }
  562. }
  563. }
  564. }
  565. </style>