index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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. coverTips: false,
  49. faddress: false,
  50. },
  51. countDownTime: 60, //倒计时
  52. dataList: ["暂无分类"], //分类列表
  53. },
  54. /**
  55. * 生命周期函数--监听页面加载
  56. */
  57. onLoad: function (options) {
  58. if (options.type) {
  59. this.setData({
  60. pageType: "changeUser"
  61. })
  62. };
  63. if (wx.getStorageSync('userData').fphonenumber != null) this.setData({
  64. fphonenumber: wx.getStorageSync('userData').fphonenumber
  65. })
  66. /* 设置按钮文本 */
  67. this.changeButText()
  68. },
  69. /* 选择类目回调 */
  70. saleprodChange(arr) {
  71. let {
  72. detail
  73. } = arr, showSaleprodclass = "";
  74. console.log(arr)
  75. for (let i = 0; i < detail.length; i++) {
  76. showSaleprodclass += (detail[i] + ',');
  77. };
  78. this.setData({
  79. popups: false,
  80. saleprodclass: detail,
  81. showSaleprodclass: showSaleprodclass.slice(0, showSaleprodclass.length - 1),
  82. "errTips.showSaleprod": false
  83. })
  84. },
  85. /* 缓存登录用户关键数据 */
  86. retentionOfCriticalData(index) {
  87. //获取用户选择的信息列表
  88. const user = getApp().globalData.account_list[index];
  89. let data = {
  90. token: user.token,
  91. fisadministrator: user.fisadministrator,
  92. tagentsid: user.tagentsid,
  93. tenterpriseid: user.tenterpriseid,
  94. userid: user.userid,
  95. index: index,
  96. fphonenumber: this.data.fphonenumber
  97. };
  98. /* 储存 */
  99. wx.setStorageSync('userData', data);
  100. console.log(wx.getStorageSync('userData'))
  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. console.log(res)
  126. /* 结果验证 */
  127. if (res.msg != '成功') {
  128. this.setData({
  129. "errTips.password": true
  130. })
  131. wx.showToast({
  132. title: '无效验证码',
  133. icon: "none"
  134. })
  135. return;
  136. };
  137. //账号列表保存到全局变量中
  138. getApp().globalData.account_list = res.account_list;
  139. console.log(getApp().globalData.account_list)
  140. getApp().globalData.servicehotline = res.servicehotline;
  141. /* 判断账号 新 单 多 isnewregister*/
  142. if (res.account_list.length == 1 && res.account_list[0].isnewregister == 1) {
  143. //新账号
  144. console.log('新账号')
  145. this.retentionOfCriticalData(0)
  146. //跳转到个人注册
  147. this.setData({
  148. pageType: 'signin'
  149. })
  150. //更改按钮内容
  151. this.changeButText()
  152. } else if (res.account_list.length == 1 && res.account_list[0].isnewregister == 0) {
  153. //单账号
  154. console.log('单账号')
  155. this.retentionOfCriticalData(0)
  156. //跳转到首页
  157. this.jumpOverToIndex()
  158. } else if (res.account_list.length > 1) {
  159. //多账号
  160. console.log('多账号')
  161. //跳转到账号选择
  162. this.setData({
  163. pageType: 'changeUser'
  164. })
  165. //更改按钮内容
  166. this.changeButText()
  167. }
  168. })
  169. },
  170. /* 提交数据 */
  171. submitData(e) {
  172. const {
  173. name
  174. } = e.currentTarget.dataset;
  175. if (name == "login") {
  176. //登录页面提交信息
  177. this.loginSubmit()
  178. } else if (name == "changeUser") {
  179. //多账号选择
  180. this.retentionOfCriticalData(this.data.userIndex)
  181. //跳转到首页
  182. this.jumpOverToIndex()
  183. } else if (name == "signin") {
  184. //个人注册提交数据后跳转商户认证页面
  185. this.savePersonalInformation()
  186. //查询类目列表
  187. _Http.basic({
  188. "accesstoken": wx.getStorageSync('userData').token,
  189. "classname": "enterprise.system.prodclass",
  190. "method": "query_typeselectList",
  191. "content": {}
  192. }).then(res => {
  193. console.log(res)
  194. if (res.msg != '成功') return;
  195. let dataList = [];
  196. for (let i = 0; i < res.data.length; i++) {
  197. dataList.push({
  198. value: res.data[i],
  199. index: i,
  200. checked: false
  201. })
  202. }
  203. this.setData({
  204. dataList
  205. })
  206. })
  207. //更改按钮内容
  208. this.changeButText()
  209. } else if (name == "firm") {
  210. //商户认证提交
  211. this.merchantsToSubmit();
  212. }
  213. },
  214. /* 商户提交前验证表单 */
  215. merchantsToSubmitVerify() {
  216. let errTips = this.data.errTips,
  217. verify = true;
  218. //验证品牌名称
  219. if (!_Verify.required(this.data.fbrand)) {
  220. errTips.fbrand = true;
  221. verify = false;
  222. };
  223. // 验证图片是否上传
  224. if (!this.selectComponent('#UploadFiles').VerifyThere()) {
  225. errTips.logoTips = true;
  226. verify = false;
  227. }
  228. // 验证图片是否上传
  229. if (!this.selectComponent('#coverUploadFiles').VerifyThere()) {
  230. errTips.coverTips = true;
  231. verify = false;
  232. }
  233. // 经营类目验证
  234. if (!_Verify.required(this.data.showSaleprodclass)) {
  235. errTips.showSaleprod = true;
  236. verify = false;
  237. };
  238. // 注册公司名验证
  239. if (!_Verify.required(this.data.fagentname)) {
  240. errTips.fagentname = true;
  241. verify = false;
  242. };
  243. // 联系人验证
  244. if (!_Verify.required(this.data.fcontact)) {
  245. errTips.fcontact = true;
  246. verify = false;
  247. };
  248. //验证联系方式
  249. if (!_Verify.phoneNumber(this.data.fphonenumber)) {
  250. errTips.fphonenumber = true;
  251. verify = false;
  252. }
  253. // 地址验证
  254. if (!_Verify.required(this.data.faddress)) {
  255. errTips.faddress = true;
  256. verify = false;
  257. };
  258. // 公司介绍验证
  259. if (!_Verify.required(this.data.fintroduction)) {
  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. getApp().globalData.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;
  410. this.setData({
  411. countDownTime: this.data.countDownTime - 1
  412. })
  413. _Http.getPassword({
  414. "phonenumber": this.data.fphonenumber,
  415. "client": "wechat_customer"
  416. }).then(res => {
  417. console.log(res)
  418. this.setData({
  419. password: res.msg.substring(res.msg.length - 6)
  420. })
  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.substring(res.msg.length - 6),
  435. icon: "none",
  436. duration: 8000
  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. fintroductionInput(e) {
  475. this.setData({
  476. fintroduction: e.detail.value
  477. })
  478. },
  479. /* 修改按钮内容 */
  480. changeButText() {
  481. const {
  482. pageType
  483. } = this.data
  484. if (pageType == 'login') {
  485. this.setData({
  486. butText: "登 录"
  487. })
  488. } else if (pageType == 'signin') {
  489. this.setData({
  490. butText: "下一步"
  491. })
  492. } else if (pageType == 'firm') {
  493. this.setData({
  494. butText: "立即创建"
  495. })
  496. } else if (pageType == 'changeUser') {
  497. this.setData({
  498. butText: "选择进入"
  499. })
  500. }
  501. },
  502. /* 弹出层控制 */
  503. showPop() {
  504. this.setData({
  505. popups: !this.data.popups
  506. })
  507. },
  508. /**
  509. * 生命周期函数--监听页面初次渲染完成
  510. */
  511. onReady: function () {
  512. },
  513. /**
  514. * 生命周期函数--监听页面显示
  515. */
  516. onShow: function () {
  517. },
  518. /**
  519. * 生命周期函数--监听页面隐藏
  520. */
  521. onHide: function () {
  522. },
  523. /**
  524. * 生命周期函数--监听页面卸载
  525. */
  526. onUnload: function () {
  527. clearInterval(countDownTime1);
  528. },
  529. /**
  530. * 页面相关事件处理函数--监听用户下拉动作
  531. */
  532. onPullDownRefresh: function () {
  533. },
  534. /**
  535. * 页面上拉触底事件的处理函数
  536. */
  537. onReachBottom: function () {
  538. },
  539. /**
  540. * 用户点击右上角分享
  541. */
  542. onShareAppMessage: function () {
  543. }
  544. })