encryptionNfc.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. // pages/nfc/encryptionNfc/encryptionNfc.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. type:null,
  8. path:null,
  9. showDialog: false,// 详情弹窗
  10. activeText:'--',
  11. scanType:'7', //1查看当前激活状态 2激活 3锁闭 4读温度 7读取UID 8读自定义信息 9写入自定义信息 10读采温周期 X106:X106端读卡
  12. seleteType:[{transportStatus:'00',transportStatusName:'入库'},{transportStatus:'10',transportStatusName:'出库'},{transportStatus:'20',transportStatusName:'结束'}],
  13. modalHidden:true,
  14. region:[],
  15. modalName: null,
  16. chainId:null,
  17. },
  18. getNfcRes(e){
  19. const {sta,msg} = e.detail;
  20. var type1 = ['X101','X102','X103','X104','X106','X107'];
  21. var type = this.data.type;
  22. var path = this.data.path;
  23. switch (path) {
  24. case 'find':
  25. this.goDetailInfo(msg.uid,type)
  26. break;
  27. case 'factorycheck':
  28. this.getInfo(msg.uid,type)
  29. break;
  30. case 'iodep':
  31. this.iodep(msg.uid,type)
  32. break;
  33. case 'addLabel':
  34. this.chainBind(msg.uid,type,this.data.chainId);
  35. break;
  36. default:
  37. break;
  38. }
  39. // this.setData({
  40. // activeText:msg
  41. // })
  42. },
  43. // 绑定标签
  44. chainBind(deviceCode,type,chainId){
  45. var that = this;
  46. const {latitude,longitude} = that.data;
  47. app.requestP({
  48. url:'/chainBound/checkBind',
  49. method:'post',
  50. data:{
  51. deviceCode,
  52. }
  53. }).then(res=>{
  54. if(res.data.data == 0){
  55. app.requestP({
  56. url:'/chainBound/bind',
  57. method:'post',
  58. contentType:' application/json',
  59. data:{
  60. chainId,
  61. deviceCode,
  62. type:type,
  63. lat:latitude,
  64. lng:longitude
  65. }
  66. }).then(response=>{
  67. app.showToptip(that,'success',response.data.msg)
  68. }).catch(err=>{
  69. app.showToptip(that,'error',err.data.msg)
  70. })
  71. }else{
  72. app.showToptip(that,'error',res.data.msg);
  73. }
  74. }).catch(err=>{
  75. app.showToptip(that,'error',err.data.msg)
  76. })
  77. },
  78. // 查一查
  79. goDetailInfo(message,type){
  80. var that = this;
  81. app.requestP({
  82. url:'/chainBound/checkBind',
  83. method:'post',
  84. // contentType:' application/json',
  85. data:{
  86. deviceCode:message,
  87. }
  88. }).then(res=>{
  89. if(res.data.data !=1){
  90. app.showToptip(that,'error',res.data.msg);
  91. return;
  92. }
  93. app.requestP({
  94. url:'/chain/scan',
  95. method:'post',
  96. contentType:' application/json',
  97. data:{
  98. inoculatorId:'',
  99. payload:message,
  100. type
  101. }
  102. }).then(res=>{
  103. var id = res.data.msg;
  104. that.setData({
  105. showDialog: !this.data.showDialog,
  106. detailId:id,
  107. deviceCode:message
  108. });
  109. }).catch(err=>{
  110. app.showToptip(that,'error',err.data.msg)
  111. })
  112. }).catch(err=>{
  113. app.showToptip(that,'error',err.data.msg);
  114. })
  115. },
  116. goDetail(){
  117. var detailId = this.data.detailId;
  118. var deviceCode = this.data.deviceCode || '';
  119. wx.navigateTo({
  120. url: '/pages/query/details?id='+detailId+'&deviceCode='+deviceCode,
  121. })
  122. this.setData({
  123. showDialog:!this.data.showDialog,
  124. })
  125. },
  126. // 出厂检测
  127. getInfo(message){
  128. var that = this;
  129. app.requestP({
  130. url: "/query/scanChip1",
  131. method:"post",
  132. needToken:false,
  133. contentType:' application/json',
  134. data:{
  135. payload:message
  136. }
  137. }).then(res=>{
  138. wx.navigateTo({
  139. url: '/pages/nfc/outNfcTempInfo/outNfcTempInfo?data='+JSON.stringify(res.data.data),
  140. })
  141. }).catch(err=>{
  142. app.showToptip(that,'error',err.data.msg)
  143. })
  144. },
  145. // 出入库
  146. iodep(code,type){
  147. var that =this;
  148. app.requestP({
  149. url:'/chainBound/checkBind',
  150. method:'post',
  151. // contentType:' application/json',
  152. data:{
  153. deviceCode:code,
  154. }
  155. }).then(res=>{
  156. if(res.data.data!=1){
  157. app.showToptip(that,'error',res.data.msg);
  158. return;
  159. }
  160. app.requestP({
  161. url:'/chain/scan',
  162. method:'post',
  163. contentType:' application/json',
  164. data:{
  165. inoculatorId:'',
  166. payload:code,
  167. type,
  168. }
  169. }).then(res=>{
  170. const {transportStatus,id,code} = res.data.chain;
  171. that.setData({
  172. transportStatus,
  173. iodepId:id,
  174. modalHidden:!that.data.modalHidden,
  175. seleteType:that.setSeleteType(transportStatus),
  176. });
  177. }).catch(err=>{
  178. app.showToptip(that,'error',err.data.msg)
  179. })
  180. }).catch(err=>{
  181. app.showToptip(that,'error',err.data.msg);
  182. })
  183. },
  184. setTransportStatus(transportStatus){
  185. var seleteType = this.data.seleteType;
  186. var deptType;
  187. for(var i=0;i<seleteType.length;i++){
  188. if(seleteType[i].transportStatus == transportStatus){
  189. deptType = i;
  190. break;
  191. }
  192. }
  193. return deptType;
  194. },
  195. setSeleteType(transportStatus){
  196. var seleteType = this.data.seleteType;
  197. var type;
  198. for(var i=0;i<seleteType.length;i++){
  199. if(seleteType[i].transportStatus == transportStatus){
  200. seleteType.splice(i,1);
  201. break;
  202. }
  203. }
  204. this.setTransportStatus(transportStatus);
  205. return seleteType;
  206. },
  207. /**
  208. * 生命周期函数--监听页面加载
  209. */
  210. onLoad: function (options) {
  211. console.log(options);
  212. const {type,path,chainId} = options;
  213. this.setData({
  214. type,path,chainId
  215. })
  216. //获取定位信息
  217. wx.getLocation({
  218. altitude: 'altitude',
  219. success(res) {
  220. that.setData({
  221. latitude: res.latitude,
  222. longitude: res.longitude,
  223. })
  224. },
  225. error() {
  226. app.showToptip(that, "worning", "获取位置信息失败")
  227. }
  228. })
  229. //判断是否是iOS
  230. wx.getSystemInfo({
  231. success:function(res){
  232. if(res.platform=="ios"){
  233. that.isIOS = true;
  234. }
  235. }
  236. })
  237. },
  238. //取消按钮点击事件
  239. modalBindcancel:function(){
  240. this.setData({
  241. modalHidden:!this.data.modalHidden,
  242. region:[],
  243. modalVal:'',
  244. iodepId:'',
  245. })
  246. },
  247. regionChange: function(e) {
  248. this.setData({
  249. region: e.detail.value
  250. })
  251. },
  252. modalBindaconfirm(){ //一型保存地址
  253. var that = this;
  254. var {region,modalVal,transportStatus,iodepId,seleteType,deptType} = that.data;
  255. var addr = region.join('')+modalVal;
  256. if(region.join('') && modalVal && seleteType[deptType].transportStatus){
  257. app.requestP({
  258. url:'/chain/editTransport',
  259. // contentType:' application/json',
  260. method:'post',
  261. data:{
  262. addr,
  263. chainId:iodepId, // 00 在库 //10 运输 // 20 已结束
  264. // transportStatus:transportStatus == '00' ? '10':transportStatus == '10' ?'00':'',
  265. transportStatus:seleteType[deptType].transportStatus,
  266. }
  267. }).then(res=>{
  268. that.setData({
  269. modalHidden:!that.data.modalHidden,
  270. region:[],
  271. modalVal:'',
  272. iodepId:'',
  273. })
  274. app.showToptip(that,'success',res.data.msg);
  275. }).catch(err=>{
  276. app.showToptip(that,'error',err.data.msg);
  277. })
  278. }else{
  279. app.showToptip(that,'error','地址不能为空');
  280. }
  281. },
  282. setType(e){
  283. var value = e.detail.value;
  284. var that = this;
  285. that.setData({
  286. deptType:value
  287. })
  288. },
  289. /**
  290. * 生命周期函数--监听页面初次渲染完成
  291. */
  292. onReady: function () {
  293. },
  294. /**
  295. * 生命周期函数--监听页面显示
  296. */
  297. onShow: function () {
  298. if(that.data.isIOS){
  299. that.goApp()
  300. return;
  301. }
  302. },
  303. goApp(e) {
  304. this.setData({
  305. modalName: "goApp"
  306. })
  307. },
  308. hideModal(e) {
  309. this.setData({
  310. modalName: null
  311. })
  312. },
  313. /**
  314. * 生命周期函数--监听页面隐藏
  315. */
  316. onHide: function () {
  317. },
  318. /**
  319. * 生命周期函数--监听页面卸载
  320. */
  321. onUnload: function () {
  322. },
  323. /**
  324. * 页面相关事件处理函数--监听用户下拉动作
  325. */
  326. onPullDownRefresh: function () {
  327. },
  328. /**
  329. * 页面上拉触底事件的处理函数
  330. */
  331. onReachBottom: function () {
  332. },
  333. /**
  334. * 用户点击右上角分享
  335. */
  336. onShareAppMessage: function () {
  337. }
  338. })