edit.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. // pages/car/edit.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. isKeyboard: false, //是否显示车牌输入键盘
  9. inputOnFocusIndex: '', //当前锁定的车号位置
  10. licensePlate: '', //车牌号
  11. defaultText: '请选择',
  12. inputPlates: { //默认显示车牌号
  13. index0: "",
  14. index1: "",
  15. index2: "",
  16. index3: "",
  17. index4: "",
  18. index5: "",
  19. index6: "",
  20. index7: ""
  21. },
  22. id: '',
  23. isShow: true,
  24. current_index: 0,
  25. blackSwitch:'2',
  26. whiteSwitch:'2',
  27. internal:2,
  28. originalInvoicePhoto: '', //base64码
  29. originalInvoicePhotoUrl: ''
  30. },
  31. //输入框焦点聚焦时隐藏车牌号输入框
  32. hideKeybord: function () {
  33. this.setData({
  34. isKeyboard: false,
  35. inputOnFocusIndex: ''
  36. })
  37. },
  38. //下拉选择
  39. bindPickerChange: function (e) { //下拉菜单
  40. let { pickername } = e.target.dataset
  41. let getIndex = pickername + 'Index'
  42. app.util.getPickerIndex(this, getIndex, e);
  43. },
  44. /**
  45. * 生命周期函数--监听页面加载
  46. */
  47. onLoad: function (options) {
  48. if (wx.getStorageSync('loginStatus')) {
  49. //获取详情
  50. var pages = getCurrentPages();
  51. var prevPage = pages[pages.length - 2];
  52. let getInfo = prevPage.data.resData[options.index]
  53. let getCarNumArr = getInfo.licensePlate ? getInfo.licensePlate.split('') : ''
  54. let inputPlates = {};
  55. for (let i = 0; i < getCarNumArr.length; i++) {
  56. inputPlates['index' + i] = getCarNumArr[i]
  57. }
  58. this.setData({
  59. id:options.id,
  60. info: getInfo,
  61. inputPlates: inputPlates,
  62. isNewEnergy: getCarNumArr.length > 7 ? true : false,
  63. licensePlate: getInfo.licensePlate,
  64. })
  65. this.getSelectData()
  66. } else {
  67. wx.switchTab({
  68. url: '/pages/center/index',
  69. })
  70. }
  71. },
  72. //获取订单下拉列表、车辆轴数下拉列表
  73. getSelectData:function(){
  74. //获取车辆轴数下拉列表
  75. app.request.GET({
  76. url: app.API.getCarzheList,
  77. params: {},
  78. page: this,
  79. successFun: true
  80. }).then(res => {
  81. this.setData({
  82. overArray:res.data.data,
  83. overIndex: app.util.getDicIndex(res.data.data, this.data.info.vehicleAxles, 'id'),
  84. })
  85. })
  86. },
  87. //查询详情
  88. getInfo: function (id) {
  89. //详情
  90. app.request.requestGetApi(app.API.api.carDetail, {
  91. 'id': id
  92. }, this, function (res, _that) {
  93. let data = res.data.data;
  94. _that.setData({
  95. info: data,
  96. inputPlates: inputPlates,
  97. isNewEnergy: getCarNumArr.length > 7 ? true : false,
  98. licensePlate: data.licensePlate,
  99. projectIndex: app.util.getDicIndex(_that.data.projectArray, data.projectId, 'id'), //请假类型,获取对应下标
  100. })
  101. })
  102. },
  103. //开关
  104. onChange(e) {
  105. let { switchType } = e.currentTarget.dataset
  106. let number = 0
  107. if(e.detail=='1'){
  108. if(this.data.blackSwitch=='1'){
  109. number = number+1
  110. }
  111. if(this.data.whiteSwitch=='1'){
  112. number = number+1
  113. }
  114. if(this.data.internal=='1'){
  115. number = number+1
  116. }
  117. if(number<1){
  118. // 需要手动对 checked 状态进行更新
  119. this.setData({
  120. [switchType]: e.detail
  121. });
  122. }else{
  123. app.util.checkForm('黑白名单及内部车辆最多只能开启一项');
  124. }
  125. }else{
  126. this.setData({
  127. [switchType]: e.detail
  128. });
  129. }
  130. },
  131. //获取车牌号
  132. licensePlate: function (e) {
  133. this.setData({
  134. licensePlate: e.detail.carNum
  135. })
  136. },
  137. // 选择图片
  138. afterRead: function (e) {
  139. wx.chooseImage({
  140. count: 1,
  141. sizeType: ['compressed'],
  142. sourceType: ['album', 'camera'],
  143. success: res => {
  144. var base64 = 'data:image/jpeg;base64,' + wx.getFileSystemManager().readFileSync(res.tempFilePaths[0], "base64");
  145. this.setData({
  146. originalInvoicePhoto: base64,
  147. originalInvoicePhotoUrl: res.tempFilePaths[0]
  148. })
  149. console.log('上传时的base64:', this.data.originalInvoicePhoto)
  150. }
  151. })
  152. },
  153. //删除当前选择的图片
  154. clearImgFun: function () {
  155. this.setData({
  156. originalInvoicePhoto: '',
  157. originalInvoicePhotoUrl: ''
  158. })
  159. },
  160. //提交事件
  161. formSubmit: function ({detail:{value}}) {
  162. let reg = /^1[3-9]\d{9}$/;
  163. var xreg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]{1}$/;
  164. var creg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1}$/;
  165. var warn = ""; //弹框时提示的内容
  166. //formData.certificateNoImage = this.data.originalInvoicePhoto
  167. if (value.licensePlate == '') {
  168. warn = "车牌不能为空!";
  169. } else if (value.licensePlate.length < 7) {
  170. warn = "请选择完整车牌号!";
  171. } else if (value.licensePlate.length == 7 && !creg.test(value.licensePlate)) {
  172. warn = "车牌号格式错误!";
  173. } else if (value.licensePlate.length == 8 && !xreg.test(value.licensePlate)) {
  174. warn = "车牌号格式错误!";
  175. } else if (value.vehicleAxles == '') {
  176. warn = "请选择车辆轴数!";
  177. }
  178. if (warn != '') {
  179. app.util.checkForm(warn);
  180. } else {
  181. app.request.POST({
  182. url: app.API.bizvehicleEdit,
  183. params: value,
  184. page: this,
  185. isLoadingTxt: '提交中...',
  186. isSubmitting: true,
  187. successFun: true
  188. }).then(res => {
  189. wx.showToast({
  190. title: '修改成功',
  191. icon: 'success',
  192. duration: 2000,
  193. mask:true,
  194. complete: function () {
  195. setTimeout(() => {
  196. wx.navigateBack()
  197. }, 1500) //延迟时间
  198. }
  199. })
  200. })
  201. }
  202. }
  203. })