sell.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. // pages/sell/sell.js
  2. import { get,post,postwithoutahth,upload } from "../../common/request.js"
  3. import pathmap from "../../common/pathmap"
  4. import stylemap from "../../common/stylemap"
  5. // import bindLog from "../../module/logs/logs"
  6. const app = getApp();
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. getbrand:pathmap.getbrands,
  13. serieslist:pathmap.carseries,
  14. windowh: app.globalData.windowh,
  15. area:{},
  16. areaselect:{},
  17. series:{},
  18. brandlistshow:false,
  19. //selectseries:{},
  20. imgs:[
  21. "",
  22. "",
  23. "",
  24. ""
  25. ],
  26. date:"2018-01-01"
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function (options) {
  32. //bindLog(this);
  33. this.setData(stylemap);
  34. this.getCararea(0,0,0);
  35. //this.getCarSeries(0,0,0);
  36. try{
  37. var authorization = wx.getStorageSync("authorization");
  38. }catch(e){
  39. }
  40. // if(!authorization){
  41. // this.openLog();
  42. // }
  43. },
  44. /**
  45. * 生命周期函数--监听页面初次渲染完成
  46. */
  47. onReady: function () {
  48. },
  49. /**
  50. * 生命周期函数--监听页面显示
  51. */
  52. onShow: function () {
  53. },
  54. /**
  55. * 生命周期函数--监听页面隐藏
  56. */
  57. onHide: function () {
  58. },
  59. /**
  60. * 生命周期函数--监听页面卸载
  61. */
  62. onUnload: function () {
  63. },
  64. /**
  65. * 页面相关事件处理函数--监听用户下拉动作
  66. */
  67. onPullDownRefresh: function () {
  68. },
  69. /**
  70. * 页面上拉触底事件的处理函数
  71. */
  72. onReachBottom: function () {
  73. },
  74. /**
  75. * 用户点击右上角分享
  76. */
  77. onShareAppMessage: function () {
  78. },
  79. getCararea:function(id,index,sel){
  80. var _self=this;
  81. sel = sel||0;
  82. get(pathmap.cararea,{pid:id},function(json){
  83. var obj = {},select={};
  84. obj[index] = json.data;
  85. select[index] = sel;
  86. _self.setData({
  87. area:Object.assign({},_self.data.area,obj),
  88. areaselect:Object.assign({},_self.data.areaselect,select)
  89. });
  90. if(index<1){
  91. _self.getCararea(obj[index][sel]['area_id'],1+parseInt(index),0);
  92. }
  93. })
  94. },
  95. changeArea:function(e){
  96. var index = e.currentTarget.dataset.index;
  97. var select = e.detail.value;
  98. var obj = {};
  99. obj[index]=select;
  100. this.setData({areaselect:Object.assign(this.data.areaselect,obj)});
  101. if(index<1){
  102. this.getCararea(this.data.area[index][select]['area_id'],1+parseInt(index),0);
  103. }
  104. },
  105. // getCarModel:function(){
  106. // var _self=this;
  107. // get(pathmap.carmodel,{pid:id},function(json){
  108. // var obj = {},select={};
  109. // obj[index] = json.data;
  110. // select[index] = sel;
  111. // _self.setData({
  112. // area:Object.assign({},_self.data.area,obj),
  113. // select:Object.assign({},_self.data.areaselect,select)
  114. // });
  115. // if(index<1){
  116. // _self.getCararea(obj[index][sel]['area_id'],1+parseInt(index),0);
  117. // }
  118. // })
  119. // },
  120. // getCarSeries:function(id,index,sel){
  121. // var _self=this;
  122. // sel = sel||0;
  123. // //resule 为借口返回数组对应的属性名
  124. // var path="",para={},key = "",resule="";
  125. // if(index==0){
  126. // path = pathmap.brandlist;
  127. // key = "brand_id";
  128. // resule = "brand";
  129. // }else if(index==1){
  130. // path = pathmap.serieslist;
  131. // para = {brand_id:id}; //this.data.series['0'][this.data.selectseries['0']].brand_id}
  132. // key = "car_series_id";
  133. // resule = "car_series";
  134. // }else if(index==2){
  135. // path = pathmap.carmodel;
  136. // para = {car_series_id:id}; //this.data.series['1'][this.data.selectseries['1']].car_series_id}
  137. // }
  138. // get(path,para,function(json){
  139. // var obj = {},select={};
  140. // obj[index] = json.data;
  141. // if(resule){
  142. // obj[index] = obj[index][resule];
  143. // }
  144. // select[index] = sel;
  145. // _self.setData({
  146. // series:Object.assign({},_self.data.series,obj),
  147. // selectseries:Object.assign({},_self.data.selectseries,select)
  148. // });
  149. // if(index<2){
  150. // _self.getCarSeries(obj[index][sel][key],1+parseInt(index),0);
  151. // }
  152. // })
  153. // },
  154. // bindSeriesChange:function(e){
  155. // var index = e.currentTarget.dataset.index;
  156. // var select = e.detail.value;
  157. // var obj = {};
  158. // var key=""
  159. // if(index==0){
  160. // key = "brand_id";
  161. // }else if(index==1){
  162. // key = "car_series_id";
  163. // }
  164. // obj[index]=select;
  165. // this.setData({selectseries:Object.assign(this.data.selectseries,obj)});
  166. // if(index<2){
  167. // this.getCarSeries(this.data.series[index][select][key],1+parseInt(index),0);
  168. // }
  169. // },
  170. uploadImg:function(e){
  171. var _self=this;
  172. var index = e.currentTarget.dataset.index;
  173. wx.chooseImage({
  174. success: function(res) {
  175. var tempFilePaths = res.tempFilePaths[0];
  176. upload(pathmap.uploadimg,tempFilePaths,function(json){
  177. var imgs = _self.data.imgs;
  178. imgs.splice(index,1,JSON.parse(json.data).url);
  179. _self.setData({imgs:imgs});
  180. })
  181. }
  182. })
  183. },
  184. getMileage:function(e){
  185. var mileage = e.detail.value;
  186. if(mileage>10){
  187. wx.showToast({
  188. title:"行驶里程最多为一位整数和一位小数",
  189. icon:"none"
  190. })
  191. this.setData({mileage:this.data.mileage});
  192. }else{
  193. this.setData({mileage:mileage});
  194. }
  195. },
  196. initMileage:function(e){
  197. var mileage = e.detail.value;
  198. mileage = new Number(mileage).toFixed(1)
  199. this.setData({mileage:mileage});
  200. },
  201. bindDateChange: function(e) {
  202. this.setData({
  203. date: e.detail.value
  204. })
  205. },
  206. bindMobile:function(e){
  207. var mobile = e.detail.value;
  208. this.setData({mobile:mobile});
  209. },
  210. subSell:function(){
  211. var _self=this;
  212. var imgs = this.data.imgs.filter(function(elem){
  213. return elem!='';
  214. })
  215. //var mobile = wx.getStorageSync("mobile")
  216. postwithoutahth(pathmap.sellingcar,{
  217. mobile:this.data.mobile,
  218. car_name:this.data.series.car_series_name,
  219. plate_at:this.data.date,
  220. mileage:this.data.mileage,
  221. city_name:`${this.data.area['0'][this.data.areaselect['0']].area_name} ${this.data.area['1'][this.data.areaselect['1']].area_name}`,
  222. imgs:imgs.join(',')
  223. },function(json){
  224. var obj = {
  225. title:json.data.message
  226. }
  227. if(json.statusCode!=200){
  228. obj.icon="none"
  229. }
  230. wx.showToast(obj);
  231. })
  232. },
  233. showSeriesSelect:function(){
  234. this.setData({brandlistshow:true});
  235. },
  236. closeBrandList:function(){
  237. this.setData({brandlistshow:false});
  238. },
  239. selectSeries:function(e){
  240. var series = e.detail.series;
  241. this.setData({
  242. brandlistshow:false,
  243. series:series
  244. })
  245. }
  246. })