form.vue 13 KB

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