activity.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. freeFlag: false,
  20. // 企业名称
  21. companyName: null,
  22. cpManager: null,
  23. cpPhone: null,
  24. webMaxNum: null,
  25. wxMaxNum: null,
  26. cpEndDate: null,
  27. activityTable: null,
  28. readFlag: false,
  29. staffCount: {
  30. maxNum: 1,
  31. webMaxNum: 0,
  32. wxMaxNum: 0
  33. },
  34. curentAdItem: null,
  35. summaryInfo: {},
  36. routeObjName: 'company',
  37. pageFlag: false,
  38. // 当前用户授权数
  39. currentUserCount: null,
  40. //按钮
  41. buttonSaveList: [
  42. { code: 'save', title: mixins.$t('save'), width: '120rpx' }
  43. ],
  44. noticeInfo: Constants.noticeInfo
  45. },
  46. /**
  47. * @desc : 选择活动明细
  48. * @author : 周兴
  49. * @date : 2024/4/1
  50. */
  51. chooseAdItem(e) {
  52. let item = e.currentTarget.dataset.item;
  53. let summaryInfo = this.data.summaryInfo
  54. // 计算截止日期
  55. let months = item.validLong + item.extraLong
  56. let endDate = app.globalData.company.endDate
  57. endDate = new Date(endDate).addMonths(months)
  58. summaryInfo.endDate = endDate.toDateStr();
  59. this.setData({
  60. curentAdItem: item,
  61. summaryInfo: summaryInfo
  62. })
  63. // 计算金额
  64. this.countSummaryAmount(item);
  65. },
  66. /**
  67. * @desc : 勾选已阅读表示
  68. * @author : 周兴
  69. * @date : 2024/5/17
  70. */
  71. handleChangeCheckbox(e) {
  72. console.log('ee', e);
  73. this.setData({
  74. readFlag: e.detail
  75. })
  76. },
  77. /**
  78. * @desc : 计算金额
  79. * @author : 周兴
  80. * @date : 2024/4/1
  81. */
  82. countSummaryAmount() {
  83. let item = this.data.curentAdItem;
  84. let staffCount = this.data.staffCount;
  85. let summaryInfo = this.data.summaryInfo
  86. let amount = 0;
  87. // 先清空
  88. summaryInfo.amountInfo = '';
  89. // 共通用户
  90. if (staffCount.maxNum) {
  91. summaryInfo.amountInfo = item.stdPrice + '(打包价格)*' + staffCount.maxNum
  92. amount += item.stdPrice * staffCount.maxNum
  93. }
  94. // 手机端用户
  95. if (staffCount.wxMaxNum) {
  96. if (summaryInfo.amountInfo) {
  97. summaryInfo.amountInfo += ' + '
  98. }
  99. summaryInfo.amountInfo += item.wxPrice + '(手机端价格)*' + staffCount.wxMaxNum
  100. amount += item.wxPrice * staffCount.wxMaxNum
  101. }
  102. // 电脑端用户
  103. if (staffCount.webMaxNum) {
  104. if (summaryInfo.amountInfo) {
  105. summaryInfo.amountInfo += ' + '
  106. }
  107. summaryInfo.amountInfo += item.webPrice + '(电脑端价格)*' + staffCount.webMaxNum
  108. amount += item.webPrice * staffCount.webMaxNum
  109. }
  110. if (summaryInfo.amountInfo) {
  111. summaryInfo.amountInfo += ' = ' + amount + '(元)'
  112. summaryInfo.amount = amount;
  113. }
  114. this.setData({
  115. summaryInfo: summaryInfo
  116. })
  117. // 统计两端用户数
  118. this.countStaffInfo();
  119. },
  120. /**
  121. * @desc : 获取标准版的价格显示
  122. * @author : 周兴
  123. * @date : 2024/4/1
  124. */
  125. countSummaryAmountSTD() {
  126. let item = this.data.curentAdItem;
  127. let summaryInfo = this.data.summaryInfo
  128. let amount = 0;
  129. // 先清空
  130. summaryInfo.amountInfo = '';
  131. // 手机端用户
  132. if (summaryInfo.wxMaxNum) {
  133. summaryInfo.amountInfo += item.wxPrice + '*' + summaryInfo.wxMaxNum
  134. amount += item.wxPrice * summaryInfo.wxMaxNum
  135. }
  136. if (summaryInfo.amountInfo) {
  137. summaryInfo.amountInfo += ' = ' + amount + '(元)'
  138. summaryInfo.amount = amount;
  139. }
  140. // 计算一授权一天的单价
  141. if (summaryInfo.userEndDate) {
  142. let extendDays = new Date(summaryInfo.userEndDate).dayDiff(new Date());
  143. let price = (summaryInfo.amount / summaryInfo.wxMaxNum / extendDays).toFixed(2);
  144. summaryInfo.priceInfo = price
  145. }
  146. this.setData({
  147. summaryInfo: summaryInfo
  148. })
  149. },
  150. /**
  151. * @desc : 统计电脑端和手机端的用户数
  152. * @author : 周兴
  153. * @date : 2024/4/1
  154. */
  155. countStaffInfo() {
  156. let summaryInfo = this.data.summaryInfo;
  157. let staffCount = this.data.staffCount;
  158. if (!staffCount) {
  159. return;
  160. }
  161. let webNum = staffCount.webMaxNum + staffCount.maxNum
  162. let wxNum = staffCount.wxMaxNum + staffCount.maxNum
  163. summaryInfo.staffInfo = '可配置手机端授权' + wxNum + '个;电脑端授权' + webNum + '个(包含当前用户)'
  164. summaryInfo.webMaxNum = webNum
  165. summaryInfo.wxMaxNum = wxNum
  166. summaryInfo.buyBeginDate = new Date(this.data.cpEndDate).addDays(1).toDateStr();
  167. summaryInfo.extendDays = new Date(summaryInfo.endDate).dayDiff(new Date(this.data.cpEndDate).addDays(1));
  168. // 计算一授权一天的单价
  169. let price = (summaryInfo.amount / (webNum + wxNum) / summaryInfo.extendDays).toFixed(2);
  170. summaryInfo.priceInfo = price
  171. this.setData({
  172. summaryInfo: summaryInfo
  173. })
  174. },
  175. /**
  176. * @desc : 修改用户数
  177. * @author : 周兴
  178. * @date : 2024/4/1
  179. */
  180. changeStaffCount(e) {
  181. let staffCount = this.data.staffCount
  182. let ds = e.currentTarget.dataset
  183. if (ds.type == 'wx') {
  184. staffCount.wxMaxNum = e.detail
  185. } else if (ds.type == 'web') {
  186. staffCount.webMaxNum = e.detail
  187. } else {
  188. staffCount.maxNum = e.detail
  189. }
  190. this.setData({
  191. staffCount: staffCount
  192. })
  193. // 计算金额
  194. this.countSummaryAmount();
  195. },
  196. /**
  197. * @desc : 保存
  198. * @author : 周兴
  199. * @date : 2024/4/1
  200. */
  201. handleSave() {
  202. let summaryInfo = this.data.summaryInfo;
  203. let currentUserCount = this.data.currentUserCount
  204. if (!currentUserCount) {
  205. return;
  206. }
  207. // 判断数量是否超出续约授权
  208. if (currentUserCount.wxNum > summaryInfo.wxMaxNum || currentUserCount.webNum > summaryInfo.webMaxNum) {
  209. 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' }]
  210. this.save({ saveFlag: false, url: '/package-basic-data/pages/activity/detail/detail?staffInfo=' + JSON.stringify(staffInfo) });
  211. } else {
  212. this.save({});
  213. }
  214. },
  215. /**
  216. * @desc : 校验
  217. * @author : 周兴
  218. * @date : 2024/4/1
  219. */
  220. validData() {
  221. if (!this.data.readFlag) {
  222. util.showToast('请勾选阅读须知');
  223. return false;
  224. }
  225. let curentAdItem = this.data.curentAdItem;
  226. if (!curentAdItem) {
  227. util.showToast('请选择活动');
  228. return false
  229. }
  230. // 必须要选择一个授权
  231. let staffCount = this.data.staffCount
  232. if (!staffCount.maxNum || !staffCount.webMaxNum || !staffCount.wxMaxNum) {
  233. util.showToast('请选择一个授权');
  234. return false
  235. }
  236. return true;
  237. },
  238. /**
  239. * @desc : 设置保存参数
  240. * @author : 周兴
  241. * @date : 2024/4/1
  242. */
  243. setParams(params) {
  244. let summaryInfo = this.data.summaryInfo
  245. let curentAdItem = this.data.curentAdItem
  246. let cpEndDate = this.data.cpEndDate
  247. if (!summaryInfo || !cpEndDate) return;
  248. params.webMaxNum = summaryInfo.webMaxNum
  249. params.wxMaxNum = summaryInfo.wxMaxNum
  250. params.endDate = summaryInfo.endDate
  251. params.gradeCode = app.globalData.company.gradeCode
  252. params.cpId = app.globalData.company.cpId
  253. params.tradeNo = this.generateRandomNo();
  254. params.wxUserId = app.globalData.user.userId
  255. params.tradeAmount = summaryInfo.amount
  256. params.buyBeginDate = summaryInfo.buyBeginDate;
  257. params.buyEndDate = summaryInfo.endDate
  258. params.extendDays = summaryInfo.extendDays;
  259. params.buyLong = curentAdItem.activityItemName
  260. return params;
  261. },
  262. /**
  263. * @desc : 保存数据
  264. * @author : 周兴
  265. * @date : 2024/5/17
  266. */
  267. saveData(params) {
  268. return this.excute(this.data.service, this.data.service.reNewCompany, this.data.params).then(res => {
  269. if (res.data.code == Constants.SUCESS_CODE) {
  270. // 成功后跳转支付
  271. this.toPay(res.data.data);
  272. }
  273. })
  274. },
  275. /**
  276. * @desc : 查询当前用户授权数
  277. * @author : 周兴
  278. * @date : 2024/4/1
  279. */
  280. getStaffCount() {
  281. let service = app.globalData['commonService']
  282. this.excute(service, service.selectUserCount, {}).then(res => {
  283. if (res.data.code == Constants.SUCESS_CODE) {
  284. if (res.data && res.data.data) {
  285. let currentUserCount = res.data.data;
  286. console.log('currentUserCount', currentUserCount);
  287. this.setData({
  288. currentUserCount: currentUserCount
  289. })
  290. }
  291. }
  292. });
  293. },
  294. /**
  295. * @desc : 查询活动
  296. * @author : 周兴
  297. * @date : 2024/4/1
  298. */
  299. getActivity() {
  300. let params = {
  301. appCode: Constants.APP_CODE,
  302. activityTypeList: [Constants.kindCode.activityGrade, Constants.kindCode.activityMenu],
  303. gradeCode: app.globalData.company.gradeCode
  304. }
  305. let service = app.globalData['activityService']
  306. this.excute(service, service.selectActivityItems, params).then(res => {
  307. if (res.data.code == Constants.SUCESS_CODE) {
  308. if (res.data && res.data.data) {
  309. let activityTable = res.data.data;
  310. this.setData({
  311. activityTable: activityTable
  312. })
  313. // 如果是标准版,需要进行截止日期的处理
  314. if (this.data.gradeCode == Constants.gradeCode.STD) {
  315. this.handleDataStd(activityTable);
  316. }
  317. }
  318. }
  319. });
  320. },
  321. /**
  322. * @desc : 标准版处理数据
  323. * @author : 周兴
  324. * @date : 2024/4/1
  325. */
  326. handleDataStd(activityTable) {
  327. if (activityTable && activityTable.length > 0) {
  328. let item = activityTable[0]
  329. this.setData({
  330. curentAdItem: item
  331. })
  332. let summaryInfo = this.data.summaryInfo
  333. let months = item.validLong + item.extraLong
  334. let endDate = new Date().addMonths(months).addDays(-1)
  335. // 如果截止日期是空,就取活动中的截止日期
  336. if (!summaryInfo.userEndDate) {
  337. summaryInfo.userEndDate = endDate.toDateStr();
  338. }
  339. console.log('summaryInfo', summaryInfo.userEndDate, endDate, months);
  340. this.setData({
  341. summaryInfo: summaryInfo
  342. })
  343. // 计算金额
  344. this.countSummaryAmountSTD();
  345. }
  346. },
  347. /**
  348. * 生命周期函数--监听页面加载
  349. */
  350. onLoad(options) {
  351. this.setData({
  352. companyName: app.globalData.company.cpName,
  353. cpManager: app.globalData.company.cpManager,
  354. cpPhone: app.globalData.company.cpPhone,
  355. cpEndDate: app.globalData.company.endDate,
  356. webMaxNum: app.globalData.company.webMaxNum,
  357. wxMaxNum: app.globalData.company.wxMaxNum,
  358. })
  359. // 如果是标准版,需要获取用户授权数(手机)
  360. let summaryInfo = {}
  361. summaryInfo.wxMaxNum = this.data.wxMaxNum
  362. // 续费用户到期日期
  363. summaryInfo.userEndDate = app.globalData.company.userEndDate
  364. this.setData({
  365. summaryInfo: summaryInfo
  366. })
  367. // 获取活动
  368. this.getActivity();
  369. // 获取当前用户授权数
  370. this.getStaffCount();
  371. },
  372. })