fourth.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. Page({
  2. /**
  3. * 页面的初始数据
  4. */
  5. data: {
  6. allowNext:false,
  7. searchValue:'',
  8. searchList:[],
  9. searchfileList:[],
  10. searchFilevalue:'',
  11. show:false,
  12. showFile:false,
  13. productList:[],
  14. title:'',
  15. fileTitle:'',
  16. carFilesList:[],
  17. is_big:'',
  18. is_set:'',
  19. set_status:''
  20. },
  21. handleCancel(){
  22. this.setData({
  23. show:false
  24. })
  25. },
  26. handleCancelFile(){
  27. this.setData({
  28. showFile:false
  29. })
  30. },
  31. onSearch(event){
  32. let arr = this.data.productList.filter(v=>v.title.indexOf(event.detail)!=-1);
  33. this.setData({
  34. searchList:arr
  35. })
  36. },
  37. onSearchFile(event){
  38. let arr = this.data.carFilesList.filter(v=>v.name.indexOf(event.detail)!=-1);
  39. this.setData({
  40. searchFileList:arr
  41. })
  42. },
  43. onChoose(){
  44. this.setData({
  45. show:true,
  46. searchList:this.data.productList
  47. })
  48. },
  49. onChooseFile(){
  50. let app = getApp();
  51. let list = [];
  52. if(app.globalData.car_type){
  53. list = this.data.carFilesList.filter(v=>v.car_type_id==app.globalData.car_type);
  54. }else{
  55. list = this.data.carFilesList
  56. }
  57. this.setData({
  58. showFile:true,
  59. searchFileList:list
  60. })
  61. },
  62. handleNext(){
  63. let app = getApp();
  64. let openid = app.globalData.openID;
  65. if(!app.globalData.car_file_id||!app.globalData.car_type){
  66. return wx.showToast({
  67. icon:'none',
  68. title: '请选择!',
  69. })
  70. }
  71. if(this.data.set_status){
  72. wx.redirectTo({
  73. url: '../fifth/fifth',
  74. })
  75. }else{
  76. app.globalData.stepData = app.globalData.stepData.filter(v=>v.sort!=5);
  77. app.globalData.stepData.push({
  78. sort:5,
  79. data:{
  80. title:this.data.title,
  81. fileTitle:this.data.fileTitle,
  82. is_big:this.data.is_big
  83. }
  84. })
  85. wx.p.request({
  86. url: `${app.globalData.url}wx/saveWxConstructionData`,
  87. method:'POST',
  88. data:{
  89. openid,
  90. type:1,
  91. data:JSON.stringify(app.globalData)
  92. }
  93. }).then(res=>{
  94. if(res.data.code==200){
  95. wx.redirectTo({
  96. url: '../fifth/fifth',
  97. })
  98. }
  99. })
  100. }
  101. },
  102. handleChoose(item){
  103. let app = getApp();
  104. app.globalData.car_type = item.target.dataset.item.id;
  105. app.globalData.car_file_id = '';
  106. app.globalData.car_type_name = item.target.dataset.item.title;
  107. app.globalData.car_file_name = '';
  108. this.setData({
  109. searchFilevalue:'',
  110. title:item.target.dataset.item.title,
  111. fileTitle:'',
  112. show:false,
  113. is_big:''
  114. })
  115. },
  116. handleChooseFile(item){
  117. let app = getApp();
  118. app.globalData.car_file_id = item.target.dataset.item.id;
  119. app.globalData.car_type = item.target.dataset.item.car_type_id;
  120. app.globalData.is_big = item.target.dataset.item.is_big;
  121. app.globalData.car_file_name = item.target.dataset.item.name;
  122. app.globalData.car_type_name = item.target.dataset.item.car_type_name;
  123. this.setData({
  124. fileTitle:item.target.dataset.item.name,
  125. showFile:false,
  126. title:item.target.dataset.item.car_type_name,
  127. is_big:item.target.dataset.item.is_big?'是':'否'
  128. })
  129. },
  130. handleReturn(){
  131. let app = getApp();
  132. let openid = app.globalData.openID;
  133. if(this.data.set_status){
  134. wx.redirectTo({
  135. url: '../writeVIN/writeVIN',
  136. })
  137. }else{
  138. app.globalData.stepData.forEach((v,index)=>{
  139. if(v.sort == '5'){
  140. app.globalData.stepData.splice(index,1);
  141. }
  142. })
  143. wx.p.request({
  144. url: `${app.globalData.url}wx/saveWxConstructionData`,
  145. method:'POST',
  146. data:{
  147. openid,
  148. type:1,
  149. data:JSON.stringify(app.globalData)
  150. }
  151. }).then(res=>{
  152. if(res.data.code==200){
  153. wx.redirectTo({
  154. url: '../writeVIN/writeVIN',
  155. })
  156. }
  157. })
  158. }
  159. },
  160. /**
  161. * 生命周期函数--监听页面加载
  162. */
  163. onLoad(option) {
  164. let app = getApp();
  165. let openid = app.globalData.openID;
  166. wx.p.request({
  167. url: `${app.globalData.url}wx/carTypeList`,
  168. method:'POST',
  169. data:{
  170. openid
  171. }
  172. }).then(res=>{
  173. if(res.data.code==200){
  174. this.setData({
  175. productList:this.getArr(res.data.data)
  176. })
  177. }
  178. })
  179. wx.p.request({
  180. url: `${app.globalData.url}wx/carFilesList`,
  181. method:'POST',
  182. data:{
  183. openid
  184. }
  185. }).then(res=>{
  186. if(res.data.code==200){
  187. this.setData({
  188. carFilesList:res.data.data.data
  189. })
  190. if(app.globalData.own_id){
  191. this.setData({
  192. is_set:false
  193. })
  194. }else{
  195. this.setData({
  196. is_set:true
  197. })
  198. }
  199. if(app.globalData.car_file_id&&app.globalData.car_type){
  200. app.globalData.is_big = this.data.carFilesList.find(v=>v.id==app.globalData.car_file_id).is_big;
  201. this.setData({
  202. title:app.globalData.car_type_name,
  203. fileTitle:app.globalData.car_file_name,
  204. is_big:app.globalData.is_big?'是':'否',
  205. })
  206. }
  207. }
  208. })
  209. if(app.globalData.set_status){
  210. this.setData({
  211. set_status:app.globalData.set_status
  212. })
  213. }else{
  214. wx.p.request({
  215. url: `${app.globalData.url}wx/getWxConstructionData`,
  216. method:'POST',
  217. data:{
  218. type:1,
  219. openid
  220. }
  221. }).then(res=>{
  222. if(res.data.code==200){
  223. if(res.data.data.data){
  224. let data = JSON.parse(res.data.data.data);
  225. let box = data.stepData.find(v=>v.sort==5);
  226. app.globalData = data;
  227. app.globalData.set_status = '';
  228. if(box){
  229. this.setData({
  230. title:box.data.title,
  231. fileTitle:box.data.fileTitle,
  232. is_big:box.data.is_big,
  233. set_status:''
  234. })
  235. }else{
  236. this.setData({
  237. set_status:''
  238. })
  239. }
  240. }
  241. }
  242. })
  243. }
  244. },
  245. getArr(arr){
  246. let data = [];
  247. arr.forEach(v=>{
  248. if(v.children.length==0){
  249. data.push(v);
  250. }else{
  251. data = [...data,this.getArr(v.children)]
  252. }
  253. })
  254. return data;
  255. },
  256. /**
  257. * 生命周期函数--监听页面初次渲染完成
  258. */
  259. onReady() {
  260. },
  261. /**
  262. * 生命周期函数--监听页面显示
  263. */
  264. onShow() {
  265. },
  266. /**
  267. * 生命周期函数--监听页面隐藏
  268. */
  269. onHide() {
  270. },
  271. /**
  272. * 生命周期函数--监听页面卸载
  273. */
  274. onUnload() {
  275. },
  276. /**
  277. * 页面相关事件处理函数--监听用户下拉动作
  278. */
  279. onPullDownRefresh() {
  280. },
  281. /**
  282. * 页面上拉触底事件的处理函数
  283. */
  284. onReachBottom() {
  285. },
  286. /**
  287. * 用户点击右上角分享
  288. */
  289. onShareAppMessage() {
  290. }
  291. })