share.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. }
  162. }
  163. });
  164. },
  165. /**
  166. * @desc : 获取优惠劵策略
  167. * @author : 刘尧
  168. * @date : 2024/7/30 09:42
  169. */
  170. getCouponTactic() {
  171. let params = {
  172. flgValid: true
  173. }
  174. let service = app.globalData['couponService']
  175. this.excute(service, service.selectByCond, params).then(res => {
  176. console.log('coupon', res.data.data.list);
  177. const list = res.data.data.list
  178. if (list.length > 0) {
  179. this.setData({
  180. couponItem: list[0]
  181. })
  182. }
  183. });
  184. },
  185. /**
  186. * @desc : 公司积分
  187. * @author : 刘尧
  188. * @date : 2024/7/25 14:32
  189. */
  190. getIntegral() {
  191. let params = {}
  192. let service = app.globalData['integralService']
  193. this.excute(service, app.globalData.company.cpId, params).then(res => {
  194. console.log(res.data, 'getIntegral');
  195. if (res.data.code == Constants.SUCESS_CODE) {
  196. if (res.data && res.data.data) {
  197. this.setData({
  198. integral: res.data.data.integral,
  199. })
  200. }
  201. }
  202. });
  203. },
  204. /**
  205. * @desc : 优惠劵数量获取
  206. * @author : 刘尧
  207. * @date : 2024/7/29 15:54
  208. */
  209. getCouponNumber() {
  210. let params = {
  211. couponStatus: Constants.couponStatus.unused,
  212. flgValid: true
  213. }
  214. let service = app.globalData['couponUseService']
  215. this.excute(service, service.countByCond, params).then(res => {
  216. this.setData({
  217. couponNumber: res.data.data
  218. })
  219. });
  220. },
  221. /**
  222. * @desc : 优惠券
  223. * @author : 刘尧
  224. * @date : 2024/7/25 14:32
  225. */
  226. getCouponCount() {
  227. let params = {}
  228. let service = app.globalData['couponService']
  229. this.excute(service, '10002024-0718-0000-0000-000005c0a01e', params).then(res => {
  230. console.log(res.data);
  231. if (res.data.code == Constants.SUCESS_CODE) {
  232. }
  233. });
  234. },
  235. /**
  236. * @desc : 点击立即助力按钮调后台服务插入优惠劵发出数据
  237. * @author : 刘尧
  238. * @date : 2024/7/25 14:32
  239. */
  240. insertNewPowerItem() {
  241. let params = {
  242. cpId: app.globalData.company.cpId,
  243. couponId: this.data.couponItem.couponId,
  244. userNum: this.data.couponItem.userNum,
  245. sendStaff: app.globalData.user.staffName,
  246. sendUser: app.globalData.user.userId,
  247. flgValid: true
  248. }
  249. let service = app.globalData['couponSendService']
  250. return this.excute(service, service.insert, params)
  251. },
  252. /**
  253. * @desc : 将两个时间进行作差计算
  254. * @author : 刘尧
  255. * @date : 2024/7/30 15:40
  256. */
  257. calculateTimeDifference(date1, date2) {
  258. // 将日期转换为时间戳
  259. const timestamp1 = date1.getTime();
  260. const timestamp2 = date2.getTime();
  261. // 计算时间戳之差
  262. const diff = Math.abs(timestamp2 - timestamp1);
  263. // 返回结果
  264. return diff;
  265. },
  266. /**
  267. * 用户点击右上角分享
  268. */
  269. onShareAppMessage: async function(e) {
  270. const url = this.data.imageUrl + 'share-background.png'
  271. this.setData({
  272. cilckViewId: e.target.dataset.detail
  273. })
  274. if (e.target.dataset.detail === "toShare") {
  275. return {
  276. title: '分享好友获取云币',
  277. desc: '分享不停歇',
  278. path: '/pages/welcome/welcome',
  279. imageUrl: url
  280. }
  281. }
  282. if (e.target.dataset.detail === "toRegister") {
  283. return {
  284. title: '邀请好友,互利共赢',
  285. desc: '邀请注册拿云币',
  286. path: '/pages/welcome/welcome',
  287. imageUrl: url
  288. }
  289. }
  290. if (e.target.dataset.detail === "toPower") {
  291. const couponDesc = this.data.couponItem.couponDesc
  292. let item = await this.getPowerItem()
  293. item = item.data.data
  294. if (item) {
  295. const that = this
  296. const endDate = item.endDate
  297. const nowTime = item.nowTime
  298. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  299. that.setData({
  300. time: time,
  301. couponSendItem: item
  302. })
  303. }
  304. if(!this.data.couponSendItem){
  305. const that = this
  306. const res = await this.insertNewPowerItem()
  307. if (res.data.code == Constants.SUCESS_CODE) {
  308. const data = res.data.data
  309. const endDate = data.endDate
  310. const nowTime = data.nowTime
  311. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  312. that.setData({
  313. time: time,
  314. couponSendItem: data
  315. })
  316. }
  317. }
  318. const that = this
  319. return {
  320. title: couponDesc,
  321. desc: '助力拿福利',
  322. 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,
  323. imageUrl: url
  324. }
  325. }
  326. }
  327. })