index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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. getApp().globalData.isLogin = true;
  139. //建立链接
  140. getApp().initSocket();
  141. },
  142. /* 登录页面提交数据 */
  143. loginSubmit() {
  144. //验证手机号码
  145. if (!_Verify.phoneNumber(this.data.fphonenumber, 1)) return this.setData({
  146. "errTips.fphonenumber": true
  147. })
  148. /* 验证验证码 */
  149. if (this.data.password == null) {
  150. this.setData({
  151. "errTips.password": true
  152. })
  153. wx.showToast({
  154. title: '无效验证码',
  155. icon: "none"
  156. })
  157. return;
  158. };
  159. /* 发送请求 */
  160. _Http.login({
  161. "phonenumber": this.data.fphonenumber,
  162. "password": utilMd5.hexMD5(this.data.password),
  163. "client": "wechat_customer"
  164. }).then(res => {
  165. console.log("用户登录",res)
  166. /* 结果验证 */
  167. if (res.msg != '成功') {
  168. this.setData({
  169. "errTips.password": true
  170. })
  171. wx.showToast({
  172. title: '无效验证码',
  173. icon: "none"
  174. })
  175. return;
  176. };
  177. //账号列表保存到全局变量中
  178. wx.setStorageSync('account_list', res.account_list);
  179. /* 判断账号 新 单 多 isnewregister*/
  180. if (res.account_list.length == 1 && res.account_list[0].isnewregister == 1) {
  181. //新账号
  182. this.retentionOfCriticalData(0)
  183. //跳转到个人注册
  184. this.setData({
  185. pageType: 'signin'
  186. })
  187. //更改按钮内容
  188. this.changeButText()
  189. } else if (res.account_list.length == 1 && res.account_list[0].isnewregister == 0) {
  190. //单账号
  191. this.retentionOfCriticalData(0)
  192. //跳转到首页
  193. this.jumpOverToIndex()
  194. } else if (res.account_list.length > 1) {
  195. //多账号
  196. //跳转到账号选择
  197. this.setData({
  198. pageType: 'changeUser'
  199. })
  200. //更改按钮内容
  201. this.changeButText()
  202. }
  203. })
  204. },
  205. /* 提交数据 */
  206. submitData(e) {
  207. const {
  208. name
  209. } = e.currentTarget.dataset;
  210. if (name == "login") {
  211. if (!this.data.rulesChecked) return wx.showToast({
  212. title: '请勾选同意协议后登录',
  213. icon: "none"
  214. })
  215. //登录页面提交信息
  216. this.loginSubmit()
  217. //getApp().getUserProfile();
  218. } else if (name == "changeUser") {
  219. //多账号选择
  220. this.retentionOfCriticalData(this.data.userIndex)
  221. //跳转到首页
  222. this.jumpOverToIndex()
  223. } else if (name == "signin") {
  224. //个人注册提交数据后跳转商户认证页面
  225. this.savePersonalInformation()
  226. //查询类目列表
  227. _Http.basic({
  228. "accesstoken": wx.getStorageSync('userData').token,
  229. "classname": "enterprise.system.prodclass",
  230. "method": "query_typeselectList",
  231. "content": {}
  232. }).then(res => {
  233. if (res.msg != '成功') return;
  234. let dataList = [];
  235. for (let i = 0; i < res.data.length; i++) {
  236. dataList.push({
  237. value: res.data[i],
  238. index: i,
  239. checked: false
  240. })
  241. }
  242. this.setData({
  243. dataList
  244. })
  245. })
  246. //getApp().getUserProfile();
  247. //更改按钮内容
  248. this.changeButText()
  249. } else if (name == "firm") {
  250. //商户认证提交
  251. this.merchantsToSubmit();
  252. }
  253. },
  254. /* 商户提交前验证表单 */
  255. merchantsToSubmitVerify() {
  256. let errTips = this.data.errTips,
  257. verify = true;
  258. //验证联系方式
  259. if (!_Verify.phoneNumber(this.data.fphonenumber)) {
  260. errTips.fphonenumber = true;
  261. verify = false;
  262. }
  263. this.setData({
  264. errTips
  265. })
  266. return verify;
  267. },
  268. /* 添加图片 */
  269. imageChange(data) {
  270. this.setData({
  271. attinfos: data.detail.fileList
  272. })
  273. },
  274. coverImageChange(data) {
  275. this.setData({
  276. coverAttinfos: data.detail.fileList
  277. })
  278. },
  279. /* 商户认证提交表单 */
  280. merchantsToSubmit() {
  281. // 验证
  282. if (!this.merchantsToSubmitVerify()) return wx.showToast({
  283. title: '请检查表单内容',
  284. icon: "none"
  285. });
  286. //截流
  287. if (!this.data.throttle) return;
  288. //发送请求
  289. _Http.basic({
  290. "accesstoken": wx.getStorageSync('userData').token,
  291. "classname": "customer.tagents.tagents",
  292. "method": "modify_enterpriseAgent",
  293. "content": {
  294. "ftype": "商户认证",
  295. "data": [{
  296. "fbrand": this.data.fbrand,
  297. "fagentname": this.data.fagentname,
  298. "fcontact": this.data.fcontact,
  299. "fphonenumber": this.data.fphonenumber,
  300. "faddress": this.data.faddress,
  301. "fdutyparagraph": this.data.fdutyparagraph,
  302. "fintroduction": this.data.fintroduction,
  303. "saleprodclass": this.data.saleprodclass
  304. }]
  305. }
  306. }).then(res => {
  307. if (res.msg != "成功") return wx.showToast({
  308. title: res.data,
  309. icon: "none"
  310. });
  311. this.setData({
  312. throttle: false
  313. })
  314. wx.showToast({
  315. title: "提交成功",
  316. icon: "none"
  317. });
  318. setTimeout(() => {
  319. wx.switchTab({
  320. url: '/pages/tabbar-pages/home/index',
  321. })
  322. }, 500);
  323. })
  324. },
  325. /* 获取焦点 */
  326. inputFocus(e) {
  327. const {
  328. name
  329. } = e.currentTarget.dataset;
  330. let errTips = this.data.errTips;
  331. errTips[name] = false;
  332. this.setData({
  333. errTips
  334. })
  335. },
  336. /* 失去焦点 */
  337. inputBlur(e) {
  338. const {
  339. name
  340. } = e.currentTarget.dataset;
  341. const {
  342. value
  343. } = e.detail;
  344. if (name == 'fphonenumber') {
  345. if (!_Verify.phoneNumber(this.data.fphonenumber, 1)) return this.setData({
  346. "errTips.fphonenumber": true
  347. })
  348. };
  349. if (value.trim() == "") {
  350. let errTips = this.data.errTips;
  351. errTips[name] = true;
  352. this.setData({
  353. errTips
  354. })
  355. }
  356. },
  357. /* 个人注册页面保存个人信息 */
  358. savePersonalInformation(is) {
  359. const {
  360. fphonenumber
  361. } = this.data
  362. let tail = fphonenumber.toString().substring(fphonenumber.toString().length - 4);
  363. let data = {
  364. fname: tail + "用户",
  365. frole: "管理员"
  366. }
  367. if (this.data.fname != '') {
  368. data.fname = this.data.fname
  369. };
  370. if (this.data.frole != '') {
  371. data.frole = this.data.frole
  372. }
  373. _Http.basic({
  374. "accesstoken": wx.getStorageSync('userData').token,
  375. "classname": "customer.usercenter.usermsg.usermsg",
  376. "method": "update_usermsg",
  377. "content": data
  378. }).then(res => {
  379. if (res.msg != '成功') return wx.showToast({
  380. title: res.data,
  381. icon: 'none'
  382. })
  383. let obj1 = wx.getStorageSync('userData');
  384. const data = [Object.assign(res.data[0], obj1)]
  385. wx.setStorageSync('account_list', data);
  386. if (is) {
  387. wx.reLaunch({
  388. url: '/pages/tabbar-pages/home/index'
  389. })
  390. } else {
  391. this.setData({
  392. pageType: "firm"
  393. })
  394. }
  395. })
  396. },
  397. /* 多用户选择下标传递 */
  398. userChange(index) {
  399. this.setData({
  400. userIndex: index.detail.userIndex
  401. })
  402. },
  403. /* 获取验证码 */
  404. getVerifyCode() {
  405. //验证手机号码
  406. if (!_Verify.phoneNumber(this.data.fphonenumber, 1)) return this.setData({
  407. "errTips.fphonenumber": true
  408. });
  409. /* 倒计时中阻止 */
  410. if (this.data.countDownTime != 60) return wx.showToast({
  411. title: '请勿重复获取验证码',
  412. icon: "none"
  413. });
  414. this.setData({
  415. countDownTime: this.data.countDownTime - 1
  416. })
  417. _Http.getPassword({
  418. "phonenumber": this.data.fphonenumber,
  419. "client": "wechat_customer"
  420. }).then(res => {
  421. console.log("验证码", res)
  422. countDownTime1 = setInterval(() => {
  423. if (this.data.countDownTime != 0) {
  424. this.setData({
  425. countDownTime: this.data.countDownTime - 1
  426. })
  427. } else {
  428. clearInterval(countDownTime1);
  429. this.setData({
  430. countDownTime: 60
  431. })
  432. }
  433. }, 1000);
  434. wx.showToast({
  435. title: res.msg,
  436. icon: "none",
  437. duration: 5000
  438. })
  439. })
  440. },
  441. /* 跳转首页 */
  442. jumpOverToIndex() {
  443. //如果是个人注册页面,保存数据后进入首页
  444. if (this.data.pageType == 'signin') {
  445. const that = this;
  446. if (this.data.fname != '' || this.data.frole != '') {
  447. wx.showModal({
  448. title: '提示',
  449. content: '是否保存已输入的信息',
  450. success: (res) => {
  451. console.log(res)
  452. if (res.confirm) {
  453. that.savePersonalInformation(true)
  454. } else {
  455. wx.reLaunch({
  456. url: '/pages/tabbar-pages/home/index'
  457. })
  458. }
  459. }
  460. })
  461. } else {
  462. that.savePersonalInformation(true)
  463. wx.reLaunch({
  464. url: '/pages/tabbar-pages/home/index'
  465. })
  466. }
  467. } else {
  468. /* 跳转到首页 */
  469. wx.reLaunch({
  470. url: '/pages/tabbar-pages/home/index'
  471. })
  472. }
  473. },
  474. /* 修改按钮内容 */
  475. changeButText() {
  476. const {
  477. pageType
  478. } = this.data
  479. if (pageType == 'login') {
  480. this.setData({
  481. butText: "登 录"
  482. })
  483. } else if (pageType == 'signin') {
  484. this.setData({
  485. butText: "下一步"
  486. })
  487. } else if (pageType == 'firm') {
  488. this.setData({
  489. butText: "立即创建"
  490. })
  491. } else if (pageType == 'changeUser') {
  492. this.setData({
  493. butText: "选择进入"
  494. })
  495. }
  496. },
  497. /* 弹出层控制 */
  498. showPop() {
  499. this.setData({
  500. popups: !this.data.popups
  501. })
  502. },
  503. /**
  504. * 生命周期函数--监听页面初次渲染完成
  505. */
  506. onReady: function () {
  507. },
  508. /**
  509. * 生命周期函数--监听页面显示
  510. */
  511. onShow: function () {
  512. },
  513. /**
  514. * 生命周期函数--监听页面隐藏
  515. */
  516. onHide: function () {
  517. },
  518. /**
  519. * 生命周期函数--监听页面卸载
  520. */
  521. onUnload: function () {
  522. clearInterval(countDownTime1);
  523. },
  524. /**
  525. * 页面相关事件处理函数--监听用户下拉动作
  526. */
  527. onPullDownRefresh: function () {
  528. },
  529. /**
  530. * 页面上拉触底事件的处理函数
  531. */
  532. onReachBottom: function () {
  533. },
  534. /**
  535. * 用户点击右上角分享
  536. */
  537. onShareAppMessage: function () {
  538. }
  539. })