form.vue 14 KB

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