form.vue 17 KB

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