vvmInfo.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. // pages/query/vvmInfo.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. detailsList:[],
  9. keyword:'',
  10. scrollHeight: 0, // scroll-view高度
  11. startX: 0, // 开始X坐标
  12. startY: 0, // 开始Y坐标
  13. showDialog: false,// 选择弹窗
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. const {details,devicetype} = JSON.parse(decodeURIComponent(options.details));
  20. var that = this;
  21. wx.getLocation({
  22. altitude: 'altitude',
  23. success(res) {
  24. that.setData({
  25. latitude: res.latitude,
  26. longitude: res.longitude,
  27. })
  28. },
  29. error() {
  30. app.showToptip(that, "worning", "获取位置信息失败")
  31. }
  32. })
  33. var name = ['X201','X202','X203','X101','X102','X103','X104','X105','X106','X107',];
  34. this.setData({
  35. detailsList:details,
  36. devicetype,
  37. devicetypeName: name.indexOf(devicetype) != -1 ? name[name.indexOf(devicetype)] : devicetype == 10 ?'追溯标签': devicetype == 11 ? '全程温控': '实时追溯',
  38. id:options.id
  39. })
  40. },
  41. toInfo(e){
  42. var that = this;
  43. const deviceCode = e.currentTarget.dataset.devicecode;
  44. const {devicetype,id} =that.data;
  45. var deviceId = e.currentTarget.dataset.id;
  46. wx.redirectTo({
  47. url: '/pages/query/details?deviceCode=' + deviceCode+'&deviceType='+devicetype+'&id='+id+'&chainBoundId='+deviceId,
  48. })
  49. },
  50. addLabel(){
  51. var that = this;
  52. var {id,devicetype} = that.data;
  53. if(devicetype == 'X101' || devicetype == 'X202' ||devicetype == 'X203'){
  54. // that.chainBind();
  55. this.setData({
  56. showDialog:!this.data.showDialog
  57. })
  58. }else {
  59. wx.navigateTo({
  60. url: '/pages/nfc/zhuisu2?id='+id+'&type='+devicetype+'&addLabel=20',
  61. })
  62. }
  63. },
  64. chainBind(){
  65. var that = this;
  66. wx.scanCode({
  67. success: function (res) {
  68. var {result} = res;
  69. if(result.indexOf('imei=') != -1){
  70. result = result.slice(result.indexOf('imei=')+5,result.length)
  71. }
  72. that.setchainBoundBind(result);
  73. },
  74. fail:function(err){
  75. app.showToptip(that, 'error', '二维码无效');
  76. }
  77. })
  78. },
  79. setchainBoundBind(result){
  80. var that = this;
  81. const {id,devicetype,latitude,longitude} = that.data;
  82. app.requestP({
  83. url:'/chainBound/checkBind',
  84. method:'post',
  85. data:{
  86. deviceCode:result,
  87. }
  88. }).then(res=>{
  89. if(res.data.data==0){
  90. app.requestP({
  91. url:'/chainBound/bind',
  92. method:'post',
  93. contentType:' application/json',
  94. data:{
  95. chainId:id,
  96. deviceCode:result,
  97. type:devicetype,
  98. lat:latitude,
  99. lng:longitude
  100. }
  101. }).then(response=>{
  102. app.showToptip(that,'success',response.data.msg);
  103. wx.navigateBack({
  104. delta: 1,
  105. })
  106. }).catch(error=>{
  107. app.showToptip(that,'error',error.data.msg)
  108. })
  109. }else{
  110. app.showToptip(that,'error',res.data.msg)
  111. }
  112. }).catch(err=>{
  113. app.showToptip(that,'error',err.data.msg)
  114. })
  115. },
  116. inputBind(){
  117. var that = this
  118. wx.showModal({
  119. title: '请输入标签编号',
  120. editable:true,
  121. success (res) {
  122. if (res.confirm) {
  123. var numreg = /^[0-9]*$/;
  124. if(res.content){
  125. if(!numreg.test(res.content)){
  126. app.showToptip(that, "error", "标签编号只能为数字!");
  127. that.inputBind()
  128. return;
  129. }
  130. that.setchainBoundBind(res.content)
  131. }else{
  132. app.showToptip(that, "error",'标签编号不能为空!')
  133. that.inputBind()
  134. }
  135. }else{
  136. //pass
  137. }
  138. }
  139. })
  140. },
  141. toggleDialog() { //弹窗关闭
  142. this.setData({
  143. showDialog: !this.data.showDialog
  144. });
  145. },
  146. // 手指触摸动作开始
  147. touchStart: function (e) {
  148. let that = this;
  149. //开始触摸时 重置所有删除
  150. that.data.detailsList.forEach(function (v, i) {
  151. if (v.isTouchMove) v.isTouchMove = false; // 只操作为true的
  152. })
  153. // 记录手指触摸开始坐标
  154. that.setData({
  155. startX: e.changedTouches[0].clientX, // 开始X坐标
  156. startY: e.changedTouches[0].clientY, // 开始Y坐标
  157. detailsList: that.data.detailsList
  158. })
  159. },
  160. // 手指触摸后移动
  161. touchMove: function (e) {
  162. let that = this,
  163. index = e.currentTarget.dataset.index, // 当前下标
  164. startX = that.data.startX, // 开始X坐标
  165. startY = that.data.startY, // 开始Y坐标
  166. touchMoveX = e.changedTouches[0].clientX, // 滑动变化坐标
  167. touchMoveY = e.changedTouches[0].clientY, // 滑动变化坐标
  168. // 获取滑动角度
  169. angle = that.angle({
  170. X: startX,
  171. Y: startY
  172. }, {
  173. X: touchMoveX,
  174. Y: touchMoveY
  175. });
  176. // 判断滑动角度
  177. that.data.detailsList.forEach(function (v, i) {
  178. v.isTouchMove = false
  179. // 滑动超过30度角 return
  180. if (Math.abs(angle) > 30) return;
  181. if (i == index) {
  182. // 右滑
  183. if (touchMoveX > startX)
  184. v.isTouchMove = false
  185. // 左滑
  186. else
  187. v.isTouchMove = true
  188. }
  189. })
  190. // 更新数据
  191. that.setData({
  192. detailsList: that.data.detailsList
  193. })
  194. },
  195. // 计算滑动角度
  196. angle: function (start, end) {
  197. let that = this,
  198. _X = end.X - start.X,
  199. _Y = end.Y - start.Y;
  200. // 返回角度 /Math.atan()返回数字的反正切值
  201. return 360 * Math.atan(_Y / _X) / (2 * Math.PI);
  202. },
  203. delList(e){
  204. var that = this;
  205. wx.showModal({
  206. title: '提示',
  207. content: '请确认是否删除!',
  208. success (res) {
  209. if (res.confirm) {
  210. var id = e.currentTarget.dataset.id;
  211. app.requestP({
  212. url:'/chainBound/deleteChainBound',
  213. method:'post',
  214. data:{
  215. id
  216. }
  217. }).then(res=>{
  218. app.showToptip(that,'success',res.data.msg);
  219. wx.navigateBack({
  220. delta: 1
  221. });
  222. }).catch(err=>{
  223. app.showToptip(that,'error',err.data.msg)
  224. })
  225. } else if (res.cancel) {
  226. //点击取消
  227. }
  228. }
  229. })
  230. }
  231. })