huhaobangding.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. const app = getApp()
  2. Page({
  3. data: {
  4. selectedTag: '',
  5. showCustomInput: false,
  6. customTagLength: 0,
  7. showDrawer: false,
  8. showPreview: false,
  9. // 新增数据
  10. waterCompany: '',
  11. waterCompanyList: ['北京水务集团', '上海水务集团', '广州水务集团', '深圳水务集团', '杭州水务集团'],
  12. waterCompanyIndex: [0],
  13. showWaterCompanyPicker: false,
  14. tempWaterCompanyIndex: [0],
  15. huHao: '',
  16. huMing: '',
  17. customTag: '',
  18. tagLength: 0,
  19. showQueryMethods: false,
  20. phoneQueryList: [
  21. {
  22. id: 1,
  23. name: '1、前进西路营业厅',
  24. phone: ' 17630145126',
  25. time: '8:30-17:30'
  26. },
  27. {
  28. id: 2,
  29. name: '2、浦江路营业厅',
  30. phone: '0516-17630145126',
  31. time: '8:30-17:30'
  32. },
  33. {
  34. id: 3,
  35. name: '3、 测试路营业厅',
  36. phone: '17630145126-345',
  37. time: '8:30-17:30'
  38. }
  39. // 可以添加更多项,将支持滚动显示
  40. ]
  41. },
  42. selectTag(e) {
  43. const tag = e.currentTarget.dataset.tag;
  44. this.setData({
  45. selectedTag: tag,
  46. showCustomInput: tag === '自定义'
  47. });
  48. },
  49. onCustomInput(e) {
  50. const value = e.detail.value;
  51. this.setData({
  52. customTagLength: value.length,
  53. customTag: value
  54. });
  55. },
  56. // 显示抽屉
  57. showDrawer() {
  58. this.setData({
  59. showDrawer: true
  60. });
  61. },
  62. // 隐藏抽屉
  63. hideDrawer() {
  64. this.setData({
  65. showDrawer: false
  66. });
  67. },
  68. // 拨打电话
  69. makePhoneCall(e) {
  70. const phone = e.currentTarget.dataset.phone;
  71. wx.makePhoneCall({
  72. phoneNumber: phone
  73. });
  74. },
  75. // 修改预览图片方法
  76. previewImage: function() {
  77. this.setData({
  78. showPreview: true
  79. });
  80. },
  81. // 关闭预览
  82. closePreview: function() {
  83. this.setData({
  84. showPreview: false
  85. });
  86. },
  87. // 防止点击图片内容时关闭预览
  88. preventBubble: function() {
  89. return;
  90. },
  91. // 显示水站公司选择器
  92. showWaterCompanyPicker: function() {
  93. this.setData({
  94. showWaterCompanyPicker: true,
  95. tempWaterCompanyIndex: this.data.waterCompanyIndex
  96. });
  97. },
  98. // 隐藏水站公司选择器
  99. hideWaterCompanyPicker: function() {
  100. this.setData({
  101. showWaterCompanyPicker: false
  102. });
  103. },
  104. // 水站公司选择变化
  105. onWaterCompanyChange: function(e) {
  106. this.setData({
  107. tempWaterCompanyIndex: e.detail.value
  108. });
  109. },
  110. // 确认水站公司选择
  111. confirmWaterCompany: function() {
  112. const index = this.data.tempWaterCompanyIndex[0];
  113. this.setData({
  114. waterCompanyIndex: this.data.tempWaterCompanyIndex,
  115. waterCompany: this.data.waterCompanyList[index],
  116. showWaterCompanyPicker: false
  117. });
  118. },
  119. // 户号输入
  120. onHuHaoInput: function(e) {
  121. this.setData({
  122. huHao: e.detail.value
  123. });
  124. },
  125. // 户名输入
  126. onHuMingInput: function(e) {
  127. this.setData({
  128. huMing: e.detail.value
  129. });
  130. },
  131. // 确认绑定
  132. confirmBinding: function() {
  133. // 验证必填字段
  134. if (!this.data.waterCompany) {
  135. wx.showToast({
  136. title: '请选择水站公司',
  137. icon: 'none'
  138. });
  139. return;
  140. }
  141. if (!this.data.huHao) {
  142. wx.showToast({
  143. title: '请输入户号',
  144. icon: 'none'
  145. });
  146. return;
  147. }
  148. if (!this.data.huMing) {
  149. wx.showToast({
  150. title: '请输入户名',
  151. icon: 'none'
  152. });
  153. return;
  154. }
  155. // 处理分组信息
  156. let groupInfo = this.data.selectedTag;
  157. if (this.data.selectedTag === '自定义' && this.data.customTag) {
  158. groupInfo = this.data.customTag;
  159. }
  160. // 提交数据
  161. wx.showLoading({
  162. title: '绑定中...',
  163. });
  164. // 模拟API调用
  165. setTimeout(() => {
  166. wx.hideLoading();
  167. wx.showToast({
  168. title: '绑定成功',
  169. icon: 'success',
  170. duration: 2000,
  171. success: () => {
  172. // 绑定成功后跳转
  173. setTimeout(() => {
  174. wx.navigateBack();
  175. }, 2000);
  176. }
  177. });
  178. }, 1500);
  179. },
  180. onLoad: function() {
  181. // 延迟设置导航栏,确保页面已完全加载
  182. setTimeout(() => {
  183. wx.setNavigationBarTitle({
  184. title: '户号绑定'
  185. });
  186. wx.setNavigationBarColor({
  187. frontColor: '#ffffff',
  188. backgroundColor: '#0066FF'
  189. });
  190. }, 100);
  191. },
  192. // 添加返回方法
  193. navigateBack: function() {
  194. wx.navigateBack();
  195. },
  196. onTagInput(e) {
  197. this.setData({
  198. tagLength: e.detail.value.length
  199. });
  200. },
  201. showQueryMethodsModal() {
  202. this.setData({
  203. showQueryMethods: true
  204. });
  205. },
  206. closeQueryMethods() {
  207. this.setData({
  208. showQueryMethods: false
  209. });
  210. }
  211. });