抖音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.

304 lines
8.6 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() {
  114. console.log('forgetPwd!!!!!!!');
  115. tt.navigateTo({
  116. url: "/pages/forgetpwd/forgetpwd",
  117. success: (res) => {
  118. console.log(res, 'res');
  119. },
  120. fail: (res) => {
  121. console.log(res, 'res');
  122. },
  123. });
  124. },
  125. getLoginInfo(e) {
  126. var phoneReg = /^1[0|1|2|3|4|5|6|7|8|9]\d{9}$/;
  127. let {
  128. phone,
  129. pwd
  130. } = e.detail.value;
  131. if (phoneReg.test(phone)) {
  132. if (pwd != '') {
  133. Common.userLogin(phone, pwd, app.globalData.latitude, app.globalData.longitude)
  134. .then(res => {
  135. // 当logined为true时,正常进入商户
  136. if (res.data && res.data.logined == true) {
  137. if (res.code == 200) {
  138. HttpBasics.setBUserId(res.data.bUserId);
  139. tt.setStorageSync("phone", phone);
  140. tt.setStorageSync("pwd", pwd);
  141. tt.setStorageSync("bUserId", res.data.bUserId);
  142. app.globalData.bUserId = res.data.bUserId;
  143. tt.setStorage({
  144. key: 'bUserId',
  145. data: res.data.bUserId,
  146. })
  147. tt.login({
  148. success: function (res) {
  149. Common.getOpenId(res.code, app.globalData.bUserId)
  150. .then(res => {
  151. console.log(res, 888)
  152. app.globalData.openId = res.data.data.openId;
  153. app.globalData.token = res.data.data.token;
  154. HttpBasics.setToken(res.data.data.token);
  155. tt.setStorageSync("openId", res.data.data.openId);
  156. tt.setStorageSync("session_key", res.data.data.session_key);
  157. tt.showToast({
  158. image: './../../assets/images/success.png',
  159. title: '登录成功',
  160. })
  161. tt.switchTab({
  162. url: '/pages/main/main',
  163. success(res) {
  164. console.log(`${res}`);
  165. },
  166. fail(err) {
  167. console.log(err, `switchTab调用失败`);
  168. },
  169. })
  170. })
  171. }
  172. })
  173. } else {
  174. tt.showToast({
  175. image: './../../assets/images/fail.png',
  176. title: res.message,
  177. icon: "none"
  178. })
  179. }
  180. // 当logined为false时,选择商户
  181. } else if (res.data && res.data.logined == false) {
  182. tt.setStorageSync("phone", phone);
  183. tt.setStorageSync("pwd", pwd);
  184. this.setData({
  185. ifShowShop: true,
  186. merchantList: res.data.merchantList
  187. })
  188. } else {
  189. console.log(res, 'res');
  190. tt.showToast({
  191. image: './../../assets/images/fail.png',
  192. title: res.message,
  193. icon: "none"
  194. })
  195. }
  196. })
  197. } else {
  198. tt.showToast({
  199. image: './../../assets/images/fail.png',
  200. title: '密码不能为空',
  201. icon: "none",
  202. })
  203. }
  204. } else if (phone == "") {
  205. tt.showToast({
  206. image: './../../assets/images/fail.png',
  207. title: '请输入手机号',
  208. icon: "none"
  209. })
  210. } else {
  211. tt.showToast({
  212. image: './../../assets/images/fail.png',
  213. title: '手机号有误',
  214. icon: "none"
  215. })
  216. }
  217. },
  218. /**
  219. * 获得超级管理员手机号
  220. */
  221. getPhoneNumber: function (e) {
  222. this.ttLogin("fromgetPhoneNumber");
  223. if (app.globalData.superopenId && app.globalData.session_key) {
  224. let {
  225. encryptedData,
  226. iv
  227. } = {
  228. encryptedData: e.detail.encryptedData,
  229. iv: e.detail.iv
  230. };
  231. if (encryptedData && iv) {
  232. Common.getUserPhone(encryptedData, iv, app.globalData.superopenId, app.globalData.session_key)
  233. .then(res => {
  234. if (res.data.code == 200 && res.data.data.admin == 1) {
  235. app.globalData.phone = res.data.data.phone;
  236. tt.navigateTo({
  237. url: `/pages/datatower/datatower?superopenId=${app.globalData.superopenId}&phone=${app.globalData.phone}`,
  238. })
  239. }
  240. })
  241. }
  242. }
  243. },
  244. goShop(e) {
  245. const id = e.currentTarget.dataset.id
  246. HttpBasics.setBUserId(id);
  247. tt.setStorageSync("bUserId", id);
  248. app.globalData.bUserId = id;
  249. tt.setStorage({
  250. key: 'bUserId',
  251. data: id,
  252. })
  253. tt.login({
  254. success: function (res) {
  255. Common.getOpenId(res.code, app.globalData.bUserId)
  256. .then(res => {
  257. console.log(res, 888)
  258. app.globalData.openId = res.data.data.openId;
  259. app.globalData.token = res.data.data.token;
  260. HttpBasics.setToken(res.data.data.token);
  261. tt.setStorageSync("openId", res.data.data.openId);
  262. tt.setStorageSync("session_key", res.data.data.session_key);
  263. tt.showToast({
  264. image: './../../assets/images/success.png',
  265. title: '登录成功',
  266. })
  267. tt.switchTab({
  268. url: '/pages/main/main',
  269. success(res) {
  270. console.log(`${res}`);
  271. },
  272. fail(err) {
  273. console.log(err, `switchTab调用失败`);
  274. },
  275. })
  276. })
  277. }
  278. })
  279. },
  280. /**
  281. * 用户点击右上角分享
  282. */
  283. onShareAppMessage: function (res) {
  284. let _this = this;
  285. return {
  286. title: '数据塔台',
  287. path: '/pages/main/main',
  288. success: function (res) {
  289. // 转发成功
  290. },
  291. fail: function (res) {
  292. // 转发失败
  293. }
  294. }
  295. },
  296. })