123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822 |
- // pages/bikeInfo/bikeInfo.js
- const app = getApp();
- import {
- BluetoothManager,
- BtErrorCode
- } from '../../service/BlueMgr'
- const bluM = new BluetoothManager
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- iconList: [{ //车辆检测指令
- id: 1,
- imgUrl: 'http://resource.weilaibike.com/yunwei/open-lock.png',
- text: '鸣笛'
- },
- {
- id: 2,
- imgUrl: 'http://resource.weilaibike.com/yunwei/open-lock.png',
- text: '开电车锁'
- },
- {
- id: 3,
- imgUrl: 'http://resource.weilaibike.com/yunwei/close-lock.png',
- text: '关电车锁'
- },
- {
- id: 4,
- imgUrl: 'http://resource.weilaibike.com/yunwei/battery-load.png',
- text: '开电池锁'
- },
- {
- id: 5,
- imgUrl: 'http://resource.weilaibike.com/yunwei/online.png',
- text: '上线'
- },
- {
- id: 6,
- imgUrl: 'http://resource.weilaibike.com/yunwei/more.png',
- text: '更多'
- },
- ],
- moreList: [{
- id: 1,
- imgUrl: 'http://resource.weilaibike.com/yunwei/offline.png',
- text: '下线'
- },
- {
- id: 2,
- imgUrl: 'http://resource.weilaibike.com/yunwei/renewalPower.png',
- text: '更新电量'
- },
- {
- id: 3,
- imgUrl: 'http://resource.weilaibike.com/yunwei/renewalLocation.png',
- text: '更新位置'
- },
- {
- id: 4,
- imgUrl: 'http://resource.weilaibike.com/yunwei/renewal.png',
- text: '重启中控'
- },
- {
- id: 5,
- imgUrl: 'http://resource.weilaibike.com/bike_yunwei/park.png',
- text: '设置为停车区'
- },
- ],
- bikeDetail: '', //车辆信息
- bike_no: '', //车牌号
- typeName: '',
- workShow: false, //工单弹窗
- workCount: '', //侧边栏报修数量(未读)
- list: [], //工单列表
- workState: 1, //工单列表状态【1 待领取 2已领】
- repairsList: [], //报修列表
- repairsCount: '', //侧边栏工单数量(未认领)
- repairsState: 1, //报修列表状态【1 未读 2已读】
- repairsShow: false, //是否显示报修弹窗 【false 不显示 true 显示】
- topNum: 0,
- delBtnWidth: 200, //删除或完成 按钮宽度
- page: 1,
- switch1Checked: '',
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- let that = this;
- let switch1Checked = app.globalData.swichChecked
- that.setData({
- switch1Checked
- })
- console.log(that.data.swich1Checked)
- console.log(app.globalData.swichChecked)
- },
- scanCode: function () {
- var that = this;
- console.log('scanCode')
- wx.scanCode({
- success: function (res) {
- let index = res.result.lastIndexOf("\=");
- var code = res.result.substring(index + 1, res.result.length);
- that.setData({
- bike_no: code
- })
- that.getBike_info(code)
- },
- fail: function () {
- wx.showModal({
- title: '提示',
- content: '手动输入车辆标号',
- success: function (res) {
- if (res.confirm) {
- wx.navigateTo({
- url: '/pages/manualInp/manualInp',
- })
- }
- }
- })
- }
- })
- },
- // 获取车辆信息
- getBike_info: function (bike_no = false) {
- console.log(bike_no)
- wx.showLoading({
- title: '加载中...',
- })
- if (typeof bike_no === 'object') {
- bike_no = this.data.bike_no
- }
- this.setData({
- bike_no
- })
- if (!this.data.bike_no) {
- wx.showToast({
- title: '请先输入车牌号',
- icon: 'none'
- })
- } else {
- app.request('bike/getBikeInfo?bike_no=' + this.data.bike_no, '', 'GET').then(res => {
- wx.hideLoading();
- if (res.data.bike_info == '') {
- wx.showToast({
- title: '暂无该车辆信息~',
- })
- } else {
- this.setData({
- bikeDetail: res.data
- })
- }
- })
- }
- app.request("work_order/list?planned=" + 1 + "&bike_no=" + bike_no, '', 'GET').then(res => {
- if (res.statusCode == 200) {
- // console.log(res.data.meta.total, '工单数量')
- this.setData({
- workCount: res.data.meta.total
- })
- }
- })
- app.request('user/userRepaired?bike_no=' + bike_no + '&&status=' + 0, '', 'GET').then(res => {
- // console.log(res.data)
- // console.log(res.data.meta.total, '报修数量')
- this.setData({
- repairsCount: res.data.meta.total
- })
- })
- },
- bindKeyInput(e) {
- // console.log(e.detail.value, 11111)
- this.setData({
- bike_no: e.detail.value
- })
- },
- operate(e) {
- var that = this;
- let idx = e.currentTarget.dataset.id;
- let url = '';
- let title = "";
- console.log(idx, 'idx')
- if (idx == 6) {
- console.log(1111)
- this.setData({
- moreShow: true
- })
- } else {
- if (!that.data.bike_no) {
- wx.showToast({
- title: '请先输入车牌号',
- icon: 'none'
- })
- } else {
- let data = '?bike_id=' + that.data.bikeDetail.bike_info.id;
- switch (idx) {
- case 1: //鸣笛
- url = "bike/bikeBell";
- title = "鸣笛成功";
- break;
- case 2: //开电车锁
- url = "bike/openBikeLock";
- title = "开电车锁成功";
- break;
- case 3: //关电车锁
- url = "bike/closeBikeLock";
- title = "关电车锁成功";
- break;
- case 4: //开电池锁
- url = "bike/openBatteryLock";
- title = "开电池锁成功";
- break;
- case 5: //上线
- url = "bike/login";
- title = "上线成功";
- break;
- default:
- break;
- }
- if (that.data.switch1Checked) {
- wx.showLoading({
- title: '连接蓝牙中...',
- })
- bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => {
- wx.showToast({
- title,
- icon: 'none'
- })
- return bluM.boxReboot()
- })
- } else {
- app.request(url + data, '', 'GET').then(res => {
- if (res.statusCode == 200) {
- bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => {
- return bluM.boxReboot()
- })
- wx.showToast({
- title,
- icon: 'none'
- })
- }
- })
- }
- }
- }
- },
- moreOperat(e) {
- var that = this;
- let idx = e.currentTarget.dataset.id;
- let url = '';
- let title = "";
- switch (idx) {
- case 1: //下线
- url = "bike/logout";
- title = "下线成功";
- break;
- case 2: //更新电量
- url = "bike/newBikeBatteryMSG";
- title = "电量更新成功";
- break;
- case 3: //更新位置
- url = "bike/newBikeLocation";
- title = "更新位置成功";
- break;
- case 4: //重启中控
- url = "bike/rebootBox";
- title = "重启中控成功";
- break;
- case 5: //设为停车区
- url = "bike/repairInParking";
- title = "设为停车区成功";
- break;
- default:
- break;
- }
- if (!that.data.bike_no) {
- wx.showToast({
- title: '请先输入车牌号',
- icon: 'none'
- })
- } else if (that.data.switch1Checked) {
- wx.showLoading({
- title: '连接蓝牙中...',
- })
- bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => {
- wx.showToast({
- title,
- icon: 'none'
- })
- return bluM.boxReboot()
- })
- } else {
- let data = '?bike_id=' + that.data.bikeDetail.bike_info.id;
- app.request(url + data, '', 'GET').then(res => {
- if (res.statusCode == 200) {
- bluM.connectDeivece(that.data.bikeDetail.bike_info.box_no).then(res => {
- return bluM.boxReboot()
- })
- wx.showToast({
- title,
- icon: 'none'
- })
- }
- })
- }
- },
- modify: function () {
- //跳转修改车辆信息
- var bike = this.data.bikeDetail.bike_info
- wx.navigateTo({
- url: '/pages/amendCar/amendCar?id=' + bike.id + '&bike_no=' + bike.bike_no + '&box_no=' + bike.box_no,
- })
- },
- reqair: function () {
- var bike = this.data.bikeDetail.bike_info;
- wx.navigateTo({
- url: '/pages/reqair/reqair?bike_no=' + bike.bike_no,
- })
- },
- bike_detail: function () {
- //车辆详情页面
- var bike = this.data.bikeDetail.bike_info;
- wx.navigateTo({
- url: '/pages/carDetails/carDetails?bike_no=' + bike.bike_no + '&id=' + bike.id,
- })
- },
- /*
- * 工单弹窗 报修弹窗 begin
- */
- //关闭弹窗
- coverHidn(e) {
- let show = e.currentTarget.dataset.show;
- if (show == 1) {
- this.setData({
- moreShow: false,
- workState: 1
- })
- } else if (show == 2) {
- this.setData({
- workShow: false,
- typeName: ''
- })
- } else if (show == 3) {
- this.setData({
- repairsShow: false,
- typeName: '',
- repairsState: 1
- })
- }
- },
- //点击可拨打电话
- phone(e) {
- console.log(1111)
- wx.makePhoneCall({
- phoneNumber: e.currentTarget.dataset.phone
- })
- },
- showPop(e) {
- let show = e.currentTarget.dataset.idx;
- this.setData({
- typeName: show
- })
- if (show == 1) {
- this.setData({
- workShow: true
- });
- this.lookWork();
- } else if (show == 2) {
- this.setData({
- repairsShow: true
- });
- this.lookRepairs();
- }
- },
- workChoose(e) {
- wx.showLoading({
- title: '加载中...',
- })
- let state = e.currentTarget.dataset.state;
- this.setData({
- workState: state,
- list: []
- })
- this.lookWork();
- this.goTop();
- },
- //工单列表
- lookWork() {
- wx.showLoading({
- title: '加载中...',
- })
- let that = this;
- let planned = '';
- let url = "";
- let state = that.data.workState
- // console.log(state, 'workState')
- if (state == 1) {
- planned = 1
- url = "work_order/list?planned=" + planned + "&bike_no=" + that.data.bike_no
- } else {
- let planned = 2;
- url = 'work_order/myWorkOrderList?planned=' + planned + "&bike_no=" + that.data.bike_no
- }
- app.request(url, '', 'GET').then(res => {
- wx.hideLoading();
- let work = res.data.data;
- // console.log(work, '工单列表')
- if (work.length == 0) {
- // wx.showToast({
- // title: '暂无工单~',
- // icon: 'none'
- // })
- that.setData({
- list: ''
- })
- } else {
- work.map(i => {
- i.txtStyle = 'left:0rpx'
- })
- that.setData({
- workShow: true,
- list: work
- })
- // console.log(that.data.list, 'list')
- }
- })
- },
- //接单
- getWork(e) {
- wx.showLoading({
- title: '领取中...',
- })
- let id = e.currentTarget.dataset.id
- console.log(id, 'getWorkid');
- app.request('work_order/receive?work_order_id=' + id, '', 'GET').then(res => {
- wx.hideLoading();
- console.log(res)
- if (res.statusCode == 200) {
- wx.showToast({
- title: '接单成功',
- icon: "none"
- })
- let work = this.data.list;
- work.map((i, index) => {
- if (i.id == id) {
- work.splice(index, 1)
- console.log(i)
- }
- })
- let count = this.data.workCount
- count = count - 1
- this.setData({
- list: work,
- workCount: count
- })
- if (work.length == 0) {
- wx.showToast({
- title: '该车辆已无待领工单~',
- icon: 'none'
- })
- this.setData({
- workShow: false,
- workCount: ''
- })
- }
- }
- })
- },
- //完成
- finishWork(e) {
- wx.showLoading({
- title: '操作中...',
- })
- // console.log('finishWork')
- let id = e.currentTarget.dataset.id
- console.log(id, 'finishWorkId')
- app.request('work_order/over?work_order_id=' + id, '', 'GET').then(res => {
- wx.hideLoading();
- if (res.statusCode == 200) {
- console.log(res)
- wx.showToast({
- title: '操作成功',
- icon: "none"
- })
- let list = this.data.list
- list.map((i, index) => {
- if (i.id == id) {
- console.log(i)
- list.splice(index, 1)
- }
- })
- this.setData({
- list
- })
- if (list.length == 0) {
- wx.showToast({
- title: '已完成所有认领工单~',
- icon: 'none'
- })
- this.setData({
- workShow: false
- })
- }
- }
- })
- },
- //上拉加载
- moreWork() {
- wx.showLoading({
- title: '加载中...',
- })
- let that = this;
- var page = that.data.page + 1;
- let planned = '';
- let url = "";
- if (that.data.workState == 1) {
- planned = 1
- url = "work_order/list?planned=" + planned + "&bike_no=" + that.data.bike_no + '&page=' + page
- } else {
- planned = 2
- url = 'work_order/myWorkOrderList?planned=' + planned + "&bike_no=" + that.data.bike_no + '&page=' + page
- }
- app.request(url, '', 'GET').then(res => {
- console.log(res, '上拉')
- wx.hideLoading();
- if (res.data.data.length > 0) {
- let work = res.data.data
- work.map(i => {
- i.txtStyle = 'left:0rpx'
- })
- this.setData({
- workShow: true,
- list: that.data.list.concat(work),
- page
- })
- } else {
- wx.showToast({
- title: '没有更多数据了~',
- icon: 'none'
- })
- }
- })
- },
- //报修列表
- lookRepairs() {
- wx.showLoading({
- title: '加载中...',
- })
- let status = ''
- let state = this.data.repairsState
- if (state == 1) {
- status = 0
- } else if (state == 2) {
- status = 1
- }
- app.request('user/userRepaired?bike_no=' + this.data.bike_no + '&status=' + status, '', 'GET').then(res => {
- if (res.statusCode == 200) {
- wx.hideLoading();
- // console.log(res, '报修列表')
- let list = res.data.data;
- if (list.length == 0) {
- // wx.showToast({
- // title: '暂无报修记录~',
- // icon: 'none'
- // })
- this.setData({
- repairsList: []
- })
- } else {
- let repairs = res.data.data;
- repairs.map(i => {
- i.txtStyle = 'left:0rpx'
- })
- this.setData({
- repairsList: res.data.data
- })
- }
- }
- })
- },
- repairsChoose(e) {
- let state = e.currentTarget.dataset.state;
- this.setData({
- repairsState: state,
- repairsList: []
- })
- this.lookRepairs();
- this.goTop();
- },
- markRead(e) {
- let id = e.currentTarget.dataset.id
- app.request('user/userRepaired/status?id=' + id, '', 'GET').then(res => {
- if (res.statusCode == 200) {
- console.log(res)
- this.lookRepairs();
- let list = this.data.repairsList;
- if (list.length == 0) {
- wx.showToast({
- title: '暂无报修~',
- icon: 'none'
- })
- this.setData({
- repairsCount: ''
- })
- } else {
- let count = this.data.repairsCount;
- count = count - 1;
- this.setData({
- repairsCount: count
- })
- }
- }
- })
- },
- morkRepairs() {
- wx.showLoading({
- title: '加载中...',
- })
- let that = this;
- let status = '';
- var page = that.data.page + 1;
- let state = this.data.repairsState
- if (state == 1) {
- status = 0
- } else if (state == 2) {
- status = 1
- }
- app.request('user/userRepaired?bike_no=' + this.data.bike_no + '&status=' + status + '&page=' + page, '', 'GET').then(res => {
- wx.hideLoading();
- if (res.statusCode == 200) {
- let list = res.data.data;
- if (list.length > 0) {
- this.setData({
- repairsList: that.data.repairsList.concat(list),
- page
- })
- } else {
- wx.showToast({
- title: '没有更多数据了~',
- icon: 'none'
- })
- }
- }
- })
- },
- goTop: function (e) { // 一键回到顶部
- this.setData({
- topNum: 0
- });
- },
- touchS: function (e) {
- if (e.touches.length == 1) {
- this.setData({
- //设置触摸起始点水平方向位置
- startX: e.touches[0].clientX
- });
- }
- },
- touchM: function (e) {
- // console.log(this.data.list[index].txtStyle)
- // console.log(e);
- if (e.touches.length == 1) {
- //手指移动时水平方向位置
- var moveX = e.touches[0].clientX;
- //手指起始点位置与移动期间的差值
- var disX = this.data.startX - moveX;
- // console.log(disX,'disX')
- var delBtnWidth = this.data.delBtnWidth;
- var txtStyle = "";
- if (disX == 0 || disX < 0) { //如果移动距离小于等于0,文本层位置不变
- txtStyle = "left:0rpx";
- } else if (disX > 0) { //移动距离大于0,文本层left值等于手指移动距离
- txtStyle = "left:-" + disX + "rpx";
- if (disX >= delBtnWidth) {
- //控制手指移动距离最大值为删除按钮的宽度
- txtStyle = "left:-" + delBtnWidth + "rpx";
- }
- }
- //获取手指触摸的是哪一项
- var index = e.currentTarget.dataset.idx;
- var list = this.data.list;
- list[index].txtStyle = txtStyle;
- //更新列表的状态
- this.setData({
- list: list
- });
- }
- },
- touchE: function (e) {
- if (e.changedTouches.length == 1) {
- //手指移动结束后水平位置
- var endX = e.changedTouches[0].clientX;
- //触摸开始与结束,手指移动的距离
- var disX = this.data.startX - endX;
- var delBtnWidth = this.data.delBtnWidth;
- //如果距离小于删除按钮的1/2,不显示删除按钮
- var txtStyle = disX > delBtnWidth / 2 ? "left:-" + delBtnWidth + "rpx" : "left:0rpx";
- //获取手指触摸的是哪一项
- var index = e.currentTarget.dataset.idx;
- var list = this.data.list;
- list[index].txtStyle = txtStyle;
- //更新列表的状态
- this.setData({
- list: list
- });
- }
- },
- // 车辆检测信息里的刷新
- refresh_power: function () {
- this.getBike_info(this.data.bike_no), wx.showToast({
- title: '刷新完成',
- icon: 'none'
- })
- },
- skipDetail() {
- if (!this.data.bike_no) {
- wx.showToast({
- title: '请先输入车牌号',
- icon: 'none'
- })
- } else {
- wx.navigateTo({
- url: '/pages/carDetails/carDetails?bike_no=' + this.data.bike_no,
- })
- }
- },
- switch1Change: function (e) {
- console.log(e)
- var that = this;
- console.log(e.detail)
- wx.openBluetoothAdapter({
- success(res) {
- console.log(res)
- that.setData({
- switch1Checked: e.detail
- })
- app.globalData.swichChecked = e.detail.value;
- },
- fail(err) {
- console.log(err)
- wx.showModal({
- title: '提示',
- content: '请开启蓝牙',
- showCancel: false
- })
- that.setData({
- switch1Checked: false
- })
- app.globalData.swichChecked = false;
- }
- })
- },
- bikePosition: function () {
- wx.navigateTo({
- url: '/pages/carPosition/carPosition?id=' + this.data.bikeDetail.bike_info.id + '&bike_no=' + this.data.bikeDetail.bike_info.bike_no,
- })
- },
- recentOrder: function () {
- wx.navigateTo({
- url: '/pages/recentOrder/recentOrder?id=' + this.data.bikeDetail.bike_info.id,
- })
- },
- /*
- * 工单弹窗 报修弹窗 end
- */
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.setData({
- switch1Checked: app.globalData.swichChecked,
- })
- console.log(this.data.switch1Checked)
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|