form.vue 15 KB

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