cardetail.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. collocatetype:[{
  14. label:"基本参数",
  15. name:"jiben"
  16. },{
  17. label:"发动机参数",
  18. name:"fadongji"
  19. },{
  20. label:"底盘及制动",
  21. name:"dipan"
  22. },{
  23. label:"安全配置",
  24. name:"anquan"
  25. },{
  26. label:"外部配置",
  27. name:"waibu"
  28. },{
  29. label:"内部配置",
  30. name:"neibu"
  31. },{
  32. label:"操控/辅助配置",
  33. name:"caokong"
  34. }],
  35. imagemap:{
  36. "事故排查":"accident",
  37. "轻微碰撞":"checkcollide",
  38. "易损耗部件":"wastage",
  39. "常用功能":"comonuse",
  40. "启动检测":"startcheck"
  41. },
  42. currentimg:1,
  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. footerbtheight:app.globalData.isIpx?120:98
  58. },
  59. /**
  60. * 生命周期函数--监听页面加载
  61. */
  62. onLoad: function (options) {
  63. this.setData(Object.assign({id:options.id},stylemap));
  64. this.getDetail();
  65. bindLog(this);
  66. },
  67. /**
  68. * 生命周期函数--监听页面初次渲染完成
  69. */
  70. onReady: function () {
  71. },
  72. /**
  73. * 生命周期函数--监听页面显示
  74. */
  75. onShow: function () {
  76. },
  77. /**
  78. * 生命周期函数--监听页面隐藏
  79. */
  80. onHide: function () {
  81. },
  82. /**
  83. * 生命周期函数--监听页面卸载
  84. */
  85. onUnload: function () {
  86. },
  87. /**
  88. * 页面相关事件处理函数--监听用户下拉动作
  89. */
  90. onPullDownRefresh: function () {
  91. },
  92. /**
  93. * 页面上拉触底事件的处理函数
  94. */
  95. onReachBottom: function () {
  96. },
  97. /**
  98. * 用户点击右上角分享
  99. */
  100. onShareAppMessage: function () {
  101. },
  102. loginback:function(){
  103. this.getDetail();
  104. },
  105. getDetail:function(){
  106. var _self=this;
  107. get(pathmap.cardetail,{id:this.data.id},function(json){
  108. if(json.statusCode==200){
  109. var detail = json.data;
  110. if(detail.first_plate_at){
  111. var time = detail.first_plate_at.split('-');
  112. detail.first_plate_atn = time[0]+"/"+time[1]+"首次上牌";
  113. detail.first_plate_atname = time[0]+"年"+parseInt(time[1])+"月";
  114. }else{
  115. detail.first_plate_atn = "未上牌";
  116. detail.first_plate_atname = "未上牌";
  117. }
  118. /*数据结构处理*/
  119. detail.imgs = detail.imgs&&detail.imgs.split(",");
  120. detail.imgslength = detail.imgs.length;
  121. detail.check_info.forEach(function(item){
  122. item.passn = 0;
  123. item.unpassn = 0;
  124. item._child.forEach(function(item2){
  125. item2.passn = 0;
  126. item2.unpassn = 0;
  127. item2.opensub=false;
  128. item2._child.forEach(function(item3){
  129. if(item3.state){
  130. item2.passn++;
  131. item.passn++;
  132. }else{
  133. item2.unpassn++;
  134. item.unpassn++;
  135. }
  136. })
  137. })
  138. })
  139. var imgh = 444*detail.imgslength+1878;
  140. var scrollitem = [532,1586,imgh].map(function(item){
  141. return item/_self.data.scale;
  142. })
  143. _self.setData({
  144. detail:detail,
  145. scrollitem:scrollitem
  146. })
  147. }else{
  148. if(json.data.message){
  149. wx.showToast({
  150. title:json.data.message,
  151. icon:"none",
  152. duration:2000
  153. })
  154. }
  155. }
  156. })
  157. },
  158. switchTab:function(e){
  159. this.setData({
  160. currentimg: e.detail.current+1
  161. });
  162. },
  163. swCollocate:function(e){
  164. var name = e.currentTarget.dataset.name;
  165. var collocatetype = this.data.collocatetype.map(function(item){
  166. if(item.name==name){
  167. if(item.opened){
  168. item.opened=false;
  169. }else{
  170. item.opened=true;
  171. }
  172. }else{
  173. item.opened=false;
  174. }
  175. return item;
  176. })
  177. this.setData({collocatetype:collocatetype});
  178. },
  179. collectCar:function(){
  180. var _self=this;
  181. if(this.data.detail.is_collect=="0"){
  182. post(pathmap.collect,{
  183. id:this.data.id
  184. },function(json){
  185. if(json.statusCode==200){
  186. wx.showToast({
  187. title:json.data.message
  188. });
  189. _self.setData({detail:Object.assign(_self.data.detail,{is_collect:'1'})});
  190. }else{
  191. wx.showToast({
  192. title:json.data.message,
  193. icon:"none"
  194. });
  195. }
  196. },null,function(){
  197. _self.openLog();
  198. })
  199. }else{
  200. post(pathmap.collectdel,{
  201. id:this.data.id
  202. },function(json){
  203. if(json.statusCode==200){
  204. wx.showToast({
  205. title:json.data.message
  206. });
  207. _self.setData({detail:Object.assign(_self.data.detail,{is_collect:'0'})});
  208. }else{
  209. wx.showToast({
  210. title:json.data.message,
  211. icon:"none"
  212. });
  213. }
  214. },null,function(){
  215. _self.openLog();
  216. })
  217. }
  218. },
  219. appointmentBuy:function(){
  220. var _self=this;
  221. var mobile = wx.getStorageSync("mobile");
  222. post(pathmap.reserve,{
  223. "car_source_id":this.data.id,
  224. mobile:mobile
  225. },function(json){
  226. var obj = {
  227. title:json.data.message
  228. }
  229. if(json.statusCode!=200){
  230. obj.icon="none"
  231. }
  232. wx.showToast(obj);
  233. },null,function(){
  234. _self.openLog();
  235. })
  236. },
  237. openScheme:function(){
  238. var _self=this;
  239. var mobile = wx.getStorageSync("mobile");
  240. if(mobile){
  241. this.setData({openscheme:true});
  242. if(!this.data.rates_a){
  243. get(pathmap.rates,{
  244. mobile:mobile
  245. },function(json){
  246. _self.setData(json.data);
  247. _self.getPay(0,0);
  248. })
  249. }
  250. }else{
  251. this.openLog();
  252. }
  253. },
  254. closeScheme:function(){
  255. this.setData({openscheme:false});
  256. },
  257. getPay:function(scaleindex,timeindex){
  258. var price = this.data.detail.price*10000;
  259. var scale = this.data.loanscale[scaleindex];
  260. var time = this.data.loantime[timeindex];
  261. var interestrate = this.data[this.data.timetorate[time]]/100;
  262. var firstpay = price*scale;
  263. var premonthpay = (price-firstpay)*interestrate*(Math.pow((1+interestrate),time))/(Math.pow((1+interestrate),time)-1);
  264. this.setData({
  265. firstpay:firstpay,
  266. premonthpay:Math.round(premonthpay),
  267. scaleindex:scaleindex,
  268. timeindex:timeindex
  269. })
  270. },
  271. selectScale:function(e){
  272. var index = e.currentTarget.dataset.n;
  273. this.getPay(index,this.data.timeindex)
  274. //this.setData({scaleindex:index});
  275. },
  276. selectTime:function(e){
  277. var index = e.currentTarget.dataset.n;
  278. this.setData({timeindex:index});
  279. this.getPay(this.data.scaleindex,index)
  280. },
  281. callPhone:function(){
  282. if(this.data.detail.custom_tel){
  283. wx.makePhoneCall({
  284. phoneNumber:this.data.detail.custom_tel
  285. })
  286. }else{
  287. wx.showToast({
  288. title:"缺少手机号码",
  289. icon:"none",
  290. duration:2000
  291. })
  292. }
  293. },
  294. swcItem:function(e){
  295. this.setData({
  296. scrollindex:e.detail
  297. })
  298. },
  299. toScroll:function(e){
  300. var index = e.target.dataset.index;
  301. var collocatetype = this.data.collocatetype.map(function (item) {
  302. item.opened = false;
  303. return item;
  304. })
  305. this.setData({
  306. collocatetype: collocatetype,
  307. scrollto:index=="0"?0:this.data.scrollitem[index]+1,
  308. desopen:false
  309. })
  310. },
  311. swdesc:function(){
  312. this.setData({
  313. desopen:!this.data.desopen
  314. })
  315. },
  316. openCheck:function(){
  317. this.setData({
  318. showcheck:true
  319. })
  320. },
  321. closeCheck:function(){
  322. this.setData({
  323. showcheck:false
  324. })
  325. },
  326. openSub:function(e){
  327. var obj = e.currentTarget.dataset;
  328. var check_info = this.data.detail.check_info;
  329. var item = Object.assign({},check_info[obj.index]._child[obj.indext]);
  330. item.opensub = !item.opensub;
  331. check_info[obj.index]._child[obj.indext] = item;
  332. this.setData({detail:Object.assign({},this.data.detail,{check_info:check_info})});
  333. },
  334. onShareAppMessage: function(){
  335. return {
  336. title: this.data.detail.name,
  337. imageUrl: this.data.detail.imgs[0],
  338. success: (res) => {
  339. wx.showToast({
  340. title:"转发成功!"
  341. })
  342. },
  343. fail: (res) => {
  344. wx.showToast({
  345. title:"转发失败!",
  346. icon:"none"
  347. })
  348. }
  349. }
  350. }
  351. },logs))