index.js 15 KB

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