form.vue 14 KB

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