form.vue 12 KB

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