detail.vue 17 KB

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