index.js 17 KB

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