checkPointDetail.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <view class="warp">
  3. <uni-card :title="'序号: ' + ciDetail.cicode" :extra="'ID: ' + ciDetail.ciid">
  4. <view style="margin: 20rpx 0;">
  5. <uni-tag :circle="true" text="系统位置" type="success" size="small"
  6. style="font-weight: bold; margin-right: 30rpx;" />
  7. <!-- <text style="padding-right: 36rpx;">检查点位置</text> -->
  8. <text style="padding-right: 20rpx;"> 经度 {{ ciDetail.position.longitude }} </text>
  9. <text>纬度 {{ ciDetail.position.latitude }}</text>
  10. </view>
  11. <view style="margin: 20rpx 0;">
  12. <uni-tag :circle="true" text="当前位置" type="warning" size="small"
  13. style="font-weight: bold; margin-right: 30rpx;" />
  14. <!-- <text style="padding-right: 65rpx;">当前位置</text> -->
  15. <text style="padding-right: 20rpx;">经度 {{ curPos.longitude }} </text>
  16. <text>纬度 {{ curPos.latitude }}</text>
  17. </view>
  18. <view style="text-align: center; margin-top: 10rpx;">
  19. <button @click="getCurPos()" class="mini-btn" type="primary" size="mini"
  20. style="margin-right: 50rpx;">获取位置</button>
  21. <button @click="savePos()" class="mini-btn" type="primary" size="mini">上报位置</button>
  22. </view>
  23. </uni-card>
  24. <uni-section title="NFC列表" type="line">
  25. <uni-list v-if="nfcList.length > 0">
  26. <!-- <uni-list-item v-for="(item, index) in nfcList" :key="item.id" :title="item.id" :note="item.data"> -->
  27. <uni-list-item v-for="(item, index) in nfcList" :key="item" :title="item">
  28. <!-- 自定义 footer-->
  29. <template v-slot:footer>
  30. <button @click="delNfc(index)" class="mini-btn" type="warn" size="mini"
  31. style="height: 60rpx;">删除</button>
  32. </template>
  33. </uni-list-item>
  34. </uni-list>
  35. <view v-else style="text-align: center;">
  36. <text>NFC列表为空</text>
  37. </view>
  38. </uni-section>
  39. <view style="text-align: center; margin-top: 30rpx;">
  40. <button @click="readNfc()" class="mini-btn" type="primary" size="mini" style="margin-right: 50rpx;">读取
  41. NFC</button>
  42. <button @click="saveControlInfo()" class="mini-btn" type="primary" size="mini">上报 NFC</button>
  43. </view>
  44. <!-- 提示信息弹窗 -->
  45. <uni-popup ref="message" type="message">
  46. <uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message>
  47. </uni-popup>
  48. </view>
  49. </template>
  50. <script>
  51. // import nfc from '../../utils/ouu-nfc.js'
  52. import {
  53. IdRequest,
  54. Position,
  55. AssControlInfoSaveRequest,
  56. AssControlInfoGpsSaveRequest
  57. } from "@/grpc/app_api_pb.js"
  58. export default {
  59. components: {},
  60. data() {
  61. return {
  62. ciId: 0,
  63. ciDetail: {
  64. cicode: '',
  65. ciid: '',
  66. position: {
  67. longitude: '',
  68. latitude: ''
  69. },
  70. nfccodelistList: []
  71. },
  72. nfcList: [],
  73. curPos: {
  74. longitude: '',
  75. latitude: ''
  76. },
  77. msgType: 'success',
  78. messageText: '',
  79. }
  80. },
  81. computed: {},
  82. mounted() {
  83. console.log('[checkPointDetail] mounted')
  84. },
  85. onLoad(option) {
  86. console.log('[checkPointDetail] onLoad')
  87. // console.log(option.ciId)
  88. if (option.ciId > 0) {
  89. // nfc.listenNFCStatus()
  90. this.ciId = option.ciId
  91. this.getAssControlInfoDetail()
  92. this.getCurPos()
  93. }
  94. },
  95. onShow() {
  96. console.log('[checkPointDetail] onShow')
  97. uni.$off('NfcRead')
  98. uni.$on('NfcRead', this.onNfcRead)
  99. },
  100. onHide() {
  101. console.log('[checkPointDetail] onHide')
  102. },
  103. beforeDestroy() {
  104. console.log('[checkPointDetail] beforeDestroy')
  105. uni.$off('NfcRead')
  106. },
  107. methods: {
  108. //msgType: success 成功 / warn 警告 / error 失败 / info 消息
  109. messageToggle(messageText = '操作成功', msgType = 'success') {
  110. this.msgType = msgType
  111. this.messageText = messageText
  112. this.$refs.message.open()
  113. },
  114. getAssControlInfoDetail() {
  115. // 创建请求参数并赋值
  116. var request = new IdRequest()
  117. request.setId(this.ciId)
  118. // 调用客户端相应的grpc方法,发送grpc请求,并接受后台发送回来的返回值
  119. this.$client.assControlInfoDetail(request, {}, (err, response) => {
  120. if (err) {
  121. console.log(`[assControlInfoDetail] err: code = ${err.code}` +
  122. `, message = "${err.message}"`)
  123. this.messageToggle('获取检查点信息失败', 'error')
  124. } else {
  125. // console.log(response)
  126. let res = response.toObject()
  127. console.log(res)
  128. this.ciDetail = res
  129. this.nfcList.length = 0
  130. this.nfcList = res.nfccodelistList
  131. }
  132. });
  133. },
  134. getCurPos() {
  135. let that = this
  136. uni.getLocation({
  137. type: 'wgs84',
  138. success: function(res) {
  139. console.log('当前位置的经度:' + res.longitude)
  140. console.log('当前位置的纬度:' + res.latitude)
  141. that.curPos.longitude = res.longitude
  142. that.curPos.latitude = res.latitude
  143. }
  144. });
  145. },
  146. savePos() {
  147. // 创建请求参数并赋值
  148. var request = new AssControlInfoGpsSaveRequest()
  149. request.setCiid(this.ciId)
  150. var position = new Position()
  151. position.setLongitude(this.curPos.longitude)
  152. position.setLatitude(this.curPos.latitude)
  153. request.setPosition(position)
  154. // 调用客户端相应的grpc方法,发送grpc请求,并接受后台发送回来的返回值
  155. this.$client.assControlInfoGpsSave(request, {}, (err, response) => {
  156. if (err) {
  157. console.log(`[assControlInfoGpsSave] err: code = ${err.code}` +
  158. `, message = "${err.message}"`)
  159. this.messageToggle('上报位置信息失败', 'error')
  160. } else {
  161. // console.log(response)
  162. // let res = response.toObject()
  163. // console.log(res)
  164. this.getAssControlInfoDetail()
  165. this.messageToggle('上报位置信息成功')
  166. }
  167. });
  168. },
  169. readNfc() {
  170. this.$nfc.readData()
  171. },
  172. onNfcRead(data) {
  173. console.log('监听到事件来自 nfcRead, data: ' + JSON.stringify(data))
  174. let length = this.nfcList.length
  175. let find = false
  176. for (let i = 0; i < length; i++) {
  177. // if (this.nfcList[i].id === data.id) {
  178. if (this.nfcList[i] === data.id) {
  179. find = true
  180. }
  181. }
  182. if (!find) {
  183. // this.nfcList.push(data)
  184. this.nfcList.push(data.id)
  185. console.log(this.nfcList)
  186. } else {
  187. uni.showToast({
  188. title: 'NFC标签 [' + data.id + '] 已存在',
  189. icon: 'none',
  190. duration: 2000
  191. })
  192. }
  193. },
  194. delNfc(index) {
  195. let that = this
  196. uni.showModal({
  197. title: '操作提示',
  198. content: '确定删除该记录吗?',
  199. success: function(res) {
  200. if (res.confirm) {
  201. console.log('用户点击确定');
  202. that.nfcList.splice(index, 1)
  203. that.messageToggle('删除成功')
  204. } else if (res.cancel) {
  205. console.log('用户点击取消');
  206. }
  207. }
  208. });
  209. },
  210. saveControlInfo() {
  211. // 创建请求参数并赋值
  212. var request = new AssControlInfoSaveRequest()
  213. request.setCiid(this.ciId)
  214. request.setNfccodelistList(this.nfcList)
  215. // 调用客户端相应的grpc方法,发送grpc请求,并接受后台发送回来的返回值
  216. this.$client.assControlInfoSave(request, {}, (err, response) => {
  217. if (err) {
  218. console.log(`[assControlInfoSave] err: code = ${err.code}` +
  219. `, message = "${err.message}"`)
  220. this.messageToggle('上报NFC信息失败', 'error')
  221. } else {
  222. console.log(response)
  223. // let res = response.toObject()
  224. // console.log(res)
  225. this.messageToggle('上报NFC信息成功')
  226. }
  227. });
  228. }
  229. }
  230. }
  231. </script>
  232. <style lang="scss">
  233. .padding {
  234. padding: 0 20rpx;
  235. }
  236. </style>