cardetail.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // pages/cardetail/cardetail.js
  2. import { get,post } from "../../common/request.js"
  3. import pathmap from "../../common/pathmap"
  4. import stylemap from "../../common/stylemap"
  5. import { retCartData } from "../../data/car"
  6. import bindLog from "../../module/logs/logs"
  7. const app = getApp();
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. windowh: app.globalData.windowh,
  14. collocatetype:[{
  15. label:"基本参数",
  16. name:"jiben"
  17. },{
  18. label:"发动机参数",
  19. name:"fadongji"
  20. },{
  21. label:"底盘及制动",
  22. name:"dipan"
  23. },{
  24. label:"安全配置",
  25. name:"anquan"
  26. },{
  27. label:"外部配置",
  28. name:"waibu"
  29. },{
  30. label:"内部配置",
  31. name:"neibu"
  32. },{
  33. label:"操控/辅助配置",
  34. name:"caokong"
  35. }],
  36. imagemap:{
  37. "事故排查":"accident",
  38. "轻微碰撞":"checkcollide",
  39. "易损耗部件":"wastage",
  40. "常用功能":"comonuse",
  41. "启动检测":"startcheck"
  42. }
  43. },
  44. /**
  45. * 生命周期函数--监听页面加载
  46. */
  47. onLoad: function (options) {
  48. this.setData(Object.assign({id:options.id},stylemap));
  49. this.getDetail();
  50. bindLog(this);
  51. },
  52. /**
  53. * 生命周期函数--监听页面初次渲染完成
  54. */
  55. onReady: function () {
  56. },
  57. /**
  58. * 生命周期函数--监听页面显示
  59. */
  60. onShow: function () {
  61. },
  62. /**
  63. * 生命周期函数--监听页面隐藏
  64. */
  65. onHide: function () {
  66. },
  67. /**
  68. * 生命周期函数--监听页面卸载
  69. */
  70. onUnload: function () {
  71. },
  72. /**
  73. * 页面相关事件处理函数--监听用户下拉动作
  74. */
  75. onPullDownRefresh: function () {
  76. },
  77. /**
  78. * 页面上拉触底事件的处理函数
  79. */
  80. onReachBottom: function () {
  81. },
  82. /**
  83. * 用户点击右上角分享
  84. */
  85. onShareAppMessage: function () {
  86. },
  87. loginback:function(){
  88. this.getDetail();
  89. },
  90. getDetail:function(){
  91. var _self=this;
  92. get(pathmap.cardetail,{id:this.data.id},function(json){
  93. if(json.statusCode==200){
  94. var detail = json.data;
  95. var time = detail.first_plate_at.split('-');
  96. /*数据结构处理*/
  97. detail.imgs = detail.imgs&&detail.imgs.split(",");
  98. detail.imgslength = detail.imgs.length;
  99. detail.first_plate_at = time[0]+"/"+time[1];
  100. detail.check_info.forEach(function(item){
  101. })
  102. _self.setData({
  103. detail:detail
  104. })
  105. }else{
  106. wx.showToast({
  107. title:json.data.message,
  108. icon:"none",
  109. duration:2000
  110. })
  111. }
  112. })
  113. },
  114. switchTab:function(e){
  115. this.setData({
  116. currentimg: e.detail.current+1
  117. });
  118. },
  119. swCollocate:function(e){
  120. var name = e.currentTarget.dataset.name;
  121. var collocatetype = this.data.collocatetype.map(function(item){
  122. if(item.name==name){
  123. if(item.opened){
  124. item.opened=false;
  125. }else{
  126. item.opened=true;
  127. }
  128. }else{
  129. item.opened=false;
  130. }
  131. return item;
  132. })
  133. this.setData({collocatetype:collocatetype});
  134. },
  135. collectCar:function(){
  136. var _self=this;
  137. if(this.data.detail.is_collect=="0"){
  138. post(pathmap.collect,{
  139. id:this.data.id
  140. },function(json){
  141. if(json.statusCode==200){
  142. wx.showToast({
  143. title:json.data.message
  144. });
  145. _self.setData({detail:Object.assign(_self.data.detail,{is_collect:'1'})});
  146. }else{
  147. wx.showToast({
  148. title:json.data.message,
  149. icon:"none"
  150. });
  151. }
  152. },null,function(){
  153. _self.openLog();
  154. })
  155. }else{
  156. post(pathmap.collectdel,{
  157. id:this.data.id
  158. },function(json){
  159. if(json.statusCode==200){
  160. wx.showToast({
  161. title:json.data.msg
  162. });
  163. _self.setData({detail:Object.assign(_self.data.detail,{is_collect:'0'})});
  164. }else{
  165. wx.showToast({
  166. title:json.data.message,
  167. icon:"none"
  168. });
  169. }
  170. },null,function(){
  171. _self.openLog();
  172. })
  173. }
  174. }
  175. })