index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // mixins/countdownMixin.js
  2. var bluetooth = require('@/common/bluetooth.js');
  3. import {getFunctionTag,setFunctionTag,getUserCurrentLocation} from '@/common/storage.js';
  4. var app = getApp();
  5. var config = require('@/common/config.js');
  6. var common = require('@/common/common.js');
  7. var http = require('@/common/http.js');
  8. import i18n from '@/locale/index.js'
  9. export default {
  10. data() {
  11. return {
  12. carOnline: false,
  13. statusBarHeight:0,
  14. popText:'',
  15. cmdType:'',
  16. myLocation:{},
  17. popupControlShow:false
  18. };
  19. },
  20. onload(){
  21. this.myLocation = getUserCurrentLocation()
  22. this.myLocation = this.$location()
  23. },
  24. mounted(){
  25. this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight || 0
  26. },
  27. methods: {
  28. tapOpenControl(e){
  29. console.log(111);
  30. const _carOnline=uni.getStorageSync('car_info').online!=0 //在线
  31. console.log(this.popupControlShow);
  32. const {name,type}=e
  33. this.setData({
  34. carOnline:_carOnline,
  35. popText:name,
  36. cmdType:type,
  37. popupControlShow:true
  38. })
  39. console.log(this.popupControlShow);
  40. },
  41. changClick(tab){
  42. const typeArr=['tirePressure','batteryInfo','navigation']
  43. const isOther=typeArr.findIndex(t => t === tab.type)!==-1
  44. console.log('isOther',isOther);
  45. if(isOther){
  46. const {name,type}=tab
  47. this.setData({
  48. popText:name,
  49. cmdType:type,
  50. })
  51. this.tapBlueToothCmd()
  52. }else{
  53. this.tapOpenControl(tab)
  54. }
  55. },
  56. closePopup(){
  57. this.popupControlShow=false
  58. },
  59. tapBlueToothCmd(isCarLocation=false){
  60. const car_info= uni.getStorageSync('car_info');
  61. if(this.cmdType=='batteryInfo'){
  62. uni.navigateTo({
  63. url:`/pages/batteryDetail/batteryDetail`
  64. })
  65. }else if(this.cmdType=='navigation'){
  66. const {
  67. address,
  68. latitude,
  69. longitude,
  70. car_name
  71. } =car_info
  72. uni.openLocation({
  73. latitude: latitude - 0,
  74. longitude: longitude - 0,
  75. scale: 15,
  76. name: car_name,
  77. address: address,
  78. success: function (res) {},
  79. })
  80. //获取胎压
  81. }else if(this.cmdType=='tirePressure'){
  82. this.bluetoothCmd()
  83. }else{
  84. // 判断车辆是否在线状态 true 在线调用接口 不在线提示连接蓝牙
  85. if (this.carOnline) {
  86. if(this.cmdType=='turnOnOrOff'){
  87. const switchType=this.contrilList.find(item => item.isTurnOn)
  88. const pData={
  89. car_sn:car_info.car_sn,
  90. switch:switchType
  91. }
  92. const me=this
  93. common.loading();
  94. http.postApi(config.API_FLK_CAR_SWITCH, pData, (resp) => {
  95. uni.hideLoading();
  96. if (resp.data.code === 200) {
  97. common.simpleToast(me.popText + '成功');
  98. const activeTag=me.contrilList.map(item=>{
  99. item.isTurnOn=(item.isTurnOn==1)?0:1
  100. item.name=i18n.t((item.isTurnOn==1)?'关机':'开机')
  101. return item
  102. })
  103. const tag=getFunctionTag().tag
  104. setFunctionTag({activeTag,tag})
  105. } else {
  106. common.simpleToast(resp.data.msg);
  107. }
  108. });
  109. }else{
  110. const testArr=[
  111. {type:'findCar',opt_type:1},
  112. {type:'openSeatBag',opt_type:0},
  113. {type:'openTailBox',opt_type:2},
  114. ]
  115. const pData = testArr.find(i=>i.type===this.cmdType)
  116. const me=this
  117. common.loading();
  118. http.postApi(config.API_FLK_CAR_REMOTE_CONTROL, pData, (resp) => {
  119. uni.hideLoading();
  120. if (resp.data.code === 200) {
  121. common.simpleToast(me.popText + '成功');
  122. } else {
  123. common.simpleToast(resp.data.msg);
  124. }
  125. });
  126. }
  127. } else {
  128. this.bluetoothCmd(isCarLocation)
  129. }
  130. }
  131. this.popupControlShow=false
  132. },
  133. bluetoothCmd(isCarLocation){
  134. const me=this
  135. const car_info= uni.getStorageSync('car_info');
  136. //蓝牙是否已经连接 未连接提示去连接 已连接下发对应指令
  137. const isBluetoothConnect = app.globalData.connectionStateChangeFunc[car_info.car_sn]
  138. if(isBluetoothConnect){
  139. const isTurnOn=this.contrilList.find(item => item.isTurnOn).isTurnOn==1
  140. console.log(isTurnOn,this.cmdType,this.contrilList);
  141. const bluetoothCommands = {
  142. 'turnOnOrOff': isTurnOn?bluetooth.turnOnCar:bluetooth.turnOffCar,
  143. 'findCar': bluetooth.findCarCmd,
  144. 'openSeatBag': bluetooth.openCarSeat,
  145. 'openTailBox': bluetooth.openCarTrunk,
  146. 'tirePressure': bluetooth.getCarPressure
  147. };
  148. common.loading();
  149. const command = bluetoothCommands[this.cmdType];
  150. const car_sn = uni.getStorageSync('car_info').car_sn
  151. if (command) {
  152. command(car_sn, () => {
  153. uni.hideLoading();
  154. if(this.cmdType=='openSeatBag'||this.cmdType=='openTailBox'){
  155. common.simpleToast('操作成功');
  156. }
  157. console.log(`发送${this.popText}指令结束`);
  158. });
  159. }
  160. }else{
  161. uni.showModal({
  162. title: '提示',
  163. content: '当前车辆处于离线,是否前往开启蓝牙配对操作车辆?',
  164. showCancel: true,
  165. cancelText: '取消',
  166. confirmText: '确定',
  167. success: function(res) {
  168. if (res.confirm) {
  169. if(isCarLocation){
  170. uni.switchTab({
  171. url:'/pages/index/index'
  172. })
  173. }else{
  174. me.$emit('toBluetooth')
  175. }
  176. }
  177. },
  178. fail: function(res) {},
  179. complete: function(res) {},
  180. })
  181. }
  182. }
  183. },
  184. beforeDestroy() {
  185. },
  186. };