index.js 15 KB

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