cardetail.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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,{logs} from "../../module/logs/logs"
  7. const app = getApp();
  8. Page(Object.assign({
  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. item.passn = 0;
  113. item.unpassn = 0;
  114. item._child.forEach(function(item2){
  115. item2.passn = 0;
  116. item2.unpassn = 0;
  117. item2._child.forEach(function(item3){
  118. if(item3.state){
  119. item2.passn++;
  120. item.passn++;
  121. }else{
  122. item2.unpassn++;
  123. item.unpassn++;
  124. }
  125. })
  126. })
  127. })
  128. _self.setData({
  129. detail:detail
  130. })
  131. }else{
  132. if(json.data.message){
  133. wx.showToast({
  134. title:json.data.message,
  135. icon:"none",
  136. duration:2000
  137. })
  138. }
  139. }
  140. })
  141. },
  142. switchTab:function(e){
  143. this.setData({
  144. currentimg: e.detail.current+1
  145. });
  146. },
  147. swCollocate:function(e){
  148. var name = e.currentTarget.dataset.name;
  149. var collocatetype = this.data.collocatetype.map(function(item){
  150. if(item.name==name){
  151. if(item.opened){
  152. item.opened=false;
  153. }else{
  154. item.opened=true;
  155. }
  156. }else{
  157. item.opened=false;
  158. }
  159. return item;
  160. })
  161. this.setData({collocatetype:collocatetype});
  162. },
  163. collectCar:function(){
  164. var _self=this;
  165. if(this.data.detail.is_collect=="0"){
  166. post(pathmap.collect,{
  167. id:this.data.id
  168. },function(json){
  169. if(json.statusCode==200){
  170. wx.showToast({
  171. title:json.data.message
  172. });
  173. _self.setData({detail:Object.assign(_self.data.detail,{is_collect:'1'})});
  174. }else{
  175. wx.showToast({
  176. title:json.data.message,
  177. icon:"none"
  178. });
  179. }
  180. },null,function(){
  181. _self.openLog();
  182. })
  183. }else{
  184. post(pathmap.collectdel,{
  185. id:this.data.id
  186. },function(json){
  187. if(json.statusCode==200){
  188. wx.showToast({
  189. title:json.data.message
  190. });
  191. _self.setData({detail:Object.assign(_self.data.detail,{is_collect:'0'})});
  192. }else{
  193. wx.showToast({
  194. title:json.data.message,
  195. icon:"none"
  196. });
  197. }
  198. },null,function(){
  199. _self.openLog();
  200. })
  201. }
  202. },
  203. appointmentBuy:function(){
  204. var _self=this;
  205. var mobile = wx.getStorageSync("mobile");
  206. post(pathmap.reserve,{
  207. "car_source_id":this.data.id,
  208. mobile:mobile
  209. },function(json){
  210. var obj = {
  211. title:json.data.message
  212. }
  213. if(json.statusCode!=200){
  214. obj.icon="none"
  215. }
  216. wx.showToast(obj);
  217. },null,function(){
  218. _self.openLog();
  219. })
  220. },
  221. openScheme:function(){
  222. var _self=this;
  223. var mobile = wx.getStorageSync("mobile");
  224. if(mobile){
  225. this.setData({openscheme:true});
  226. if(!this.data.rates_a){
  227. get(pathmap.rates,{
  228. mobile:mobile
  229. },function(json){
  230. _self.setData(json.data);
  231. _self.getPay(0,0);
  232. })
  233. }
  234. }else{
  235. this.openLog();
  236. }
  237. },
  238. closeScheme:function(){
  239. this.setData({openscheme:false});
  240. },
  241. getPay:function(scaleindex,timeindex){
  242. var price = this.data.detail.price*10000;
  243. var scale = this.data.loanscale[scaleindex];
  244. var time = this.data.loantime[timeindex];
  245. var interestrate = this.data[this.data.timetorate[time]]/100;
  246. var firstpay = price*scale;
  247. var premonthpay = (price-firstpay)*interestrate*(Math.pow((1+interestrate),time))/(Math.pow((1+interestrate),time)-1);
  248. this.setData({
  249. firstpay:firstpay,
  250. premonthpay:Math.round(premonthpay),
  251. scaleindex:scaleindex,
  252. timeindex:timeindex
  253. })
  254. },
  255. selectScale:function(e){
  256. var index = e.currentTarget.dataset.n;
  257. this.getPay(index,this.data.timeindex)
  258. //this.setData({scaleindex:index});
  259. },
  260. selectTime:function(e){
  261. var index = e.currentTarget.dataset.n;
  262. this.setData({timeindex:index});
  263. this.getPay(this.data.scaleindex,index)
  264. },
  265. callPhone:function(){
  266. if(this.data.detail.custom_tel){
  267. wx.makePhoneCall({
  268. phoneNumber:this.data.detail.custom_tel
  269. })
  270. }else{
  271. wx.showToast({
  272. title:"缺少手机号码",
  273. icon:"none",
  274. duration:2000
  275. })
  276. }
  277. }
  278. },logs))