index.js 13 KB

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