detail.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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. <van-field
  82. required
  83. :maxlength="255"
  84. v-model="item.remark"
  85. rows="1"
  86. autosize
  87. label="情况描述:"
  88. type="textarea"
  89. placeholder="请输入(255字以内)"
  90. />
  91. <select-cell
  92. required
  93. :disabled="!enable"
  94. title="整改期限"
  95. v-model="item.rectificationDeadline"
  96. :data-list="getDictItem('rectification_deadline')"
  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" plain @click="accredit" v-show="showGrantBtn">授权</van-button>
  122. <van-button type="info" plain hairline @click="saveData">保存</van-button>
  123. <van-button type="info" @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" :orgType="taskInfo.beCheckOrgType"></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',"roleList",'orgId']),
  187. showGrantBtn(){
  188. let userRoleIds = this.roleList.map((r) => r.roleId);
  189. let taskRoleIds = this.taskInfo.checkRoles
  190. ? this.taskInfo.checkRoles.map((r) => r.id)
  191. : [];
  192. return (
  193. this.taskInfo.status != 3 &&
  194. this.taskInfo.planType==3 &&
  195. this.taskInfo.checkOrgId == this.orgId &&
  196. userRoleIds.find((ur) => taskRoleIds.includes(ur))
  197. );
  198. }
  199. },
  200. mounted() {
  201. this.id = this.$route.query.id
  202. this.getData()
  203. },
  204. beforeDestroy() {
  205. window.openCameraCallBack = null
  206. window.openNFCScanCallBack = null
  207. },
  208. methods: {
  209. //长度校验
  210. validator(val) {
  211. let len = val.length;
  212. if( len > 5) {
  213. this.$toast.fail('问题情况输入长度不能超过200');
  214. return true
  215. }else {
  216. return false
  217. }
  218. },
  219. getNfcState(arr){
  220. arr = arr || [];
  221. let num = 0;
  222. arr.forEach(v=>{
  223. if(v.status === 1){
  224. num++
  225. }
  226. })
  227. return num;
  228. },
  229. checkNFC(){
  230. window.openNFCScanCallBack = this.openNFCScanCallBack;
  231. this.useNFC();
  232. this.$toast.loading({
  233. duration: 0, // 持续展示 toast
  234. position: 'top',
  235. forbidClick: true,
  236. message: '请靠近NFC标签,进行扫描!',
  237. });
  238. let second = 30;
  239. this.timer = setInterval(() => {
  240. second--;
  241. if(!second){
  242. this.$toast.clear();
  243. clearInterval(this.timer);
  244. this.$toast.fail({
  245. message: '未扫描到任何信息!',
  246. });
  247. }
  248. }, 1000);
  249. },
  250. openNFCScanCallBack(nfcStr){
  251. clearInterval(this.timer);
  252. let nfcCode = '';
  253. try{
  254. let nfc = JSON.parse(nfcStr);
  255. nfcCode = nfc.content;
  256. }catch (e) {
  257. nfcCode = nfcStr.content;
  258. }
  259. // let nfc = JSON.parse(nfcStr);
  260. // let nfcCode = nfc.content;
  261. //alert(nfcCode)
  262. this.checkNfcFilter(nfcCode);
  263. },
  264. checkNfcFilter(nfcCode){
  265. let areaId = null;
  266. let checkOk = false;
  267. this.NFCList.forEach(v => {
  268. if(v.nfcCode === nfcCode){
  269. areaId = v.areaId;
  270. this.switchArea(areaId);
  271. if(v.status === 1){
  272. this.$toast.fail('NFC点位:' + v.nfcName + '已扫描,请勿重复扫描!');
  273. throw new Error('NFC点位:' + v.nfcName + '已扫描,请勿重复扫描!');
  274. }
  275. v.status = 1;
  276. v.scanMethod = 0;
  277. v.submitTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
  278. v.submitBy = this.id;
  279. this.$toast.success('NFC点位:' + v.nfcName + '扫描成功!');
  280. checkOk = true;
  281. }
  282. });
  283. if(checkOk){
  284. this.yesNFCnums++
  285. this.resumptionData.yesNFCNums++
  286. this.resumptionData.noNFCNums--
  287. }else{
  288. this.$toast.fail(nfcCode + ",不在本次履职范围内!");
  289. }
  290. this.validateArea(areaId)
  291. },
  292. switchArea(areaId){
  293. this.areas.forEach((area, i) => {
  294. if (areaId === area.areaId) {
  295. this.activeArea(area, i)
  296. }
  297. })
  298. },
  299. //是否显示nfc图标
  300. nfcState(item){
  301. if(item.nfcList && item.nfcList.length > 0){
  302. return item.nfcList.some(v=>{
  303. return v.status === 0
  304. })
  305. }
  306. return false
  307. },
  308. //格式化时间范围
  309. formatTime(start,end,format){
  310. format = format || 'YYYY-MM-DD'
  311. return `${this.dayjs(start).format(format)} ~ ${this.dayjs(end).format(format)}`;
  312. },
  313. //插入检查项
  314. addItem(val) {
  315. console.log(val, 'list')
  316. if (!val) return
  317. let str = JSON.parse(JSON.stringify(val))
  318. str.forEach(valItem => {
  319. console.log(this.checkList, 'checkList')
  320. // 查找是否有与 valItem.itemId 相同的项
  321. const existingItem = this.checkList.find(checkItem => checkItem.itemId === valItem.itemId)
  322. if (existingItem) {
  323. // // 如果存在相同 itemId 的项,查找 pointList 是否有与 valItem.pointId 相同的项
  324. const existingPoint = existingItem.pointList.find(pointItem => pointItem.pointId === valItem.id)
  325. if (!existingPoint) {
  326. console.log(existingItem, 'point添加成功')
  327. this.$nextTick(() => {
  328. valItem.isAdd = 1;
  329. existingItem.pointList.push(valItem)
  330. this.active = true
  331. })
  332. } else {
  333. this.$toast(existingPoint.pointName + '已添加')
  334. }
  335. } else {
  336. console.log(valItem, 'item添加成功')
  337. this.checkList.push({
  338. isAdd:1,
  339. itemId: valItem.itemId,
  340. itemName: valItem.itemName,
  341. pointList: [valItem]
  342. })
  343. this.active = true
  344. }
  345. })
  346. },
  347. goBack() {
  348. this.active = true
  349. },
  350. getState(state) {
  351. switch (state){
  352. case '待检查':
  353. return '#008cd6';
  354. case '进行中':
  355. return '#bc9f71';
  356. case '完成':
  357. return '#009240';
  358. case '已过期':
  359. return '#D7000F';
  360. }
  361. },
  362. addCheck() {
  363. this.active = false
  364. },
  365. clickWarnImage(arr, i) {
  366. this.preViewImages.images = arr.map(v => imgUrl(v.imgPath))
  367. this.preViewImages.startPosition = i
  368. ImagePreview(this.preViewImages)
  369. },
  370. preViewNFC(i) {
  371. this.preViewImages.images = this.nfcImage.map(v => imgUrl(v.img))
  372. this.preViewImages.startPosition = i
  373. ImagePreview(this.preViewImages)
  374. },
  375. getDicts(s) {
  376. return this.stateList.find(v => s == v.dictValue).dictLabel
  377. },
  378. //初始化数据
  379. getData() {
  380. let taskId = this.$route.query.id
  381. registerDetail(taskId).then(res => {
  382. console.log(res, 'res')
  383. this.taskInfo = res.data
  384. this.enable = this.taskInfo.status === 1 || this.taskInfo.status === 2 //是否可编辑
  385. this.checkList = res.data.checkList
  386. //设置默认展开项
  387. this.activeNames = this.checkList.map(v => v.itemName)
  388. })
  389. },
  390. //保存数据
  391. saveData() {
  392. //验证必填项
  393. // let pointData = []
  394. // this.checkList.forEach(v => {
  395. // v.pointList.forEach(item => {
  396. // pointData.push(item)
  397. // })
  398. // })
  399. // let arr = pointData.filter(v => {
  400. // if (v.status === 1) {
  401. // return !v.remark || !v.rectificationDeadline
  402. // }
  403. // })
  404. //if (arr.length) return this.$toast(`${arr[0].itemName}:该信息不完整请填写`)
  405. this.taskInfo.isSubmit = 0;
  406. registerSubmit(this.taskInfo).then(res => {
  407. this.$toast('保存成功')
  408. this.$router.replace({
  409. path: '/securityCheckRegister'
  410. })
  411. })
  412. },
  413. //提交数据
  414. submitData() {
  415. //验证必填项
  416. let pointData = []
  417. this.checkList.forEach(v => {
  418. v.pointList.forEach(item => {
  419. pointData.push(item)
  420. })
  421. })
  422. let arr = pointData.filter(v => {
  423. if (v.status === 1) {
  424. return !v.remark || !v.rectificationDeadline
  425. }
  426. })
  427. if (arr.length) return this.$toast(`${arr[0].itemName}:该信息不完整请填写`)
  428. //console.log( this.taskInfo,' this.taskInfo')
  429. this.taskInfo.isSubmit = 1
  430. registerSubmit(this.taskInfo).then(res => {
  431. this.$toast('提交成功')
  432. this.$router.replace({
  433. path: '/securityCheckRegister'
  434. })
  435. })
  436. },
  437. //授权
  438. accredit() {
  439. let { checkOrgId, ymdDate, planId, beCheckedOrgId, id } = this.taskInfo
  440. console.log(checkOrgId, 'checkOrgId')
  441. this.$router.push({
  442. path: '/addWorker',
  443. query: {
  444. orgId: checkOrgId,
  445. ymdDate,
  446. planId,
  447. beCheckedOrgId,
  448. taskId: id
  449. }
  450. })
  451. },
  452. //点击NFC图标
  453. clickNFC(arr) {
  454. this.NFCList = arr;
  455. console.log(this.NFCList,'NFCList')
  456. this.$refs.NfcPopup.show(arr);
  457. },
  458. //清空数据
  459. clearData() {
  460. this.areaList = []
  461. this.taskInfo = []
  462. this.selectArea = []
  463. this.NFCList = []
  464. this.checkList = []
  465. this.checkItemList = []
  466. this.NFCNum = 0
  467. this.enable = false
  468. },
  469. //切换开关时添加操作时间
  470. switchChange(item) {
  471. console.log(item, '666')
  472. //item.resTime = formatDate(new Date());
  473. },
  474. //添加图片时的回调
  475. changeNfcImg(imgItem) {
  476. console.log(imgItem, this.NFCList, 'imgItem')
  477. this.NFCList.forEach(v => {
  478. if (v.nfcCode === imgItem.nfcCode) {
  479. v.img = imgItem.url
  480. v.status = 1
  481. v.scanMethod = 1
  482. this.nfcImage.push(v)
  483. }
  484. })
  485. console.log(this.NFCList, this.nfcImage, 'nfcObj')
  486. },
  487. }
  488. }
  489. </script>
  490. <style lang="scss" scoped>
  491. .register-edit {
  492. height: 100%;
  493. overflow: hidden;
  494. .page-container {
  495. height: calc(100vh - 220px);
  496. overflow: auto;
  497. padding: 20px;
  498. }
  499. .flex-box {
  500. padding: 20px;
  501. display: flex;
  502. justify-content: space-between;
  503. align-items: center;
  504. > span {
  505. margin: 0 20px;
  506. }
  507. >button{
  508. flex:.45;
  509. margin:0 10px;
  510. /* min-width: 30%;
  511. max-width: 50%; */
  512. }
  513. }
  514. .legend {
  515. background-color: #fff;
  516. padding: 0 20px;
  517. height: 80px;
  518. line-height: 80px;
  519. font-size: 30px;
  520. display: flex;
  521. justify-content: space-between;
  522. > span {
  523. color: orange;
  524. }
  525. }
  526. .card {
  527. margin-bottom: 20px;
  528. box-shadow: 0 10px 10px #eaeaea;
  529. &:last-child {
  530. margin-bottom: 0;
  531. }
  532. }
  533. .check-area {
  534. background-color: #f1f1f1;
  535. margin: 10px;
  536. padding: 20px;
  537. color: #aaa;
  538. border-radius: 6px;
  539. display: flex;
  540. justify-content: space-between;
  541. align-items: center;
  542. box-shadow: 0 2px 6px #ddd;
  543. }
  544. .nfc-icon {
  545. width: 50px;
  546. height: 50px;
  547. margin-left: 20px;
  548. }
  549. .custom-title {
  550. align-self: center;
  551. vertical-align: middle;
  552. }
  553. .upload-box {
  554. margin: 30px;
  555. }
  556. .warning-msg {
  557. color: orange;
  558. text-align: center;
  559. height: 80px;
  560. line-height: 80px;
  561. }
  562. .active {
  563. color: #fff;
  564. background-color: #1989fa;
  565. }
  566. .nfc-img {
  567. display: inline-block;
  568. width: 140px;
  569. height: 140px;
  570. margin: 0 10px;
  571. position: relative;
  572. > img {
  573. width: 100%;
  574. height: 100%;
  575. border: none;
  576. }
  577. > span {
  578. position: absolute;
  579. padding: 0 10px;
  580. bottom: 0;
  581. left: 0;
  582. display: block;
  583. width: 100%;
  584. background-color: rgba(0, 0, 0, 0.2);
  585. color: #eaeaea;
  586. font-size: 20px;
  587. overflow: hidden;
  588. text-overflow: ellipsis;
  589. white-space: nowrap;
  590. line-height: 30px;
  591. height: 30px;
  592. }
  593. }
  594. }
  595. </style>