index.js 13 KB

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