form.vue 16 KB

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