detail.vue 17 KB

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