|
@@ -12,14 +12,14 @@ Page({
|
|
|
|
|
|
// 新增数据
|
|
|
waterCompany: '',
|
|
|
- waterCompanyList: app.globalData.waterCompanys,
|
|
|
+ waterCompanyList: [],
|
|
|
//当前用户的默认水务公司的下标
|
|
|
waterCompanyIndex: [0],
|
|
|
waterCompanyId: app.globalData.launchPara,
|
|
|
showWaterCompanyPicker: false,
|
|
|
|
|
|
huHao: '',
|
|
|
- // huMing: '',
|
|
|
+ huMing: '',
|
|
|
phone: '', // 添加手机号字段
|
|
|
customTag: '',
|
|
|
tagLength: 0,
|
|
@@ -95,18 +95,11 @@ Page({
|
|
|
showWaterCompanyPicker: function() {
|
|
|
// 检查水务公司列表是否已加载
|
|
|
if (!this.data.waterCompanyList || this.data.waterCompanyList.length === 0) {
|
|
|
- // 如果列表为空,尝试重新获取全局数据
|
|
|
- if (app.globalData.waterCompanys && app.globalData.waterCompanys.length > 0) {
|
|
|
- this.setData({
|
|
|
- waterCompanyList: app.globalData.waterCompanys
|
|
|
- });
|
|
|
- } else {
|
|
|
- wx.showToast({
|
|
|
- title: '水务公司数据加载中,请稍后再试',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
+ wx.showToast({
|
|
|
+ title: '水务公司数据加载中,请稍后再试',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
// 确保waterCompanyIndex的有效性
|
|
@@ -204,6 +197,7 @@ Page({
|
|
|
this.setData({
|
|
|
waterCompanyIndex: [index],
|
|
|
waterCompany: selectedCompany.name,
|
|
|
+ waterCompanyId: selectedCompany.id,
|
|
|
showWaterCompanyPicker: false,
|
|
|
phoneQueryList: phoneList,
|
|
|
ylt: yltUrl
|
|
@@ -221,13 +215,80 @@ Page({
|
|
|
},
|
|
|
|
|
|
// 户名输入
|
|
|
- // onHuMingInput: function(e) {
|
|
|
- // // 使用正则表达式去除所有空格
|
|
|
- // const value = e.detail.value.replace(/\s/g, '');
|
|
|
- // this.setData({
|
|
|
- // huMing: value
|
|
|
- // });
|
|
|
- // },
|
|
|
+ onHuMingInput: function(e) {
|
|
|
+ // 使用正则表达式去除所有空格
|
|
|
+ const value = e.detail.value.replace(/\s/g, '');
|
|
|
+ this.setData({
|
|
|
+ huMing: value
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // 获取户名
|
|
|
+ getHuMing: function() {
|
|
|
+ const { huHao, waterCompanyId } = this.data;
|
|
|
+ debugger
|
|
|
+ // 验证户号是否已输入
|
|
|
+ if (!huHao) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '请输入户号',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 验证水站公司是否已选择
|
|
|
+ if (!waterCompanyId) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '请选择水站公司',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 显示加载中
|
|
|
+ wx.showLoading({
|
|
|
+ title: '获取中...',
|
|
|
+ mask: true
|
|
|
+ });
|
|
|
+ // 调用获取户名接口
|
|
|
+ wx.request({
|
|
|
+ url: app.globalData.interfaceUrls.getHuMing,
|
|
|
+ method: 'GET',
|
|
|
+ data: {
|
|
|
+ huHao: huHao,
|
|
|
+ waterCompanyId: waterCompanyId
|
|
|
+ },
|
|
|
+ header: {
|
|
|
+ 'content-type': 'application/json', // 默认值
|
|
|
+ 'token':app.globalData.userWxInfo.token,
|
|
|
+ 'source':"wc",
|
|
|
+ '!SAAS_LOGIN_TOKEN_!':this.data.waterCompanyList[this.data.waterCompanyIndex[0]].id
|
|
|
+ },
|
|
|
+ success: (res) => {
|
|
|
+ wx.hideLoading();
|
|
|
+ if (res.data.code === '200' && res.data.msg) {
|
|
|
+ this.setData({
|
|
|
+ huMing: res.data.msg
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.setData({
|
|
|
+ huMing: ''
|
|
|
+ });
|
|
|
+ wx.showToast({
|
|
|
+ title: res.data.message || '未找到户名信息',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (error) => {
|
|
|
+ wx.hideLoading();
|
|
|
+ wx.showToast({
|
|
|
+ title: '获取户名失败,请稍后重试',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ console.error('获取户名失败:', error);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
|
|
|
// 手机号输入
|
|
|
onPhoneInput: function(e) {
|
|
@@ -315,7 +376,7 @@ Page({
|
|
|
const bindingData = {
|
|
|
bindWaterCompany: this.data.waterCompanyList[this.data.waterCompanyIndex[0]].id,
|
|
|
accountNum: this.data.huHao,
|
|
|
- // accountName: this.data.huMing,
|
|
|
+ accountName: this.data.huMing,
|
|
|
phoneNum: this.data.phone, // 添加手机号字段
|
|
|
groupType: finalTag, // 使用处理后的标签值
|
|
|
openId: app.globalData.userWxInfo.openid,
|
|
@@ -400,80 +461,130 @@ Page({
|
|
|
},
|
|
|
|
|
|
onLoad: function() {
|
|
|
- // 检查是否从FirstBangDing页面跳转过来
|
|
|
- const goingToBindNewAccount = wx.getStorageSync('goingToBindNewAccount');
|
|
|
- if (goingToBindNewAccount) {
|
|
|
- // 清除标记
|
|
|
- wx.removeStorageSync('goingToBindNewAccount');
|
|
|
- // 不需要额外处理,因为FirstBangDing已经设置了必要的标记
|
|
|
- }
|
|
|
-
|
|
|
- // 延迟设置导航栏,确保页面已完全加载
|
|
|
- setTimeout(() => {
|
|
|
- wx.setNavigationBarTitle({
|
|
|
- title: '户号绑定'
|
|
|
- });
|
|
|
- wx.setNavigationBarColor({
|
|
|
- frontColor: '#ffffff',
|
|
|
- backgroundColor: '#0066FF'
|
|
|
- });
|
|
|
- }, 100);
|
|
|
+ const that = this;
|
|
|
|
|
|
- // 设置固定的预览图地址
|
|
|
- this.setData({
|
|
|
- ylt: '/static_file/jcsfcjtzd.jpg'
|
|
|
+ // 通过POST请求获取水站列表
|
|
|
+ wx.showLoading({
|
|
|
+ title: '加载中...',
|
|
|
});
|
|
|
|
|
|
- // 确保水务公司列表已加载
|
|
|
- if (!this.data.waterCompanyList || this.data.waterCompanyList.length === 0) {
|
|
|
- if (app.globalData.waterCompanys && app.globalData.waterCompanys.length > 0) {
|
|
|
- this.setData({
|
|
|
- waterCompanyList: app.globalData.waterCompanys
|
|
|
- });
|
|
|
- } else {
|
|
|
- console.error('水务公司数据未加载');
|
|
|
- // 可以在这里添加重试逻辑或者提示用户刷新页面
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(app.globalData.launchPara){
|
|
|
- // 在设置数据前检查水务公司是否存在
|
|
|
- const companyIndex = app.globalData.waterCompanys.findIndex(data => data.id == app.globalData.launchPara);
|
|
|
- if (companyIndex === -1) {
|
|
|
- console.error('未找到指定的水务公司');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const company = app.globalData.waterCompanys[companyIndex];
|
|
|
- if (!company) {
|
|
|
- console.error('水务公司数据无效');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 获取营业点数据
|
|
|
- let phoneList = [];
|
|
|
- try {
|
|
|
- if (company.businessPoint && Array.isArray(company.businessPoint)) {
|
|
|
- phoneList = company.businessPoint.map((data, index) => {
|
|
|
- return {
|
|
|
- id: index+1,
|
|
|
- name: data.address,
|
|
|
- phone: data.contactphone,
|
|
|
- time: data.worktime
|
|
|
- };
|
|
|
+ wx.request({
|
|
|
+ url: app.globalData.interfaceUrls.waterList,
|
|
|
+ method: 'POST',
|
|
|
+ data: {"dsKey":""},
|
|
|
+ header: {
|
|
|
+ 'content-type': 'application/json',
|
|
|
+ 'token': app.globalData.userWxInfo.token,
|
|
|
+ 'source': "wc"
|
|
|
+ },
|
|
|
+ success(res) {
|
|
|
+ wx.hideLoading();
|
|
|
+ if (res.data.code == '200' && res.data.data) {
|
|
|
+ // 获取成功,设置水务公司列表
|
|
|
+ that.setData({
|
|
|
+ waterCompanyList: res.data.data
|
|
|
+ });
|
|
|
+
|
|
|
+ // 检查是否从FirstBangDing页面跳转过来
|
|
|
+ const goingToBindNewAccount = wx.getStorageSync('goingToBindNewAccount');
|
|
|
+ if (goingToBindNewAccount) {
|
|
|
+ // 清除标记
|
|
|
+ wx.removeStorageSync('goingToBindNewAccount');
|
|
|
+ // 不需要额外处理,因为FirstBangDing已经设置了必要的标记
|
|
|
+ }
|
|
|
+
|
|
|
+ // 延迟设置导航栏,确保页面已完全加载
|
|
|
+ setTimeout(() => {
|
|
|
+ wx.setNavigationBarTitle({
|
|
|
+ title: '户号绑定'
|
|
|
+ });
|
|
|
+ wx.setNavigationBarColor({
|
|
|
+ frontColor: '#ffffff',
|
|
|
+ backgroundColor: '#0066FF'
|
|
|
+ });
|
|
|
+ }, 100);
|
|
|
+
|
|
|
+ // 设置固定的预览图地址
|
|
|
+ that.setData({
|
|
|
+ ylt: '/static_file/jcsfcjtzd.jpg'
|
|
|
+ });
|
|
|
+
|
|
|
+ // 从app.globalData.dsId获取当前用户的dsid
|
|
|
+ const dsid = app.globalData.currentAccountInfo.dsId;
|
|
|
+ let companyIndex = -1;
|
|
|
+
|
|
|
+ // 如果dsid不为null,查找匹配的水站公司
|
|
|
+ if (dsid) {
|
|
|
+ companyIndex = that.data.waterCompanyList.findIndex(data => data.id == dsid);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果没有找到匹配的dsid或dsid为null,则检查其他可能的水站信息
|
|
|
+ if (companyIndex === -1) {
|
|
|
+ // 先检查当前用户信息中是否存在水站信息
|
|
|
+ if (app.globalData.userWxInfo && app.globalData.userWxInfo.waterCompanyId) {
|
|
|
+ companyIndex = that.data.waterCompanyList.findIndex(data => data.id == app.globalData.userWxInfo.waterCompanyId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 再检查当前账户信息中是否存在水站信息
|
|
|
+ if (companyIndex === -1 && app.globalData.currentAccountInfo && app.globalData.currentAccountInfo.waterCompanyId) {
|
|
|
+ companyIndex = that.data.waterCompanyList.findIndex(data => data.id == app.globalData.currentAccountInfo.waterCompanyId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果指定了启动参数,则优先使用启动参数
|
|
|
+ if(app.globalData.launchPara){
|
|
|
+ companyIndex = that.data.waterCompanyList.findIndex(data => data.id == app.globalData.launchPara);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果找到了对应的水站公司
|
|
|
+ if (companyIndex !== -1) {
|
|
|
+ const company = that.data.waterCompanyList[companyIndex];
|
|
|
+ if (!company) {
|
|
|
+ console.error('水务公司数据无效');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取营业点数据
|
|
|
+ let phoneList = [];
|
|
|
+ try {
|
|
|
+ if (company.businessPoint && Array.isArray(company.businessPoint)) {
|
|
|
+ phoneList = company.businessPoint.map((data, index) => {
|
|
|
+ return {
|
|
|
+ id: index+1,
|
|
|
+ name: data.address,
|
|
|
+ phone: data.contactphone,
|
|
|
+ time: data.worktime
|
|
|
+ };
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('处理营业点数据时出错:', error);
|
|
|
+ }
|
|
|
+
|
|
|
+ that.setData({
|
|
|
+ waterCompanyIndex: [companyIndex],
|
|
|
+ waterCompany: company.name,
|
|
|
+ waterCompanyId: company.id,
|
|
|
+ isChange: true,
|
|
|
+ phoneQueryList: phoneList
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: res.data.msg || '获取水务公司列表失败',
|
|
|
+ icon: 'none'
|
|
|
});
|
|
|
}
|
|
|
- } catch (error) {
|
|
|
- console.error('处理营业点数据时出错:', error);
|
|
|
+ },
|
|
|
+ fail(error) {
|
|
|
+ wx.hideLoading();
|
|
|
+ wx.showToast({
|
|
|
+ title: '网络错误,请稍后再试',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ console.error('获取水务公司列表失败:', error);
|
|
|
}
|
|
|
-
|
|
|
- this.setData({
|
|
|
- waterCompanyIndex: [companyIndex],
|
|
|
- waterCompany: company.name,
|
|
|
- isChange: false,
|
|
|
- phoneQueryList: phoneList
|
|
|
- });
|
|
|
- }
|
|
|
+ });
|
|
|
},
|
|
|
|
|
|
/**
|