form.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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. return true
  293. // unfitInfos.value.forEach((e, i) => {
  294. // if (e.name)
  295. // })
  296. }
  297. const handleFinishDaywork = () => {
  298. if (!validHandle()) {
  299. return
  300. }
  301. const saveData = {
  302. rejectList: unfitInfos.value,
  303. consult: consultations.value,
  304. id: dayworkItem.value.id,
  305. prodNum: dayworkItem.value.prodNum,
  306. rejectNum: dayworkItem.value.rejectNum,
  307. qualifiedNum: dayworkItem.value.qualifiedNum,
  308. remark: dayworkItem.value.remark
  309. }
  310. finish(saveData).then(res => {
  311. if (res.code === 200) {
  312. uni.navigateBack()
  313. } else {
  314. uni.showToast({
  315. icon: 'none',
  316. title: res.message
  317. })
  318. }
  319. })
  320. }
  321. const handleUpdateDaywork = () => {
  322. if (!validHandle()) {
  323. return
  324. }
  325. const saveData = {
  326. rejectList: unfitInfos.value,
  327. consult: consultations.value,
  328. id: dayworkItem.value.id,
  329. prodNum: dayworkItem.value.prodNum,
  330. rejectNum: dayworkItem.value.rejectNum,
  331. qualifiedNum: dayworkItem.value.qualifiedNum,
  332. remark: dayworkItem.value.remark
  333. }
  334. update(saveData).then(res => {
  335. if (res.code === 200) {
  336. uni.navigateBack()
  337. } else {
  338. uni.showToast({
  339. icon: 'none',
  340. title: res.message
  341. })
  342. }
  343. })
  344. }
  345. </script>
  346. <style lang="scss">
  347. .page-container {
  348. height: 100%;
  349. background-color: #ececec;
  350. font-size: 28rpx;
  351. >.title {
  352. font-weight: 700;
  353. margin: 24rpx 16rpx;
  354. }
  355. }
  356. .lot-info {
  357. margin: 32rpx 16rpx 0 16rpx;
  358. padding: 24rpx;
  359. background-color: #ffffff;
  360. border-radius: 8rpx;
  361. .lot-code {
  362. font-size: 32rpx;
  363. font-weight: 700;
  364. margin-bottom: 16rpx;
  365. }
  366. .product-info {
  367. font-size: 28rpx;
  368. color: #9f9f9f;
  369. }
  370. }
  371. .unfit-title {
  372. margin-bottom: 24rpx;
  373. justify-content: space-between;
  374. align-items: center;
  375. text {
  376. font-size: 28rpx;
  377. font-weight: 700;
  378. }
  379. .add-btn {
  380. padding: 12rpx 32rpx;
  381. background-color: #a4adb3;
  382. color: #ffffff;
  383. border-radius: 12rpx;
  384. font-size: 24rpx;
  385. }
  386. }
  387. .unfit-container {
  388. padding: 24rpx;
  389. margin: 0 16rpx;
  390. background-color: #ffffff;
  391. border-radius: 12rpx;
  392. .unfit-item-container {
  393. position: relative;
  394. >* {
  395. margin-bottom: 24rpx;
  396. }
  397. .title {
  398. font-weight: 700;
  399. justify-content: space-between;
  400. align-items: center;
  401. image {
  402. width: 40rpx;
  403. height: 40rpx;
  404. }
  405. }
  406. .standard {}
  407. .result {
  408. align-items: center;
  409. border-bottom: 1px solid #9f9f9f;
  410. padding-bottom: 32rpx;
  411. .label {
  412. flex: 1;
  413. }
  414. input {
  415. width: 280rpx;
  416. height: 56rpx;
  417. border: 1px solid #9f9f9f;
  418. font-size: 28rpx;
  419. &.number {
  420. width: 104rpx;
  421. text-align: center;
  422. }
  423. }
  424. }
  425. }
  426. .unfit-item-container:last-child {
  427. .result {
  428. border-bottom: none;
  429. padding-bottom: 0;
  430. }
  431. }
  432. }
  433. .consultation-container {
  434. margin: 0 16rpx;
  435. padding: 24rpx;
  436. background-color: #ffffff;
  437. border-radius: 8rpx;
  438. .consultation-item-container {
  439. margin-bottom: 24rpx;
  440. border-bottom: 2px solid #888888;
  441. padding-bottom: 24rpx;
  442. }
  443. .consultation-item-container:last-child {
  444. margin-bottom: 0;
  445. border-bottom: 0;
  446. padding-bottom: 0;
  447. }
  448. .question,
  449. .answer {
  450. .label {
  451. justify-content: space-between;
  452. margin-bottom: 16rpx;
  453. font-weight: 700;
  454. }
  455. .content {
  456. line-height: 40rpx;
  457. }
  458. }
  459. .answer {
  460. margin-top: 24rpx;
  461. }
  462. }
  463. .daywork-container {
  464. margin-top: 24rpx;
  465. padding: 24rpx;
  466. background-color: #ffffff;
  467. border: 1px solid #bcbcbc;
  468. .result {
  469. align-items: center;
  470. .label {
  471. width: 112rpx;
  472. }
  473. input {
  474. flex: 1;
  475. height: 56rpx;
  476. border: 1px solid #9f9f9f;
  477. font-size: 28rpx;
  478. text-align: center;
  479. }
  480. }
  481. .remark {
  482. margin-top: 24rpx;
  483. .label {
  484. width: 112rpx;
  485. }
  486. textarea {
  487. flex: 1;
  488. border: 1px solid #9f9f9f;
  489. height: 168rpx;
  490. }
  491. }
  492. .btns-container {
  493. margin-top: 24rpx;
  494. .finished-btn {
  495. display: flex;
  496. flex: 1;
  497. height: 80rpx;
  498. background-color: #fc6565;
  499. color: #ffffff;
  500. text-align: center;
  501. justify-content: center;
  502. align-items: center;
  503. border-radius: 8rpx;
  504. }
  505. .pause-btn {
  506. display: flex;
  507. flex: 1;
  508. height: 80rpx;
  509. background-color: #55d90d;
  510. color: #ffffff;
  511. text-align: center;
  512. justify-content: center;
  513. align-items: center;
  514. border-radius: 8rpx;
  515. }
  516. .question-btn {
  517. width: 80rpx;
  518. align-items: flex-end;
  519. image {
  520. width: 48rpx;
  521. height: 48rpx;
  522. }
  523. text {
  524. font-size: 24rpx;
  525. }
  526. }
  527. }
  528. }
  529. </style>