share.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. // package-basic-data/pages/share/share.js
  2. const Constants = require('@/utils/Constants.js');
  3. const mixins = require('@/mixins/index.js');
  4. const config = require('@/config/config.js');
  5. const app = getApp()
  6. Page({
  7. mixins: [mixins],
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. routeObjName: 'share',
  13. staffName: '',
  14. staffPhone: '',
  15. companyName: '',
  16. versionName: '',
  17. gradeCode: null,
  18. integral: 0,
  19. couponNumber: 0,
  20. cilckViewId: 'toShare',
  21. integralTacticItem: {},
  22. avatarUrl: config.image_url + '/static/img/' + '/order_billing_detail_01.png',
  23. couponItem: undefined,
  24. time: 129600000,
  25. timeData: {},
  26. couponSendItem: undefined,
  27. settingFlg: false,
  28. },
  29. /**
  30. * @desc : 头像
  31. * @date : 2024/7/1 15:49
  32. * @author : 姜永辉
  33. */
  34. getUser() {
  35. let service = app.globalData['oauthService']
  36. return this.excute(service, service.getUser + '/' + app.globalData.user.userId, {}).then(res => {
  37. if (res.data.code == Constants.SUCESS_CODE) {
  38. let avatarUrl = res.data.data.userImage || this.data.defaultAvatarUrl
  39. this.setData({
  40. avatarUrl: avatarUrl
  41. })
  42. }
  43. });
  44. },
  45. /**
  46. * 生命周期函数--监听页面加载
  47. */
  48. onLoad(options) {
  49. // 从我的进入 和 首页进入 不同
  50. if (options.settingFlg) {
  51. this.setData({
  52. settingFlg: options.settingFlg
  53. })
  54. }
  55. },
  56. /**
  57. * @desc : onLoad生命周期回调
  58. * @date : 2024/7/30 09:11
  59. * @author : 刘尧
  60. */
  61. loadInit() {
  62. wx.hideShareMenu({})
  63. // 版本
  64. this.setData({
  65. staffName: app.globalData.user.staffName,
  66. staffPhone: app.globalData.user.staffPhone,
  67. companyName: app.globalData.company.cpName,
  68. versionName: this.data.freeVersionFlag ? mixins.$t('standardVersion') : mixins.$t('professionalVersion')
  69. })
  70. // 策略
  71. this.getIntegralTactic()
  72. // 获取优惠劵助力信息
  73. this.getCouponTactic()
  74. // 积分
  75. this.getIntegral()
  76. // 获取用户头像
  77. this.getUser()
  78. // 优惠劵
  79. this.getCouponNumber()
  80. },
  81. /**
  82. * @desc : 显示活动卡片明细
  83. * @author : 刘尧
  84. * @date : 2024/7/29 15:23
  85. */
  86. showCardItem(e) {
  87. this.setData({
  88. cilckViewId: e.currentTarget.dataset.name
  89. })
  90. if (e.currentTarget.dataset.name != 'toShare') {
  91. switch (e.currentTarget.dataset.name) {
  92. case 'toPower':
  93. this.getPowerItem().then(res => {
  94. const data = res.data.data
  95. if (data) {
  96. const that = this
  97. const endDate = data.endDate
  98. const nowTime = data.nowTime
  99. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  100. that.setData({
  101. time: time,
  102. couponSendItem: data
  103. })
  104. }
  105. })
  106. break;
  107. case 'toRegister':
  108. // this.getRegisterItem()
  109. break;
  110. }
  111. }
  112. },
  113. /**
  114. * @desc : 获取助力明细
  115. * @author : 刘尧
  116. * @date : 2024/7/30
  117. */
  118. getPowerItem() {
  119. let params = {
  120. cpId: app.globalData.company.cpId,
  121. couponId: this.data.couponItem.couponId,
  122. sendUser: app.globalData.user.userId,
  123. }
  124. let service = app.globalData['couponSendService']
  125. return this.excute(service, 'get_item', params)
  126. },
  127. /**
  128. * @desc : 倒计时事件
  129. * @author : 刘尧
  130. * @date : 2024/7/30
  131. */
  132. onCountDownChange(e) {
  133. this.setData({
  134. timeData: e.detail,
  135. });
  136. },
  137. /**
  138. * @desc : 服务器的日期
  139. * @author : 姜永辉
  140. * @date : 2024/4/1
  141. */
  142. getCurrentDate() {
  143. let _this = this
  144. let service = app.globalData['commonService']
  145. return _this.excute(service, service.getCurrentDate, { 'DateFormat': 'yyyy-MM-dd hh:mm:ss' });
  146. },
  147. /**
  148. * @desc : 策略
  149. * @author : 刘尧
  150. * @date : 2024/7/25 14:32
  151. */
  152. getIntegralTactic() {
  153. let params = {}
  154. let service = app.globalData['integralTacticService']
  155. this.excute(service, service.selectByCond, params).then(res => {
  156. if (res.data.code == Constants.SUCESS_CODE) {
  157. if (res.data && res.data.data.list && res.data.data.list.length > 0) {
  158. this.setData({
  159. integralTacticItem: res.data.data.list[0],
  160. })
  161. this.getShareNumber()
  162. }
  163. }
  164. });
  165. },
  166. /**
  167. * @desc : 获取优惠劵策略
  168. * @author : 刘尧
  169. * @date : 2024/7/30 09:42
  170. */
  171. getCouponTactic() {
  172. let params = {
  173. flgValid: true
  174. }
  175. let service = app.globalData['couponService']
  176. this.excute(service, service.selectByCond, params).then(res => {
  177. console.log('coupon', res.data.data.list);
  178. const list = res.data.data.list
  179. if (list.length > 0) {
  180. this.setData({
  181. couponItem: list[0]
  182. })
  183. }
  184. });
  185. },
  186. /**
  187. * @desc : 公司积分
  188. * @author : 刘尧
  189. * @date : 2024/7/25 14:32
  190. */
  191. getIntegral() {
  192. let params = {}
  193. let service = app.globalData['integralService']
  194. this.excute(service, app.globalData.company.cpId, params).then(res => {
  195. console.log(res.data, 'getIntegral');
  196. if (res.data.code == Constants.SUCESS_CODE) {
  197. if (res.data && res.data.data) {
  198. this.setData({
  199. integral: res.data.data.integral,
  200. })
  201. }
  202. }
  203. });
  204. },
  205. /**
  206. * @desc : 优惠劵数量获取
  207. * @author : 刘尧
  208. * @date : 2024/7/29 15:54
  209. */
  210. getCouponNumber() {
  211. let params = {
  212. couponStatus: Constants.couponStatus.unused,
  213. flgValid: true
  214. }
  215. let service = app.globalData['couponUseService']
  216. this.excute(service, service.countByCond, params).then(res => {
  217. this.setData({
  218. couponNumber: res.data.data
  219. })
  220. });
  221. },
  222. /**
  223. * @desc : 点击立即助力按钮调后台服务插入优惠劵发出数据
  224. * @author : 刘尧
  225. * @date : 2024/7/25 14:32
  226. */
  227. insertNewPowerItem() {
  228. let params = {
  229. cpId: app.globalData.company.cpId,
  230. couponId: this.data.couponItem.couponId,
  231. userNum: this.data.couponItem.userNum,
  232. sendStaff: app.globalData.user.staffName,
  233. sendUser: app.globalData.user.userId,
  234. flgValid: true
  235. }
  236. let service = app.globalData['couponSendService']
  237. return this.excute(service, service.insert, params)
  238. },
  239. /**
  240. * @desc : 将两个时间进行作差计算
  241. * @author : 刘尧
  242. * @date : 2024/7/30 15:40
  243. */
  244. calculateTimeDifference(date1, date2) {
  245. // 将日期转换为时间戳
  246. const timestamp1 = date1.getTime();
  247. const timestamp2 = date2.getTime();
  248. // 计算时间戳之差
  249. const diff = Math.abs(timestamp2 - timestamp1);
  250. // 返回结果
  251. return diff;
  252. },
  253. /**
  254. * @desc : 分享调用
  255. * @author : 刘尧
  256. * @date : 2024/7/30 15:40
  257. */
  258. shareIntegral(){
  259. let service = app.globalData['integralShareService']
  260. const params = {
  261. cpId: app.globalData.company.cpId,
  262. tacticId: this.data.integralTacticItem.tacticId,
  263. flgValid: true,
  264. integralType: Constants.integralType.share,
  265. userId: app.globalData.user.userId,
  266. }
  267. return this.excute(service, service.insert, params)
  268. },
  269. /**
  270. * @desc : 获取用户剩余分享次数
  271. * @author : 刘尧
  272. * @date : 2024/7/30 15:40
  273. */
  274. getShareNumber(){
  275. let service = app.globalData['integralShareService']
  276. const params = {
  277. cpId: app.globalData.company.cpId,
  278. tacticId: this.data.integralTacticItem.tacticId,
  279. flgValid: true,
  280. integralType: Constants.integralType.share,
  281. userId: app.globalData.user.userId,
  282. }
  283. this.excute(service, 'select_share_number', params).then(res => {
  284. console.log('getShareNumber', res.data.data);
  285. const integralTacticItem = this.data.integralTacticItem
  286. integralTacticItem.shareDayNum = integralTacticItem.shareDayNum - res.data.data
  287. this.setData({
  288. integralTacticItem: integralTacticItem
  289. })
  290. })
  291. },
  292. /**
  293. * 用户点击右上角分享
  294. */
  295. onShareAppMessage: async function(e) {
  296. const url = this.data.imageUrl + 'share-background.png'
  297. this.setData({
  298. cilckViewId: e.target.dataset.detail
  299. })
  300. if (e.target.dataset.detail === "toShare") {
  301. const res = await this.shareIntegral()
  302. console.log('shareIntegral', res);
  303. if (res.data.code == Constants.SUCESS_CODE) {
  304. this.getShareNumber()
  305. return {
  306. title: '分享好友获取云币',
  307. desc: '分享不停歇',
  308. path: '/pages/welcome/welcome',
  309. imageUrl: url
  310. }
  311. }
  312. }
  313. if (e.target.dataset.detail === "toRegister") {
  314. return {
  315. title: '邀请好友,互利共赢',
  316. desc: '邀请注册拿云币',
  317. path: '/pages/welcome/welcome',
  318. imageUrl: url
  319. }
  320. }
  321. if (e.target.dataset.detail === "toPower") {
  322. const couponDesc = this.data.couponItem.couponDesc
  323. let item = await this.getPowerItem()
  324. item = item.data.data
  325. if (item) {
  326. const that = this
  327. const endDate = item.endDate
  328. const nowTime = item.nowTime
  329. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  330. that.setData({
  331. time: time,
  332. couponSendItem: item
  333. })
  334. }
  335. if(!this.data.couponSendItem){
  336. const that = this
  337. const res = await this.insertNewPowerItem()
  338. if (res.data.code == Constants.SUCESS_CODE) {
  339. const data = res.data.data
  340. const endDate = data.endDate
  341. const nowTime = data.nowTime
  342. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  343. that.setData({
  344. time: time,
  345. couponSendItem: data
  346. })
  347. }
  348. }
  349. const that = this
  350. return {
  351. title: couponDesc,
  352. desc: '助力拿福利',
  353. path: '/package-basic-data/pages/share-power/share-power?cpId=' + app.globalData.company.cpId + '&couponId=' + that.data.couponItem.couponId + '&sendId=' + that.data.couponSendItem.sendId + '&discount=' + that.data.couponItem.discount,
  354. imageUrl: url
  355. }
  356. }
  357. }
  358. })