抖音b端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

293 line
8.5 KiB

  1. const config = require('../../config/config.js')
  2. const app = getApp()
  3. const Common = require('../../common/common.js')
  4. const Http = require('../../utils/http.js')
  5. const HttpBasics = require('../../utils/HttpBasics.js')
  6. Page({
  7. data: {
  8. logo: '../../assets/images/logo.png',
  9. phone: '',
  10. pwd: '',
  11. status: '',
  12. showpass: "hidepass",
  13. focus: false,
  14. password: true,
  15. ifShowShop: false,
  16. merchantList: []
  17. },
  18. onLoad() {
  19. Common.getMallIcon()
  20. .then(data => {
  21. // debugge
  22. console.log(data, 777)
  23. this.setData({
  24. logo: data.data && data.data.mallImgUrl ? data.data.mallImgUrl : '../../assets/images/logo.png',
  25. })
  26. })
  27. },
  28. onShow() {
  29. var that = this;
  30. var phone = tt.getStorageSync("phone");
  31. var pwd = tt.getStorageSync("pwd");
  32. that.ttLogin();
  33. if (phone) {
  34. that.setData({
  35. phone: phone
  36. });
  37. }
  38. if (pwd) {
  39. that.setData({
  40. pwd: pwd
  41. });
  42. }
  43. // 进入页面后清空bUserId
  44. HttpBasics.setBUserId('');
  45. tt.setStorageSync("bUserId", '');
  46. app.globalData.bUserId = '';
  47. tt.setStorage({
  48. key: 'bUserId',
  49. data: '',
  50. })
  51. },
  52. //显示具体的密码
  53. showpassword: function () {
  54. console.log(this.data.password);
  55. let that = this;
  56. if (that.data.password) {
  57. that.setData({
  58. password: false,
  59. focus: true
  60. })
  61. } else {
  62. that.setData({
  63. password: true,
  64. focus: true
  65. })
  66. }
  67. },
  68. ttLogin(flag) {
  69. let that = this;
  70. tt.login({
  71. success: res => {
  72. Common.getSuperOpenId(res.code)
  73. .then(res => {
  74. console.log(res)
  75. if (res.data && res.data.data && res.data.data.openId) {
  76. app.globalData.superopenId = res.data.data.openId;
  77. }
  78. if (res.data && res.data.data && res.data.data.session_key) {
  79. app.globalData.session_key = res.data.data.session_key;
  80. }
  81. if (res.data.code == 200) {
  82. app.globalData.phone = res.data.data.phone;
  83. that.setData({
  84. ifAlBoss: true,
  85. status: "use"
  86. })
  87. if (flag == 'fromgetPhoneNumber') {
  88. tt.navigateTo({
  89. url: `/pages/datatower/datatower?superopenId=${app.globalData.superopenId}&phone=${app.globalData.phone}`,
  90. })
  91. }
  92. } else {
  93. if (flag == 'fromgetPhoneNumber') {
  94. tt.showToast({
  95. title: res.data.message,
  96. icon: "none",
  97. duration: 2000
  98. })
  99. }
  100. }
  101. }).catch(error => {
  102. console.log(error, "error");
  103. that.setData({
  104. error: error.message
  105. })
  106. })
  107. }
  108. })
  109. },
  110. showpass: function () {
  111. let that = this;
  112. },
  113. forgetPwd: function () {
  114. tt.navigateTo({
  115. url: '/pages/index/forgetpwd/forgetpwd',
  116. })
  117. },
  118. getLoginInfo(e) {
  119. var phoneReg = /^1[0|1|2|3|4|5|6|7|8|9]\d{9}$/;
  120. let {
  121. phone,
  122. pwd
  123. } = e.detail.value;
  124. if (phoneReg.test(phone)) {
  125. if (pwd != '') {
  126. Common.userLogin(phone, pwd, app.globalData.latitude, app.globalData.longitude)
  127. .then(res => {
  128. // 当logined为true时,正常进入商户
  129. if (res.data && res.data.logined == true) {
  130. if (res.code == 200) {
  131. HttpBasics.setBUserId(res.data.bUserId);
  132. tt.setStorageSync("phone", phone);
  133. tt.setStorageSync("pwd", pwd);
  134. tt.setStorageSync("bUserId", res.data.bUserId);
  135. app.globalData.bUserId = res.data.bUserId;
  136. tt.setStorage({
  137. key: 'bUserId',
  138. data: res.data.bUserId,
  139. })
  140. tt.login({
  141. success: function (res) {
  142. Common.getOpenId(res.code, app.globalData.bUserId)
  143. .then(res => {
  144. console.log(res, 888)
  145. app.globalData.openId = res.data.data.openId;
  146. app.globalData.token = res.data.data.token;
  147. HttpBasics.setToken(res.data.data.token);
  148. tt.setStorageSync("openId", res.data.data.openId);
  149. tt.setStorageSync("session_key", res.data.data.session_key);
  150. tt.showToast({
  151. image: './../../assets/images/success.png',
  152. title: '登录成功',
  153. })
  154. tt.switchTab({
  155. url: '/pages/main/main',
  156. success(res) {
  157. console.log(`${res}`);
  158. },
  159. fail(err) {
  160. console.log(err, `switchTab调用失败`);
  161. },
  162. })
  163. })
  164. }
  165. })
  166. } else {
  167. tt.showToast({
  168. image: './../../assets/images/fail.png',
  169. title: res.message,
  170. icon: "none"
  171. })
  172. }
  173. // 当logined为false时,选择商户
  174. } else if (res.data && res.data.logined == false) {
  175. tt.setStorageSync("phone", phone);
  176. tt.setStorageSync("pwd", pwd);
  177. this.setData({
  178. ifShowShop: true,
  179. merchantList: res.data.merchantList
  180. })
  181. } else {
  182. console.log(res, 'res');
  183. tt.showToast({
  184. image: './../../assets/images/fail.png',
  185. title: res.message,
  186. icon: "none"
  187. })
  188. }
  189. })
  190. } else {
  191. tt.showToast({
  192. image: './../../assets/images/fail.png',
  193. title: '密码不能为空',
  194. icon: "none",
  195. })
  196. }
  197. } else if (phone == "") {
  198. tt.showToast({
  199. image: './../../assets/images/fail.png',
  200. title: '请输入手机号',
  201. icon: "none"
  202. })
  203. } else {
  204. tt.showToast({
  205. image: './../../assets/images/fail.png',
  206. title: '手机号有误',
  207. icon: "none"
  208. })
  209. }
  210. },
  211. /**
  212. * 获得超级管理员手机号
  213. */
  214. getPhoneNumber: function (e) {
  215. this.ttLogin("fromgetPhoneNumber");
  216. if (app.globalData.superopenId && app.globalData.session_key) {
  217. let {
  218. encryptedData,
  219. iv
  220. } = {
  221. encryptedData: e.detail.encryptedData,
  222. iv: e.detail.iv
  223. };
  224. if (encryptedData && iv) {
  225. Common.getUserPhone(encryptedData, iv, app.globalData.superopenId, app.globalData.session_key)
  226. .then(res => {
  227. if (res.data.code == 200 && res.data.data.admin == 1) {
  228. app.globalData.phone = res.data.data.phone;
  229. tt.navigateTo({
  230. url: `/pages/datatower/datatower?superopenId=${app.globalData.superopenId}&phone=${app.globalData.phone}`,
  231. })
  232. }
  233. })
  234. }
  235. }
  236. },
  237. goShop(e) {
  238. const id = e.currentTarget.dataset.id
  239. HttpBasics.setBUserId(id);
  240. tt.setStorageSync("bUserId", id);
  241. app.globalData.bUserId = id;
  242. tt.setStorage({
  243. key: 'bUserId',
  244. data: id,
  245. })
  246. tt.login({
  247. success: function (res) {
  248. Common.getOpenId(res.code, app.globalData.bUserId)
  249. .then(res => {
  250. console.log(res, 888)
  251. app.globalData.openId = res.data.data.openId;
  252. app.globalData.token = res.data.data.token;
  253. HttpBasics.setToken(res.data.data.token);
  254. tt.setStorageSync("openId", res.data.data.openId);
  255. tt.setStorageSync("session_key", res.data.data.session_key);
  256. tt.showToast({
  257. image: './../../assets/images/success.png',
  258. title: '登录成功',
  259. })
  260. tt.switchTab({
  261. url: '/pages/main/main',
  262. success(res) {
  263. console.log(`${res}`);
  264. },
  265. fail(err) {
  266. console.log(err, `switchTab调用失败`);
  267. },
  268. })
  269. })
  270. }
  271. })
  272. },
  273. /**
  274. * 用户点击右上角分享
  275. */
  276. onShareAppMessage: function (res) {
  277. let _this = this;
  278. return {
  279. title: '数据塔台',
  280. path: '/pages/main/main',
  281. success: function (res) {
  282. // 转发成功
  283. },
  284. fail: function (res) {
  285. // 转发失败
  286. }
  287. }
  288. },
  289. })