1
0

eggsactivity.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. // share/pages/eggsactivity/eggsactivity.js
  2. const app = getApp();
  3. const utils = require("../../../utils/http");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. loginFlag: false,
  10. canIUseGetUserProfile: false,
  11. phoneFlag:false,
  12. showWinning: true,
  13. showNoCount: true,
  14. showNoWinning: true,
  15. active: '',
  16. activeEggs: '',
  17. prizesContent: '',
  18. textContent: '',
  19. clientype: '',
  20. companyobj: {},
  21. activityDetail: {},
  22. egg_status_log: [],
  23. prizesObject: {},
  24. uploadText: '截图上传',
  25. lottery: 0,
  26. },
  27. handleClick(e) {
  28. let currentData = e.currentTarget.dataset;
  29. var that = this;
  30. if (currentData.status == true) {
  31. wx.showToast({
  32. title: '金蛋已砸开',
  33. icon: 'none'
  34. })
  35. return;
  36. }
  37. if (this.data.lottery == 0) {
  38. this.setData({
  39. showNoCount: false,
  40. })
  41. return;
  42. }
  43. this.setData({
  44. active: currentData.id,
  45. })
  46. utils.$post({
  47. url: app.globalData.webUrl + 'api/lottery/user_lottery',
  48. header: {
  49. 'Authorization': 'bearer ' + app.globalData.token
  50. },
  51. data: {
  52. actid: that.data.actid,
  53. eggid: that.data.active
  54. },
  55. success: function (res) {
  56. let data = res.data.data;
  57. console.log(res,'<<<砸金蛋')
  58. if (res.data.code == '0') {
  59. //抽奖次数减1
  60. that.setData({
  61. lottery: that.data.lottery - 1
  62. })
  63. if (data == -1) {
  64. setTimeout(() => {
  65. that.setData({
  66. showNoWinning: false,
  67. })
  68. }, 500)
  69. that.changeGoldenEggStatus(currentData, '空空如也')
  70. } else {
  71. let prizesObj = that.getWinningPrizes(data);
  72. setTimeout(() => {
  73. that.setData({
  74. prizesObject: prizesObj,
  75. showWinning: false,
  76. })
  77. }, 500)
  78. that.changeGoldenEggStatus(currentData, prizesObj.good_name)
  79. }
  80. }
  81. }
  82. })
  83. },
  84. getWinningPrizes(prizesId) {
  85. let data = {};
  86. if (this.data.activityDetail && this.data.activityDetail.good.length) {
  87. this.data.activityDetail.good.forEach(v => {
  88. if (v.id == prizesId) {
  89. data = v;
  90. }
  91. });
  92. return data;
  93. } else {
  94. return {};
  95. }
  96. },
  97. changeGoldenEggStatus(currentData, name) {
  98. //更改金蛋状态
  99. let arrData = JSON.parse(JSON.stringify(this.data.egg_status_log))
  100. arrData[parseInt(currentData.index)].status = true;
  101. arrData[parseInt(currentData.index)].good_name = name;
  102. this.setData({
  103. egg_status_log: arrData
  104. })
  105. },
  106. closeMask() {
  107. this.setData({
  108. showWinning: true,
  109. showNoCount: true,
  110. showNoWinning: true,
  111. })
  112. },
  113. preventHandle() { },
  114. /**
  115. * 客户授权登录
  116. */
  117. login: function () {
  118. var that = this;
  119. wx.login({
  120. success: function (data) {
  121. if (data.errMsg == 'login:ok') {
  122. utils.$post({
  123. method: "POST", //TESTAPIURL APIURL/users/auth
  124. url: app.globalData.webUrl + 'api/users/code2session',
  125. data: {
  126. client_type: that.clientype,
  127. code: data.code,
  128. share: app.globalData.shareuserid
  129. },
  130. success: function (r) {
  131. if (r.data.code == '0') {
  132. app.globalData.sharepersonobj = r.data.share;
  133. app.globalData.token = r.data.token;
  134. that.setData({
  135. shareobj: app.globalData.sharepersonobj
  136. })
  137. if (!!r.data.user.phone) {
  138. that.setData({
  139. datashow: true,
  140. loginFlag: false,
  141. phoneFlag:false,
  142. employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false
  143. })
  144. app.globalData.personMsg = r.data.user;
  145. app.globalData.userflag = false; //有个人信息
  146. } else {
  147. wx.hideLoading();
  148. that.setData({
  149. loginFlag: false,
  150. phoneFlag: true
  151. })
  152. }
  153. that.addActivityUser();
  154. } else {
  155. setTimeout(function () {
  156. wx.hideLoading()
  157. }, 500)
  158. }
  159. }
  160. })
  161. }
  162. }
  163. })
  164. },
  165. unreadMsg: function () {
  166. this.addActivityUser();
  167. },
  168. addActivityUser() {
  169. var that = this;
  170. utils.$post({
  171. url: app.globalData.webUrl + 'api/lottery/add_user',
  172. header: {
  173. 'Authorization': 'bearer ' + app.globalData.token
  174. },
  175. data: {
  176. empid: app.globalData.currentUserId,
  177. actid: that.data.actid
  178. },
  179. success: function (res) {
  180. wx.hideLoading();
  181. let data = res.data.data;
  182. if (res.data.code == '0') {
  183. that.setData({
  184. egg_status_log: JSON.parse(data.user_data.egg_status_log),
  185. activityDetail: data.act_data ? data.act_data : {},
  186. lottery: data.user_data.lottery,
  187. companyobj: data.act_data ? data.act_data.company : {},
  188. prizesContent: data.act_data ? data.act_data.good.map(v => v.good_name).join('/') : '',
  189. uploadText: data.user_data.share_status == 1 ? '截图上传' : '已截图上传'
  190. })
  191. wx.setNavigationBarTitle({
  192. title: data.act_data.title,
  193. })
  194. that.getActivityInfo();
  195. } else {
  196. let msg = res.data.msg;
  197. wx.showModal({
  198. title: '大转盘提示',
  199. content: msg,
  200. showCancel: false,
  201. confirmText: '退出应用',
  202. success: () => {
  203. wx.exitMiniProgram();
  204. }
  205. })
  206. }
  207. }
  208. })
  209. },
  210. getActivityInfo() {
  211. var that = this;
  212. utils.$post({
  213. url: app.globalData.webUrl + 'api/lottery/user_detail_lukus',
  214. header: {
  215. 'Authorization': 'bearer ' + app.globalData.token
  216. },
  217. data: {
  218. actid: that.data.actid
  219. },
  220. success: function (res) {
  221. let data = res.data.data;
  222. if (res.data.code == '0') {
  223. let str = that.setWinningString(data);
  224. that.setData({
  225. textContent: str ? `中奖客户:${str}` : '暂无中奖客户'
  226. })
  227. }
  228. }
  229. })
  230. },
  231. setWinningString(data) {
  232. if (data.length > 3) {
  233. let client = data.slice(0, 3);
  234. return client.map(v => v.user.nickname).join(',');
  235. } else {
  236. return data.map(v => v.user.nickname).join(',');
  237. }
  238. },
  239. myWinning() {
  240. wx.navigateTo({
  241. url: '/pages/other/other?type=63&actid=' + this.data.actid,
  242. })
  243. },
  244. copyTextContent(e) {
  245. wx.setClipboardData({
  246. data: e.currentTarget.dataset.text,
  247. success: function (res) {
  248. console.log(res)
  249. },
  250. fail: function (err) {
  251. console.log(err)
  252. }
  253. })
  254. },
  255. cutUpload() {
  256. let that = this;
  257. if (this.data.uploadText == '已截图上传') {
  258. wx.showToast({
  259. title: '只能截图上传一次',
  260. icon: 'none'
  261. })
  262. return;
  263. }
  264. wx.chooseMedia({
  265. count: 1,
  266. mediaType: ['image'],
  267. sourceType: ['album'],
  268. success: function (res) {
  269. console.log(res)
  270. let tempFilePath = res.tempFiles[0].tempFilePath;
  271. that.uploadImage(tempFilePath)
  272. }
  273. })
  274. },
  275. uploadImage(filePath) {
  276. let that = this;
  277. wx.uploadFile({
  278. url: app.globalData.webUrl + 'api/lottery/user_upimg',
  279. filePath: filePath,
  280. name: 'img',
  281. header: {
  282. 'Authorization': 'bearer ' + app.globalData.token
  283. },
  284. formData: {
  285. actid: this.data.actid
  286. },
  287. success: function (res) {
  288. let data = JSON.parse(res.data);
  289. if (data.code == 0) {
  290. that.setData({
  291. uploadText: '已截图上传'
  292. })
  293. that.addActivityUser();
  294. } else {
  295. wx.showToast({
  296. title: data.msg,
  297. icon: 'none'
  298. })
  299. }
  300. },
  301. fail: function (res) {
  302. console.log(res, '>>>')
  303. }
  304. })
  305. },
  306. /**
  307. * 生命周期函数--监听页面加载
  308. */
  309. onLoad(options) {
  310. if (!!options.uid) {
  311. app.globalData.shareuserid = options.uid;
  312. }
  313. if (!!options.empid) {
  314. app.globalData.currentUserId = options.empid;
  315. }
  316. if (!!options.actid) {
  317. this.setData({
  318. actid: options.actid
  319. })
  320. }
  321. if (!!options.clientype) {
  322. this.setData({
  323. clientype: options.clientype
  324. })
  325. app.globalData.clientype = options.clientype;
  326. }
  327. if (wx.getUserProfile) {
  328. this.setData({
  329. canIUseGetUserProfile: true
  330. })
  331. }
  332. wx.hideHomeButton()
  333. },
  334. //用户同意隐私协议
  335. agreePrivacy() {
  336. wx.showLoading({
  337. title: '加载中...',
  338. })
  339. this.login();
  340. },
  341. /**
  342. * 生命周期函数--监听页面初次渲染完成
  343. */
  344. onReady() {
  345. },
  346. /**
  347. * 生命周期函数--监听页面显示
  348. */
  349. onShow() {
  350. },
  351. /**
  352. * 生命周期函数--监听页面隐藏
  353. */
  354. onHide() {
  355. },
  356. /**
  357. * 生命周期函数--监听页面卸载
  358. */
  359. onUnload() {
  360. },
  361. /**
  362. * 页面相关事件处理函数--监听用户下拉动作
  363. */
  364. onPullDownRefresh() {
  365. },
  366. /**
  367. * 页面上拉触底事件的处理函数
  368. */
  369. onReachBottom() {
  370. },
  371. /**
  372. * 用户点击右上角分享
  373. */
  374. })