Route.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <view>
  3. <uni-nav-bar fixed="true" height="80px" dark color="#ffffff" backgroundColor="#1989fa" shadow left-icon="back"
  4. title="巡检中" @clickLeft="GoBack()"/>
  5. <view class="uni-flex uni-row" style="background-color: #666;color:#fff;margin-bottom:20px;padding:10px">
  6. <view class="flex-item;">
  7. <uni-icons style="position:relative;top:20px" type="person" size="40" color="#fff"></uni-icons>
  8. <text style="font-size:20px;line-height:20px;padding-left: 15px;;">正在巡检 {{routename}}</text>
  9. </view>
  10. <view class="flex-item" style="padding-left:60px;font-size:18px;">{{this.plantime}}</view>
  11. </view>
  12. <button style="height:40px;line-height:40px;border-radius:4px;background-color:#1989fa;color:#fff;border:#1989fa;margin:20px;" class="button" type="info" @click="NfcScan()">NFC感应</button>
  13. <uni-list>
  14. <uni-list-item direction="row" v-for="item in listdata" :key="item.autoid" :title="item.pointname" :note="item.hname" thumb="/static/img/route.png"
  15. thumb-size="lg" :rightText="item.status" @click="GoRouteViews(item)" link>
  16. </uni-list-item>
  17. </uni-list>
  18. </view>
  19. </template>
  20. <script>
  21. import NFC from "../../static/js/nfc.js"
  22. export default {
  23. data() {
  24. return {
  25. planCode:'',
  26. planDate:'',
  27. plantime:'',
  28. routename:'',
  29. nfcId:'',
  30. pointArr:[],
  31. listdata: []
  32. };
  33. },
  34. created(){
  35. this.planCode =decodeURIComponent(this.getUrlParam('plancode'))
  36. this.planDate =decodeURIComponent(this.getUrlParam('plandate'))
  37. this.plantime =decodeURIComponent(this.getUrlParam('plantime'))
  38. console.log(this.planCode+"==="+this.planDate+"===="+this.plantime)
  39. this.getRouteList()
  40. },
  41. methods:{
  42. getRouteList() {
  43. var data = {
  44. planCode: this.planCode,
  45. planDate: this.planDate,
  46. planTime: this.plantime
  47. }
  48. this.$api.GetRouteList(data).then(res=>{
  49. if (res.isSuccess && res.data !=undefined && res.data.length>0) {
  50. this.listdata = res.data // 将接口返回赋值data定义的数组
  51. this.routename = res.data[0].routename
  52. //巡更点加入数组 用于nfc感应验证
  53. this.listdata.forEach(e => {
  54. this.pointArr.push(e.pointcode)
  55. })
  56. }else{
  57. this.listdata =[]
  58. uni.showToast({
  59. icon: 'none',
  60. title: "没有查询到记录~"
  61. });
  62. }
  63. })
  64. },
  65. async NfcScan(){
  66. // 这里用异步获取读取到的NFC数据
  67. this.nfcId =await NFC.listenNFCStatus()
  68. if(!this.nfcId) return
  69. if (this.pointArr.indexOf(this.nfcId) === -1) {
  70. uni.showToast({
  71. icon: 'none',
  72. title: '未找到对应巡检点!',
  73. duration: 2000
  74. });
  75. } else {
  76. uni.showToast({
  77. icon: 'none',
  78. title: '识别成功! 编号:'+this.nfcId,
  79. duration: 2000
  80. });
  81. this.postNfcData()
  82. }
  83. },
  84. postNfcData(){
  85. if(this.$store.state.data.staffCode == undefined){
  86. uni.showToast({
  87. icon: 'none',
  88. title: "token过期请重新登录~",
  89. duration:1500
  90. });
  91. setTimeout(function() {
  92. uni.navigateTo({
  93. url:'../index/login'
  94. })
  95. }, 1500);
  96. return
  97. }
  98. var data= {
  99. userId: this.$store.state.data.staffCode,
  100. pointCode: this.nfcId
  101. }
  102. this.$api.NfcScan(data).then(res=>{
  103. if(!res.isSuccess){
  104. uni.showToast({
  105. icon: 'none',
  106. title: res.errMsg
  107. });
  108. return
  109. }
  110. this.getRouteList()
  111. })
  112. },
  113. GoRouteViews (item) {
  114. if(item.status=='未巡检'){
  115. uni.showToast({
  116. icon: 'none',
  117. title: 'NFC感应后才可点击'
  118. });
  119. return
  120. }
  121. uni.navigateTo({
  122. url:'/pages/inspection/Detail?pkcode='+encodeURIComponent(item.autoid)
  123. });
  124. },
  125. GoBack(){
  126. uni.navigateTo({
  127. url:"/pages/inspection/Plan"
  128. })
  129. },
  130. getUrlParam(_key){
  131. var pages = getCurrentPages() //获取加载的页面
  132. var currentPage = pages[pages.length - 1] //获取当前页面的对象
  133. var url = currentPage.route //当前页面url
  134. var options = currentPage.options //如果要获取url中所带的参数可以查看options
  135. return options[_key];
  136. },
  137. },
  138. }
  139. </script>
  140. <style>
  141. </style>