index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. const _Http = new ApiModel();
  5. import {
  6. TestVerify
  7. } from "../../utils/verify"
  8. const _Verify = new TestVerify();
  9. const utilMd5 = require('../../utils/md5');
  10. let countDownTime1 = null;
  11. Page({
  12. /**
  13. * 页面的初始数据
  14. */
  15. data: {
  16. rulesChecked: true,
  17. popups: false, //弹出层控制
  18. pageType: "login", //页面类型 login 手机登录页面 signin 注册页面 firm 商户认证 changeUser 切换用户
  19. butText: "", //按钮文本
  20. attinfos: [], //logo
  21. /* 登录 */
  22. fphonenumber: null, //手机号码
  23. password: null, //验证码
  24. /* 个人注册 */
  25. fname: "", //用户名
  26. frole: "", //用户身份
  27. /* 商户注册 */
  28. fbrand: "", //品牌名
  29. saleprodclass: [], //经营类目
  30. showSaleprodclass: "", //表单显示经营类目
  31. fagentname: "", //公司名称
  32. fcontact: "", //联系人
  33. fintroduction: "", //公司介绍
  34. faddress: "", //公司地址
  35. fdutyparagraph: "", //统一社会代码
  36. /* 用户选择 */
  37. userIndex: 0, //多用户选择下标
  38. throttle: true, //商户认证截流
  39. /* 错误提示 */
  40. errTips: {
  41. fphonenumber: false, //手机号码
  42. password: false, //验证码
  43. },
  44. countDownTime: 60, //倒计时
  45. dataList: ["暂无分类"], //分类列表
  46. },
  47. /* input事件剔除特殊字符 */
  48. eliminate(value) {
  49. const {
  50. name
  51. } = value.target.dataset;
  52. this.setData({
  53. [name]: _Verify.Eliminate(value.detail)
  54. })
  55. },
  56. /* 用户守则 */
  57. rulesOnChange() {
  58. this.setData({
  59. rulesChecked: !this.data.rulesChecked
  60. })
  61. },
  62. viewRules() {
  63. wx.downloadFile({
  64. url: 'https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/PrivacyPolicy.docx',
  65. success:(res)=>{
  66. console.log(res)
  67. wx.openDocument({
  68. filePath: res.tempFilePath,
  69. fail: (err) => {
  70. console.log(err)
  71. wx.showToast({
  72. title: '读取失败,请稍后再试',
  73. icon: "none"
  74. })
  75. }
  76. })
  77. },
  78. fail:(err)=>{
  79. console.log(err)
  80. wx.showToast({
  81. title: '读取失败,请稍后再试',
  82. icon: "none"
  83. })
  84. }
  85. })
  86. return
  87. },
  88. /**
  89. * 生命周期函数--监听页面加载
  90. */
  91. onLoad: function (options) {
  92. if (options.type) {
  93. this.setData({
  94. pageType: "changeUser"
  95. })
  96. };
  97. if (wx.getStorageSync('userData').fphonenumber != null) this.setData({
  98. fphonenumber: wx.getStorageSync('userData').fphonenumber
  99. })
  100. /* 设置按钮文本 */
  101. this.changeButText()
  102. },
  103. /* 选择类目回调 */
  104. saleprodChange(arr) {
  105. let {
  106. detail
  107. } = arr, showSaleprodclass = "";
  108. console.log(arr)
  109. for (let i = 0; i < detail.length; i++) {
  110. showSaleprodclass += (detail[i] + ',');
  111. };
  112. this.setData({
  113. popups: false,
  114. saleprodclass: detail,
  115. showSaleprodclass: showSaleprodclass.slice(0, showSaleprodclass.length - 1),
  116. "errTips.showSaleprod": false
  117. })
  118. },
  119. /* 缓存登录用户关键数据 */
  120. retentionOfCriticalData(index) {
  121. //获取用户选择的信息列表
  122. const user = wx.getStorageSync('account_list')[index];
  123. let data = {
  124. token: user.token,
  125. fisadministrator: user.fisadministrator,
  126. tagentsid: user.tagentsid,
  127. tenterpriseid: user.tenterpriseid,
  128. userid: user.userid,
  129. index: index,
  130. fphonenumber: this.data.fphonenumber
  131. };
  132. /* 储存 */
  133. wx.setStorageSync('userData', data);
  134. if (getApp().globalData.socketEstablish) getApp().globalData.SocketTask.close(function (res) {
  135. console.log('WebSocket连接已关闭!readyState=' + that.globalData.SocketTask.readyState)
  136. that.globalData.socketEstablish = false;
  137. });
  138. //建立链接
  139. getApp().initSocket();
  140. },
  141. /* 登录页面提交数据 */
  142. loginSubmit() {
  143. //验证手机号码
  144. if (!_Verify.phoneNumber(this.data.fphonenumber, 1)) return this.setData({
  145. "errTips.fphonenumber": true
  146. })
  147. /* 验证验证码 */
  148. if (this.data.password == null) {
  149. this.setData({
  150. "errTips.password": true
  151. })
  152. wx.showToast({
  153. title: '无效验证码',
  154. icon: "none"
  155. })
  156. return;
  157. };
  158. /* 发送请求 */
  159. _Http.login({
  160. "phonenumber": this.data.fphonenumber,
  161. "password": utilMd5.hexMD5(this.data.password),
  162. "client": "wechat_customer"
  163. }).then(res => {
  164. /* 结果验证 */
  165. if (res.msg != '成功') {
  166. this.setData({
  167. "errTips.password": true
  168. })
  169. wx.showToast({
  170. title: '无效验证码',
  171. icon: "none"
  172. })
  173. return;
  174. };
  175. //账号列表保存到全局变量中
  176. wx.setStorageSync('account_list', res.account_list);
  177. wx.setStorageSync('servicehotline', res.servicehotline);
  178. /* 判断账号 新 单 多 isnewregister*/
  179. if (res.account_list.length == 1 && res.account_list[0].isnewregister == 1) {
  180. //新账号
  181. this.retentionOfCriticalData(0)
  182. //跳转到个人注册
  183. this.setData({
  184. pageType: 'signin'
  185. })
  186. //更改按钮内容
  187. this.changeButText()
  188. } else if (res.account_list.length == 1 && res.account_list[0].isnewregister == 0) {
  189. //单账号
  190. this.retentionOfCriticalData(0)
  191. //跳转到首页
  192. this.jumpOverToIndex()
  193. } else if (res.account_list.length > 1) {
  194. //多账号
  195. //跳转到账号选择
  196. this.setData({
  197. pageType: 'changeUser'
  198. })
  199. //更改按钮内容
  200. this.changeButText()
  201. }
  202. })
  203. },
  204. /* 提交数据 */
  205. submitData(e) {
  206. const {
  207. name
  208. } = e.currentTarget.dataset;
  209. if (name == "login") {
  210. if(!this.data.rulesChecked) return wx.showToast({
  211. title: '请勾选同意协议后登录',
  212. icon:"none"
  213. })
  214. //登录页面提交信息
  215. this.loginSubmit()
  216. //getApp().getUserProfile();
  217. } else if (name == "changeUser") {
  218. //多账号选择
  219. this.retentionOfCriticalData(this.data.userIndex)
  220. //跳转到首页
  221. this.jumpOverToIndex()
  222. } else if (name == "signin") {
  223. //个人注册提交数据后跳转商户认证页面
  224. this.savePersonalInformation()
  225. //查询类目列表
  226. _Http.basic({
  227. "accesstoken": wx.getStorageSync('userData').token,
  228. "classname": "enterprise.system.prodclass",
  229. "method": "query_typeselectList",
  230. "content": {}
  231. }).then(res => {
  232. if (res.msg != '成功') return;
  233. let dataList = [];
  234. for (let i = 0; i < res.data.length; i++) {
  235. dataList.push({
  236. value: res.data[i],
  237. index: i,
  238. checked: false
  239. })
  240. }
  241. this.setData({
  242. dataList
  243. })
  244. })
  245. //getApp().getUserProfile();
  246. //更改按钮内容
  247. this.changeButText()
  248. } else if (name == "firm") {
  249. //商户认证提交
  250. this.merchantsToSubmit();
  251. }
  252. },
  253. /* 商户提交前验证表单 */
  254. merchantsToSubmitVerify() {
  255. let errTips = this.data.errTips,
  256. verify = true;
  257. //验证联系方式
  258. if (!_Verify.phoneNumber(this.data.fphonenumber)) {
  259. errTips.fphonenumber = true;
  260. verify = false;
  261. }
  262. this.setData({
  263. errTips
  264. })
  265. return verify;
  266. },
  267. /* 添加图片 */
  268. imageChange(data) {
  269. this.setData({
  270. attinfos: data.detail.fileList
  271. })
  272. },
  273. coverImageChange(data) {
  274. this.setData({
  275. coverAttinfos: data.detail.fileList
  276. })
  277. },
  278. /* 商户认证提交表单 */
  279. merchantsToSubmit() {
  280. // 验证
  281. if (!this.merchantsToSubmitVerify()) return wx.showToast({
  282. title: '请检查表单内容',
  283. icon: "none"
  284. });
  285. //截流
  286. if (!this.data.throttle) return;
  287. //发送请求
  288. _Http.basic({
  289. "accesstoken": wx.getStorageSync('userData').token,
  290. "classname": "customer.tagents.tagents",
  291. "method": "modify_enterpriseAgent",
  292. "content": {
  293. "ftype": "商户认证",
  294. "data": [{
  295. "fbrand": this.data.fbrand,
  296. "fagentname": this.data.fagentname,
  297. "fcontact": this.data.fcontact,
  298. "fphonenumber": this.data.fphonenumber,
  299. "faddress": this.data.faddress,
  300. "fdutyparagraph": this.data.fdutyparagraph,
  301. "fintroduction": this.data.fintroduction,
  302. "saleprodclass": this.data.saleprodclass
  303. }]
  304. }
  305. }).then(res => {
  306. if (res.msg != "成功") return wx.showToast({
  307. title: res.data,
  308. icon: "none"
  309. });
  310. this.setData({
  311. throttle: false
  312. })
  313. wx.showToast({
  314. title: "提交成功",
  315. icon: "none"
  316. });
  317. setTimeout(() => {
  318. wx.switchTab({
  319. url: '/pages/tabbar-pages/home/index',
  320. })
  321. }, 500);
  322. })
  323. },
  324. /* 获取焦点 */
  325. inputFocus(e) {
  326. const {
  327. name
  328. } = e.currentTarget.dataset;
  329. let errTips = this.data.errTips;
  330. errTips[name] = false;
  331. this.setData({
  332. errTips
  333. })
  334. },
  335. /* 失去焦点 */
  336. inputBlur(e) {
  337. const {
  338. name
  339. } = e.currentTarget.dataset;
  340. const {
  341. value
  342. } = e.detail;
  343. if (name == 'fphonenumber') {
  344. if (!_Verify.phoneNumber(this.data.fphonenumber, 1)) return this.setData({
  345. "errTips.fphonenumber": true
  346. })
  347. };
  348. if (value.trim() == "") {
  349. let errTips = this.data.errTips;
  350. errTips[name] = true;
  351. this.setData({
  352. errTips
  353. })
  354. }
  355. },
  356. /* 个人注册页面保存个人信息 */
  357. savePersonalInformation(is) {
  358. const {
  359. fphonenumber
  360. } = this.data
  361. let tail = fphonenumber.toString().substring(fphonenumber.toString().length - 4);
  362. let data = {
  363. fname: tail + "用户",
  364. frole: "管理员"
  365. }
  366. if (this.data.fname != '') {
  367. data.fname = this.data.fname
  368. };
  369. if (this.data.frole != '') {
  370. data.frole = this.data.frole
  371. }
  372. _Http.basic({
  373. "accesstoken": wx.getStorageSync('userData').token,
  374. "classname": "customer.usercenter.usermsg.usermsg",
  375. "method": "update_usermsg",
  376. "content": data
  377. }).then(res => {
  378. if (res.msg != '成功') return wx.showToast({
  379. title: res.data,
  380. icon: 'none'
  381. })
  382. let obj1 = wx.getStorageSync('userData');
  383. const data = [Object.assign(res.data[0], obj1)]
  384. wx.setStorageSync('account_list', data);
  385. if (is) {
  386. wx.reLaunch({
  387. url: '/pages/tabbar-pages/home/index'
  388. })
  389. } else {
  390. this.setData({
  391. pageType: "firm"
  392. })
  393. }
  394. })
  395. },
  396. /* 多用户选择下标传递 */
  397. userChange(index) {
  398. this.setData({
  399. userIndex: index.detail.userIndex
  400. })
  401. },
  402. /* 获取验证码 */
  403. getVerifyCode() {
  404. //验证手机号码
  405. if (!_Verify.phoneNumber(this.data.fphonenumber, 1)) return this.setData({
  406. "errTips.fphonenumber": true
  407. });
  408. /* 倒计时中阻止 */
  409. if (this.data.countDownTime != 60) return wx.showToast({
  410. title: '请勿重复获取验证码',
  411. icon: "none"
  412. });
  413. this.setData({
  414. countDownTime: this.data.countDownTime - 1
  415. })
  416. _Http.getPassword({
  417. "phonenumber": this.data.fphonenumber,
  418. "client": "wechat_customer"
  419. }).then(res => {
  420. console.log("验证码", res)
  421. countDownTime1 = setInterval(() => {
  422. if (this.data.countDownTime != 0) {
  423. this.setData({
  424. countDownTime: this.data.countDownTime - 1
  425. })
  426. } else {
  427. clearInterval(countDownTime1);
  428. this.setData({
  429. countDownTime: 60
  430. })
  431. }
  432. }, 1000);
  433. wx.showToast({
  434. title: res.msg,
  435. icon: "none",
  436. duration: 5000
  437. })
  438. })
  439. },
  440. /* 跳转首页 */
  441. jumpOverToIndex() {
  442. //如果是个人注册页面,保存数据后进入首页
  443. if (this.data.pageType == 'signin') {
  444. const that = this;
  445. if (this.data.fname != '' || this.data.frole != '') {
  446. wx.showModal({
  447. title: '提示',
  448. content: '是否保存已输入的信息',
  449. success: (res) => {
  450. console.log(res)
  451. if (res.confirm) {
  452. that.savePersonalInformation(true)
  453. } else {
  454. wx.reLaunch({
  455. url: '/pages/tabbar-pages/home/index'
  456. })
  457. }
  458. }
  459. })
  460. } else {
  461. that.savePersonalInformation(true)
  462. wx.reLaunch({
  463. url: '/pages/tabbar-pages/home/index'
  464. })
  465. }
  466. } else {
  467. /* 跳转到首页 */
  468. wx.reLaunch({
  469. url: '/pages/tabbar-pages/home/index'
  470. })
  471. }
  472. },
  473. /* 修改按钮内容 */
  474. changeButText() {
  475. const {
  476. pageType
  477. } = this.data
  478. if (pageType == 'login') {
  479. this.setData({
  480. butText: "登 录"
  481. })
  482. } else if (pageType == 'signin') {
  483. this.setData({
  484. butText: "下一步"
  485. })
  486. } else if (pageType == 'firm') {
  487. this.setData({
  488. butText: "立即创建"
  489. })
  490. } else if (pageType == 'changeUser') {
  491. this.setData({
  492. butText: "选择进入"
  493. })
  494. }
  495. },
  496. /* 弹出层控制 */
  497. showPop() {
  498. this.setData({
  499. popups: !this.data.popups
  500. })
  501. },
  502. /**
  503. * 生命周期函数--监听页面初次渲染完成
  504. */
  505. onReady: function () {
  506. },
  507. /**
  508. * 生命周期函数--监听页面显示
  509. */
  510. onShow: function () {
  511. },
  512. /**
  513. * 生命周期函数--监听页面隐藏
  514. */
  515. onHide: function () {
  516. },
  517. /**
  518. * 生命周期函数--监听页面卸载
  519. */
  520. onUnload: function () {
  521. clearInterval(countDownTime1);
  522. },
  523. /**
  524. * 页面相关事件处理函数--监听用户下拉动作
  525. */
  526. onPullDownRefresh: function () {
  527. },
  528. /**
  529. * 页面上拉触底事件的处理函数
  530. */
  531. onReachBottom: function () {
  532. },
  533. /**
  534. * 用户点击右上角分享
  535. */
  536. onShareAppMessage: function () {
  537. }
  538. })