cardetail.js 6.7 KB

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