cardetail.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. scrollindex:0,
  55. desopen:false,
  56. showcheck:false
  57. },
  58. /**
  59. * 生命周期函数--监听页面加载
  60. */
  61. onLoad: function (options) {
  62. this.setData(Object.assign({id:options.id},stylemap));
  63. this.getDetail();
  64. bindLog(this);
  65. },
  66. /**
  67. * 生命周期函数--监听页面初次渲染完成
  68. */
  69. onReady: function () {
  70. },
  71. /**
  72. * 生命周期函数--监听页面显示
  73. */
  74. onShow: function () {
  75. },
  76. /**
  77. * 生命周期函数--监听页面隐藏
  78. */
  79. onHide: function () {
  80. },
  81. /**
  82. * 生命周期函数--监听页面卸载
  83. */
  84. onUnload: function () {
  85. },
  86. /**
  87. * 页面相关事件处理函数--监听用户下拉动作
  88. */
  89. onPullDownRefresh: function () {
  90. },
  91. /**
  92. * 页面上拉触底事件的处理函数
  93. */
  94. onReachBottom: function () {
  95. },
  96. /**
  97. * 用户点击右上角分享
  98. */
  99. onShareAppMessage: function () {
  100. },
  101. loginback:function(){
  102. this.getDetail();
  103. },
  104. getDetail:function(){
  105. var _self=this;
  106. get(pathmap.cardetail,{id:this.data.id},function(json){
  107. if(json.statusCode==200){
  108. var detail = json.data;
  109. var time = detail.first_plate_at.split('-');
  110. /*数据结构处理*/
  111. detail.imgs = detail.imgs&&detail.imgs.split(",");
  112. detail.imgslength = detail.imgs.length;
  113. detail.first_plate_at = time[0]+"/"+time[1];
  114. detail.first_plate_atname = time[0]+"年"+parseInt(time[1])+"月";
  115. detail.check_info.forEach(function(item){
  116. item.passn = 0;
  117. item.unpassn = 0;
  118. item._child.forEach(function(item2){
  119. item2.passn = 0;
  120. item2.unpassn = 0;
  121. item2.opensub=false;
  122. item2._child.forEach(function(item3){
  123. if(item3.state){
  124. item2.passn++;
  125. item.passn++;
  126. }else{
  127. item2.unpassn++;
  128. item.unpassn++;
  129. }
  130. })
  131. })
  132. })
  133. var imgh = 444*detail.imgslength+1878;
  134. var scrollitem = [532,1586,imgh].map(function(item){
  135. return item/app.globalData.scale;
  136. })
  137. _self.setData({
  138. detail:detail,
  139. scrollitem:scrollitem
  140. })
  141. }else{
  142. if(json.data.message){
  143. wx.showToast({
  144. title:json.data.message,
  145. icon:"none",
  146. duration:2000
  147. })
  148. }
  149. }
  150. })
  151. },
  152. switchTab:function(e){
  153. this.setData({
  154. currentimg: e.detail.current+1
  155. });
  156. },
  157. swCollocate:function(e){
  158. var name = e.currentTarget.dataset.name;
  159. var collocatetype = this.data.collocatetype.map(function(item){
  160. if(item.name==name){
  161. if(item.opened){
  162. item.opened=false;
  163. }else{
  164. item.opened=true;
  165. }
  166. }else{
  167. item.opened=false;
  168. }
  169. return item;
  170. })
  171. this.setData({collocatetype:collocatetype});
  172. },
  173. collectCar:function(){
  174. var _self=this;
  175. if(this.data.detail.is_collect=="0"){
  176. post(pathmap.collect,{
  177. id:this.data.id
  178. },function(json){
  179. if(json.statusCode==200){
  180. wx.showToast({
  181. title:json.data.message
  182. });
  183. _self.setData({detail:Object.assign(_self.data.detail,{is_collect:'1'})});
  184. }else{
  185. wx.showToast({
  186. title:json.data.message,
  187. icon:"none"
  188. });
  189. }
  190. },null,function(){
  191. _self.openLog();
  192. })
  193. }else{
  194. post(pathmap.collectdel,{
  195. id:this.data.id
  196. },function(json){
  197. if(json.statusCode==200){
  198. wx.showToast({
  199. title:json.data.message
  200. });
  201. _self.setData({detail:Object.assign(_self.data.detail,{is_collect:'0'})});
  202. }else{
  203. wx.showToast({
  204. title:json.data.message,
  205. icon:"none"
  206. });
  207. }
  208. },null,function(){
  209. _self.openLog();
  210. })
  211. }
  212. },
  213. appointmentBuy:function(){
  214. var _self=this;
  215. var mobile = wx.getStorageSync("mobile");
  216. post(pathmap.reserve,{
  217. "car_source_id":this.data.id,
  218. mobile:mobile
  219. },function(json){
  220. var obj = {
  221. title:json.data.message
  222. }
  223. if(json.statusCode!=200){
  224. obj.icon="none"
  225. }
  226. wx.showToast(obj);
  227. },null,function(){
  228. _self.openLog();
  229. })
  230. },
  231. openScheme:function(){
  232. var _self=this;
  233. var mobile = wx.getStorageSync("mobile");
  234. if(mobile){
  235. this.setData({openscheme:true});
  236. if(!this.data.rates_a){
  237. get(pathmap.rates,{
  238. mobile:mobile
  239. },function(json){
  240. _self.setData(json.data);
  241. _self.getPay(0,0);
  242. })
  243. }
  244. }else{
  245. this.openLog();
  246. }
  247. },
  248. closeScheme:function(){
  249. this.setData({openscheme:false});
  250. },
  251. getPay:function(scaleindex,timeindex){
  252. var price = this.data.detail.price*10000;
  253. var scale = this.data.loanscale[scaleindex];
  254. var time = this.data.loantime[timeindex];
  255. var interestrate = this.data[this.data.timetorate[time]]/100;
  256. var firstpay = price*scale;
  257. var premonthpay = (price-firstpay)*interestrate*(Math.pow((1+interestrate),time))/(Math.pow((1+interestrate),time)-1);
  258. this.setData({
  259. firstpay:firstpay,
  260. premonthpay:Math.round(premonthpay),
  261. scaleindex:scaleindex,
  262. timeindex:timeindex
  263. })
  264. },
  265. selectScale:function(e){
  266. var index = e.currentTarget.dataset.n;
  267. this.getPay(index,this.data.timeindex)
  268. //this.setData({scaleindex:index});
  269. },
  270. selectTime:function(e){
  271. var index = e.currentTarget.dataset.n;
  272. this.setData({timeindex:index});
  273. this.getPay(this.data.scaleindex,index)
  274. },
  275. callPhone:function(){
  276. if(this.data.detail.custom_tel){
  277. wx.makePhoneCall({
  278. phoneNumber:this.data.detail.custom_tel
  279. })
  280. }else{
  281. wx.showToast({
  282. title:"缺少手机号码",
  283. icon:"none",
  284. duration:2000
  285. })
  286. }
  287. },
  288. swcItem:function(e){
  289. this.setData({
  290. scrollindex:e.detail
  291. })
  292. },
  293. toScroll:function(e){
  294. var index = e.target.dataset.index;
  295. this.setData({
  296. scrollto:index=="0"?0:this.data.scrollitem[index]+1,
  297. desopen:false
  298. })
  299. },
  300. swdesc:function(){
  301. this.setData({
  302. desopen:!this.data.desopen
  303. })
  304. },
  305. openCheck:function(){
  306. this.setData({
  307. showcheck:true
  308. })
  309. },
  310. closeCheck:function(){
  311. this.setData({
  312. showcheck:false
  313. })
  314. },
  315. openSub:function(e){
  316. var obj = e.target.dataset;
  317. var check_info = this.data.detail.check_info;
  318. var item = Object.assign({},check_info[obj.index]._child[obj.indext]);
  319. item.opensub = !item.opensub;
  320. check_info[obj.index]._child[obj.indext] = item;
  321. this.setData({detail:Object.assign({},this.data.detail,{check_info:check_info})});
  322. }
  323. },logs))