chooseCar.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // pages/ucenter/car/chooseCar.js
  2. var selectPopup;
  3. var idx;
  4. var plateNumber;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. textArray : ["设为默认","使用此车牌号","修改车牌号","删除车牌号"],
  11. textArrayColor : ["#576B95","#576B95","#576B95","#576B95"],
  12. userCarList: []
  13. },
  14. showMore(e){
  15. idx = e.currentTarget.dataset.idx;
  16. plateNumber = e.currentTarget.dataset.plateNumber;
  17. if(idx.defaultType==0){
  18. this.setData({
  19. textArray : ["设为默认","使用此车牌号","修改车牌号","删除车牌号"],
  20. })
  21. }else{
  22. this.setData({
  23. textArray : ["使用此车牌号","修改车牌号","删除车牌号"],
  24. })
  25. }
  26. selectPopup.show(this.data.textArray,this.data.textArrayColor);
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad(options) {
  32. },
  33. /**
  34. * 生命周期函数--监听页面初次渲染完成
  35. */
  36. onReady() {
  37. selectPopup = this.selectComponent("#selectpopup");
  38. },
  39. /**
  40. * 生命周期函数--监听页面显示
  41. */
  42. onShow() {
  43. let that = this;
  44. let userInfo = wx.getStorageSync('userInfo');
  45. wx.request({
  46. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/carList?loginName=' + userInfo.loginName,
  47. // data: {
  48. // loginName: userInfo.loginName
  49. // },
  50. method: 'POST',
  51. success: function (res) {
  52. console.info(res)
  53. that.setData({
  54. userCarList: res.data
  55. })
  56. },
  57. fail(e) {
  58. console.log("查询车辆失败");
  59. log.info('[查询车辆]','[fail]', e);
  60. }
  61. });
  62. },
  63. /**
  64. * 生命周期函数--监听页面隐藏
  65. */
  66. onHide() {
  67. },
  68. /**
  69. * 生命周期函数--监听页面卸载
  70. */
  71. onUnload() {
  72. },
  73. /**
  74. * 页面相关事件处理函数--监听用户下拉动作
  75. */
  76. onPullDownRefresh() {
  77. },
  78. /**
  79. * 页面上拉触底事件的处理函数
  80. */
  81. onReachBottom() {
  82. },
  83. /**
  84. * 用户点击右上角分享
  85. */
  86. onShareAppMessage() {
  87. },
  88. bindCar(){
  89. let url = '/pages/ucenter/car/chooseAndBindCar'
  90. wx.navigateTo({
  91. url
  92. });
  93. },
  94. selectPopupItemClick:function(e){
  95. let that = this;
  96. if((!idx) && idx!=0){
  97. console.info("idx is null!!!")
  98. return;
  99. }
  100. let index = e.detail[0]
  101. let textArrVal = this.data.textArray[index]
  102. // ["设为默认","修改车牌号","删除车牌号"],
  103. let userInfo = wx.getStorageSync('userInfo');
  104. if(textArrVal=="设为默认"){
  105. console.info("设为默认")
  106. wx.request({
  107. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/carAlter?loginName=' + userInfo.loginName,
  108. data: {
  109. defaultType: 1,
  110. carId: idx.carId,
  111. plateNumber: idx.plateNumber
  112. },
  113. method: 'POST',
  114. success: function (res) {
  115. console.info(res)
  116. that.onShow()
  117. },
  118. fail(e) {
  119. console.log("查询车辆失败");
  120. log.info('[查询车辆]','[fail]', e);
  121. }
  122. });
  123. }else if(textArrVal=="修改车牌号"){
  124. console.info("修改车牌号")
  125. console.info(idx)
  126. let url = '/pages/ucenter/car/bindCar?carId=' + idx.carId + '&plateNumber=' + idx.plateNumber + '&defaultType=' + idx.defaultType
  127. wx.navigateTo({
  128. url
  129. });
  130. }else if(textArrVal=="删除车牌号"){
  131. console.info("删除车牌号")
  132. wx.showModal({
  133. title: '提示',
  134. content: '确定要删除当前车辆信息?',
  135. confirmText: '确定',
  136. showCancel:true,
  137. confirmColor:'#00AADD',
  138. cancelColor:'#00AADD',
  139. success: function (res1) {
  140. if(!res1.confirm){
  141. return;
  142. }
  143. wx.request({
  144. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/carRemove?loginName=' + userInfo.loginName + '&carId=' + idx.carId,
  145. // data: {
  146. // loginName: userInfo.loginName
  147. // },
  148. method: 'POST',
  149. success: function (res) {
  150. console.log("删除车辆成功");
  151. console.info(res)
  152. that.onShow()
  153. // that.setData({
  154. // userCarList: res.data
  155. // })
  156. },
  157. fail(e) {
  158. console.log("删除车辆失败");
  159. log.info('[删除车辆]','[fail]', e);
  160. }
  161. });
  162. }
  163. });
  164. }else if(textArrVal=="使用此车牌号"){
  165. /*
  166. {
  167. carId: 4168
  168. createBy: "yawuga"
  169. createTime: "2023-08-11 20:41:36"
  170. defaultType: 0
  171. params: {}
  172. plateNumber: "232321111"
  173. remark: null
  174. searchValue: null
  175. status: 0
  176. sysUser: {searchValue: null, createBy: null, createTime: "2019-05-30 13:34:38", updateBy: null, updateTime: null, …}
  177. updateBy: "yawuga"
  178. updateTime: "2023-08-11 20:45:12"
  179. }
  180. */
  181. console.info(idx)
  182. wx.setStorageSync("chooseCar_plateNumber", idx);
  183. wx.navigateBack();
  184. }
  185. // console.log("选择的item下标:"+e.detail[0])
  186. // console.log("组件标识:"+e.detail[1])
  187. },
  188. selectPopupExit:function(e){
  189. console.log(e)
  190. // console.log("点击了取消或空白区域取消")
  191. // console.log("组件标识:"+e.detail[1])
  192. }
  193. })