index.js 12 KB

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