cardetail.js 8.2 KB

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