sell.js 6.8 KB

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