form.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. <template>
  2. <view class="page-container uni-column">
  3. <view class="lot-info uni-column">
  4. <view class="lot-code uni-row">
  5. <text>批次号</text>
  6. <text style="margin-left: 24rpx;">{{ dayworkItem.lotCode }}</text>
  7. </view>
  8. <view class="product-info">
  9. 产品描述: {{ dayworkItem.productDescription }}
  10. </view>
  11. <view class="product-info">
  12. 原材料厂家: {{ dayworkInfo.furnaceNoInfo.factory }}
  13. </view>
  14. <view class="product-info">
  15. 投产数量: {{ dayworkItem.prodNum }}
  16. </view>
  17. </view>
  18. <!-- 不合格信息 -->
  19. <view class="title unfit-title uni-row">
  20. <text>不合格信息</text>
  21. <view v-if="Number(dayworkItem.status) < 3" class="add-btn" @click="handleAddUnfit">添加</view>
  22. </view>
  23. <view class="unfit-container">
  24. <view class="unfit-item-container uni-column" v-for="(item, index) in unfitInfos" :key="index">
  25. <view class="title uni-row">
  26. <text>检查标准-{{ item.checkStandard }}</text>
  27. <uni-icons v-if="Number(dayworkItem.status) < 3" type="trash" size="24" color="#fc6565"
  28. @click="handleDelUnfit(index)" />
  29. </view>
  30. <!-- <view class="standard">检查标准:{{ item.checkStandard }}</view> -->
  31. <view class="result uni-row" style="display: flex;flex-direction: row;justify-content: space-between;">
  32. <!-- align-items: flex-start; -->
  33. <view class="label" style="padding-right: 16rpx;flex: 0 1 auto; min-width: 118rpx;">
  34. 检查结果</view>
  35. <input v-if="Number(dayworkItem.status) < 3" v-model="item.reason" placeholder="请输入检查结果" />
  36. <span v-else style="flex-grow: 1;">{{ item.reason }}</span>
  37. <view class="label"
  38. style="text-align: right; padding-right: 16rpx;flex: 0 1 auto; min-width: 68rpx;">数量</view>
  39. <input v-if="Number(dayworkItem.status) < 3" class="number" type="number" v-model="item.rejectNum"
  40. @blur="rejectNumberChange" />
  41. <span v-else>{{ item.rejectNum }}</span>
  42. </view>
  43. </view>
  44. </view>
  45. <!-- 咨询部分 -->
  46. <view class="title">咨询</view>
  47. <view class="consultation-container uni-column">
  48. <view class="consultation-item-container" v-for="(item, index) in consultations" :key="index">
  49. <view class="question uni-column">
  50. <view class="label uni-row">
  51. <text>问题描述</text>
  52. <text :style="{ color: showStatusColor(item.status) }">{{item.consultDepartment == 0?'技术':'品管'}} {{ showStatus(item.status) }}</text>
  53. </view>
  54. <view class="content">{{ item.content }}</view>
  55. </view>
  56. <!-- <view v-if="item.answer !== ''" class="answer"
  57. style="margin-top: 24rpx; padding-top: 24rpx; border-top: 1px dotted #aaaaaa;">
  58. <view class="label">回复</view>
  59. <view class="content">{{ item.answer }}</view>
  60. </view> -->
  61. </view>
  62. </view>
  63. <!-- 报工部分 -->
  64. <view class="daywork-container">
  65. <view class="result uni-row">
  66. <view class="label">合格量</view>
  67. <input v-if="Number(dayworkItem.status) < 3" type="number" placeholder="请输入合格量"
  68. v-model="dayworkItem.qualifiedNum" />
  69. <span v-else>{{ dayworkItem.qualifiedNum }}</span>
  70. <view class="label" style="text-align: right; padding-right: 24rpx">废品量</view>
  71. <input v-if="Number(dayworkItem.status) < 3" :disabled="true" type="number" placeholder="请输入废品量"
  72. v-model="dayworkItem.rejectNum" />
  73. <span v-else>{{ dayworkItem.rejectNum }}</span>
  74. </view>
  75. <view class="remark uni-row">
  76. <view class="label">备注</view>
  77. <textarea v-if="Number(dayworkItem.status) < 3" v-model="dayworkItem.remark" />
  78. <span v-else>{{ dayworkItem.remark }}</span>
  79. </view>
  80. <view class="btns-container uni-row">
  81. <!-- 最后一步完成不能更换载具 -->
  82. <view v-if="dayworkItem.daywork != null && dayworkItem.daywork.status != 2" class="bottom-btn left-btn "
  83. @click="handleChangeCarrier">
  84. 更换载具</view>
  85. <view v-if="checkFinishable()&&Number(dayworkItem.status) < 3" class="finished-btn"
  86. @click.stop="handleFinishDaywork">结束报工</view>
  87. <view v-if="!checkFinishable()&&Number(dayworkItem.status) < 3" class="pause-btn"
  88. @click.stop="handleUpdateDaywork">暂停</view>
  89. <view v-if="Number(dayworkItem.status) < 3" class="question-btn uni-column"
  90. @click.stop="handleAddConsultation">
  91. <uni-icons type="headphones" size="24" />
  92. <text>咨询</text>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. </template>
  98. <script setup>
  99. import {
  100. ref
  101. } from 'vue'
  102. import {
  103. onMounted,
  104. getCurrentInstance
  105. } from 'vue';
  106. import {
  107. getSortingDayworkItem,
  108. saveConsult,
  109. finish,
  110. update
  111. } from '@/api/business/sortDaywork.js'
  112. import {
  113. getTakeStockPeriod
  114. } from '@/api/business/taksStackLot.js'
  115. import {
  116. onLoad,
  117. onReady,
  118. onUnload,
  119. onShow
  120. } from '@dcloudio/uni-app'
  121. import {
  122. store
  123. } from '@/store/index.js'
  124. const isEventTriggered = ref(false); // 创建一个标志位
  125. const unfitInfos = ref([])
  126. const consultations = ref([])
  127. const dayworkInfo = ref({})
  128. // 创建一个引用来存储最后一次请求的时间戳
  129. const lastRequestTimestamp = ref(0);
  130. const dayworkItem = ref({})
  131. /***************************** 页面生命周期函数 *****************************/
  132. onShow(() => {
  133. })
  134. onMounted(() => {
  135. const instance = getCurrentInstance().proxy
  136. const eventChannel = instance.getOpenerEventChannel();
  137. eventChannel.on('acceptDataFromOpenerPage', function(data) {
  138. if (data && data.data) {
  139. dayworkInfo.value = data.data
  140. init({
  141. id: data.data.id
  142. })
  143. } else {
  144. let reqParam = {
  145. id: dayworkInfo.value.id
  146. }
  147. init(reqParam);
  148. }
  149. })
  150. })
  151. /***************************** 定义了一些方法 *****************************/
  152. const init = (data) => {
  153. console.log("dayworkInfo", dayworkInfo.value);
  154. // 获取当前报工信息
  155. getSortingDayworkItem(data).then(res => {
  156. console.log(res)
  157. if (res.code === 200) {
  158. dayworkItem.value = res.data
  159. console.log(dayworkItem.value)
  160. if (dayworkItem.value.qualifiedNum === 0 && dayworkItem.value.rejectNum === 0) {
  161. dayworkItem.value.qualifiedNum = res.data.prodNum
  162. }
  163. consultations.value = res.data.consults
  164. unfitInfos.value = res.data.rejectList
  165. } else {
  166. uni.showToast({
  167. icon: none,
  168. title: res.message
  169. })
  170. }
  171. })
  172. }
  173. const addUnfitInfo = (data) => {
  174. console.log(data)
  175. if (data.index > unfitInfos.value.length) {
  176. const info = {
  177. inspectionInstructionId: data.id,
  178. title: data.title,
  179. standard: data.standard,
  180. checkStandard: data.standard,
  181. type: data.type,
  182. reason: ''
  183. }
  184. unfitInfos.value.push(info)
  185. }
  186. }
  187. const addConsultation = (data) => {
  188. const info = {
  189. dayworkItemId: dayworkItem.value.id,
  190. content: data.content,
  191. userId: store.userInfo.userId,
  192. nickName: store.userInfo.nickName,
  193. dayworkId: dayworkItem.value.dayworkId,
  194. productionPlandetailId: dayworkItem.value.productionPlandetailId,
  195. productionPlanDetailSubDetailId: dayworkItem.value.productionPlanDetailSubDetailId,
  196. lotId: dayworkItem.value.lotId,
  197. lotCode: dayworkItem.value.lotCode,
  198. productId: dayworkItem.value.productId,
  199. productDescription: dayworkItem.value.productDescription,
  200. technologicalProcessId: dayworkItem.value.technologicalProcessId,
  201. technologicalProcessDetailId: dayworkItem.value.technologicalProcessDetailId,
  202. processId: dayworkItem.value.processId,
  203. processAlias: dayworkItem.value.process.processAlias,
  204. technicianId: dayworkItem.value.technicianId,
  205. departments : data.departments,
  206. pictures : data.pictures
  207. }
  208. saveConsult(info).then(res => {
  209. if (res.code === 200) {
  210. consultations.value = res.data
  211. console.log(consultations.value)
  212. } else {
  213. uni.showToast({
  214. icon: 'none',
  215. title: res.message
  216. })
  217. }
  218. })
  219. isEventTriggered.value = true; // 更新标志位状态
  220. consultations.value.push(info)
  221. }
  222. /***************************** 定义了一些事件 *****************************/
  223. // 添加不合格信息
  224. const handleAddUnfit = () => {
  225. // 监听事件
  226. uni.$once('addUnfitInfoEvent', (data) => {
  227. addUnfitInfo(data)
  228. })
  229. // console.log(dayworkItem.value)
  230. uni.navigateTo({
  231. url: "/pages/sorting/options",
  232. success: (res) => {
  233. // 通过eventChannel向被打开页面传送数据
  234. res.eventChannel.emit('acceptDataFromOpenerPage', {
  235. data: dayworkItem.value,
  236. query: {
  237. productId: dayworkItem.value.daywork.productId,
  238. processId: dayworkItem.value.process.id,
  239. technologyVersion: dayworkItem.value.technologicalProcessDetail
  240. .technologyVersion
  241. },
  242. index: unfitInfos.value.length
  243. })
  244. }
  245. })
  246. }
  247. // 删除不合格信息
  248. const handleDelUnfit = (index) => {
  249. let tempInfo = unfitInfos.value[index]
  250. console.log(tempInfo)
  251. uni.showModal({
  252. title: '提示',
  253. content: '确定删除该项?',
  254. success: function(res) {
  255. if (res.confirm) {
  256. dayworkItem.value.rejectNum = dayworkItem.value.rejectNum - tempInfo.rejectNum
  257. dayworkItem.value.qualifiedNum = parseInt(dayworkItem.value.qualifiedNum) + parseInt(
  258. tempInfo.rejectNum)
  259. unfitInfos.value.splice(index, 1)
  260. } else if (res.cancel) {
  261. return
  262. }
  263. }
  264. })
  265. }
  266. /* 更换载具*/
  267. function handleChangeCarrier(item) {
  268. // uni.$once('refreshQuickReport', () => {
  269. // init()
  270. // })
  271. store.dayworkInfo = null
  272. uni.navigateTo({
  273. url: "/pages/changeBox/index",
  274. success: function(res) {
  275. // 通过eventChannel向被打开页面传送数据
  276. res.eventChannel.emit('sortingFromOpenerPage', {
  277. data: dayworkItem.value
  278. })
  279. }
  280. })
  281. }
  282. // 添加不合格信息
  283. const handleAddConsultation = () => {
  284. isEventTriggered.value = false; // 更新标志位状态
  285. // 监听事件
  286. uni.$once('addConsulttationEvent', (data) => {
  287. if (!isEventTriggered.value) {
  288. // 如果事件尚未触发,则执行事件触发逻辑
  289. addConsultation(data)
  290. }
  291. })
  292. uni.navigateTo({
  293. url: "/pages/sorting/consultation",
  294. success: (res) => {
  295. // 通过eventChannel向被打开页面传送数据
  296. res.eventChannel.emit('acceptDataFromOpenerPage', {
  297. data: dayworkItem.value
  298. })
  299. }
  300. })
  301. }
  302. const checkFinishable = () => {
  303. if (consultations.value.findIndex(v => v.status === 0) >= 0) {
  304. return false
  305. } else {
  306. return true
  307. }
  308. }
  309. const showStatus = (status) => {
  310. // console.log(status)
  311. switch (status) {
  312. case 0:
  313. return '未确认'
  314. case 1:
  315. return '不合格'
  316. case 2:
  317. return '合格'
  318. default:
  319. return ''
  320. }
  321. }
  322. const showStatusColor = (status) => {
  323. // console.log(status)
  324. switch (status) {
  325. case 0:
  326. return '#fcab53'
  327. case 1:
  328. return '#fc044f'
  329. case 2:
  330. return '#1deb19'
  331. default:
  332. return ''
  333. }
  334. }
  335. const rejectNumberChange = () => {
  336. let sumReject = 0
  337. unfitInfos.value.forEach(v => {
  338. sumReject += v.rejectNum == null ? 0 : Number(v.rejectNum)
  339. })
  340. dayworkItem.value.rejectNum = sumReject
  341. dayworkItem.value.qualifiedNum = dayworkItem.value.prodNum - sumReject
  342. console.log(dayworkItem.value)
  343. }
  344. const validHandle = () => {
  345. for (let i = 0; i < unfitInfos.value.length; i++) {
  346. const e = unfitInfos.value[i]
  347. if (e.rejectNum == null || e.rejectNum == 0) {
  348. uni.showToast({
  349. icon: 'none',
  350. title: `第${i + 1}条不合格信息未输入不合格数量`
  351. })
  352. return false
  353. }
  354. }
  355. if (!dayworkItem.value.qualifiedNum) {
  356. uni.showToast({
  357. icon: 'none',
  358. title: "合格数不能为空",
  359. duration: 2000
  360. })
  361. return false;
  362. }
  363. if (dayworkItem.value.qualifiedNum < 0) {
  364. uni.showToast({
  365. icon: 'none',
  366. title: "合格数不能为负数,请检查不合格信息后提交",
  367. duration: 2000
  368. })
  369. return false;
  370. }
  371. return true
  372. // unfitInfos.value.forEach((e, i) => {
  373. // if (e.name)
  374. // })
  375. }
  376. async function handleCheckStock() {
  377. let currentProcessStepNumber = dayworkInfo.value.currentProcess.processStepNumber;
  378. let lastProcess = dayworkInfo.value.processSequence[dayworkInfo.value.processSequence.length - 1];
  379. // 判断当前工序是否是最后一道序
  380. if (currentProcessStepNumber === lastProcess.processStepNumber) {
  381. // 等待 getTakeStockPeriod() 的 Promise 完成
  382. const res = await getTakeStockPeriod({dayworkId: dayworkInfo.value.id});
  383. console.log(res.data.length);
  384. if (res.data.length > 0) {
  385. uni.showToast({
  386. icon: 'none',
  387. title: "此次盘点未结束,不能结束报工",
  388. duration: 2000
  389. });
  390. return false; // 如果盘点未结束,返回 false
  391. }
  392. }
  393. // 如果不是最后一道工序或盘点已结束,返回 true
  394. return true;
  395. }
  396. async function handleFinishDaywork() {
  397. if (!validHandle()) {
  398. return
  399. }
  400. //判断当前批次是否在盘点,如果盘点未结束,则不能结束报工
  401. let checkStockResult = await handleCheckStock();
  402. console.log(checkStockResult)
  403. if(!checkStockResult ) {
  404. return;
  405. }
  406. console.log("777")
  407. const saveData = {
  408. rejectList: unfitInfos.value,
  409. consult: consultations.value,
  410. id: dayworkItem.value.id,
  411. prodNum: dayworkItem.value.prodNum,
  412. rejectNum: dayworkItem.value.rejectNum,
  413. qualifiedNum: dayworkItem.value.qualifiedNum,
  414. remark: dayworkItem.value.remark
  415. }
  416. const currentTime = Date.now();
  417. // 检查是否已经过去了 2 秒
  418. if (currentTime - lastRequestTimestamp.value < 2000) {
  419. // 如果在 2 秒 内已经点击,那么不执行
  420. uni.showToast({
  421. icon: 'none',
  422. title: `请勿重复点击`,
  423. duration: 2000
  424. })
  425. return;
  426. }
  427. finish(saveData).then(res => {
  428. if (res.code === 200) {
  429. uni.navigateBack()
  430. } else {
  431. uni.showToast({
  432. icon: 'none',
  433. title: res.message
  434. })
  435. }
  436. })
  437. }
  438. const handleUpdateDaywork = () => {
  439. if (!validHandle()) {
  440. return
  441. }
  442. const saveData = {
  443. rejectList: unfitInfos.value,
  444. consult: consultations.value,
  445. id: dayworkItem.value.id,
  446. prodNum: dayworkItem.value.prodNum,
  447. rejectNum: dayworkItem.value.rejectNum,
  448. qualifiedNum: dayworkItem.value.qualifiedNum,
  449. remark: dayworkItem.value.remark
  450. }
  451. update(saveData).then(res => {
  452. if (res.code === 200) {
  453. uni.$emit("formBack")
  454. uni.navigateBack()
  455. } else {
  456. uni.showToast({
  457. icon: 'none',
  458. title: res.message
  459. })
  460. }
  461. })
  462. }
  463. </script>
  464. <style lang="scss">
  465. .page-container {
  466. height: 100%;
  467. background-color: #ececec;
  468. font-size: 28rpx;
  469. >.title {
  470. font-weight: 700;
  471. margin: 24rpx 16rpx;
  472. }
  473. }
  474. .lot-info {
  475. margin: 32rpx 16rpx 0 16rpx;
  476. padding: 24rpx;
  477. background-color: #ffffff;
  478. border-radius: 8rpx;
  479. .lot-code {
  480. font-size: 32rpx;
  481. font-weight: 700;
  482. margin-bottom: 16rpx;
  483. }
  484. .product-info {
  485. font-size: 28rpx;
  486. color: #9f9f9f;
  487. }
  488. }
  489. .unfit-title {
  490. margin-bottom: 24rpx;
  491. justify-content: space-between;
  492. align-items: center;
  493. text {
  494. font-size: 28rpx;
  495. font-weight: 700;
  496. }
  497. .add-btn {
  498. padding: 12rpx 32rpx;
  499. background-color: #a4adb3;
  500. color: #ffffff;
  501. border-radius: 12rpx;
  502. font-size: 24rpx;
  503. }
  504. }
  505. .unfit-container {
  506. padding: 24rpx;
  507. margin: 0 16rpx;
  508. background-color: #ffffff;
  509. border-radius: 12rpx;
  510. .unfit-item-container {
  511. position: relative;
  512. >* {
  513. margin-bottom: 24rpx;
  514. }
  515. .title {
  516. font-weight: 700;
  517. justify-content: space-between;
  518. align-items: center;
  519. image {
  520. width: 40rpx;
  521. height: 40rpx;
  522. }
  523. }
  524. .standard {}
  525. .result {
  526. align-items: center;
  527. border-bottom: 1px solid #9f9f9f;
  528. padding-bottom: 32rpx;
  529. .label {
  530. flex: 1;
  531. }
  532. input {
  533. width: 280rpx;
  534. height: 56rpx;
  535. border: 1px solid #9f9f9f;
  536. font-size: 28rpx;
  537. &.number {
  538. width: 104rpx;
  539. text-align: center;
  540. }
  541. }
  542. }
  543. }
  544. .unfit-item-container:last-child {
  545. .result {
  546. border-bottom: none;
  547. padding-bottom: 0;
  548. }
  549. }
  550. }
  551. .consultation-container {
  552. margin: 0 16rpx;
  553. padding: 24rpx;
  554. background-color: #ffffff;
  555. border-radius: 8rpx;
  556. .consultation-item-container {
  557. margin-bottom: 24rpx;
  558. border-bottom: 2px solid #888888;
  559. padding-bottom: 24rpx;
  560. }
  561. .consultation-item-container:last-child {
  562. margin-bottom: 0;
  563. border-bottom: 0;
  564. padding-bottom: 0;
  565. }
  566. .question,
  567. .answer {
  568. .label {
  569. justify-content: space-between;
  570. margin-bottom: 16rpx;
  571. font-weight: 700;
  572. }
  573. .content {
  574. line-height: 40rpx;
  575. }
  576. }
  577. .answer {
  578. margin-top: 24rpx;
  579. }
  580. }
  581. .daywork-container {
  582. margin-top: 24rpx;
  583. padding: 24rpx;
  584. background-color: #ffffff;
  585. border: 1px solid #bcbcbc;
  586. .result {
  587. align-items: center;
  588. .label {
  589. width: 112rpx;
  590. }
  591. input {
  592. flex: 1;
  593. height: 56rpx;
  594. border: 1px solid #9f9f9f;
  595. font-size: 28rpx;
  596. text-align: center;
  597. }
  598. }
  599. .remark {
  600. margin-top: 24rpx;
  601. .label {
  602. width: 112rpx;
  603. }
  604. textarea {
  605. flex: 1;
  606. border: 1px solid #9f9f9f;
  607. height: 168rpx;
  608. }
  609. }
  610. .btns-container {
  611. margin-top: 24rpx;
  612. .bottom-btn {
  613. display: flex;
  614. flex: 1;
  615. height: 80rpx;
  616. background-color: #5555ff;
  617. color: #ffffff;
  618. text-align: center;
  619. justify-content: center;
  620. align-items: center;
  621. border-radius: 8rpx;
  622. margin-right: 10rpx;
  623. &.left-btn {
  624. background-color: rgba(85, 85, 255, 1.0);
  625. }
  626. &.right-btn {
  627. margin-left: 24rpx;
  628. }
  629. }
  630. .finished-btn {
  631. display: flex;
  632. flex: 1;
  633. height: 80rpx;
  634. background-color: #fc6565;
  635. color: #ffffff;
  636. text-align: center;
  637. justify-content: center;
  638. align-items: center;
  639. border-radius: 8rpx;
  640. }
  641. .pause-btn {
  642. display: flex;
  643. flex: 1;
  644. height: 80rpx;
  645. background-color: #55d90d;
  646. color: #ffffff;
  647. text-align: center;
  648. justify-content: center;
  649. align-items: center;
  650. border-radius: 8rpx;
  651. }
  652. .question-btn {
  653. width: 80rpx;
  654. align-items: flex-end;
  655. image {
  656. width: 48rpx;
  657. height: 48rpx;
  658. }
  659. text {
  660. font-size: 24rpx;
  661. }
  662. }
  663. }
  664. }
  665. </style>