baoxiudj.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. Page({
  2. data: {
  3. address: '安平镇安坪村安平小区12栋305室',
  4. contact: '',
  5. phone: '',
  6. repairType: '',
  7. description: '',
  8. imageList: [],
  9. showNotification: true,
  10. countDown: 3
  11. },
  12. onLoad: function(options) {
  13. this.startCountDown();
  14. },
  15. startCountDown: function() {
  16. let that = this;
  17. let timer = setInterval(function() {
  18. if (that.data.countDown > 0) {
  19. that.setData({
  20. countDown: that.data.countDown - 1
  21. });
  22. } else {
  23. clearInterval(timer);
  24. }
  25. }, 1000);
  26. },
  27. closeNotification: function() {
  28. if (this.data.countDown <= 0) {
  29. this.setData({
  30. showNotification: false
  31. });
  32. }
  33. },
  34. goBack: function() {
  35. wx.navigateBack();
  36. },
  37. inputContact: function(e) {
  38. this.setData({
  39. contact: e.detail.value
  40. });
  41. },
  42. inputPhone: function(e) {
  43. const value = e.detail.value;
  44. const phoneNumber = value.replace(/\D/g, '');
  45. this.setData({
  46. phone: phoneNumber
  47. });
  48. },
  49. validatePhone: function(phone) {
  50. const phoneReg = /^1[3-9]\d{9}$/;
  51. return phoneReg.test(phone);
  52. },
  53. showRepairTypeSelector: function() {
  54. let that = this;
  55. wx.showActionSheet({
  56. itemList: ['水管漏水', '水表故障', '水龙头故障', '其他问题'],
  57. success: function(res) {
  58. const types = ['水管漏水', '水表故障', '水龙头故障', '其他问题'];
  59. that.setData({
  60. repairType: types[res.tapIndex]
  61. });
  62. }
  63. });
  64. },
  65. inputDescription: function(e) {
  66. this.setData({
  67. description: e.detail.value
  68. });
  69. },
  70. chooseImage: function() {
  71. let that = this;
  72. if (that.data.imageList.length >= 10) {
  73. wx.showToast({
  74. title: '最多只能上传10张图片',
  75. icon: 'none'
  76. });
  77. return;
  78. }
  79. wx.chooseMedia({
  80. count: 3 - that.data.imageList.length,
  81. mediaType: ['image'],
  82. sourceType: ['album', 'camera'],
  83. sizeType: ['compressed'],
  84. success: function(res) {
  85. let tempFiles = res.tempFiles;
  86. let validFiles = [];
  87. for (let i = 0; i < tempFiles.length; i++) {
  88. const file = tempFiles[i];
  89. if (file.size <= 5 * 1024 * 1024) {
  90. validFiles.push(file.tempFilePath);
  91. } else {
  92. wx.showToast({
  93. title: '图片大小不能超过5M',
  94. icon: 'none'
  95. });
  96. }
  97. }
  98. if (validFiles.length > 0) {
  99. let newImageList = that.data.imageList.concat(validFiles);
  100. that.setData({
  101. imageList: newImageList
  102. });
  103. }
  104. }
  105. });
  106. },
  107. previewImage: function(e) {
  108. let index = e.currentTarget.dataset.index;
  109. wx.previewImage({
  110. current: this.data.imageList[index],
  111. urls: this.data.imageList
  112. });
  113. },
  114. deleteImage: function(e) {
  115. let index = e.currentTarget.dataset.index;
  116. let imageList = this.data.imageList;
  117. imageList.splice(index, 1);
  118. this.setData({
  119. imageList: imageList
  120. });
  121. },
  122. submitRepair: function() {
  123. if (!this.data.contact) {
  124. wx.showToast({
  125. title: '请输入联系人',
  126. icon: 'none'
  127. });
  128. return;
  129. }
  130. if (!this.data.phone) {
  131. wx.showToast({
  132. title: '请输入联系电话',
  133. icon: 'none'
  134. });
  135. return;
  136. }
  137. if (!this.validatePhone(this.data.phone)) {
  138. wx.showToast({
  139. title: '请输入正确的手机号',
  140. icon: 'none'
  141. });
  142. return;
  143. }
  144. if (!this.data.repairType) {
  145. wx.showToast({
  146. title: '请选择报修类型',
  147. icon: 'none'
  148. });
  149. return;
  150. }
  151. if (!this.data.description) {
  152. wx.showToast({
  153. title: '请输入故障说明',
  154. icon: 'none'
  155. });
  156. return;
  157. }
  158. const submitData = {
  159. address: this.data.address,
  160. contact: this.data.contact,
  161. phone: this.data.phone,
  162. repairType: this.data.repairType,
  163. description: this.data.description,
  164. images: this.data.imageList
  165. };
  166. console.log('提交的数据:', submitData);
  167. wx.showLoading({
  168. title: '提交中...',
  169. });
  170. setTimeout(() => {
  171. wx.hideLoading();
  172. wx.showToast({
  173. title: '报修提交成功',
  174. icon: 'success',
  175. duration: 2000,
  176. success: function() {
  177. setTimeout(() => {
  178. wx.navigateBack();
  179. }, 2000);
  180. }
  181. });
  182. }, 1500);
  183. }
  184. });