huhaobangding.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. const app = getApp()
  2. const utils = require("../../utils/util.js")
  3. Page({
  4. data: {
  5. selectedTag: '',
  6. showCustomInput: false,
  7. customTagLength: 0,
  8. showDrawer: false,
  9. showPreview: false,
  10. // 是否可以切换水务公司
  11. isChange: true,
  12. // 新增数据
  13. waterCompany: '',
  14. waterCompanyList: app.globalData.waterCompanys,
  15. //当前用户的默认水务公司的下标
  16. waterCompanyIndex: [0],
  17. waterCompanyId: app.globalData.launchPara,
  18. showWaterCompanyPicker: false,
  19. huHao: '',
  20. huMing: '',
  21. customTag: '',
  22. tagLength: 0,
  23. showQueryMethods: false,
  24. phoneQueryList: [
  25. {
  26. id: 1,
  27. name: '1、前进西路营业厅',
  28. phone: ' 17630145126',
  29. time: '8:30-17:30'
  30. },
  31. {
  32. id: 2,
  33. name: '2、浦江路营业厅',
  34. phone: '0516-17630145126',
  35. time: '8:30-17:30'
  36. },
  37. {
  38. id: 3,
  39. name: '3、 测试路营业厅',
  40. phone: '17630145126-345',
  41. time: '8:30-17:30'
  42. }
  43. // 可以添加更多项,将支持滚动显示
  44. ]
  45. },
  46. selectTag(e) {
  47. const tag = e.currentTarget.dataset.tag;
  48. this.setData({
  49. selectedTag: tag,
  50. showCustomInput: tag === '自定义'
  51. });
  52. },
  53. onCustomInput(e) {
  54. const value = e.detail.value;
  55. this.setData({
  56. customTagLength: value.length,
  57. customTag: value
  58. });
  59. },
  60. // 显示抽屉
  61. showDrawer() {
  62. this.setData({
  63. showDrawer: true
  64. });
  65. },
  66. // 隐藏抽屉
  67. hideDrawer() {
  68. this.setData({
  69. showDrawer: false
  70. });
  71. },
  72. // 拨打电话
  73. makePhoneCall(e) {
  74. const phone = e.currentTarget.dataset.phone;
  75. wx.makePhoneCall({
  76. phoneNumber: phone
  77. });
  78. },
  79. // 修改预览图片方法
  80. previewImage: function() {
  81. this.setData({
  82. showPreview: true
  83. });
  84. },
  85. // 关闭预览
  86. closePreview: function() {
  87. this.setData({
  88. showPreview: false
  89. });
  90. },
  91. // 防止点击图片内容时关闭预览
  92. preventBubble: function() {
  93. return;
  94. },
  95. // 显示水站公司选择器
  96. showWaterCompanyPicker: function() {
  97. this.setData({
  98. showWaterCompanyPicker: true,
  99. waterCompanyIndex: this.data.waterCompanyIndex
  100. });
  101. },
  102. // 隐藏水站公司选择器
  103. hideWaterCompanyPicker: function() {
  104. this.setData({
  105. showWaterCompanyPicker: false
  106. });
  107. },
  108. // 水站公司选择变化
  109. onWaterCompanyChange: function(e) {
  110. this.setData({
  111. waterCompanyIndex: e.detail.value
  112. });
  113. },
  114. // 确认水站公司选择
  115. confirmWaterCompany: function(e) {
  116. const index = this.data.waterCompanyIndex[0];
  117. this.setData({
  118. waterCompanyIndex: this.data.waterCompanyIndex,
  119. waterCompany: this.data.waterCompanyList[index].name,
  120. showWaterCompanyPicker: false
  121. });
  122. },
  123. // 户号输入
  124. onHuHaoInput: function(e) {
  125. this.setData({
  126. huHao: e.detail.value
  127. });
  128. },
  129. // 户名输入
  130. onHuMingInput: function(e) {
  131. this.setData({
  132. huMing: e.detail.value
  133. });
  134. },
  135. // 确认绑定
  136. confirmBinding: function() {
  137. // 验证必填字段
  138. if (!this.data.waterCompany) {
  139. wx.showToast({
  140. title: '请选择水站公司',
  141. icon: 'none'
  142. });
  143. return;
  144. }
  145. if (!this.data.huHao) {
  146. wx.showToast({
  147. title: '请输入户号',
  148. icon: 'none'
  149. });
  150. return;
  151. }
  152. if (!this.data.huMing) {
  153. wx.showToast({
  154. title: '请输入户名',
  155. icon: 'none'
  156. });
  157. return;
  158. }
  159. // 处理分组信息
  160. let groupInfo = this.data.selectedTag;
  161. if (this.data.selectedTag === '自定义' && this.data.customTag) {
  162. groupInfo = this.data.customTag;
  163. }
  164. // 提交数据
  165. wx.showLoading({
  166. title: '绑定中...',
  167. });
  168. // 调用绑定接口
  169. wx.request({
  170. url: app.globalData.interfaceUrls.accoundBind,
  171. method: 'POST',
  172. data: {
  173. bindWaterCompany: this.data.waterCompanyList[this.data.waterCompanyIndex[0]].id,
  174. accountNum: this.data.huHao,
  175. accountName: this.data.huMing,
  176. groupType: groupInfo,
  177. openId: app.globalData.userWxInfo.openId,
  178. defaultAccount: 0,
  179. otherDsKey: (app.globalData.bindAccountInfo||[]).map(data=>data.dsKey)
  180. },
  181. header: {
  182. 'content-type': 'application/json', // 默认值
  183. 'token':app.globalData.userWxInfo.token,
  184. 'source':"wc",
  185. '!SAAS_LOGIN_TOKEN_!':this.data.waterCompanyList[this.data.waterCompanyIndex[0]].id
  186. },
  187. success (res) {
  188. wx.hideLoading();
  189. let apiReturnData=res.data
  190. if(apiReturnData.code=='200'){
  191. wx.hideLoading();
  192. utils.simleInfo('绑定成功')
  193. setTimeout(function(){
  194. wx.switchTab({
  195. url: '/pages/homepage/homepage',
  196. })
  197. },2000)
  198. }else{
  199. wx.showToast({
  200. title: apiReturnData.msg,
  201. icon: 'error',
  202. duration: 2000
  203. })
  204. }
  205. },fail(error) {
  206. wx.hideLoading()
  207. utils.simleInfo('登录失败,请稍后再试')
  208. }
  209. })
  210. },
  211. onLoad: function() {
  212. // 延迟设置导航栏,确保页面已完全加载
  213. setTimeout(() => {
  214. wx.setNavigationBarTitle({
  215. title: '户号绑定'
  216. });
  217. wx.setNavigationBarColor({
  218. frontColor: '#ffffff',
  219. backgroundColor: '#0066FF'
  220. });
  221. }, 100);
  222. if(app.globalData.launchPara){
  223. this.setData({
  224. waterCompanyIndex:[app.globalData.waterCompanys.findIndex(data=>data.id==app.globalData.launchPara)],
  225. waterCompany: app.globalData.waterCompanys.filter(data=>data.id==app.globalData.launchPara)[0].name,
  226. isChange:false,
  227. });
  228. }
  229. },
  230. // 添加返回方法
  231. navigateBack: function() {
  232. wx.navigateBack();
  233. },
  234. onTagInput(e) {
  235. this.setData({
  236. tagLength: e.detail.value.length
  237. });
  238. },
  239. showQueryMethodsModal() {
  240. this.setData({
  241. showQueryMethods: true
  242. });
  243. },
  244. closeQueryMethods() {
  245. this.setData({
  246. showQueryMethods: false
  247. });
  248. }
  249. });