cardetail.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. openscheme:false,
  44. loanscale:[0.1,0.2,0.3,0.4,0.5,0.6],
  45. loantime:[12,24,48],
  46. scaleindex:1,
  47. timeindex:1
  48. },
  49. /**
  50. * 生命周期函数--监听页面加载
  51. */
  52. onLoad: function (options) {
  53. this.setData(Object.assign({id:options.id},stylemap));
  54. this.getDetail();
  55. bindLog(this);
  56. },
  57. /**
  58. * 生命周期函数--监听页面初次渲染完成
  59. */
  60. onReady: function () {
  61. },
  62. /**
  63. * 生命周期函数--监听页面显示
  64. */
  65. onShow: function () {
  66. },
  67. /**
  68. * 生命周期函数--监听页面隐藏
  69. */
  70. onHide: function () {
  71. },
  72. /**
  73. * 生命周期函数--监听页面卸载
  74. */
  75. onUnload: function () {
  76. },
  77. /**
  78. * 页面相关事件处理函数--监听用户下拉动作
  79. */
  80. onPullDownRefresh: function () {
  81. },
  82. /**
  83. * 页面上拉触底事件的处理函数
  84. */
  85. onReachBottom: function () {
  86. },
  87. /**
  88. * 用户点击右上角分享
  89. */
  90. onShareAppMessage: function () {
  91. },
  92. loginback:function(){
  93. this.getDetail();
  94. },
  95. getDetail:function(){
  96. var _self=this;
  97. get(pathmap.cardetail,{id:this.data.id},function(json){
  98. if(json.statusCode==200){
  99. var detail = json.data;
  100. var time = detail.first_plate_at.split('-');
  101. /*数据结构处理*/
  102. detail.imgs = detail.imgs&&detail.imgs.split(",");
  103. detail.imgslength = detail.imgs.length;
  104. detail.first_plate_at = time[0]+"/"+time[1];
  105. detail.check_info.forEach(function(item){
  106. })
  107. _self.setData({
  108. detail:detail
  109. })
  110. }else{
  111. wx.showToast({
  112. title:json.data.message,
  113. icon:"none",
  114. duration:2000
  115. })
  116. }
  117. })
  118. },
  119. switchTab:function(e){
  120. this.setData({
  121. currentimg: e.detail.current+1
  122. });
  123. },
  124. swCollocate:function(e){
  125. var name = e.currentTarget.dataset.name;
  126. var collocatetype = this.data.collocatetype.map(function(item){
  127. if(item.name==name){
  128. if(item.opened){
  129. item.opened=false;
  130. }else{
  131. item.opened=true;
  132. }
  133. }else{
  134. item.opened=false;
  135. }
  136. return item;
  137. })
  138. this.setData({collocatetype:collocatetype});
  139. },
  140. collectCar:function(){
  141. var _self=this;
  142. if(this.data.detail.is_collect=="0"){
  143. post(pathmap.collect,{
  144. id:this.data.id
  145. },function(json){
  146. if(json.statusCode==200){
  147. wx.showToast({
  148. title:json.data.message
  149. });
  150. _self.setData({detail:Object.assign(_self.data.detail,{is_collect:'1'})});
  151. }else{
  152. wx.showToast({
  153. title:json.data.message,
  154. icon:"none"
  155. });
  156. }
  157. },null,function(){
  158. _self.openLog();
  159. })
  160. }else{
  161. post(pathmap.collectdel,{
  162. id:this.data.id
  163. },function(json){
  164. if(json.statusCode==200){
  165. wx.showToast({
  166. title:json.data.msg
  167. });
  168. _self.setData({detail:Object.assign(_self.data.detail,{is_collect:'0'})});
  169. }else{
  170. wx.showToast({
  171. title:json.data.message,
  172. icon:"none"
  173. });
  174. }
  175. },null,function(){
  176. _self.openLog();
  177. })
  178. }
  179. },
  180. appointmentBuy:function(){
  181. var _self=this;
  182. var mobile = wx.getStorageSync("mobile");
  183. post(pathmap.reserve,{
  184. "car_source_id":this.data.id,
  185. mobile:mobile
  186. },function(json){
  187. var obj = {
  188. title:json.data.message
  189. }
  190. if(json.statusCode!=200){
  191. obj.icon="none"
  192. }
  193. wx.showToast(obj);
  194. },null,function(){
  195. _self.openLog();
  196. })
  197. },
  198. openScheme:function(){
  199. this.setData({openscheme:true});
  200. },
  201. closeScheme:function(){
  202. this.setData({openscheme:false});
  203. },
  204. getPay:function(){
  205. var price = this.data.detail.price*100;
  206. var scale = this.data.loanscale[this.data.scaleindex];
  207. var tiem = this.data.loantime[this.data.timeindex];
  208. },
  209. selectScale:function(e){
  210. var index = e.currentTarget.dataset.n;
  211. this.setData({scaleindex:index});
  212. },
  213. selectTime:function(e){
  214. var index = e.currentTarget.dataset.n;
  215. this.setData({timeindex:index});
  216. }
  217. })