1
0

eggsactivity.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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/code2sessionmini',
  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. let data = res.data.data;
  181. if (res.data.code == '0') {
  182. that.setData({
  183. egg_status_log: JSON.parse(data.user_data.egg_status_log),
  184. activityDetail: data.act_data ? data.act_data : {},
  185. lottery: data.user_data.lottery,
  186. companyobj: data.act_data ? data.act_data.company : {},
  187. prizesContent: data.act_data ? data.act_data.good.map(v => v.good_name).join('/') : '',
  188. uploadText: data.user_data.share_status == 1 ? '截图上传' : '已截图上传'
  189. })
  190. wx.setNavigationBarTitle({
  191. title: data.act_data.title,
  192. })
  193. that.getActivityInfo();
  194. } else {
  195. let msg = res.data.msg;
  196. wx.showModal({
  197. title: '大转盘提示',
  198. content: msg,
  199. showCancel: false,
  200. confirmText: '退出应用',
  201. success: () => {
  202. wx.exitMiniProgram();
  203. }
  204. })
  205. }
  206. }
  207. })
  208. },
  209. getActivityInfo() {
  210. var that = this;
  211. utils.$post({
  212. url: app.globalData.webUrl + 'api/lottery/user_detail_lukus',
  213. header: {
  214. 'Authorization': 'bearer ' + app.globalData.token
  215. },
  216. data: {
  217. actid: that.data.actid
  218. },
  219. success: function (res) {
  220. let data = res.data.data;
  221. if (res.data.code == '0') {
  222. let str = that.setWinningString(data);
  223. that.setData({
  224. textContent: str ? `中奖客户:${str}` : '暂无中奖客户'
  225. })
  226. }
  227. }
  228. })
  229. },
  230. setWinningString(data) {
  231. if (data.length > 3) {
  232. let client = data.slice(0, 3);
  233. return client.map(v => v.user.nickname).join(',');
  234. } else {
  235. return data.map(v => v.user.nickname).join(',');
  236. }
  237. },
  238. myWinning() {
  239. wx.navigateTo({
  240. url: '/pages/other/other?type=63&actid=' + this.data.actid,
  241. })
  242. },
  243. copyTextContent(e) {
  244. wx.setClipboardData({
  245. data: e.currentTarget.dataset.text,
  246. success: function (res) {
  247. console.log(res)
  248. },
  249. fail: function (err) {
  250. console.log(err)
  251. }
  252. })
  253. },
  254. cutUpload() {
  255. let that = this;
  256. if (this.data.uploadText == '已截图上传') {
  257. wx.showToast({
  258. title: '只能截图上传一次',
  259. icon: 'none'
  260. })
  261. return;
  262. }
  263. wx.chooseMedia({
  264. count: 1,
  265. mediaType: ['image'],
  266. sourceType: ['album'],
  267. success: function (res) {
  268. console.log(res)
  269. let tempFilePath = res.tempFiles[0].tempFilePath;
  270. that.uploadImage(tempFilePath)
  271. }
  272. })
  273. },
  274. uploadImage(filePath) {
  275. let that = this;
  276. wx.uploadFile({
  277. url: app.globalData.webUrl + 'api/lottery/user_upimg',
  278. filePath: filePath,
  279. name: 'img',
  280. header: {
  281. 'Authorization': 'bearer ' + app.globalData.token
  282. },
  283. formData: {
  284. actid: this.data.actid
  285. },
  286. success: function (res) {
  287. let data = JSON.parse(res.data);
  288. if (data.code == 0) {
  289. that.setData({
  290. uploadText: '已截图上传'
  291. })
  292. that.addActivityUser();
  293. } else {
  294. wx.showToast({
  295. title: data.msg,
  296. icon: 'none'
  297. })
  298. }
  299. },
  300. fail: function (res) {
  301. console.log(res, '>>>')
  302. }
  303. })
  304. },
  305. /**
  306. * 生命周期函数--监听页面加载
  307. */
  308. onLoad(options) {
  309. if (!!options.uid) {
  310. app.globalData.shareuserid = options.uid;
  311. }
  312. if (!!options.empid) {
  313. app.globalData.currentUserId = options.empid;
  314. }
  315. if (!!options.actid) {
  316. this.setData({
  317. actid: options.actid
  318. })
  319. }
  320. if (!!options.clientype) {
  321. this.setData({
  322. clientype: options.clientype
  323. })
  324. app.globalData.clientype = options.clientype;
  325. }
  326. if (wx.getUserProfile) {
  327. this.setData({
  328. canIUseGetUserProfile: true
  329. })
  330. }
  331. this.login();
  332. wx.hideHomeButton()
  333. },
  334. /**
  335. * 生命周期函数--监听页面初次渲染完成
  336. */
  337. onReady() {
  338. },
  339. /**
  340. * 生命周期函数--监听页面显示
  341. */
  342. onShow() {
  343. },
  344. /**
  345. * 生命周期函数--监听页面隐藏
  346. */
  347. onHide() {
  348. },
  349. /**
  350. * 生命周期函数--监听页面卸载
  351. */
  352. onUnload() {
  353. },
  354. /**
  355. * 页面相关事件处理函数--监听用户下拉动作
  356. */
  357. onPullDownRefresh() {
  358. },
  359. /**
  360. * 页面上拉触底事件的处理函数
  361. */
  362. onReachBottom() {
  363. },
  364. /**
  365. * 用户点击右上角分享
  366. */
  367. })