form.vue 17 KB

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