index.js 13 KB

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