detail.vue 14 KB

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