cartConfing.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <view>
  3. <view class="iconList flex">
  4. <navigator :url="'/pages/user/myCart/authorization?id='+item.car_number" v-if="item.auth_num!=-1">
  5. <view class="iconItem">
  6. <view class="iconImgItem">
  7. <image src="../../../static/icon/iconAuthorization.png" mode="widthFix"></image>
  8. </view>
  9. <view class="iconName">
  10. 授权
  11. </view>
  12. </view>
  13. </navigator>
  14. <navigator :url="'/pages/user/reportForRepair/Report?id='+item.car_number">
  15. <view class="iconItem">
  16. <view class="iconImgItem">
  17. <image src="../../../static/icon/iconBaoxiu.png" mode="widthFix"></image>
  18. </view>
  19. <view class="iconName">
  20. 报修
  21. </view>
  22. </view>
  23. </navigator>
  24. <!-- <view class="iconItem">
  25. <view class="iconImgItem">
  26. <image src="../../../static/icon/iconSet.png" mode="widthFix"></image>
  27. </view>
  28. </view> -->
  29. <view class="iconItem" @click="tabCarStatus('seek',item)">
  30. <view class="iconImgItem">
  31. <image src="../../../static/icon/iconAlarm.png" mode="widthFix"></image>
  32. </view>
  33. <view class="iconName">
  34. 寻车
  35. </view>
  36. </view>
  37. <view class="iconItem" @click="tabCarStatus('tab',item)">
  38. <view class="iconImgItem">
  39. <image v-if="item.status==1||item.status==3||item.status==4" src="../../../static/icon/lockGreen.png" mode="widthFix">
  40. </image>
  41. <image v-else src="../../../static/icon/lockRed.png" mode="widthFix"></image>
  42. </view>
  43. <view class="iconName">
  44. <view class="greed" v-if="item.status==1||item.status==3||item.status==4">
  45. 启动
  46. </view>
  47. <view class="red" v-else>
  48. 关闭
  49. </view>
  50. </view>
  51. </view>
  52. <view class="iconItem" @click="tabCarStatus('unlock',item)">
  53. <view class="iconImgItem">
  54. <image src="../../../static/icon/lockGray.png" mode="widthFix"></image>
  55. </view>
  56. <view class="iconName">
  57. 解锁
  58. </view>
  59. </view>
  60. </view>
  61. <uni-popup ref="message" type="message">
  62. <uni-popup-message type="error" message="错误消息" :duration="0">
  63. </uni-popup-message>
  64. </uni-popup>
  65. </view>
  66. </template>
  67. <script>
  68. import {
  69. car_switch
  70. } from '@/api/user.js';
  71. // #ifdef MP
  72. import {
  73. openGetAddress,
  74. } from '@/utils/rocessor.js';
  75. // #endif
  76. // #ifdef H5
  77. import weixinObj from "@/plugin/jweixin-module/index.js";
  78. import {
  79. weixindata
  80. } from "@/utils/wxAuthorized.js"
  81. // #endif
  82. import {
  83. mapState,
  84. mapMutations
  85. } from 'vuex';
  86. export default {
  87. props: {
  88. item: {
  89. type: Object,
  90. default () {
  91. return {
  92. }
  93. }
  94. },
  95. },
  96. data() {
  97. return {
  98. loadShopData: false, //判断是否已经开启监听
  99. }
  100. },
  101. computed: {
  102. auth_num() {
  103. return this.item ? +this.item.auth_num : 0
  104. },
  105. ...mapState('user', ['address']),
  106. },
  107. methods: {
  108. ...mapMutations('user', ['setAddress']),
  109. // 数据加载中
  110. // 保存地址
  111. car_switch(data, type, item) {
  112. car_switch(data).then(() => {
  113. if (type == 'tab') {
  114. const status = (item.status == 1) ? 2 : 1;
  115. this.$emit("tab", status)
  116. }
  117. uni.hideLoading()
  118. uni.showToast({
  119. title: '发送成功'
  120. });
  121. }).catch((e) => {
  122. uni.hideLoading()
  123. // this.$refs.message.open();
  124. uni.showModal({
  125. title: '错误',
  126. content: e.msg,
  127. showCancel: false,
  128. });
  129. })
  130. },
  131. // 调用切换
  132. tabCarStatus(type = 'tab', item) {
  133. let that = this;
  134. let data = {
  135. car_number: item.car_number,
  136. };
  137. // 是否开关锁
  138. if (type == 'tab') {
  139. data.status = (item.status == 1) ? 2 : 1;
  140. }
  141. // 是否解锁
  142. if (type == 'unlock') {
  143. data.status = 6;
  144. }
  145. // 是否寻车
  146. if (type == 'seek') {
  147. data.status = 5;
  148. }
  149. // #ifdef H5
  150. let bool = uni.getStorageSync('weichatBrowser') || '';
  151. // 判断是否公众号
  152. if (bool) {
  153. weixindata().then(() => {
  154. weixinObj.getLocation({
  155. type: 'gcj02',
  156. success: (e) => {
  157. data.latitude = e.latitude;
  158. data.longitude = e.longitude;
  159. that.car_switch(data, type, item)
  160. }
  161. });
  162. })
  163. } else {
  164. uni.getLocation({
  165. type: 'gcj02',
  166. success(e) {
  167. data.latitude = e.latitude;
  168. data.longitude = e.longitude;
  169. that.car_switch(data, type, item)
  170. },
  171. fail(e) {
  172. console.log(e, 'cw');
  173. }
  174. })
  175. }
  176. // #endif
  177. // #ifdef MP
  178. // 判断是否已经有位置数据
  179. if (!that.address.latitude || !that.address.longitude) {
  180. // 判断是否已经获取授权
  181. openGetAddress().then((e) => {
  182. // 获取当前选中开锁的对象
  183. uni.showLoading({
  184. title: '请求发送中',
  185. mask: true
  186. });
  187. console.log("授权");
  188. wx.startLocationUpdateBackground({
  189. type: 'gcj02',
  190. success: (e) => {
  191. console.log(e);
  192. // 调用鉴定位置变化事件
  193. wx.onLocationChange((res) => {
  194. console.log(res, '位置数据');
  195. // 保存当前经纬度
  196. that.setAddress({
  197. latitude: res.latitude,
  198. longitude: res.longitude
  199. })
  200. // 判断是否已经加载过最近商家信息
  201. if (!that.loadShopData) {
  202. data.latitude = res.latitude;
  203. data.longitude = res.longitude;
  204. that.car_switch(data, type, item)
  205. that.loadShopData = true;
  206. }
  207. })
  208. },
  209. fail: () => {
  210. uni.hideLoading()
  211. }
  212. })
  213. })
  214. } else {
  215. uni.showLoading({
  216. title: '请求发送中',
  217. mask: true
  218. });
  219. data.latitude = that.address.latitude;
  220. data.longitude = that.address.longitude;
  221. that.car_switch(data, type, item)
  222. }
  223. // #endif
  224. }
  225. }
  226. };
  227. </script>
  228. <style lang="scss">
  229. .iconList {
  230. padding: 30rpx;
  231. padding-bottom: 0;
  232. .iconItem {
  233. .iconImgItem {
  234. width: 62rpx;
  235. margin: 0 auto;
  236. image {
  237. width: 100%;
  238. height: 62rpx;
  239. }
  240. }
  241. .iconName {
  242. color: $font-color-base;
  243. font-size: 22rpx;
  244. text-align: center;
  245. padding: 15rpx 0;
  246. font-weight: 100;
  247. .greed {
  248. color: $color-green;
  249. }
  250. .red {
  251. color: $color-red;
  252. }
  253. }
  254. }
  255. }
  256. </style>