form.vue 14 KB

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