activity.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. /*******************************************************************************
  2. * Copyright(c) 2022 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:活动(用于续费、注册)
  5. * 编辑履历:
  6. * 作者 日期 版本 修改内容
  7. * 周兴 2024-5-15 1.00 新建
  8. *******************************************************************************/
  9. const Constants = require('@/utils/Constants.js');
  10. const util = require('@/utils/util.js')
  11. const mixins = require('@/mixins/index.js');
  12. const app = getApp()
  13. Page({
  14. mixins: [mixins],
  15. /**
  16. * 页面的初始数据
  17. */
  18. data: {
  19. // 是否加载完毕
  20. loadFlag:false,
  21. // 是否显示vip
  22. showVip:false,
  23. // 升级标识
  24. upgradeFlag: false,
  25. gradeCode: null,
  26. freeFlag: false,
  27. // 企业名称
  28. companyName: null,
  29. cpManager: null,
  30. cpPhone: null,
  31. webMaxNum: null,
  32. wxMaxNum: null,
  33. cpEndDate: null,
  34. activityTable: null,
  35. vipTable: null,
  36. readFlag: false,
  37. staffCount: {
  38. maxNum: 1,
  39. webMaxNum: 0,
  40. wxMaxNum: 0
  41. },
  42. curentAdItem: null,
  43. // 选择的vip报表
  44. chooseVipFlag:false,
  45. summaryInfo: {},
  46. routeObjName: 'company',
  47. pageFlag: false,
  48. // 当前用户授权数
  49. currentUserCount: null,
  50. //按钮
  51. buttonSaveList: [
  52. { code: 'save', title: mixins.$t('save'), width: '120rpx' }
  53. ],
  54. noticeInfo: Constants.noticeInfo
  55. },
  56. /**
  57. * @desc : 选择活动明细
  58. * @author : 周兴
  59. * @date : 2024/4/1
  60. */
  61. chooseAdItem(e) {
  62. let item = e.currentTarget.dataset.item;
  63. let summaryInfo = this.data.summaryInfo
  64. // 计算截止日期
  65. let months = item.validLong + item.extraLong
  66. let endDate = app.globalData.company.endDate
  67. // 升级需要从当天开始算
  68. if (this.data.upgradeFlag) {
  69. endDate = new Date()
  70. }
  71. endDate = new Date(endDate).addMonths(months).addDays(-1)
  72. summaryInfo.endDate = endDate.toDateStr();
  73. this.setData({
  74. curentAdItem: item,
  75. summaryInfo: summaryInfo
  76. })
  77. // 计算金额
  78. this.countSummaryAmount(item);
  79. },
  80. /**
  81. * @desc : 选择VIP报表明细
  82. * @author : 周兴
  83. * @date : 2024/4/1
  84. */
  85. chooseVipItem(e) {
  86. let item = e.currentTarget.dataset.item;
  87. // let summaryInfo = this.data.summaryInfo
  88. // // 计算截止日期
  89. // let months = item.validLong + item.extraLong
  90. // let endDate = app.globalData.company.endDate
  91. // // 升级需要从当天开始算
  92. // if (this.data.upgradeFlag) {
  93. // endDate = new Date()
  94. // }
  95. // endDate = new Date(endDate).addMonths(months).addDays(-1)
  96. // summaryInfo.endDate = endDate.toDateStr();
  97. this.setData({
  98. chooseVipFlag: !this.data.chooseVipFlag,
  99. // summaryInfo: summaryInfo
  100. })
  101. // 计算金额
  102. this.countSummaryAmountSTD();
  103. },
  104. /**
  105. * @desc : 勾选已阅读表示
  106. * @author : 周兴
  107. * @date : 2024/5/17
  108. */
  109. handleChangeCheckbox(e) {
  110. console.log('ee', e);
  111. this.setData({
  112. readFlag: e.detail
  113. })
  114. },
  115. /**
  116. * @desc : 计算金额
  117. * @author : 周兴
  118. * @date : 2024/4/1
  119. */
  120. countSummaryAmount() {
  121. let item = this.data.curentAdItem;
  122. let staffCount = this.data.staffCount;
  123. let summaryInfo = this.data.summaryInfo
  124. let amount = 0;
  125. // 先清空
  126. summaryInfo.amountInfo = '';
  127. // 共通用户
  128. if (staffCount.maxNum) {
  129. summaryInfo.amountInfo = item.stdPrice + '(打包价格)*' + staffCount.maxNum
  130. amount += item.stdPrice * staffCount.maxNum
  131. }
  132. // 手机端用户
  133. if (staffCount.wxMaxNum) {
  134. if (summaryInfo.amountInfo) {
  135. summaryInfo.amountInfo += ' + '
  136. }
  137. summaryInfo.amountInfo += item.wxPrice + '(手机端价格)*' + staffCount.wxMaxNum
  138. amount += item.wxPrice * staffCount.wxMaxNum
  139. }
  140. // 电脑端用户
  141. if (staffCount.webMaxNum) {
  142. if (summaryInfo.amountInfo) {
  143. summaryInfo.amountInfo += ' + '
  144. }
  145. summaryInfo.amountInfo += item.webPrice + '(电脑端价格)*' + staffCount.webMaxNum
  146. amount += item.webPrice * staffCount.webMaxNum
  147. }
  148. if (summaryInfo.amountInfo) {
  149. summaryInfo.amountInfo += ' = ' + amount + '(元)'
  150. summaryInfo.amount = amount;
  151. }
  152. this.setData({
  153. summaryInfo: summaryInfo
  154. })
  155. // 统计两端用户数
  156. this.countStaffInfo();
  157. },
  158. /**
  159. * @desc : 获取标准版的价格显示
  160. * @author : 周兴
  161. * @date : 2024/4/1
  162. */
  163. countSummaryAmountSTD() {
  164. let item = this.data.curentAdItem;
  165. let vipTable = this.data.vipTable
  166. let summaryInfo = this.data.summaryInfo
  167. let amount = 0;
  168. // 先清空
  169. summaryInfo.amountInfo = '';
  170. let extendDays = null;
  171. let nowDate = new Date(new Date().toDateStr());
  172. if (summaryInfo.reCountFlag) {
  173. // 手机端用户
  174. if (summaryInfo.wxMaxNum) {
  175. summaryInfo.amountInfo += item.wxPrice + '(元) * ' + summaryInfo.wxMaxNum + '(个) '
  176. amount += item.wxPrice * summaryInfo.wxMaxNum
  177. }
  178. // vip报表
  179. if(this.data.chooseVipFlag && vipTable && vipTable.length > 0){
  180. let vipItem = vipTable[0]
  181. summaryInfo.amountInfo += + ' + ' +vipItem.wxPrice + '(元/VIP) ';
  182. amount += vipItem.wxPrice;
  183. }
  184. if (summaryInfo.amountInfo) {
  185. summaryInfo.amountInfo += ' = ' + amount + '(元)'
  186. summaryInfo.amount = amount;
  187. }
  188. extendDays = new Date(summaryInfo.userEndDate).dayDiff(nowDate) + 1;
  189. } else {
  190. extendDays = new Date(summaryInfo.userEndDate).dayDiff(nowDate) + 1;
  191. if (summaryInfo.wxMaxNum) {
  192. summaryInfo.amountInfo += item.wxPrice + '(元) '
  193. amount += item.wxPrice * summaryInfo.wxMaxNum
  194. }
  195. // vip报表
  196. if(this.data.chooseVipFlag && vipTable && vipTable.length > 0){
  197. let vipItem = vipTable[0]
  198. console.log('vipItem.wxPrice',vipItem.wxPrice);
  199. summaryInfo.amountInfo += ' + ' + vipItem.wxPrice + '(元/VIP) ';
  200. summaryInfo.amountInfo = '( ' + summaryInfo.amountInfo + ' ) ';
  201. amount += vipItem.wxPrice;
  202. }
  203. summaryInfo.amountInfo += ' / 365(天) * ' + extendDays + '(天) * ' + summaryInfo.wxMaxNum + '(个)'
  204. if (summaryInfo.amountInfo) {
  205. amount = (amount / 365 * extendDays) .toFixed(2);
  206. summaryInfo.amountInfo += ' = ' + amount + '(元)'
  207. summaryInfo.amount = amount;
  208. }
  209. }
  210. // 计算一授权一天的单价
  211. if (summaryInfo.userEndDate) {
  212. let price = (summaryInfo.amount / summaryInfo.wxMaxNum / extendDays).toFixed(2);
  213. summaryInfo.priceInfo = price
  214. summaryInfo.extendDays = extendDays
  215. }
  216. this.setData({
  217. summaryInfo: summaryInfo
  218. })
  219. },
  220. /**
  221. * @desc : 统计电脑端和手机端的用户数
  222. * @author : 周兴
  223. * @date : 2024/4/1
  224. */
  225. countStaffInfo() {
  226. let summaryInfo = this.data.summaryInfo;
  227. let staffCount = this.data.staffCount;
  228. if (!staffCount) {
  229. return;
  230. }
  231. let webNum = staffCount.webMaxNum + staffCount.maxNum
  232. let wxNum = staffCount.wxMaxNum + staffCount.maxNum
  233. summaryInfo.staffInfo = '可配置手机端授权' + wxNum + '个;电脑端授权' + webNum + '个(包含当前用户)'
  234. summaryInfo.webMaxNum = webNum
  235. summaryInfo.wxMaxNum = wxNum
  236. // 升级从当天算
  237. if (this.data.upgradeFlag) {
  238. summaryInfo.buyBeginDate = new Date().addDays(1).toDateStr();
  239. summaryInfo.extendDays = new Date(summaryInfo.endDate).dayDiff(new Date().addDays(1));
  240. } else {
  241. summaryInfo.buyBeginDate = new Date(this.data.cpEndDate).addDays(1).toDateStr();
  242. summaryInfo.extendDays = new Date(summaryInfo.endDate).dayDiff(new Date(this.data.cpEndDate).addDays(1));
  243. }
  244. // 计算一授权一天的单价
  245. let price = (summaryInfo.amount / (webNum + wxNum) / summaryInfo.extendDays).toFixed(2);
  246. summaryInfo.priceInfo = price
  247. this.setData({
  248. summaryInfo: summaryInfo
  249. })
  250. },
  251. /**
  252. * @desc : 修改用户数
  253. * @author : 周兴
  254. * @date : 2024/4/1
  255. */
  256. changeStaffCount(e) {
  257. let staffCount = this.data.staffCount
  258. let ds = e.currentTarget.dataset
  259. if (ds.type == 'wx') {
  260. staffCount.wxMaxNum = e.detail
  261. } else if (ds.type == 'web') {
  262. staffCount.webMaxNum = e.detail
  263. } else {
  264. staffCount.maxNum = e.detail
  265. }
  266. this.setData({
  267. staffCount: staffCount
  268. })
  269. // 计算金额
  270. this.countSummaryAmount();
  271. },
  272. /**
  273. * @desc : 保存
  274. * @author : 周兴
  275. * @date : 2024/4/1
  276. */
  277. handleSave() {
  278. let summaryInfo = this.data.summaryInfo;
  279. let currentUserCount = this.data.currentUserCount
  280. if (!currentUserCount) {
  281. return;
  282. }
  283. if (this.data.gradeCode == Constants.gradeCode.STD) {
  284. // 判断数量是否超出续约授权
  285. if (currentUserCount.wxNum > summaryInfo.wxMaxNum && summaryInfo.reCountFlag) {
  286. let staffInfo = [{ wxMaxNum: this.data.wxMaxNum, title: '当前授权', wxTitle: '手机授权', code: 'current', userTitle: '当前用户' }, { wxMaxNum: summaryInfo.wxMaxNum, title: '续费授权', wxTitle: '手机授权', code: 'renew' }]
  287. this.save({ saveFlag: false, url: '/package-basic-data/pages/activity/detail/detail?staffInfo=' + JSON.stringify(staffInfo) });
  288. } else {
  289. this.save({});
  290. }
  291. } else {
  292. // 判断数量是否超出续约授权
  293. if (currentUserCount.wxNum > summaryInfo.wxMaxNum || currentUserCount.webNum > summaryInfo.webMaxNum) {
  294. let staffInfo = [{ wxMaxNum: this.data.wxMaxNum, webMaxNum: this.data.webMaxNum, title: '当前授权', wxTitle: '手机授权', webTitle: '电脑授权', code: 'current' }, { wxMaxNum: summaryInfo.wxMaxNum, webMaxNum: summaryInfo.webMaxNum, title: '续费授权', wxTitle: '手机授权', webTitle: '电脑授权', code: 'renew' }]
  295. this.save({ saveFlag: false, url: '/package-basic-data/pages/activity/detail/detail?staffInfo=' + JSON.stringify(staffInfo) });
  296. } else {
  297. this.save({});
  298. }
  299. }
  300. },
  301. /**
  302. * @desc : 改变用户授权数
  303. * @author : 周兴
  304. * @date : 2024/4/1
  305. */
  306. changeUserSTD(e) {
  307. let summaryInfo = this.data.summaryInfo
  308. summaryInfo.wxMaxNum = e.detail
  309. this.setData({
  310. summaryInfo: summaryInfo
  311. })
  312. // 计算金额
  313. this.countSummaryAmountSTD();
  314. },
  315. /**
  316. * @desc : 校验
  317. * @author : 周兴
  318. * @date : 2024/4/1
  319. */
  320. validData() {
  321. // 专业版校验
  322. if (this.data.gradeCode == Constants.gradeCode.PRO) {
  323. if (!this.data.readFlag) {
  324. util.showToast('请勾选阅读须知');
  325. return false;
  326. }
  327. let curentAdItem = this.data.curentAdItem;
  328. if (!curentAdItem) {
  329. util.showToast('请选择活动');
  330. return false
  331. }
  332. // 必须要选择一个授权
  333. let staffCount = this.data.staffCount
  334. if (!staffCount.maxNum && !staffCount.webMaxNum && !staffCount.wxMaxNum) {
  335. util.showToast('请选择一个授权');
  336. return false
  337. }
  338. } else {
  339. let curentAdItem = this.data.curentAdItem;
  340. if (!curentAdItem) {
  341. util.showToast('请选择活动');
  342. return false
  343. }
  344. }
  345. return true;
  346. },
  347. /**
  348. * @desc : 设置保存参数
  349. * @author : 周兴
  350. * @date : 2024/4/1
  351. */
  352. setParams(params) {
  353. let summaryInfo = this.data.summaryInfo
  354. let curentAdItem = this.data.curentAdItem
  355. let cpEndDate = this.data.cpEndDate
  356. console.log('summaryInfo', summaryInfo);
  357. if (!summaryInfo || !cpEndDate) return;
  358. params.endDate = summaryInfo.endDate
  359. params.userEndDate = summaryInfo.userEndDate
  360. params.gradeCode = this.data.gradeCode
  361. params.cpId = app.globalData.company.cpId
  362. params.tradeNo = this.generateRandomNo();
  363. params.wxUserId = app.globalData.user.userId
  364. params.tradeAmount = summaryInfo.amount
  365. params.buyBeginDate = summaryInfo.buyBeginDate;
  366. params.buyEndDate = summaryInfo.endDate
  367. params.extendDays = summaryInfo.extendDays;
  368. if (this.data.gradeCode == Constants.gradeCode.STD) {
  369. params.buyEndDate = summaryInfo.userEndDate
  370. params.endDate = app.globalData.company.endDate
  371. params.wxMaxNum = summaryInfo.wxMaxNum
  372. if(this.data.showVip && this.data.chooseVipFlag){
  373. params.vip = true;
  374. }else if(!this.data.showVip && app.globalData.company.vip){
  375. params.vip = true;
  376. }
  377. if(this.data.chooseVipFlag){
  378. params.vip = true;
  379. }
  380. if (!summaryInfo.reCountFlag && summaryInfo.wxMaxNumSocial) {
  381. params.wxMaxNum = summaryInfo.wxMaxNum + summaryInfo.wxMaxNumSocial
  382. }
  383. } else {
  384. params.webMaxNum = summaryInfo.webMaxNum
  385. params.wxMaxNum = summaryInfo.wxMaxNum
  386. }
  387. params.buyLong = curentAdItem.activityItemName
  388. return params;
  389. },
  390. /**
  391. * @desc : 保存数据
  392. * @author : 周兴
  393. * @date : 2024/5/17
  394. */
  395. saveData(params) {
  396. return this.excute(this.data.service, this.data.service.reNewCompany, this.data.params).then(res => {
  397. if (res.data.code == Constants.SUCESS_CODE) {
  398. // 成功后跳转支付
  399. this.toPay(res.data.data);
  400. }
  401. })
  402. },
  403. /**
  404. * @desc : 查询当前用户授权数
  405. * @author : 周兴
  406. * @date : 2024/4/1
  407. */
  408. getStaffCount() {
  409. let service = app.globalData['commonService']
  410. this.excute(service, service.selectUserCount, {}).then(res => {
  411. if (res.data.code == Constants.SUCESS_CODE) {
  412. if (res.data && res.data.data) {
  413. let currentUserCount = res.data.data;
  414. console.log('currentUserCount', currentUserCount);
  415. this.setData({
  416. currentUserCount: currentUserCount
  417. })
  418. }
  419. }
  420. this.setData({
  421. loadFlag:true
  422. })
  423. });
  424. },
  425. /**
  426. * @desc : 查询活动
  427. * @author : 周兴
  428. * @date : 2024/4/1
  429. */
  430. getActivity() {
  431. let params = {
  432. appCode: Constants.APP_CODE,
  433. gradeCode: this.data.gradeCode
  434. }
  435. // 标准版
  436. if (this.data.gradeCode == Constants.gradeCode.STD) {
  437. params.activityTypeList = [Constants.kindCode.activityGrade, Constants.kindCode.activityVip];
  438. } else {
  439. params.activityTypeList = [Constants.kindCode.activityGrade];
  440. }
  441. let service = app.globalData['activityService']
  442. this.excute(service, service.selectActivityItems, params).then(res => {
  443. if (res.data.code == Constants.SUCESS_CODE) {
  444. if (res.data && res.data.data) {
  445. let activityTable = res.data.data;
  446. // 如果是标准版,需要进行截止日期的处理
  447. if (this.data.gradeCode == Constants.gradeCode.STD) {
  448. this.setData({
  449. activityTable:activityTable.filter(it=>it.activityType == Constants.kindCode.activityGrade),
  450. vipTable:activityTable.filter(it=>it.activityType == Constants.kindCode.activityVip),
  451. })
  452. this.handleDataStd(activityTable);
  453. }else{
  454. this.setData({
  455. activityTable: activityTable
  456. })
  457. }
  458. }
  459. }
  460. });
  461. },
  462. /**
  463. * @desc : 标准版处理数据
  464. * @author : 周兴
  465. * @date : 2024/4/1
  466. */
  467. handleDataStd(activityTable) {
  468. if (activityTable && activityTable.length > 0) {
  469. let item = activityTable[0]
  470. this.setData({
  471. curentAdItem: item
  472. })
  473. let summaryInfo = this.data.summaryInfo
  474. let months = item.validLong + item.extraLong
  475. let endDate = new Date().addMonths(months).addDays(-1)
  476. let dayDiffs = null;
  477. if (summaryInfo.userEndDate) {
  478. dayDiffs = new Date(summaryInfo.userEndDate).dayDiff(new Date(new Date().toDateStr()))
  479. }
  480. // 如果截止日期是空,就取活动中的截止日期
  481. if (!summaryInfo.userEndDate || !dayDiffs || dayDiffs < 0) {
  482. summaryInfo.userEndDate = endDate.toDateStr();
  483. // 重新统计,到期续费或者第一次购买用户
  484. summaryInfo.reCountFlag = true;
  485. summaryInfo.wxMaxNum = summaryInfo.wxMaxNumSocial
  486. this.setData({
  487. showVip:true
  488. })
  489. }else{
  490. // 如果没有购买,需要显示
  491. if(!app.globalData.company.vip){
  492. this.setData({
  493. showVip:true
  494. })
  495. }
  496. }
  497. summaryInfo.buyBeginDate = new Date().toDateStr();
  498. console.log('summaryInfo', summaryInfo.userEndDate, endDate, months);
  499. this.setData({
  500. summaryInfo: summaryInfo
  501. })
  502. // 计算金额
  503. this.countSummaryAmountSTD();
  504. }
  505. },
  506. /**
  507. * 生命周期函数--监听页面加载
  508. */
  509. onLoad(options) {
  510. console.log('options', options);
  511. // 升级
  512. if (options && options.upgrade) {
  513. wx.setNavigationBarTitle({
  514. title: mixins.$t('updateSpecialized'),
  515. })
  516. this.setData({
  517. gradeCode: Constants.gradeCode.PRO,
  518. upgradeFlag: true
  519. })
  520. } else {
  521. wx.setNavigationBarTitle({
  522. title: mixins.$t('reNew'),
  523. })
  524. this.setData({
  525. gradeCode: app.globalData.company.gradeCode
  526. })
  527. }
  528. this.setData({
  529. companyName: app.globalData.company.cpName,
  530. cpManager: app.globalData.company.cpManager,
  531. cpPhone: app.globalData.company.cpPhone,
  532. cpEndDate: app.globalData.company.endDate,
  533. webMaxNum: app.globalData.company.webMaxNum,
  534. wxMaxNum: app.globalData.company.wxMaxNum,
  535. })
  536. // 如果是标准版,需要获取用户授权数(手机)
  537. let summaryInfo = {}
  538. summaryInfo.wxMaxNum = 1
  539. summaryInfo.wxMaxNumSocial = this.data.wxMaxNum
  540. // 续费用户到期日期
  541. summaryInfo.userEndDate = app.globalData.company.userEndDate
  542. this.setData({
  543. summaryInfo: summaryInfo
  544. })
  545. // 获取活动
  546. this.getActivity();
  547. // 获取当前用户授权数
  548. this.getStaffCount();
  549. },
  550. })