cardetail.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. var time = detail.first_plate_at.split('-');
  111. /*数据结构处理*/
  112. detail.imgs = detail.imgs&&detail.imgs.split(",");
  113. detail.imgslength = detail.imgs.length;
  114. detail.first_plate_at = time[0]+"/"+time[1];
  115. detail.first_plate_atname = time[0]+"年"+parseInt(time[1])+"月";
  116. detail.check_info.forEach(function(item){
  117. item.passn = 0;
  118. item.unpassn = 0;
  119. item._child.forEach(function(item2){
  120. item2.passn = 0;
  121. item2.unpassn = 0;
  122. item2.opensub=false;
  123. item2._child.forEach(function(item3){
  124. if(item3.state){
  125. item2.passn++;
  126. item.passn++;
  127. }else{
  128. item2.unpassn++;
  129. item.unpassn++;
  130. }
  131. })
  132. })
  133. })
  134. var imgh = 444*detail.imgslength+1878;
  135. var scrollitem = [532,1586,imgh].map(function(item){
  136. return item/app.globalData.scale;
  137. })
  138. _self.setData({
  139. detail:detail,
  140. scrollitem:scrollitem
  141. })
  142. }else{
  143. if(json.data.message){
  144. wx.showToast({
  145. title:json.data.message,
  146. icon:"none",
  147. duration:2000
  148. })
  149. }
  150. }
  151. })
  152. },
  153. switchTab:function(e){
  154. this.setData({
  155. currentimg: e.detail.current+1
  156. });
  157. },
  158. swCollocate:function(e){
  159. var name = e.currentTarget.dataset.name;
  160. var collocatetype = this.data.collocatetype.map(function(item){
  161. if(item.name==name){
  162. if(item.opened){
  163. item.opened=false;
  164. }else{
  165. item.opened=true;
  166. }
  167. }else{
  168. item.opened=false;
  169. }
  170. return item;
  171. })
  172. this.setData({collocatetype:collocatetype});
  173. },
  174. collectCar:function(){
  175. var _self=this;
  176. if(this.data.detail.is_collect=="0"){
  177. post(pathmap.collect,{
  178. id:this.data.id
  179. },function(json){
  180. if(json.statusCode==200){
  181. wx.showToast({
  182. title:json.data.message
  183. });
  184. _self.setData({detail:Object.assign(_self.data.detail,{is_collect:'1'})});
  185. }else{
  186. wx.showToast({
  187. title:json.data.message,
  188. icon:"none"
  189. });
  190. }
  191. },null,function(){
  192. _self.openLog();
  193. })
  194. }else{
  195. post(pathmap.collectdel,{
  196. id:this.data.id
  197. },function(json){
  198. if(json.statusCode==200){
  199. wx.showToast({
  200. title:json.data.message
  201. });
  202. _self.setData({detail:Object.assign(_self.data.detail,{is_collect:'0'})});
  203. }else{
  204. wx.showToast({
  205. title:json.data.message,
  206. icon:"none"
  207. });
  208. }
  209. },null,function(){
  210. _self.openLog();
  211. })
  212. }
  213. },
  214. appointmentBuy:function(){
  215. var _self=this;
  216. var mobile = wx.getStorageSync("mobile");
  217. post(pathmap.reserve,{
  218. "car_source_id":this.data.id,
  219. mobile:mobile
  220. },function(json){
  221. var obj = {
  222. title:json.data.message
  223. }
  224. if(json.statusCode!=200){
  225. obj.icon="none"
  226. }
  227. wx.showToast(obj);
  228. },null,function(){
  229. _self.openLog();
  230. })
  231. },
  232. openScheme:function(){
  233. var _self=this;
  234. var mobile = wx.getStorageSync("mobile");
  235. if(mobile){
  236. this.setData({openscheme:true});
  237. if(!this.data.rates_a){
  238. get(pathmap.rates,{
  239. mobile:mobile
  240. },function(json){
  241. _self.setData(json.data);
  242. _self.getPay(0,0);
  243. })
  244. }
  245. }else{
  246. this.openLog();
  247. }
  248. },
  249. closeScheme:function(){
  250. this.setData({openscheme:false});
  251. },
  252. getPay:function(scaleindex,timeindex){
  253. var price = this.data.detail.price*10000;
  254. var scale = this.data.loanscale[scaleindex];
  255. var time = this.data.loantime[timeindex];
  256. var interestrate = this.data[this.data.timetorate[time]]/100;
  257. var firstpay = price*scale;
  258. var premonthpay = (price-firstpay)*interestrate*(Math.pow((1+interestrate),time))/(Math.pow((1+interestrate),time)-1);
  259. this.setData({
  260. firstpay:firstpay,
  261. premonthpay:Math.round(premonthpay),
  262. scaleindex:scaleindex,
  263. timeindex:timeindex
  264. })
  265. },
  266. selectScale:function(e){
  267. var index = e.currentTarget.dataset.n;
  268. this.getPay(index,this.data.timeindex)
  269. //this.setData({scaleindex:index});
  270. },
  271. selectTime:function(e){
  272. var index = e.currentTarget.dataset.n;
  273. this.setData({timeindex:index});
  274. this.getPay(this.data.scaleindex,index)
  275. },
  276. callPhone:function(){
  277. if(this.data.detail.custom_tel){
  278. wx.makePhoneCall({
  279. phoneNumber:this.data.detail.custom_tel
  280. })
  281. }else{
  282. wx.showToast({
  283. title:"缺少手机号码",
  284. icon:"none",
  285. duration:2000
  286. })
  287. }
  288. },
  289. swcItem:function(e){
  290. this.setData({
  291. scrollindex:e.detail
  292. })
  293. },
  294. toScroll:function(e){
  295. var index = e.target.dataset.index;
  296. var collocatetype = this.data.collocatetype.map(function (item) {
  297. item.opened = false;
  298. return item;
  299. })
  300. this.setData({
  301. collocatetype: collocatetype,
  302. scrollto:index=="0"?0:this.data.scrollitem[index]+1,
  303. desopen:false
  304. })
  305. },
  306. swdesc:function(){
  307. this.setData({
  308. desopen:!this.data.desopen
  309. })
  310. },
  311. openCheck:function(){
  312. this.setData({
  313. showcheck:true
  314. })
  315. },
  316. closeCheck:function(){
  317. this.setData({
  318. showcheck:false
  319. })
  320. },
  321. openSub:function(e){
  322. var obj = e.currentTarget.dataset;
  323. var check_info = this.data.detail.check_info;
  324. var item = Object.assign({},check_info[obj.index]._child[obj.indext]);
  325. item.opensub = !item.opensub;
  326. check_info[obj.index]._child[obj.indext] = item;
  327. this.setData({detail:Object.assign({},this.data.detail,{check_info:check_info})});
  328. },
  329. onShareAppMessage: function(){
  330. return {
  331. title: this.data.detail.name,
  332. imageUrl: this.data.detail.imgs[0],
  333. success: (res) => {
  334. wx.showToast({
  335. title:"转发成功!"
  336. })
  337. },
  338. fail: (res) => {
  339. wx.showToast({
  340. title:"转发失败!",
  341. icon:"none"
  342. })
  343. }
  344. }
  345. }
  346. },logs))