detail.vue 18 KB

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