myRenew.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <view class="myRenew">
  3. <view v-if="!isConnect" class="myRenew_main">
  4. <view class="myRenew_main-top">
  5. <p>更新巡更点信息时,需要保持手机与巡更点贴合~</p>
  6. </view>
  7. <view class="myRenew_main-content">
  8. <image src="../../../static/bg1.png" mode=""></image>
  9. <view class="myRenew_main-text">
  10. <p>请将手机贴至巡更点处~({{timeOutNum}}s)</p>
  11. </view>
  12. <view class="myRenew_main-text1">
  13. <p>巡更点</p>
  14. </view>
  15. </view>
  16. </view>
  17. <view v-else class="myRenew_main">
  18. <view class="myRenew_main-top">
  19. <p>已跟踪到巡更点,请选择更新的信息,请勿抬离手机~</p>
  20. </view>
  21. <view class="myRenew_main-list">
  22. <view class="order_item" v-for="(item,index) in data" :key="index">
  23. <view class="item-top">
  24. <view class="top-box-address">
  25. <p>{{item.positionName}}</p>
  26. </view>
  27. <view @click="handleChoose(item)" class="top-box-time">
  28. 选择
  29. </view>
  30. </view>
  31. </view>
  32. <view class="line" style="margin-top: 30px;">
  33. <u-loadmore loadmoreText="没有更多了" line />
  34. </view>
  35. <view class="footer">
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. getPositionPage
  44. } from '@/api/login.js'
  45. import NFCTool, {
  46. NFC_STATUS_ENUM
  47. } from '@/utils/nfcTool.js'
  48. export default {
  49. data() {
  50. return {
  51. content: 1,
  52. isLoading: false,
  53. searchData: {
  54. data: {},
  55. pageNumber: 1, // 页码
  56. pageSize: 15 // 每页条数
  57. },
  58. total: 0,
  59. data: [],
  60. isConnect: false,
  61. timeOutNum: 60,
  62. };
  63. },
  64. methods: {
  65. // 获取列表
  66. async fetchData() {
  67. uni.showLoading({
  68. title: '加载中...',
  69. icon: 'loading',
  70. mask: true
  71. })
  72. this.isLoading = true
  73. try {
  74. const res = await getPositionPage(this.searchData)
  75. uni.hideLoading()
  76. if (res.data.records && res.data.records.length > 0) {
  77. this.data = [...this.data, ...res.data.records]
  78. }
  79. this.total = res.data.total
  80. this.searchData.pageNumber++
  81. } finally {
  82. this.isLoading = false
  83. uni.hideLoading()
  84. }
  85. },
  86. // 选择
  87. handleChoose(item) {
  88. uni.showModal({
  89. title: '提示',
  90. content: `确定将当前巡更点的信息更新为 ${item.positionName} 吗?`,
  91. success: res => {
  92. if (res.confirm) {
  93. this.write(item);
  94. }
  95. }
  96. })
  97. },
  98. // 识别倒计时
  99. countDownFunc2() {
  100. let count = this.timeOutNum;
  101. if (count > 0) {
  102. this.timerId2 = setTimeout(() => {
  103. count--;
  104. this.timeOutNum = count;
  105. this.countDownFunc2();
  106. }, 1000);
  107. } else {
  108. clearTimeout(this.timerId2)
  109. }
  110. },
  111. // 回调
  112. NFCToolCallBack({
  113. status,
  114. tip,
  115. data
  116. }) {
  117. // console.log('NFCToolCallBack', status, tip, data)
  118. switch (status) {
  119. case NFC_STATUS_ENUM.INIT_ERROR:
  120. clearTimeout(this.timerId2)
  121. uni.showModal({
  122. title: '提示',
  123. content: tip,
  124. showCancel: false,
  125. success: res => {
  126. if (res.confirm) {
  127. uni.switchTab({
  128. url: '/pages/my/my'
  129. })
  130. }
  131. }
  132. })
  133. break;
  134. case NFC_STATUS_ENUM.TIMEOUT_ERROR:
  135. uni.showModal({
  136. title: '提示',
  137. content: 'NFC读取超时,是否重试?',
  138. success: res => {
  139. if (res.confirm) {
  140. this.timeOutNum = 60
  141. this.countDownFunc2()
  142. this.onStart()
  143. } else {
  144. uni.switchTab({
  145. url: '/pages/my/my'
  146. })
  147. }
  148. }
  149. })
  150. break;
  151. case NFC_STATUS_ENUM.WRITE_SUCCESS:
  152. this.isConnect = data?.isConnect;
  153. uni.redirectTo({
  154. url: '/pages/my/myRenewOk/myRenewOk',
  155. })
  156. break;
  157. case NFC_STATUS_ENUM.WRITING:
  158. this.isConnect = data?.isConnect;
  159. break;
  160. case NFC_STATUS_ENUM.WRITE_FAIL:
  161. this.isConnect = data?.isConnect;
  162. clearTimeout(this.timerId2)
  163. this.timeOutNum = 60
  164. uni.showModal({
  165. title: '提示',
  166. content: '未检测到巡更点,请保持手机与巡更点贴合',
  167. showCancel: false,
  168. success: res => {
  169. if (res.confirm) {
  170. this.timeOutNum = 60
  171. this.countDownFunc2()
  172. this.onStart()
  173. }
  174. }
  175. })
  176. break;
  177. default:
  178. break;
  179. }
  180. },
  181. // 开始调用
  182. start() {
  183. this.nfcTool = new NFCTool(this.NFCToolCallBack, {
  184. timeOutNum: this.timeOutNum * 1000
  185. });
  186. this.onStart();
  187. },
  188. write(data) {
  189. // 调用 js 文件里面的方法
  190. this.nfcTool?.writeTag({
  191. id: data.encryptionCode,
  192. positionName: data.positionName
  193. })
  194. },
  195. onStart() {
  196. // 调用 js 文件里面的方法
  197. this.nfcTool?.startDiscovery({
  198. readyWrite: true
  199. })
  200. },
  201. /**
  202. * 注销 NFCAdapter
  203. */
  204. destroy() {
  205. // 调用 js 文件里面的方法
  206. this.nfcTool?.stopDiscovery();
  207. this.nfcTool = null;
  208. }
  209. },
  210. onLoad(options) {
  211. this.start();
  212. },
  213. onShow() {
  214. this.searchData.pageNumber = 1
  215. this.data = []
  216. this.fetchData()
  217. if (!this.isConnect) {
  218. this.countDownFunc2()
  219. }
  220. },
  221. onUnload() {
  222. clearTimeout(this.timerId2)
  223. this.destroy()
  224. },
  225. onHide() {
  226. this.destroy()
  227. },
  228. onReachBottom() {
  229. const {
  230. total,
  231. searchData: {
  232. pageNumber,
  233. pageSize
  234. }
  235. } = this
  236. if (total <= (pageNumber - 1) * pageSize) {
  237. return uni.$u.toast('没有更多了')
  238. }
  239. if (this.isLoading) return
  240. this.fetchData()
  241. },
  242. }
  243. </script>
  244. <style lang="scss">
  245. .myRenew {
  246. .myRenew_main {
  247. .myRenew_main-top {
  248. display: flex;
  249. align-items: center;
  250. justify-content: center;
  251. height: 40px;
  252. font-weight: 400;
  253. color: #3A3C65B2;
  254. font-size: 14px;
  255. line-height: 21px;
  256. }
  257. .myRenew_main-content {
  258. position: relative;
  259. width: 100%;
  260. height: 530px;
  261. margin-bottom: 20px;
  262. image {
  263. width: 100%;
  264. height: 100%;
  265. object-fit: cover;
  266. }
  267. .myRenew_main-text {
  268. position: fixed;
  269. top: 80px;
  270. height: 80px;
  271. width: 100%;
  272. display: flex;
  273. align-items: center;
  274. justify-content: center;
  275. color: #1677FF;
  276. font-weight: 700;
  277. font-size: 24px;
  278. }
  279. .myRenew_main-text1 {
  280. position: fixed;
  281. top: 330px;
  282. right: 48px;
  283. color: #57597C;
  284. }
  285. }
  286. // 列表样式
  287. .myRenew_main-list {
  288. padding: 0 12px;
  289. .order_item {
  290. background: #fff;
  291. padding: 12px;
  292. margin-top: 14px;
  293. border-radius: 10px;
  294. &:last-child {
  295. margin-bottom: 40px;
  296. }
  297. .item-top {
  298. display: flex;
  299. align-items: center;
  300. justify-content: space-between;
  301. .top-box-address {
  302. font-weight: 500;
  303. font-size: 17px;
  304. }
  305. .top-box-time {
  306. padding: 5px 20px;
  307. border-radius: 15px;
  308. background: #F0F8FF;
  309. font-size: 14px;
  310. color: #1677FF;
  311. }
  312. }
  313. }
  314. }
  315. }
  316. }
  317. .footer {
  318. height: 20px;
  319. }
  320. </style>