index.js 17 KB

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