add.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. <template>
  2. <div v-if="active" class="register-edit">
  3. <nav-bar :go="go"></nav-bar>
  4. <div class="page-container">
  5. <!-- 基本信息 -->
  6. <div class="card" v-if="taskInfo">
  7. <van-cell-group>
  8. <van-cell :title="taskInfo.taskName">
  9. <template #right-icon>
  10. <span :style="{ color: getState(getDictLabel(taskInfo.status, 'safety_check_status')) }">
  11. {{ getDictLabel(taskInfo.status, 'safety_check_status') }}
  12. </span>
  13. </template>
  14. </van-cell>
  15. <van-cell title="日期时间" :value="formatTime(taskInfo.planStartTime,taskInfo.planEndTime)" />
  16. <van-cell title="受检机构" :value="taskInfo.beCheckedOrgName" />
  17. <van-cell v-if="!enable" title="检查组成员" :value="taskInfo.checkTeam || '无'" />
  18. <van-field
  19. v-else
  20. v-model="taskInfo.checkTeam"
  21. label="检查组成员"
  22. rows="1"
  23. maxlength="100"
  24. autosize
  25. type="textarea"
  26. placeholder="请输入"
  27. />
  28. </van-cell-group>
  29. </div>
  30. <!-- 检查项目 -->
  31. <fieldset class="fieldset" :disabled="!enable">
  32. <div class="card">
  33. <p class="legend">检查项目 <span v-if="enable" @click="addCheck">添加检查内容</span></p>
  34. <!-- 搜索框 -->
  35. <van-search v-model="itemName" class="van-hairline--top" placeholder="请输入检查项名称" />
  36. <van-collapse v-model="activeNames" v-for="v in resultList" :key="v.itemId">
  37. <van-collapse-item :title="v.itemName" :name="v.itemName">
  38. <div v-for="(item, index) in v.pointList" :key="item.pointId" class="collapse-box" :class="{'van-hairline--bottom':item.status}">
  39. <van-cell :border="Boolean(item.status)">
  40. <template #title>
  41. <pre>{{ item.pointName }}</pre>
  42. </template>
  43. <template #right-icon>
  44. <span v-if="item.nfcList && item.nfcList.length">
  45. <span style="color:#009240;">{{ getNfcState(item.nfcList) }}</span>/<span >{{item.nfcList.length}}</span>
  46. </span>
  47. <img
  48. v-if="enable && item.nfcList && item.nfcList.length"
  49. :src="require('../../../assets/svg/NFC.svg')"
  50. class="nfc-icon"
  51. @click="clickNFC(item.nfcList)"
  52. />
  53. <van-switch
  54. v-if="enable"
  55. style="margin-left: 10px"
  56. v-model="item.status"
  57. :active-value="1"
  58. :inactive-value="0"
  59. inactive-color="#4fc08d"
  60. active-color="#ee0a24"
  61. @change="switchChange(item)"
  62. size="20"
  63. />
  64. <span v-else>
  65. <van-tag v-if="item.status" type="warning">隐患</van-tag>
  66. <van-tag v-else type="success">正常</van-tag>
  67. </span>
  68. </template>
  69. </van-cell>
  70. <van-cell-group v-show="item.status" :border="false">
  71. <van-cell v-if="item.nfcList && item.nfcList.length > 0" :border="false">
  72. <div
  73. v-if="img.img"
  74. class="nfc-img"
  75. v-for="(img, i) in item.nfcList"
  76. :key="img.img"
  77. @click="preViewNFC(i)"
  78. >
  79. <img :src="imgUrl(img.img)" alt="" />
  80. <span>{{ img.checkName }}</span>
  81. </div>
  82. </van-cell>
  83. <van-field
  84. required
  85. :maxlength="255"
  86. v-model="item.remark"
  87. rows="1"
  88. autosize
  89. label="情况描述"
  90. type="textarea"
  91. placeholder="请输入(255字以内)"
  92. />
  93. <select-cell
  94. required
  95. :disabled="!enable"
  96. is-row
  97. title="整改期限"
  98. v-model="item.rectificationDeadline"
  99. :data-list="dateList"
  100. />
  101. <div class="upload-box">
  102. <uploader v-if="enable" :maxCount="5" v-model="item.imgData" />
  103. <van-cell v-else-if="item.imgData">
  104. <div
  105. class="nfc-img"
  106. v-for="(v, i) in item.imgData"
  107. :key="v.imgPath"
  108. @click="clickWarnImage(item.imgData, i)"
  109. >
  110. <img :src="imgUrl(v.imgPath)" alt="" />
  111. </div>
  112. <!-- <img class="nfc-img" v-for="v in item.imgData" :src="imgUrl(v.imgPath)" alt="" :key="v.id">-->
  113. </van-cell>
  114. </div>
  115. </van-cell-group>
  116. </div>
  117. </van-collapse-item>
  118. </van-collapse>
  119. </div>
  120. </fieldset>
  121. </div>
  122. <!-- 按钮 -->
  123. <div v-if="enable" class="bottom-box">
  124. <p>注:未到任务开始时间,不可提交</p>
  125. <div class="flex-box">
  126. <van-button type="default" plain @click="accredit" v-show="showGrantBtn">授权</van-button>
  127. <van-button type="info" plain hairline @click="saveData">保存</van-button>
  128. <van-button type="info" :disabled="Boolean(!isSubmit)" @click="submitData">提交</van-button>
  129. </div>
  130. </div>
  131. <!-- <van-image-preview v-model="showPreView" :images="preViewImages.images" :startPosition="preViewImages.startPosition">-->
  132. <!-- <template v-slot:index>第{{ index }}页</template>-->
  133. <!-- </van-image-preview>-->
  134. <!-- nfc弹窗 -->
  135. <nfc-popup v-if="enable" ref="NfcPopup" @checkNFC="checkNFC" @change="changeNfcImg"></nfc-popup>
  136. </div>
  137. <!-- 添加检查内容 -->
  138. <AddCheck v-else @goBack="goBack" @addItem="addItem" :orgType="taskInfo.beCheckOrgType"></AddCheck>
  139. </template>
  140. <script>
  141. import NavBar from '@/components/NavBar'
  142. import SelectCell from '@/components/selectCell'
  143. import DateCell from '@/components/dateCell'
  144. import Uploader from '@/components/upload/gxuploader'
  145. import NfcPopup from '@/components/nfcPopup/more'
  146. import AddCheck from './addCheck'
  147. import { registerDetail, registerSubmit } from './api'
  148. import { imgUrl } from '@/utils'
  149. import { ImagePreview } from 'vant'
  150. import { mapGetters } from 'vuex'
  151. export default {
  152. name: 'securityDetail',
  153. components: { NavBar, SelectCell, DateCell, Uploader, NfcPopup, AddCheck },
  154. data() {
  155. return {
  156. id: null,
  157. activeNames: ['1'],
  158. //基本信息
  159. taskInfo: [],
  160. //选中的nfc列表
  161. NFCList: [],
  162. //区域下检查内容列表
  163. checkList: [],
  164. //检查内容具体项列表
  165. checkItemList: [],
  166. //nfc扫描数量
  167. NFCNum: 0,
  168. //所有检查项数量
  169. allCheckNum: 0,
  170. //区域下检查项数量
  171. checkNum: 0,
  172. //nfc图片
  173. nfcImage: [],
  174. //是否能提交
  175. isSubmit:false, //未到提交时间不能提交
  176. enable: false,
  177. stateList: [],
  178. dayList: [],
  179. itemName:null,
  180. preViewImages: {
  181. images: [],
  182. startPosition: 0
  183. },
  184. dicts: ['safety_check_status', 'rectification_deadline'],
  185. showPreView: false,
  186. selected: null,
  187. active: true,
  188. dateList:[],
  189. go: {
  190. type: 'replace',
  191. path: '/securityCheckRegister'
  192. }
  193. }
  194. },
  195. computed: {
  196. ...mapGetters(['dictionary',"roleList",'orgId']),
  197. showGrantBtn(){
  198. let userRoleIds = this.roleList.map((r) => r.roleId);
  199. let taskRoleIds = this.taskInfo.checkRoles
  200. ? this.taskInfo.checkRoles.map((r) => r.id)
  201. : [];
  202. return (
  203. this.taskInfo.status != 3 &&
  204. this.taskInfo.planType==3 &&
  205. this.taskInfo.checkOrgId == this.orgId &&
  206. userRoleIds.find((ur) => taskRoleIds.includes(ur))
  207. );
  208. },
  209. resultList(){
  210. if (!this.itemName) {
  211. return this.checkList;
  212. }
  213. // 使用传入的值来过滤数据
  214. const filteredData = this.checkList.map(item => ({
  215. ...item,
  216. pointList:
  217. item.pointList.filter(point =>
  218. (point.itemName.includes(this.itemName) || point.pointName.includes(this.itemName))
  219. )
  220. })).filter(item => item.pointList.length > 0);
  221. return filteredData;
  222. },
  223. },
  224. mounted() {
  225. this.id = this.$route.query.id;
  226. this.getData();
  227. },
  228. beforeDestroy() {
  229. window.openCameraCallBack = null;
  230. window.openNFCScanCallBack = null;
  231. },
  232. methods: {
  233. //长度校验
  234. validator(val) {
  235. let len = val.length;
  236. if( len > 5) {
  237. this.$toast.fail('问题情况输入长度不能超过200');
  238. return true
  239. }else {
  240. return false
  241. }
  242. },
  243. //获取NFC已扫描数据
  244. getNfcState(arr){
  245. arr = arr || [];
  246. let nums = arr.filter(v=>{return v.status === 1});
  247. return nums.length;
  248. },
  249. //调用nfc
  250. checkNFC(){
  251. //设置nfc调用后的回调
  252. window.openNFCScanCallBack = this.openNFCScanCallBack;
  253. //设置loading弹窗
  254. this.$toast.loading({
  255. duration: 0, // 持续展示 toast
  256. position: 'top',
  257. forbidClick: true,
  258. message: '请靠近NFC标签,进行扫描!',
  259. });
  260. let second = 30;
  261. this.timer = setInterval(() => {
  262. second--;
  263. if(!second){
  264. this.$toast.clear();
  265. clearInterval(this.timer);
  266. this.$toast.fail({
  267. message: '未扫描到任何信息!',
  268. });
  269. }
  270. }, 1000);
  271. //挂载nfc
  272. this.useNFC();
  273. },
  274. //调用nfc后的回调
  275. openNFCScanCallBack(nfcStr){
  276. //alert(JSON.stringify(nfcStr))
  277. clearInterval(this.timer);
  278. let nfcCode = '';
  279. try{
  280. let nfc = JSON.parse(nfcStr);
  281. nfcCode = nfc.content;
  282. }catch (e) {
  283. nfcCode = nfcStr.content;
  284. }
  285. // let nfc = JSON.parse(nfcStr);
  286. // let nfcCode = nfc.content;
  287. //alert(nfcCode)
  288. this.checkNfcFilter(nfcCode);
  289. },
  290. //验证nfc数据
  291. checkNfcFilter(nfcCode){
  292. //let areaId = null;
  293. let checkOk = false;
  294. //alert(JSON.stringify(this.NFCList,'NFCList'));
  295. this.NFCList.forEach(v => {
  296. if(v.nfcCode === nfcCode){
  297. if(v.status === 1){
  298. this.$toast.fail('NFC点位:' + v.nfcName + '已扫描,请勿重复扫描!');
  299. throw new Error('NFC点位:' + v.nfcName + '已扫描,请勿重复扫描!');
  300. }
  301. v.status = 1;
  302. v.scanMethod = 0;
  303. this.$toast('NFC点位:' + v.nfcName + '扫描成功!');
  304. checkOk = true;
  305. }
  306. });
  307. if(!checkOk){
  308. this.$toast.fail( "扫描结果不在本次检查范围内!");
  309. }
  310. },
  311. //是否显示nfc图标
  312. nfcState(item){
  313. if(item.nfcList && item.nfcList.length > 0){
  314. return item.nfcList.some(v=>{
  315. return v.status === 0
  316. })
  317. }
  318. return false
  319. },
  320. //格式化时间范围
  321. formatTime(start,end,format){
  322. format = format || 'YYYY-MM-DD'
  323. return `${this.dayjs(start).format(format)} ~ ${this.dayjs(end).format(format)}`;
  324. },
  325. //插入检查项
  326. addItem(val) {
  327. console.log(val, 'list')
  328. if (!val) return
  329. let str = JSON.parse(JSON.stringify(val))
  330. str.forEach(valItem => {
  331. console.log(this.checkList, 'checkList')
  332. // 查找是否有与 valItem.itemId 相同的项
  333. const existingItem = this.checkList.find(checkItem => checkItem.itemId === valItem.itemId)
  334. if (existingItem) {
  335. // 如果存在相同 itemId 的项,查找 pointList 是否有与 valItem.pointId 相同的项
  336. const existingPoint = existingItem.pointList.find(pointItem => pointItem.pointId === valItem.id)
  337. if (!existingPoint) {
  338. console.log(existingItem, 'point添加成功')
  339. this.$nextTick(() => {
  340. valItem.isAdd = 1;
  341. existingItem.pointList.push(valItem)
  342. this.active = true
  343. })
  344. } else {
  345. this.$toast(existingPoint.pointName + '已添加')
  346. }
  347. } else {
  348. console.log(valItem, 'item添加成功')
  349. this.checkList.push({
  350. isAdd:1,
  351. itemId: valItem.itemId,
  352. itemName: valItem.itemName,
  353. pointList: [valItem]
  354. })
  355. this.active = true
  356. }
  357. })
  358. },
  359. goBack() {
  360. this.active = true
  361. },
  362. getState(state) {
  363. switch (state){
  364. case '待检查':
  365. return '#008cd6';
  366. case '进行中':
  367. return '#bc9f71';
  368. case '已完成':
  369. return '#009240';
  370. case '已逾期':
  371. return '#D7000F';
  372. }
  373. },
  374. addCheck() {
  375. this.active = false
  376. },
  377. clickWarnImage(arr, i) {
  378. this.preViewImages.images = arr.map(v => imgUrl(v.imgPath))
  379. this.preViewImages.startPosition = i
  380. ImagePreview(this.preViewImages)
  381. },
  382. preViewNFC(i) {
  383. this.preViewImages.images = this.nfcImage.map(v => imgUrl(v.img))
  384. this.preViewImages.startPosition = i
  385. ImagePreview(this.preViewImages)
  386. },
  387. getDicts(s) {
  388. return this.stateList.find(v => s == v.dictValue).dictLabel
  389. },
  390. //初始化数据
  391. getData() {
  392. let taskId = this.$route.query.id;
  393. registerDetail(taskId).then(res => {
  394. console.log(res, 'res')
  395. this.taskInfo = res.data;
  396. this.enable = this.taskInfo.status === 1 || this.taskInfo.status === 2; //是否可编辑
  397. this.checkList = res.data.checkList;
  398. this.dateList = this.getDictItem('rectification_deadline');
  399. //设置默认展开项
  400. this.activeNames = this.checkList.map(v => v.itemName);
  401. this.isSubmit = res.data.inRegisterTime;
  402. })
  403. },
  404. //保存数据
  405. saveData() {
  406. //验证必填项
  407. // let pointData = []
  408. // this.checkList.forEach(v => {
  409. // v.pointList.forEach(item => {
  410. // pointData.push(item)
  411. // })
  412. // })
  413. // let arr = pointData.filter(v => {
  414. // if (v.status === 1) {
  415. // return !v.remark || !v.rectificationDeadline
  416. // }
  417. // })
  418. //if (arr.length) return this.$toast(`${arr[0].itemName}:该信息不完整请填写`)
  419. this.taskInfo.isSubmit = 0;
  420. registerSubmit(this.taskInfo).then(res => {
  421. this.$toast('保存成功');
  422. this.$router.replace({
  423. name:'securityCheckRegister',
  424. path:'/securityCheckRegister',
  425. params:{event:'refresh'}
  426. });
  427. })
  428. },
  429. //提交数据
  430. submitData() {
  431. //验证必填项
  432. let pointData = this.checkList.flatMap(v => v.pointList);
  433. let allNfcList = pointData.flatMap(v=>v.nfcList);
  434. let result = allNfcList.some(v=>v.status != 1);
  435. //some函数的用法
  436. if(result){
  437. this.$toast('请先扫描NFC标签');
  438. return;
  439. }
  440. let arr = pointData.filter(v => {
  441. if (v.status === 1) {
  442. return !v.remark || !v.rectificationDeadline
  443. }
  444. })
  445. if (arr.length) return this.$toast(`${arr[0].itemName}:该信息不完整请填写`);
  446. this.taskInfo.isSubmit = 1;
  447. registerSubmit(this.taskInfo).then(res => {
  448. this.$toast('提交成功')
  449. this.$router.replace({
  450. name:'securityCheckRegister',
  451. path:'/securityCheckRegister',
  452. params:{event:'refresh'}
  453. });
  454. })
  455. },
  456. //授权
  457. accredit() {
  458. let { checkOrgId, ymdDate, planId, beCheckedOrgId, id } = this.taskInfo
  459. this.$router.push({
  460. path: '/addWorker',
  461. query: {
  462. orgId: checkOrgId,
  463. ymdDate,
  464. planId,
  465. beCheckedOrgId,
  466. taskId: id
  467. }
  468. })
  469. },
  470. //点击NFC图标
  471. clickNFC(arr) {
  472. this.NFCList = arr;
  473. console.log(this.NFCList,'NFCList')
  474. this.$refs.NfcPopup.show(arr);
  475. },
  476. //清空数据
  477. clearData() {
  478. this.areaList = []
  479. this.taskInfo = []
  480. this.selectArea = []
  481. this.NFCList = []
  482. this.checkList = []
  483. this.checkItemList = []
  484. this.NFCNum = 0
  485. this.enable = false
  486. },
  487. //切换开关时添加操作时间
  488. switchChange(item) {
  489. console.log(item, '666')
  490. //item.resTime = formatDate(new Date());
  491. },
  492. //添加图片时的回调
  493. changeNfcImg(imgItem) {
  494. console.log(imgItem, this.NFCList, 'imgItem')
  495. this.NFCList.forEach(v => {
  496. if (v.nfcCode === imgItem.nfcCode) {
  497. v.img = imgItem.url
  498. v.status = 1
  499. v.scanMethod = 1
  500. this.nfcImage.push(v)
  501. }
  502. })
  503. console.log(this.NFCList, this.nfcImage, 'nfcObj')
  504. },
  505. }
  506. }
  507. </script>
  508. <style lang="scss" scoped>
  509. .register-edit {
  510. height: 100%;
  511. overflow: hidden;
  512. .page-container {
  513. height: calc(100vh - 246px);
  514. overflow: auto;
  515. padding: 20px;
  516. }
  517. .bottom-box{
  518. padding:10px 20px 20px 20px;
  519. >P{
  520. padding-left: 10px;
  521. font-size: 22px;
  522. color: red;
  523. line-height: 36px;
  524. }
  525. .flex-box {
  526. display: flex;
  527. justify-content: space-between;
  528. align-items: center;
  529. > span {
  530. margin: 0 20px;
  531. }
  532. >button{
  533. flex:.45;
  534. margin:0 10px;
  535. /* min-width: 30%;
  536. max-width: 50%; */
  537. }
  538. }
  539. }
  540. .legend {
  541. background-color: #fff;
  542. padding: 0 20px;
  543. height: 80px;
  544. line-height: 80px;
  545. font-size: 30px;
  546. display: flex;
  547. justify-content: space-between;
  548. > span {
  549. color: orange;
  550. }
  551. }
  552. .card {
  553. margin-bottom: 20px;
  554. box-shadow: 0 10px 10px #eaeaea;
  555. &:last-child {
  556. margin-bottom: 0;
  557. }
  558. }
  559. .collapse-box{
  560. -padding-bottom: 10px;
  561. }
  562. .check-area {
  563. background-color: #f1f1f1;
  564. margin: 10px;
  565. padding: 20px;
  566. color: #aaa;
  567. border-radius: 6px;
  568. display: flex;
  569. justify-content: space-between;
  570. align-items: center;
  571. box-shadow: 0 2px 6px #ddd;
  572. }
  573. .nfc-icon {
  574. width: 50px;
  575. height: 50px;
  576. margin-left: 20px;
  577. }
  578. .custom-title {
  579. align-self: center;
  580. vertical-align: middle;
  581. }
  582. .upload-box {
  583. padding: 30px;
  584. }
  585. .warning-msg {
  586. color: orange;
  587. text-align: center;
  588. height: 80px;
  589. line-height: 80px;
  590. }
  591. .active {
  592. color: #fff;
  593. background-color: #1989fa;
  594. }
  595. .nfc-img {
  596. display: inline-block;
  597. width: 140px;
  598. height: 140px;
  599. margin: 0 10px;
  600. position: relative;
  601. > img {
  602. width: 100%;
  603. height: 100%;
  604. border: none;
  605. }
  606. > span {
  607. position: absolute;
  608. padding: 0 10px;
  609. bottom: 0;
  610. left: 0;
  611. display: block;
  612. width: 100%;
  613. background-color: rgba(0, 0, 0, 0.2);
  614. color: #eaeaea;
  615. font-size: 20px;
  616. overflow: hidden;
  617. text-overflow: ellipsis;
  618. white-space: nowrap;
  619. line-height: 30px;
  620. height: 30px;
  621. }
  622. }
  623. }
  624. </style>