index.js 6.3 KB

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