form.vue 16 KB

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