// pages/cardetail/cardetail.js import { get,post } from "../../common/request.js" import pathmap from "../../common/pathmap" import stylemap from "../../common/stylemap" import { retCartData } from "../../data/car" import bindLog from "../../module/logs/logs" const app = getApp(); Page({ /** * 页面的初始数据 */ data: { windowh: app.globalData.windowh, collocatetype:[{ label:"基本参数", name:"jiben" },{ label:"发动机参数", name:"fadongji" },{ label:"底盘及制动", name:"dipan" },{ label:"安全配置", name:"anquan" },{ label:"外部配置", name:"waibu" },{ label:"内部配置", name:"neibu" },{ label:"操控/辅助配置", name:"caokong" }], imagemap:{ "事故排查":"accident", "轻微碰撞":"checkcollide", "易损耗部件":"wastage", "常用功能":"comonuse", "启动检测":"startcheck" } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData(Object.assign({id:options.id},stylemap)); this.getDetail(); bindLog(this); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, loginback:function(){ this.getDetail(); }, getDetail:function(){ var _self=this; get(pathmap.cardetail,{id:this.data.id},function(json){ if(json.statusCode==200){ var detail = json.data; var time = detail.first_plate_at.split('-'); /*数据结构处理*/ detail.imgs = detail.imgs&&detail.imgs.split(","); detail.imgslength = detail.imgs.length; detail.first_plate_at = time[0]+"/"+time[1]; detail.check_info.forEach(function(item){ }) _self.setData({ detail:detail }) }else{ wx.showToast({ title:json.data.message, icon:"none", duration:2000 }) } }) }, switchTab:function(e){ this.setData({ currentimg: e.detail.current+1 }); }, swCollocate:function(e){ var name = e.currentTarget.dataset.name; var collocatetype = this.data.collocatetype.map(function(item){ if(item.name==name){ if(item.opened){ item.opened=false; }else{ item.opened=true; } }else{ item.opened=false; } return item; }) this.setData({collocatetype:collocatetype}); }, collectCar:function(){ var _self=this; if(this.data.detail.is_collect=="0"){ post(pathmap.collect,{ id:this.data.id },function(json){ if(json.statusCode==200){ wx.showToast({ title:json.data.message }); _self.setData({detail:Object.assign(_self.data.detail,{is_collect:'1'})}); }else{ wx.showToast({ title:json.data.message, icon:"none" }); } },null,function(){ _self.openLog(); }) }else{ post(pathmap.collectdel,{ id:this.data.id },function(json){ if(json.statusCode==200){ wx.showToast({ title:json.data.msg }); _self.setData({detail:Object.assign(_self.data.detail,{is_collect:'0'})}); }else{ wx.showToast({ title:json.data.message, icon:"none" }); } },null,function(){ _self.openLog(); }) } } })