form.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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. uni.showModal({
  232. title: '提示',
  233. content: '确定删除该项?',
  234. success: function(res) {
  235. if (res.confirm) {
  236. unfitInfos.value.splice(index, 1)
  237. } else if (res.cancel) {
  238. return
  239. }
  240. }
  241. })
  242. }
  243. /* 更换载具*/
  244. function handleChangeCarrier(item) {
  245. // uni.$once('refreshQuickReport', () => {
  246. // init()
  247. // })
  248. store.dayworkInfo = null
  249. uni.navigateTo({
  250. url: "/pages/changeBox/index",
  251. success: function(res) {
  252. // 通过eventChannel向被打开页面传送数据
  253. res.eventChannel.emit('sortingFromOpenerPage', {
  254. data: dayworkItem.value
  255. })
  256. }
  257. })
  258. }
  259. // 添加不合格信息
  260. const handleAddConsultation = () => {
  261. isEventTriggered.value = false; // 更新标志位状态
  262. // 监听事件
  263. uni.$once('addConsulttationEvent', (data) => {
  264. if (!isEventTriggered.value) {
  265. // 如果事件尚未触发,则执行事件触发逻辑
  266. addConsultation(data)
  267. }
  268. })
  269. uni.navigateTo({
  270. url: "/pages/sorting/consultation",
  271. success: (res) => {
  272. // 通过eventChannel向被打开页面传送数据
  273. res.eventChannel.emit('acceptDataFromOpenerPage', {
  274. data: dayworkItem.value
  275. })
  276. }
  277. })
  278. }
  279. const checkFinishable = () => {
  280. if (consultations.value.findIndex(v => v.status === 0) >= 0) {
  281. return false
  282. } else {
  283. return true
  284. }
  285. }
  286. const showStatus = (status) => {
  287. // console.log(status)
  288. switch (status) {
  289. case 0:
  290. return '未确认'
  291. case 1:
  292. return '不合格'
  293. case 2:
  294. return '合格'
  295. default:
  296. return ''
  297. }
  298. }
  299. const showStatusColor = (status) => {
  300. // console.log(status)
  301. switch (status) {
  302. case 0:
  303. return '#fcab53'
  304. case 1:
  305. return '#fc044f'
  306. case 2:
  307. return '#1deb19'
  308. default:
  309. return ''
  310. }
  311. }
  312. const rejectNumberChange = () => {
  313. let sumReject = 0
  314. unfitInfos.value.forEach(v => {
  315. sumReject += v.rejectNum == null ? 0 : Number(v.rejectNum)
  316. })
  317. dayworkItem.value.rejectNum = sumReject
  318. dayworkItem.value.qualifiedNum = dayworkItem.value.prodNum - sumReject
  319. console.log(dayworkItem.value)
  320. }
  321. const validHandle = () => {
  322. for (let i = 0; i < unfitInfos.value.length; i++) {
  323. const e = unfitInfos.value[i]
  324. if (e.rejectNum == null || e.rejectNum == 0) {
  325. uni.showToast({
  326. icon: 'none',
  327. title: `第${i + 1}条不合格信息未输入不合格数量`
  328. })
  329. return false
  330. }
  331. }
  332. if (!dayworkItem.value.qualifiedNum) {
  333. uni.showToast({
  334. icon: 'none',
  335. title: "合格数不能为空",
  336. duration: 2000
  337. })
  338. return false;
  339. }
  340. return true
  341. // unfitInfos.value.forEach((e, i) => {
  342. // if (e.name)
  343. // })
  344. }
  345. const handleFinishDaywork = () => {
  346. if (!validHandle()) {
  347. return
  348. }
  349. const saveData = {
  350. rejectList: unfitInfos.value,
  351. consult: consultations.value,
  352. id: dayworkItem.value.id,
  353. prodNum: dayworkItem.value.prodNum,
  354. rejectNum: dayworkItem.value.rejectNum,
  355. qualifiedNum: dayworkItem.value.qualifiedNum,
  356. remark: dayworkItem.value.remark
  357. }
  358. const currentTime = Date.now();
  359. // 检查是否已经过去了 2 秒
  360. if (currentTime - lastRequestTimestamp.value < 2000) {
  361. // 如果在 2 秒 内已经点击,那么不执行
  362. uni.showToast({
  363. icon: 'none',
  364. title: `请勿重复点击`,
  365. duration: 2000
  366. })
  367. return;
  368. }
  369. finish(saveData).then(res => {
  370. if (res.code === 200) {
  371. uni.navigateBack()
  372. } else {
  373. uni.showToast({
  374. icon: 'none',
  375. title: res.message
  376. })
  377. }
  378. })
  379. }
  380. const handleUpdateDaywork = () => {
  381. if (!validHandle()) {
  382. return
  383. }
  384. const saveData = {
  385. rejectList: unfitInfos.value,
  386. consult: consultations.value,
  387. id: dayworkItem.value.id,
  388. prodNum: dayworkItem.value.prodNum,
  389. rejectNum: dayworkItem.value.rejectNum,
  390. qualifiedNum: dayworkItem.value.qualifiedNum,
  391. remark: dayworkItem.value.remark
  392. }
  393. update(saveData).then(res => {
  394. if (res.code === 200) {
  395. uni.$emit("formBack")
  396. uni.navigateBack()
  397. } else {
  398. uni.showToast({
  399. icon: 'none',
  400. title: res.message
  401. })
  402. }
  403. })
  404. }
  405. </script>
  406. <style lang="scss">
  407. .page-container {
  408. height: 100%;
  409. background-color: #ececec;
  410. font-size: 28rpx;
  411. >.title {
  412. font-weight: 700;
  413. margin: 24rpx 16rpx;
  414. }
  415. }
  416. .lot-info {
  417. margin: 32rpx 16rpx 0 16rpx;
  418. padding: 24rpx;
  419. background-color: #ffffff;
  420. border-radius: 8rpx;
  421. .lot-code {
  422. font-size: 32rpx;
  423. font-weight: 700;
  424. margin-bottom: 16rpx;
  425. }
  426. .product-info {
  427. font-size: 28rpx;
  428. color: #9f9f9f;
  429. }
  430. }
  431. .unfit-title {
  432. margin-bottom: 24rpx;
  433. justify-content: space-between;
  434. align-items: center;
  435. text {
  436. font-size: 28rpx;
  437. font-weight: 700;
  438. }
  439. .add-btn {
  440. padding: 12rpx 32rpx;
  441. background-color: #a4adb3;
  442. color: #ffffff;
  443. border-radius: 12rpx;
  444. font-size: 24rpx;
  445. }
  446. }
  447. .unfit-container {
  448. padding: 24rpx;
  449. margin: 0 16rpx;
  450. background-color: #ffffff;
  451. border-radius: 12rpx;
  452. .unfit-item-container {
  453. position: relative;
  454. >* {
  455. margin-bottom: 24rpx;
  456. }
  457. .title {
  458. font-weight: 700;
  459. justify-content: space-between;
  460. align-items: center;
  461. image {
  462. width: 40rpx;
  463. height: 40rpx;
  464. }
  465. }
  466. .standard {}
  467. .result {
  468. align-items: center;
  469. border-bottom: 1px solid #9f9f9f;
  470. padding-bottom: 32rpx;
  471. .label {
  472. flex: 1;
  473. }
  474. input {
  475. width: 280rpx;
  476. height: 56rpx;
  477. border: 1px solid #9f9f9f;
  478. font-size: 28rpx;
  479. &.number {
  480. width: 104rpx;
  481. text-align: center;
  482. }
  483. }
  484. }
  485. }
  486. .unfit-item-container:last-child {
  487. .result {
  488. border-bottom: none;
  489. padding-bottom: 0;
  490. }
  491. }
  492. }
  493. .consultation-container {
  494. margin: 0 16rpx;
  495. padding: 24rpx;
  496. background-color: #ffffff;
  497. border-radius: 8rpx;
  498. .consultation-item-container {
  499. margin-bottom: 24rpx;
  500. border-bottom: 2px solid #888888;
  501. padding-bottom: 24rpx;
  502. }
  503. .consultation-item-container:last-child {
  504. margin-bottom: 0;
  505. border-bottom: 0;
  506. padding-bottom: 0;
  507. }
  508. .question,
  509. .answer {
  510. .label {
  511. justify-content: space-between;
  512. margin-bottom: 16rpx;
  513. font-weight: 700;
  514. }
  515. .content {
  516. line-height: 40rpx;
  517. }
  518. }
  519. .answer {
  520. margin-top: 24rpx;
  521. }
  522. }
  523. .daywork-container {
  524. margin-top: 24rpx;
  525. padding: 24rpx;
  526. background-color: #ffffff;
  527. border: 1px solid #bcbcbc;
  528. .result {
  529. align-items: center;
  530. .label {
  531. width: 112rpx;
  532. }
  533. input {
  534. flex: 1;
  535. height: 56rpx;
  536. border: 1px solid #9f9f9f;
  537. font-size: 28rpx;
  538. text-align: center;
  539. }
  540. }
  541. .remark {
  542. margin-top: 24rpx;
  543. .label {
  544. width: 112rpx;
  545. }
  546. textarea {
  547. flex: 1;
  548. border: 1px solid #9f9f9f;
  549. height: 168rpx;
  550. }
  551. }
  552. .btns-container {
  553. margin-top: 24rpx;
  554. .bottom-btn {
  555. display: flex;
  556. flex: 1;
  557. height: 80rpx;
  558. background-color: #5555ff;
  559. color: #ffffff;
  560. text-align: center;
  561. justify-content: center;
  562. align-items: center;
  563. border-radius: 8rpx;
  564. margin-right: 10rpx;
  565. &.left-btn {
  566. background-color: rgba(85, 85, 255, 1.0);
  567. }
  568. &.right-btn {
  569. margin-left: 24rpx;
  570. }
  571. }
  572. .finished-btn {
  573. display: flex;
  574. flex: 1;
  575. height: 80rpx;
  576. background-color: #fc6565;
  577. color: #ffffff;
  578. text-align: center;
  579. justify-content: center;
  580. align-items: center;
  581. border-radius: 8rpx;
  582. }
  583. .pause-btn {
  584. display: flex;
  585. flex: 1;
  586. height: 80rpx;
  587. background-color: #55d90d;
  588. color: #ffffff;
  589. text-align: center;
  590. justify-content: center;
  591. align-items: center;
  592. border-radius: 8rpx;
  593. }
  594. .question-btn {
  595. width: 80rpx;
  596. align-items: flex-end;
  597. image {
  598. width: 48rpx;
  599. height: 48rpx;
  600. }
  601. text {
  602. font-size: 24rpx;
  603. }
  604. }
  605. }
  606. }
  607. </style>