detail.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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. let arr = [];
  204. this.checkList.forEach(v=>{
  205. if(v.itemName.indexOf(this.itemName) > -1){
  206. arr.push(v)
  207. }
  208. })
  209. return arr;
  210. },
  211. },
  212. mounted() {
  213. this.id = this.$route.query.id
  214. this.getData()
  215. },
  216. beforeDestroy() {
  217. window.openCameraCallBack = null
  218. window.openNFCScanCallBack = null
  219. },
  220. methods: {
  221. //长度校验
  222. validator(val) {
  223. let len = val.length;
  224. if( len > 5) {
  225. this.$toast.fail('问题情况输入长度不能超过200');
  226. return true
  227. }else {
  228. return false
  229. }
  230. },
  231. getNfcState(arr){
  232. arr = arr || [];
  233. let num = 0;
  234. arr.forEach(v=>{
  235. if(v.status === 1){
  236. num++
  237. }
  238. })
  239. return num;
  240. },
  241. checkNFC(){
  242. window.openNFCScanCallBack = this.openNFCScanCallBack;
  243. this.useNFC();
  244. this.$toast.loading({
  245. duration: 0, // 持续展示 toast
  246. position: 'top',
  247. forbidClick: true,
  248. message: '请靠近NFC标签,进行扫描!',
  249. });
  250. let second = 30;
  251. this.timer = setInterval(() => {
  252. second--;
  253. if(!second){
  254. this.$toast.clear();
  255. clearInterval(this.timer);
  256. this.$toast.fail({
  257. message: '未扫描到任何信息!',
  258. });
  259. }
  260. }, 1000);
  261. },
  262. openNFCScanCallBack(nfcStr){
  263. clearInterval(this.timer);
  264. let nfcCode = '';
  265. try{
  266. let nfc = JSON.parse(nfcStr);
  267. nfcCode = nfc.content;
  268. }catch (e) {
  269. nfcCode = nfcStr.content;
  270. }
  271. // let nfc = JSON.parse(nfcStr);
  272. // let nfcCode = nfc.content;
  273. //alert(nfcCode)
  274. this.checkNfcFilter(nfcCode);
  275. },
  276. checkNfcFilter(nfcCode){
  277. let areaId = null;
  278. let checkOk = false;
  279. this.NFCList.forEach(v => {
  280. if(v.nfcCode === nfcCode){
  281. areaId = v.areaId;
  282. this.switchArea(areaId);
  283. if(v.status === 1){
  284. this.$toast.fail('NFC点位:' + v.nfcName + '已扫描,请勿重复扫描!');
  285. throw new Error('NFC点位:' + v.nfcName + '已扫描,请勿重复扫描!');
  286. }
  287. v.status = 1;
  288. v.scanMethod = 0;
  289. v.submitTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
  290. v.submitBy = this.id;
  291. this.$toast.success('NFC点位:' + v.nfcName + '扫描成功!');
  292. checkOk = true;
  293. }
  294. });
  295. if(checkOk){
  296. this.yesNFCnums++
  297. this.resumptionData.yesNFCNums++
  298. this.resumptionData.noNFCNums--
  299. }else{
  300. this.$toast.fail(nfcCode + ",不在本次履职范围内!");
  301. }
  302. this.validateArea(areaId)
  303. },
  304. switchArea(areaId){
  305. this.areas.forEach((area, i) => {
  306. if (areaId === area.areaId) {
  307. this.activeArea(area, i)
  308. }
  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. //设置默认展开项
  399. this.activeNames = this.checkList.map(v => v.itemName);
  400. })
  401. },
  402. //保存数据
  403. saveData() {
  404. //验证必填项
  405. // let pointData = []
  406. // this.checkList.forEach(v => {
  407. // v.pointList.forEach(item => {
  408. // pointData.push(item)
  409. // })
  410. // })
  411. // let arr = pointData.filter(v => {
  412. // if (v.status === 1) {
  413. // return !v.remark || !v.rectificationDeadline
  414. // }
  415. // })
  416. //if (arr.length) return this.$toast(`${arr[0].itemName}:该信息不完整请填写`)
  417. this.taskInfo.isSubmit = 0;
  418. registerSubmit(this.taskInfo).then(res => {
  419. this.$toast('保存成功')
  420. this.$router.replace({
  421. path: '/securityCheckRegister'
  422. })
  423. })
  424. },
  425. //提交数据
  426. submitData() {
  427. //验证必填项
  428. let pointData = []
  429. this.checkList.forEach(v => {
  430. v.pointList.forEach(item => {
  431. pointData.push(item)
  432. })
  433. })
  434. let arr = pointData.filter(v => {
  435. if (v.status === 1) {
  436. return !v.remark || !v.rectificationDeadline
  437. }
  438. })
  439. if (arr.length) return this.$toast(`${arr[0].itemName}:该信息不完整请填写`)
  440. //console.log( this.taskInfo,' this.taskInfo')
  441. this.taskInfo.isSubmit = 1
  442. registerSubmit(this.taskInfo).then(res => {
  443. this.$toast('提交成功')
  444. this.$router.replace({
  445. path: '/securityCheckRegister'
  446. })
  447. })
  448. },
  449. //授权
  450. accredit() {
  451. let { checkOrgId, ymdDate, planId, beCheckedOrgId, id } = this.taskInfo
  452. console.log(checkOrgId, 'checkOrgId')
  453. this.$router.push({
  454. path: '/addWorker',
  455. query: {
  456. orgId: checkOrgId,
  457. ymdDate,
  458. planId,
  459. beCheckedOrgId,
  460. taskId: id
  461. }
  462. })
  463. },
  464. //点击NFC图标
  465. clickNFC(arr) {
  466. this.NFCList = arr;
  467. console.log(this.NFCList,'NFCList')
  468. this.$refs.NfcPopup.show(arr);
  469. },
  470. //清空数据
  471. clearData() {
  472. this.areaList = []
  473. this.taskInfo = []
  474. this.selectArea = []
  475. this.NFCList = []
  476. this.checkList = []
  477. this.checkItemList = []
  478. this.NFCNum = 0
  479. this.enable = false
  480. },
  481. //切换开关时添加操作时间
  482. switchChange(item) {
  483. console.log(item, '666')
  484. //item.resTime = formatDate(new Date());
  485. },
  486. //添加图片时的回调
  487. changeNfcImg(imgItem) {
  488. console.log(imgItem, this.NFCList, 'imgItem')
  489. this.NFCList.forEach(v => {
  490. if (v.nfcCode === imgItem.nfcCode) {
  491. v.img = imgItem.url
  492. v.status = 1
  493. v.scanMethod = 1
  494. this.nfcImage.push(v)
  495. }
  496. })
  497. console.log(this.NFCList, this.nfcImage, 'nfcObj')
  498. },
  499. }
  500. }
  501. </script>
  502. <style lang="scss" scoped>
  503. .register-edit {
  504. height: 100%;
  505. overflow: hidden;
  506. .page-container {
  507. height: calc(100vh - 220px);
  508. overflow: auto;
  509. padding: 20px;
  510. }
  511. .flex-box {
  512. padding: 20px;
  513. display: flex;
  514. justify-content: space-between;
  515. align-items: center;
  516. > span {
  517. margin: 0 20px;
  518. }
  519. >button{
  520. flex:.45;
  521. margin:0 10px;
  522. /* min-width: 30%;
  523. max-width: 50%; */
  524. }
  525. }
  526. .legend {
  527. background-color: #fff;
  528. padding: 0 20px;
  529. height: 80px;
  530. line-height: 80px;
  531. font-size: 30px;
  532. display: flex;
  533. justify-content: space-between;
  534. > span {
  535. color: orange;
  536. }
  537. }
  538. .card {
  539. margin-bottom: 20px;
  540. box-shadow: 0 10px 10px #eaeaea;
  541. &:last-child {
  542. margin-bottom: 0;
  543. }
  544. }
  545. .check-area {
  546. background-color: #f1f1f1;
  547. margin: 10px;
  548. padding: 20px;
  549. color: #aaa;
  550. border-radius: 6px;
  551. display: flex;
  552. justify-content: space-between;
  553. align-items: center;
  554. box-shadow: 0 2px 6px #ddd;
  555. }
  556. .nfc-icon {
  557. width: 50px;
  558. height: 50px;
  559. margin-left: 20px;
  560. }
  561. .custom-title {
  562. align-self: center;
  563. vertical-align: middle;
  564. }
  565. .upload-box {
  566. margin: 30px;
  567. }
  568. .warning-msg {
  569. color: orange;
  570. text-align: center;
  571. height: 80px;
  572. line-height: 80px;
  573. }
  574. .active {
  575. color: #fff;
  576. background-color: #1989fa;
  577. }
  578. .nfc-img {
  579. display: inline-block;
  580. width: 140px;
  581. height: 140px;
  582. margin: 0 10px;
  583. position: relative;
  584. > img {
  585. width: 100%;
  586. height: 100%;
  587. border: none;
  588. }
  589. > span {
  590. position: absolute;
  591. padding: 0 10px;
  592. bottom: 0;
  593. left: 0;
  594. display: block;
  595. width: 100%;
  596. background-color: rgba(0, 0, 0, 0.2);
  597. color: #eaeaea;
  598. font-size: 20px;
  599. overflow: hidden;
  600. text-overflow: ellipsis;
  601. white-space: nowrap;
  602. line-height: 30px;
  603. height: 30px;
  604. }
  605. }
  606. }
  607. </style>