sell.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // pages/sell/sell.js
  2. import { get,post,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. windowh: app.globalData.windowh,
  13. area:{},
  14. areaselect:{},
  15. series:{},
  16. selectseries:{},
  17. imgs:[
  18. "",
  19. "",
  20. "",
  21. ""
  22. ],
  23. date:"2018-01-01"
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad: function (options) {
  29. bindLog(this);
  30. this.setData(stylemap);
  31. this.getCararea(0,0,0);
  32. this.getCarSeries(0,0,0);
  33. try{
  34. var authorization = wx.getStorageSync("authorization");
  35. }catch(e){
  36. }
  37. if(!authorization){
  38. this.openLog();
  39. }
  40. },
  41. /**
  42. * 生命周期函数--监听页面初次渲染完成
  43. */
  44. onReady: function () {
  45. },
  46. /**
  47. * 生命周期函数--监听页面显示
  48. */
  49. onShow: function () {
  50. },
  51. /**
  52. * 生命周期函数--监听页面隐藏
  53. */
  54. onHide: function () {
  55. },
  56. /**
  57. * 生命周期函数--监听页面卸载
  58. */
  59. onUnload: function () {
  60. },
  61. /**
  62. * 页面相关事件处理函数--监听用户下拉动作
  63. */
  64. onPullDownRefresh: function () {
  65. },
  66. /**
  67. * 页面上拉触底事件的处理函数
  68. */
  69. onReachBottom: function () {
  70. },
  71. /**
  72. * 用户点击右上角分享
  73. */
  74. onShareAppMessage: function () {
  75. },
  76. getCararea:function(id,index,sel){
  77. var _self=this;
  78. sel = sel||0;
  79. get(pathmap.cararea,{pid:id},function(json){
  80. var obj = {},select={};
  81. obj[index] = json.data;
  82. select[index] = sel;
  83. _self.setData({
  84. area:Object.assign({},_self.data.area,obj),
  85. areaselect:Object.assign({},_self.data.areaselect,select)
  86. });
  87. if(index<1){
  88. _self.getCararea(obj[index][sel]['area_id'],1+parseInt(index),0);
  89. }
  90. })
  91. },
  92. changeArea:function(e){
  93. var index = e.currentTarget.dataset.index;
  94. var select = e.detail.value;
  95. var obj = {};
  96. obj[index]=select;
  97. this.setData({areaselect:Object.assign(this.data.areaselect,obj)});
  98. if(index<1){
  99. this.getCararea(this.data.area[index][select]['area_id'],1+parseInt(index),0);
  100. }
  101. },
  102. // getCarModel:function(){
  103. // var _self=this;
  104. // get(pathmap.carmodel,{pid:id},function(json){
  105. // var obj = {},select={};
  106. // obj[index] = json.data;
  107. // select[index] = sel;
  108. // _self.setData({
  109. // area:Object.assign({},_self.data.area,obj),
  110. // select:Object.assign({},_self.data.areaselect,select)
  111. // });
  112. // if(index<1){
  113. // _self.getCararea(obj[index][sel]['area_id'],1+parseInt(index),0);
  114. // }
  115. // })
  116. // },
  117. getCarSeries:function(id,index,sel){
  118. var _self=this;
  119. sel = sel||0;
  120. //resule 为借口返回数组对应的属性名
  121. var path="",para={},key = "",resule="";
  122. if(index==0){
  123. path = pathmap.brandlist;
  124. key = "brand_id";
  125. resule = "brand";
  126. }else if(index==1){
  127. path = pathmap.serieslist;
  128. para = {brand_id:id}; //this.data.series['0'][this.data.selectseries['0']].brand_id}
  129. key = "car_series_id";
  130. resule = "car_series";
  131. }else if(index==2){
  132. path = pathmap.carmodel;
  133. para = {car_series_id:id}; //this.data.series['1'][this.data.selectseries['1']].car_series_id}
  134. }
  135. get(path,para,function(json){
  136. var obj = {},select={};
  137. obj[index] = json.data;
  138. if(resule){
  139. obj[index] = obj[index][resule];
  140. }
  141. select[index] = sel;
  142. _self.setData({
  143. series:Object.assign({},_self.data.series,obj),
  144. selectseries:Object.assign({},_self.data.selectseries,select)
  145. });
  146. if(index<2){
  147. _self.getCarSeries(obj[index][sel][key],1+parseInt(index),0);
  148. }
  149. })
  150. },
  151. bindSeriesChange:function(e){
  152. var index = e.currentTarget.dataset.index;
  153. var select = e.detail.value;
  154. var obj = {};
  155. var key=""
  156. if(index==0){
  157. key = "brand_id";
  158. }else if(index==1){
  159. key = "car_series_id";
  160. }
  161. obj[index]=select;
  162. this.setData({selectseries:Object.assign(this.data.selectseries,obj)});
  163. if(index<2){
  164. this.getCarSeries(this.data.series[index][select][key],1+parseInt(index),0);
  165. }
  166. },
  167. uploadImg:function(e){
  168. var _self=this;
  169. var index = e.currentTarget.dataset.index;
  170. wx.chooseImage({
  171. success: function(res) {
  172. var tempFilePaths = res.tempFilePaths[0];
  173. upload(pathmap.uploadimg,tempFilePaths,function(json){
  174. var imgs = _self.data.imgs;
  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. this.setData({mileage:mileage});
  184. },
  185. bindDateChange: function(e) {
  186. this.setData({
  187. date: e.detail.value
  188. })
  189. },
  190. subSell:function(){
  191. var _self=this;
  192. var mobile = wx.getStorageSync("mobile")
  193. post(pathmap.sellingcar,{
  194. mobile:mobile,
  195. car_name:this.data.series['2'][this.data.selectseries['2']].car_model_name,
  196. plate_at:this.data.date,
  197. mileage:this.data.mileage,
  198. city_name:`${this.data.area['0'][this.data.areaselect['0']].area_name} ${this.data.area['1'][this.data.areaselect['1']].area_name}`,
  199. imgs:this.data.imgs
  200. },function(json){
  201. var obj = {
  202. title:json.data.message
  203. }
  204. if(json.statusCode!=200){
  205. obj.icon="none"
  206. }
  207. wx.showToast(obj);
  208. })
  209. }
  210. })