form.vue 12 KB

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