cardetail.js 6.0 KB

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