index.js 17 KB

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