index.js 12 KB

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