form.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  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-left: 10px;" 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. if (unf[i].rejectNum < 0 || unf[i].examiningNum < 0 || unf[i].disqualificationNum < 0) {
  307. uni.showToast({
  308. icon: 'none',
  309. title: '检查量,不良品量,废品量不能小于0',
  310. duration: 2000
  311. })
  312. return
  313. }
  314. if (unf[i].examiningNum > processInspecion.value.lot.pudName) {
  315. uni.showToast({
  316. icon: 'none',
  317. title: '检查量不能大于投产量'
  318. })
  319. return
  320. }
  321. }
  322. let sumReject = 0
  323. unfitInfos.value.forEach(v => {
  324. sumReject += Number(v.rejectNum)
  325. })
  326. if (processInspecion.value.rejectNum != sumReject) {
  327. uni.showToast({
  328. icon: 'none',
  329. title: "废品量与废品信息不一致",
  330. duration: 2000
  331. })
  332. return;
  333. }
  334. if (processInspecion.value.rejectNum > processInspecion.value.lot.pudName) {
  335. uni.showToast({
  336. icon: 'none',
  337. title: '废品量不能大于投产量'
  338. })
  339. return
  340. }
  341. if (processInspecion.value.disqualificationNum > processInspecion.value.lot.pudName) {
  342. uni.showToast({
  343. icon: 'none',
  344. title: '不良品量不能大于投产量'
  345. })
  346. return
  347. }
  348. save();
  349. }
  350. function save() {
  351. const currentTime = Date.now();
  352. // 检查是否已经过去了 2 秒
  353. if (currentTime - lastRequestTimestamp.value < 2000) {
  354. // 如果在 2 秒 内已经点击,那么不执行
  355. uni.showToast({
  356. icon: 'none',
  357. title: `请勿重复点击`,
  358. duration: 2000
  359. })
  360. return;
  361. }
  362. let pages = getCurrentPages();
  363. processInspecion.value.dayworkItemConsults = consultations.value;
  364. processInspecion.value.dayworkItemRejects = unfitInfos.value;
  365. processInspecion.value.user = store.userInfo;
  366. saveOutsourcedInspecion(processInspecion.value).then(res => {
  367. if (res.code == 200) {
  368. let index = 0;
  369. for (let i = 0; i < pages.length; i++) {
  370. if (pages[i].$page.fullPath == "/pages/outsourcedInspection/index") {
  371. index = pages.length - i - 1;
  372. }
  373. }
  374. console.log("index", index);
  375. uni.navigateBack({
  376. delta: index
  377. });
  378. } else {
  379. uni.showToast({
  380. icon: 'none',
  381. title: res.msg,
  382. duration: 2000
  383. })
  384. }
  385. });
  386. }
  387. //咨询样式
  388. function selectType(item) {
  389. for (var i = 0; i < consul.length; i++) {
  390. if (item.status == consul[i].value) {
  391. return consul[i].type
  392. }
  393. }
  394. }
  395. const addWasteInfo = (data) => {
  396. const info = {
  397. title: data.title,
  398. checkStandard: data.standard
  399. }
  400. unfitInfos.value.push(info)
  401. }
  402. const addConsultation = (data) => {
  403. const info = {
  404. content: data.question,
  405. status: 0
  406. }
  407. consultations.value.push(info)
  408. isEventTriggered.value = true; // 更新标志位状态
  409. }
  410. /***************************** 定义了一些事件 *****************************/
  411. // 添加不合格信息
  412. const handleAddWaste = () => {
  413. let info = {}
  414. unfitInfos.value.push(info)
  415. // 监听事件,暂时不用,后续会使用
  416. // uni.$once('addWasteInfoEvent', (data) => {
  417. // addWasteInfo(data)
  418. // })
  419. // uni.navigateTo({
  420. // url: "/pages/processInspection/options"
  421. // })
  422. }
  423. // 删除不合格信息
  424. const handleDelWaste = (index) => {
  425. uni.showModal({
  426. title: '提示',
  427. content: '确定删除该项?',
  428. success: function(res) {
  429. if (res.confirm) {
  430. unfitInfos.value.splice(index, 1)
  431. rejectNumberChange()
  432. } else if (res.cancel) {
  433. return
  434. }
  435. }
  436. })
  437. }
  438. // 咨询
  439. const handleAddConsultation = () => {
  440. isEventTriggered.value = false;
  441. // 监听事件
  442. uni.$once('wasteConsultationEvent', (data) => {
  443. if (!isEventTriggered.value) {
  444. // 如果事件尚未触发,则执行事件触发逻辑
  445. addConsultation(data)
  446. }
  447. })
  448. uni.navigateTo({
  449. url: "/pages/outsourcedInspection/consultation",
  450. success: (res) => {
  451. // 通过eventChannel向被打开页面传送数据
  452. res.eventChannel.emit("outsourcedInspectionConsultation", {
  453. data: processInspecion.value.lot
  454. })
  455. }
  456. })
  457. }
  458. </script>
  459. <style lang="scss">
  460. .page-container {
  461. // height: 100%;
  462. background-color: #ececec;
  463. font-size: 28rpx;
  464. >.title {
  465. font-weight: 700;
  466. margin: 24rpx 16rpx;
  467. }
  468. }
  469. .carrier-info {
  470. margin: 32rpx 16rpx 0 16rpx;
  471. padding: 24rpx;
  472. background-color: #ffffff;
  473. border-radius: 8rpx;
  474. .carrier-code {
  475. font-size: 32rpx;
  476. font-weight: 700;
  477. }
  478. .info-row {
  479. margin-top: 16rpx;
  480. color: #767676;
  481. .label {
  482. width: 160rpx;
  483. }
  484. .value {
  485. flex: 1;
  486. textarea {
  487. flex: 1;
  488. border: 1px solid #888888;
  489. box-sizing: border-box;
  490. padding: 16rpx;
  491. }
  492. }
  493. }
  494. }
  495. .unfit-title {
  496. margin-bottom: 24rpx;
  497. justify-content: space-between;
  498. align-items: center;
  499. text {
  500. font-size: 28rpx;
  501. font-weight: 700;
  502. }
  503. .add-btn {
  504. padding: 12rpx 32rpx;
  505. background-color: #a4adb3;
  506. color: #ffffff;
  507. border-radius: 12rpx;
  508. font-size: 24rpx;
  509. }
  510. }
  511. .unfit-container {
  512. padding: 24rpx;
  513. margin: 0 16rpx;
  514. background-color: #ffffff;
  515. border-radius: 12rpx;
  516. .unfit-item-container {
  517. position: relative;
  518. >* {
  519. margin-bottom: 24rpx;
  520. }
  521. .title {
  522. font-weight: 700;
  523. justify-content: space-between;
  524. align-items: center;
  525. image {
  526. width: 40rpx;
  527. height: 40rpx;
  528. }
  529. }
  530. .standard {}
  531. .resu {
  532. width: 100%;
  533. align-items: center;
  534. input {
  535. margin-left: 20rpx;
  536. width: 200rpx;
  537. height: 56rpx;
  538. flex: 1;
  539. border: 1px solid #9f9f9f;
  540. font-size: 28rpx;
  541. }
  542. .label {
  543. width: 160rpx;
  544. }
  545. .value {
  546. flex: 1;
  547. textarea {
  548. flex: 1;
  549. border: 1px solid #888888;
  550. box-sizing: border-box;
  551. padding: 16rpx;
  552. }
  553. }
  554. }
  555. .result {
  556. border-bottom: 1px solid #9f9f9f;
  557. padding-bottom: 32rpx;
  558. align-items: center;
  559. .label {
  560. width: 160rpx;
  561. }
  562. .value {
  563. flex: 1;
  564. textarea {
  565. flex: 1;
  566. border: 1px solid #888888;
  567. box-sizing: border-box;
  568. padding: 16rpx;
  569. }
  570. }
  571. input {
  572. width: 280rpx;
  573. height: 56rpx;
  574. border: 1px solid #9f9f9f;
  575. font-size: 28rpx;
  576. &.number {
  577. width: 104rpx;
  578. text-align: center;
  579. }
  580. }
  581. }
  582. }
  583. .unfit-item-container:last-child {
  584. .result {
  585. border-bottom: none;
  586. padding-bottom: 0;
  587. }
  588. }
  589. }
  590. .consultation-container {
  591. margin: 0 16rpx;
  592. padding: 24rpx;
  593. background-color: #ffffff;
  594. border-radius: 8rpx;
  595. .consultation-item-container {
  596. margin-bottom: 24rpx;
  597. border-bottom: 2px solid #888888;
  598. padding-bottom: 24rpx;
  599. }
  600. .consultation-item-container:last-child {
  601. margin-bottom: 0;
  602. border-bottom: 0;
  603. padding-bottom: 0;
  604. }
  605. .question,
  606. .answer {
  607. .label {
  608. justify-content: space-between;
  609. margin-bottom: 16rpx;
  610. font-weight: 700;
  611. }
  612. .content {
  613. line-height: 40rpx;
  614. }
  615. }
  616. .answer {
  617. margin-top: 24rpx;
  618. }
  619. }
  620. .daywork-container {
  621. margin-top: 24rpx;
  622. padding: 24rpx;
  623. background-color: #ffffff;
  624. border: 1px solid #bcbcbc;
  625. .result {
  626. align-items: center;
  627. .label {
  628. width: 112rpx;
  629. }
  630. input {
  631. flex: 1;
  632. height: 56rpx;
  633. border: 1px solid #9f9f9f;
  634. font-size: 28rpx;
  635. text-align: center;
  636. }
  637. }
  638. .remark {
  639. margin-top: 24rpx;
  640. .label {
  641. width: 112rpx;
  642. }
  643. textarea {
  644. flex: 1;
  645. border: 1px solid #9f9f9f;
  646. height: 168rpx;
  647. }
  648. }
  649. .btns-container {
  650. margin-top: 24rpx;
  651. .finished-btn {
  652. display: flex;
  653. flex: 1;
  654. height: 80rpx;
  655. background-color: #fc6565;
  656. color: #ffffff;
  657. text-align: center;
  658. justify-content: center;
  659. align-items: center;
  660. border-radius: 8rpx;
  661. }
  662. .question-btn {
  663. width: 80rpx;
  664. align-items: flex-end;
  665. image {
  666. width: 48rpx;
  667. height: 48rpx;
  668. }
  669. text {
  670. font-size: 24rpx;
  671. }
  672. }
  673. }
  674. }
  675. </style>