vvmInfo.js 7.4 KB

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