form.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <template>
  2. <view class="page-container uni-column">
  3. <view class="carrier-info uni-column">
  4. <view class="carrier-code uni-row">
  5. <text>箱号</text>
  6. <text style="margin-left: 24rpx;">{{processInspecion.lot.allCarrierName}}</text>
  7. </view>
  8. <view class="info-row uni-row">
  9. <view class="label">图号</view>
  10. <view class="value">{{ processInspecion.lot.drawingNumber }}</view>
  11. </view>
  12. <view class="info-row uni-row">
  13. <view class="label">批次号</view>
  14. <view class="value">{{ processInspecion.lot.lotCode }}</view>
  15. </view>
  16. <view class="info-row uni-row">
  17. <view class="label">工艺版本</view>
  18. <view class="value">{{ processInspecion.lot.technologyVersion }}</view>
  19. </view>
  20. <view class="info-row uni-row">
  21. <view class="label">产品描述</view>
  22. <view class="value">{{processInspecion.lot. productDescription }}</view>
  23. </view>
  24. <view class="info-row uni-row">
  25. <view class="label">当前工序</view>
  26. <view class="value">{{ processInspecion.lot.processAlias }}</view>
  27. </view>
  28. <view class="info-row uni-row">
  29. <view class="label">投产数量</view>
  30. <view class="value">{{ processInspecion.lot.pudName }}</view>
  31. </view>
  32. </view>
  33. <!-- 废品信息 -->
  34. <view class="title unfit-title uni-row">
  35. <text>废品信息</text>
  36. <view class="add-btn" @click="handleAddWaste">添加</view>
  37. </view>
  38. <view class="unfit-container">
  39. <view class="unfit-item-container uni-column" v-for="(item, index) in unfitInfos" :key="index">
  40. <!-- 暂时注释,后续会使用 -->
  41. <!-- <view class="title uni-row">
  42. <text>检查项-{{ item.title }}</text>
  43. <uni-icons type="trash" size="24" color="#fc6565" @click="handleDelWaste(index)" />
  44. </view> -->
  45. <!-- <view class="standard">检查标准:{{ item.standard }}</view> -->
  46. <view class="resu uni-row">
  47. <view class="label">检查标准</view>
  48. <input v-model="item.checkStandard" placeholder="请输入检查标准" />
  49. <uni-icons type="trash" size="24" style="margin-left: 55rpx;" color="#fc6565"
  50. @click="handleDelWaste(index)" />
  51. </view>
  52. <view class="result uni-row">
  53. <view class="label">检查结果</view>
  54. <input v-model="item.checkResult" placeholder="请输入检查结果" />
  55. <view class="label" style="text-align: right; padding-right: 16rpx;">数量
  56. </view>
  57. <input class="number" type="number" @blur="rejectNumberChange" v-model="item.rejectNum"
  58. placeholder="" />
  59. </view>
  60. </view>
  61. </view>
  62. <!-- 咨询部分 -->
  63. <view class="title">咨询</view>
  64. <view class="consultation-container uni-column">
  65. <view class="consultation-item-container" v-for="(item, index) in consultations" :key="index">
  66. <view class="question uni-column">
  67. <view class="label uni-row">
  68. <text>问题描述</text>
  69. <text :style="selectType(item)">{{ selectText(item) }}</text>
  70. </view>
  71. <view class="content">{{ item.content }}</view>
  72. </view>
  73. <!-- 不需要暂时注释 -->
  74. <!-- <view v-if="item.answer !== ''" class="answer"
  75. style="margin-top: 24rpx; padding-top: 24rpx; border-top: 1px dotted #aaaaaa;">
  76. <view class="label">回复</view>
  77. <view class="content">{{ item.answer }}</view>
  78. </view> -->
  79. </view>
  80. </view>
  81. <!-- 报工部分 -->
  82. <view class="daywork-container">
  83. <!-- 此处后续要加上条件限制,当状态为合格或不合格的时候不能修改状态,需要有权限的人来进行修改 -->
  84. <view class="result uni-row">
  85. <view class="label">检测量</view>
  86. <input type="number" v-model="processInspecion.examiningNum" placeholder="请输入检测量" />
  87. <view class="label" style="text-align: right; padding-right: 24rpx">废品量</view>
  88. <input type="number" v-model="processInspecion.rejectNum" placeholder="请输入废品量" />
  89. </view>
  90. <view class="result uni-row">
  91. <view class="label" style="margin-top: 20rpx; margin-right: 10rpx;">序检状态</view>
  92. <uni-data-checkbox style="margin-top: 20rpx;" v-model="processInspecion.status" :localdata="range"
  93. @change="change"></uni-data-checkbox>
  94. </view>
  95. <view class="remark uni-row">
  96. <view class="label">备注</view>
  97. <textarea v-model="processInspecion.remark" />
  98. </view>
  99. <view class="btns-container uni-row">
  100. <view class="finished-btn" @click="endWork">结束报工</view>
  101. <view class="question-btn uni-column" @click.stop="handleAddConsultation">
  102. <uni-icons type="headphones" size="24" />
  103. <text>咨询</text>
  104. </view>
  105. </view>
  106. </view>
  107. </view>
  108. </template>
  109. <script setup>
  110. import {
  111. ref,
  112. onMounted,
  113. getCurrentInstance
  114. } from 'vue'
  115. import {
  116. onLoad,
  117. onReady,
  118. onUnload,
  119. onShow
  120. } from '@dcloudio/uni-app'
  121. import {
  122. store
  123. } from '@/store/index.js'
  124. import {
  125. saveOutsourcedInspecion,
  126. selectOutsourcedInspecion
  127. } from '@/api/business/processInspection.js'
  128. const lot = ref({})
  129. const unfitInfos = ref([]) //废品信息
  130. const isEventTriggered = ref(false); // 创建一个标志位
  131. // 创建一个引用来存储最后一次请求的时间戳
  132. const lastRequestTimestamp = ref(0);
  133. const consultations = ref([]) //咨询信息
  134. const processInspecion = ref({
  135. remark: "",
  136. rejectNum: 0,
  137. examiningNum: 0,
  138. status: 0,
  139. })
  140. const consul = [{
  141. value: 0,
  142. text: "待确认",
  143. type: "color: #fcab53"
  144. }, {
  145. value: 2,
  146. text: "合格",
  147. type: "color: #55ff7f"
  148. }, {
  149. value: 1,
  150. text: "不合格",
  151. type: "color: #ff0c2c"
  152. }]
  153. const range = [{
  154. value: 0,
  155. text: "待确认",
  156. type: "color: #fcab53"
  157. }, {
  158. value: 1,
  159. text: "合格",
  160. type: "color: #55ff7f"
  161. }, {
  162. value: 2,
  163. text: "不合格",
  164. type: "color: #ff0c2c"
  165. }]
  166. /***************************** 页面生命周期函数 *****************************/
  167. onMounted(() => {
  168. const instance = getCurrentInstance().proxy
  169. const eventChannel = instance.getOpenerEventChannel();
  170. eventChannel.on('outsourcedInspectionFrom', function(data) {
  171. console.log('outsourcedInspectionFrom', data)
  172. if (data && data.data) {
  173. processInspecion.value.lot = data.data;
  174. }
  175. })
  176. })
  177. onShow(() => {
  178. if (store.processInspection != null) {
  179. uni.showLoading({
  180. title: '加载中'
  181. });
  182. processInspecion.value = store.processInspection
  183. selectOutsourcedInspecion(processInspecion.value).then(res => {
  184. console.log("res", res);
  185. if (res.code == 200) {
  186. processInspecion.value = res.data;
  187. unfitInfos.value = res.data.dayworkItemRejects;
  188. consultations.value = res.data.dayworkItemConsults;
  189. console.log("res", res);
  190. uni.hideLoading();
  191. // getInspecion();
  192. } else {
  193. uni.showToast({
  194. icon: 'none',
  195. title: res.msg,
  196. duration: 2000
  197. })
  198. }
  199. });
  200. }
  201. })
  202. /***************************** 定义了一些方法 *****************************/
  203. //咨询文本
  204. function selectText(item) {
  205. for (var i = 0; i < consul.length; i++) {
  206. if (item.status == consul[i].value) {
  207. return consul[i].text
  208. }
  209. }
  210. }
  211. const rejectNumberChange = () => {
  212. let sumReject = 0
  213. unfitInfos.value.forEach(v => {
  214. sumReject += Number(v.rejectNum)
  215. })
  216. processInspecion.value.rejectNum = sumReject
  217. console.log(processInspecion.value)
  218. }
  219. //查询咨询列表
  220. function getInspecion() {
  221. processInspecion.value = store.processInspection
  222. selectInspecion(processInspecion.value).then(res => {
  223. console.log("咨询", res);
  224. if (res.code == 200) {
  225. console.log("res", res);
  226. } else {
  227. uni.showToast({
  228. icon: 'none',
  229. title: res.msg,
  230. duration: 2000
  231. })
  232. }
  233. });
  234. }
  235. //结束报工按钮
  236. function endWork() {
  237. let unf = unfitInfos.value;
  238. for (var i = 0; i < unfitInfos.value.length; i++) {
  239. console.log("废品信息");
  240. if (!unf[i].checkStandard && !unf[i].checkResult && !unf[i].rejectNum) {
  241. uni.showToast({
  242. icon: 'none',
  243. title: "废品信息不能为空",
  244. duration: 2000
  245. })
  246. return;
  247. }
  248. }
  249. let sumReject = 0
  250. unfitInfos.value.forEach(v => {
  251. sumReject += Number(v.rejectNum)
  252. })
  253. if (processInspecion.value.rejectNum != sumReject) {
  254. uni.showToast({
  255. icon: 'none',
  256. title: "废品量与废品信息不一致",
  257. duration: 2000
  258. })
  259. return;
  260. }
  261. save();
  262. }
  263. function save() {
  264. const currentTime = Date.now();
  265. // 检查是否已经过去了 2 秒
  266. if (currentTime - lastRequestTimestamp.value < 2000) {
  267. // 如果在 2 秒 内已经点击,那么不执行
  268. uni.showToast({
  269. icon: 'none',
  270. title: `请勿重复点击`,
  271. duration: 2000
  272. })
  273. return;
  274. }
  275. let pages = getCurrentPages();
  276. processInspecion.value.dayworkItemConsults = consultations.value;
  277. processInspecion.value.dayworkItemRejects = unfitInfos.value;
  278. processInspecion.value.user = store.userInfo;
  279. saveOutsourcedInspecion(processInspecion.value).then(res => {
  280. if (res.code == 200) {
  281. let index = 0;
  282. for (let i = 0; i < pages.length; i++) {
  283. if (pages[i].$page.fullPath == "/pages/outsourcedInspection/index") {
  284. index = pages.length - i - 1;
  285. }
  286. }
  287. console.log("index", index);
  288. uni.navigateBack({
  289. delta: index
  290. });
  291. } else {
  292. uni.showToast({
  293. icon: 'none',
  294. title: res.msg,
  295. duration: 2000
  296. })
  297. }
  298. });
  299. }
  300. //咨询样式
  301. function selectType(item) {
  302. for (var i = 0; i < consul.length; i++) {
  303. if (item.status == consul[i].value) {
  304. return consul[i].type
  305. }
  306. }
  307. }
  308. const addWasteInfo = (data) => {
  309. const info = {
  310. title: data.title,
  311. checkStandard: data.standard
  312. }
  313. unfitInfos.value.push(info)
  314. }
  315. const addConsultation = (data) => {
  316. const info = {
  317. content: data.question,
  318. status: 0
  319. }
  320. consultations.value.push(info)
  321. isEventTriggered.value = true; // 更新标志位状态
  322. }
  323. /***************************** 定义了一些事件 *****************************/
  324. // 添加不合格信息
  325. const handleAddWaste = () => {
  326. let info = {}
  327. unfitInfos.value.push(info)
  328. // 监听事件,暂时不用,后续会使用
  329. // uni.$once('addWasteInfoEvent', (data) => {
  330. // addWasteInfo(data)
  331. // })
  332. // uni.navigateTo({
  333. // url: "/pages/processInspection/options"
  334. // })
  335. }
  336. // 删除不合格信息
  337. const handleDelWaste = (index) => {
  338. uni.showModal({
  339. title: '提示',
  340. content: '确定删除该项?',
  341. success: function(res) {
  342. if (res.confirm) {
  343. unfitInfos.value.splice(index, 1)
  344. } else if (res.cancel) {
  345. return
  346. }
  347. }
  348. })
  349. }
  350. // 咨询
  351. const handleAddConsultation = () => {
  352. isEventTriggered.value = false;
  353. // 监听事件
  354. uni.$once('wasteConsultationEvent', (data) => {
  355. if (!isEventTriggered.value) {
  356. // 如果事件尚未触发,则执行事件触发逻辑
  357. addConsultation(data)
  358. }
  359. })
  360. uni.navigateTo({
  361. url: "/pages/outsourcedInspection/consultation",
  362. success: (res) => {
  363. // 通过eventChannel向被打开页面传送数据
  364. res.eventChannel.emit("outsourcedInspectionConsultation", {
  365. data: processInspecion.value.lot
  366. })
  367. }
  368. })
  369. }
  370. </script>
  371. <style lang="scss">
  372. .page-container {
  373. height: 100%;
  374. background-color: #ececec;
  375. font-size: 28rpx;
  376. >.title {
  377. font-weight: 700;
  378. margin: 24rpx 16rpx;
  379. }
  380. }
  381. .carrier-info {
  382. margin: 32rpx 16rpx 0 16rpx;
  383. padding: 24rpx;
  384. background-color: #ffffff;
  385. border-radius: 8rpx;
  386. .carrier-code {
  387. font-size: 32rpx;
  388. font-weight: 700;
  389. }
  390. .info-row {
  391. margin-top: 16rpx;
  392. color: #767676;
  393. .label {
  394. width: 160rpx;
  395. }
  396. .value {
  397. flex: 1;
  398. textarea {
  399. flex: 1;
  400. border: 1px solid #888888;
  401. box-sizing: border-box;
  402. padding: 16rpx;
  403. }
  404. }
  405. }
  406. }
  407. .unfit-title {
  408. margin-bottom: 24rpx;
  409. justify-content: space-between;
  410. align-items: center;
  411. text {
  412. font-size: 28rpx;
  413. font-weight: 700;
  414. }
  415. .add-btn {
  416. padding: 12rpx 32rpx;
  417. background-color: #a4adb3;
  418. color: #ffffff;
  419. border-radius: 12rpx;
  420. font-size: 24rpx;
  421. }
  422. }
  423. .unfit-container {
  424. padding: 24rpx;
  425. margin: 0 16rpx;
  426. background-color: #ffffff;
  427. border-radius: 12rpx;
  428. .unfit-item-container {
  429. position: relative;
  430. >* {
  431. margin-bottom: 24rpx;
  432. }
  433. .title {
  434. font-weight: 700;
  435. justify-content: space-between;
  436. align-items: center;
  437. image {
  438. width: 40rpx;
  439. height: 40rpx;
  440. }
  441. }
  442. .standard {}
  443. .resu {
  444. width: 100%;
  445. align-items: center;
  446. input {
  447. margin-left: 20rpx;
  448. width: 200rpx;
  449. height: 56rpx;
  450. flex: 1;
  451. border: 1px solid #9f9f9f;
  452. font-size: 28rpx;
  453. }
  454. }
  455. .result {
  456. align-items: center;
  457. border-bottom: 1px solid #9f9f9f;
  458. padding-bottom: 32rpx;
  459. .label {
  460. flex: 1;
  461. }
  462. input {
  463. width: 280rpx;
  464. height: 56rpx;
  465. border: 1px solid #9f9f9f;
  466. font-size: 28rpx;
  467. &.number {
  468. width: 104rpx;
  469. text-align: center;
  470. }
  471. }
  472. }
  473. }
  474. .unfit-item-container:last-child {
  475. .result {
  476. border-bottom: none;
  477. padding-bottom: 0;
  478. }
  479. }
  480. }
  481. .consultation-container {
  482. margin: 0 16rpx;
  483. padding: 24rpx;
  484. background-color: #ffffff;
  485. border-radius: 8rpx;
  486. .consultation-item-container {
  487. margin-bottom: 24rpx;
  488. border-bottom: 2px solid #888888;
  489. padding-bottom: 24rpx;
  490. }
  491. .consultation-item-container:last-child {
  492. margin-bottom: 0;
  493. border-bottom: 0;
  494. padding-bottom: 0;
  495. }
  496. .question,
  497. .answer {
  498. .label {
  499. justify-content: space-between;
  500. margin-bottom: 16rpx;
  501. font-weight: 700;
  502. }
  503. .content {
  504. line-height: 40rpx;
  505. }
  506. }
  507. .answer {
  508. margin-top: 24rpx;
  509. }
  510. }
  511. .daywork-container {
  512. margin-top: 24rpx;
  513. padding: 24rpx;
  514. background-color: #ffffff;
  515. border: 1px solid #bcbcbc;
  516. .result {
  517. align-items: center;
  518. .label {
  519. width: 112rpx;
  520. }
  521. input {
  522. flex: 1;
  523. height: 56rpx;
  524. border: 1px solid #9f9f9f;
  525. font-size: 28rpx;
  526. text-align: center;
  527. }
  528. }
  529. .remark {
  530. margin-top: 24rpx;
  531. .label {
  532. width: 112rpx;
  533. }
  534. textarea {
  535. flex: 1;
  536. border: 1px solid #9f9f9f;
  537. height: 168rpx;
  538. }
  539. }
  540. .btns-container {
  541. margin-top: 24rpx;
  542. .finished-btn {
  543. display: flex;
  544. flex: 1;
  545. height: 80rpx;
  546. background-color: #fc6565;
  547. color: #ffffff;
  548. text-align: center;
  549. justify-content: center;
  550. align-items: center;
  551. border-radius: 8rpx;
  552. }
  553. .question-btn {
  554. width: 80rpx;
  555. align-items: flex-end;
  556. image {
  557. width: 48rpx;
  558. height: 48rpx;
  559. }
  560. text {
  561. font-size: 24rpx;
  562. }
  563. }
  564. }
  565. }
  566. </style>