eggsactivity.js 12 KB

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