gasRecordCard.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view class="gas-record-card">
  3. <view class="record-top-area">
  4. <view class="record-write-box">
  5. <text class="dialog-label">卡ID:</text>
  6. <u--input v-model="cardId" placeholder="请输入卡片ID" type="number" size="small" clearable
  7. style="width:220px;padding: 2px 9px;"></u--input>
  8. </view>
  9. <!-- <u-button type="primary" size="small" style="margin: 2px 0px;" @click="getNfcFormat">格式化tag</u-button> -->
  10. <u-button type="primary" size="small" style="margin: 2px 0px;" @click="getNfcWrite">录入</u-button>
  11. <u-button type="primary" size="small" style="margin: 2px 0px;" @click="getNfcRead">读取</u-button>
  12. </view>
  13. <view class="record-bot-area">
  14. <u-toast ref="uToast"></u-toast>
  15. <view class="record-container" v-if="cardData.id">
  16. <view class="record-title">
  17. <span class="record-text">卡片ID读取</span>
  18. </view>
  19. <view class="record-card">
  20. <view class="record-card-item">
  21. <text class="card-item-label">当前卡ID为:</text>
  22. <text class="card-item-value">{{ cardData.id }}</text>
  23. </view>
  24. <view class="record-card-item">
  25. <text class="card-item-label">当前巡检点为:</text>
  26. <text class="card-item-value">{{ cardData.address }}</text>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import api from "@/api/api";
  35. import testNfc from "@/common/util/hexiii-nfc.js"
  36. export default {
  37. name: 'gasRecordCard',
  38. data() {
  39. return {
  40. isNfc: true,
  41. cardId: '',
  42. cardData: { id: '', address: '' },
  43. }
  44. },
  45. computed: {
  46. cardIds:function(){
  47. return this.$store.getters.nfcreadtxt;
  48. }
  49. },
  50. watch:{
  51. cardIds:{
  52. handler(newV,oldV){
  53. console.log(newV,'newV------------------------')
  54. this.getCardLists(newV)
  55. },
  56. }
  57. },
  58. mounted() {
  59. testNfc.listenNFCStatus()
  60. },
  61. methods: {
  62. //获取NFC卡读取内容
  63. getCardLists(ids) {
  64. let that = this
  65. new Promise((resolve, reject) => {
  66. api
  67. .getCardList({ id: ids })
  68. .then((response) => {
  69. if (response.data.code == 200) {
  70. let data = response.data.result
  71. that.cardData.id = data.id
  72. that.cardData.address = data.strInstallPos
  73. } else {
  74. that.$refs.uToast.show({
  75. type: 'default',
  76. icon: false,
  77. message: response.data.message,
  78. })
  79. }
  80. })
  81. });
  82. },
  83. //格式化tag
  84. // getNfcFormat() {
  85. // testNfc.__write()
  86. // },
  87. //nfc 写入
  88. getNfcWrite() {
  89. let that = this
  90. new Promise((resolve, reject) => {
  91. api
  92. .enterCardId({ id: that.cardId, })
  93. .then((response) => {
  94. if (response.data.code == 200) {
  95. if (that.isNfc) {
  96. // 调用 js 文件里面的方法
  97. // testNfc.setTxt(that.cardId);
  98. testNfc.writeData();
  99. } else {
  100. that.$refs.uToast.show({
  101. type: 'default',
  102. icon: false,
  103. message: '录入成功!',
  104. })
  105. }
  106. } else {
  107. that.$refs.uToast.show({
  108. type: 'default',
  109. icon: false,
  110. message: response.data.message,
  111. })
  112. }
  113. })
  114. });
  115. },
  116. //nfc读取
  117. getNfcRead() {
  118. let that = this
  119. if (that.isNfc) {
  120. // 调用 js 文件里面的方法
  121. testNfc.readData();
  122. } else {
  123. that.getCardLists(that.cardId)
  124. }
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .gas-record-card {
  131. position: relative;
  132. width: 100%;
  133. height: 100%;
  134. .record-top-area {
  135. display: flex;
  136. flex-direction: column;
  137. align-items: center;
  138. width: 100%;
  139. padding: 10px 20px;
  140. box-sizing: border-box;
  141. background-color: #FFF;
  142. margin-bottom: 2px;
  143. }
  144. .record-write-box {
  145. display: flex;
  146. align-items: center;
  147. justify-content: center;
  148. margin-bottom: 10px;
  149. .dialog-label {
  150. width: 60px;
  151. text-align: right;
  152. }
  153. }
  154. .record-bot-area {
  155. width: 100%;
  156. height: calc(100% - 138px);
  157. padding: 10px;
  158. box-sizing: border-box;
  159. background-color: #FFF;
  160. margin-bottom: 2px;
  161. overflow-y: auto;
  162. .record-container {
  163. .record-title {
  164. position: relative;
  165. width: 100%;
  166. height: 50rpx;
  167. background: url(/static/warndata/title.png);
  168. background-repeat: no-repeat;
  169. background-size: 100% 100%;
  170. display: flex;
  171. /* 将父级元素设置为 Flex 容器 */
  172. align-items: center;
  173. /* 垂直居中子元素 */
  174. }
  175. .record-text {
  176. margin: 20px;
  177. }
  178. .record-card {
  179. display: flex;
  180. flex-direction: column;
  181. justify-content: center;
  182. width: 100%;
  183. height: 100px;
  184. margin: 10px auto;
  185. border-radius: 10px;
  186. background: url(/static/warndata/work.png),
  187. linear-gradient(to right,
  188. rgba(55, 135, 254, 0.08),
  189. rgba(4, 184, 255, 0.08),
  190. rgba(60, 161, 237, 0.08));
  191. }
  192. .record-card-item {
  193. width: 100%;
  194. padding: 10px;
  195. font-size: 14px;
  196. box-sizing: border-box;
  197. .card-item-label {
  198. display: inline-block;
  199. width: 53%;
  200. text-align: right;
  201. color: #3787fe;
  202. font-weight: bold;
  203. }
  204. }
  205. }
  206. }
  207. }
  208. </style>