chooseCar.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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.info(res)
  151. if(res.data.code==200){
  152. console.log("删除车辆成功");
  153. that.onShow()
  154. }else{
  155. wx.showModal({
  156. title: '提示',
  157. content: res.data.msg,
  158. showCancel: false,
  159. complete: (res) => {
  160. if (res.cancel) {
  161. }
  162. if (res.confirm) {
  163. }
  164. }
  165. })
  166. }
  167. // that.setData({
  168. // userCarList: res.data
  169. // })
  170. },
  171. fail(e) {
  172. console.log("删除车辆失败");
  173. log.info('[删除车辆]','[fail]', e);
  174. }
  175. });
  176. }
  177. });
  178. }else if(textArrVal=="使用此车牌号"){
  179. /*
  180. {
  181. carId: 4168
  182. createBy: "yawuga"
  183. createTime: "2023-08-11 20:41:36"
  184. defaultType: 0
  185. params: {}
  186. plateNumber: "232321111"
  187. remark: null
  188. searchValue: null
  189. status: 0
  190. sysUser: {searchValue: null, createBy: null, createTime: "2019-05-30 13:34:38", updateBy: null, updateTime: null, …}
  191. updateBy: "yawuga"
  192. updateTime: "2023-08-11 20:45:12"
  193. }
  194. */
  195. console.info(idx)
  196. wx.setStorageSync("chooseCar_plateNumber", idx);
  197. wx.navigateBack();
  198. }
  199. // console.log("选择的item下标:"+e.detail[0])
  200. // console.log("组件标识:"+e.detail[1])
  201. },
  202. selectPopupExit:function(e){
  203. console.log(e)
  204. // console.log("点击了取消或空白区域取消")
  205. // console.log("组件标识:"+e.detail[1])
  206. }
  207. })