activity.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  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 config = require('@/config/config.js');
  13. const app = getApp()
  14. Page({
  15. mixins: [mixins],
  16. /**
  17. * 页面的初始数据
  18. */
  19. data: {
  20. imageUrl: config.image_url + '/static/img/',
  21. // 是否加载完毕
  22. loadFlag: false,
  23. // 是否显示vip
  24. showVip: false,
  25. // 升级标识
  26. upgradeFlag: false,
  27. gradeCode: null,
  28. freeFlag: false,
  29. // 企业名称
  30. companyName: null,
  31. cpManager: null,
  32. cpPhone: null,
  33. webMaxNum: null,
  34. wxMaxNum: null,
  35. cpEndDate: null,
  36. activityTable: null,
  37. vipTable: [],
  38. readFlag: false,
  39. staffCount: {
  40. maxNum: 1,
  41. webMaxNum: 0,
  42. wxMaxNum: 0
  43. },
  44. curentAdItem: null,
  45. // 选择的vip报表
  46. chooseVipFlag: false,
  47. summaryInfo: {},
  48. routeObjName: 'company',
  49. pageFlag: false,
  50. // 当前用户授权数
  51. currentUserCount: null,
  52. //按钮
  53. buttonSaveList: [
  54. { code: 'save', title: mixins.$t('buyNow'), width: '120rpx' }
  55. ],
  56. noticeInfo: Constants.noticeInfo,
  57. funcMenu: [
  58. {
  59. title: '订单开单',
  60. icon: 'btn-account-receivable.png',
  61. },
  62. {
  63. title: '销售出库',
  64. icon: 'btn-shipped.png',
  65. },
  66. {
  67. title: '销售退货',
  68. icon: 'btn-stored.png',
  69. },
  70. {
  71. title: '销售跟踪',
  72. icon: 'btn-shipped-out.png',
  73. },
  74. {
  75. title: '采购订单',
  76. icon: 'btn-account-receivable.png',
  77. },
  78. {
  79. title: '采购入库',
  80. icon: 'btn-shipped.png',
  81. },
  82. {
  83. title: '采购退货',
  84. icon: 'btn-stored.png',
  85. },
  86. {
  87. title: '以销定采',
  88. icon: 'btn-shipped-out.png',
  89. },
  90. ],
  91. funcMenuFlg: false,
  92. userEndDate: null,
  93. // 优惠劵数量获取 积分策略 积分
  94. integral: 0,
  95. viewHeight: 205,
  96. couponList: [],
  97. couponUse: {},
  98. // 策略
  99. integralTacticItem: {},
  100. },
  101. /**
  102. * @desc : 选择活动明细
  103. * @author : 周兴
  104. * @date : 2024/4/1
  105. */
  106. chooseAdItem(e) {
  107. let item = e.currentTarget.dataset.item;
  108. let summaryInfo = this.data.summaryInfo
  109. // 计算截止日期
  110. let months = item.validLong + item.extraLong
  111. let endDate = app.globalData.company.endDate
  112. // 升级需要从当天开始算
  113. if (this.data.upgradeFlag) {
  114. endDate = new Date()
  115. }
  116. endDate = new Date(endDate).addMonths(months).addDays(-1)
  117. summaryInfo.endDate = endDate.toDateStr();
  118. this.setData({
  119. curentAdItem: item,
  120. summaryInfo: summaryInfo
  121. })
  122. // 计算金额
  123. this.countSummaryAmount(item);
  124. },
  125. /**
  126. * @desc : 选择VIP报表明细
  127. * @author : 周兴
  128. * @date : 2024/4/1
  129. */
  130. chooseVipItem(e) {
  131. let item = e.currentTarget.dataset.item
  132. let index = e.currentTarget.dataset.index
  133. let vipTable = this.data.vipTable
  134. item.chooseVipFlag = !item.chooseVipFlag
  135. vipTable[index] = item
  136. this.setData({
  137. chooseVipFlag: !this.data.chooseVipFlag,
  138. vipTable,
  139. })
  140. // 计算金额
  141. this.countSummaryAmountSTD();
  142. },
  143. /**
  144. * @desc : 勾选已阅读表示
  145. * @author : 周兴
  146. * @date : 2024/5/17
  147. */
  148. handleChangeCheckbox(e) {
  149. this.setData({
  150. readFlag: e.detail
  151. })
  152. },
  153. /**
  154. * @desc : 计算金额
  155. * @author : 周兴
  156. * @date : 2024/4/1
  157. */
  158. countSummaryAmount() {
  159. let _this = this
  160. let item = this.data.curentAdItem;
  161. if (!item) return;
  162. let staffCount = this.data.staffCount;
  163. let summaryInfo = this.data.summaryInfo
  164. let amount = 0;
  165. // 先清空
  166. summaryInfo.amountInfo = '';
  167. // 共通用户
  168. if (staffCount.maxNum) {
  169. summaryInfo.amountInfo = item.stdPrice + '(打包价格)*' + staffCount.maxNum
  170. amount += item.stdPrice * staffCount.maxNum
  171. }
  172. // 手机端用户
  173. if (staffCount.wxMaxNum) {
  174. if (summaryInfo.amountInfo) {
  175. summaryInfo.amountInfo += ' + '
  176. }
  177. summaryInfo.amountInfo += item.wxPrice + '(手机端价格)*' + staffCount.wxMaxNum
  178. amount += item.wxPrice * staffCount.wxMaxNum
  179. }
  180. // 电脑端用户
  181. if (staffCount.webMaxNum) {
  182. if (summaryInfo.amountInfo) {
  183. summaryInfo.amountInfo += ' + '
  184. }
  185. summaryInfo.amountInfo += item.webPrice + '(电脑端价格)*' + staffCount.webMaxNum
  186. amount += item.webPrice * staffCount.webMaxNum
  187. }
  188. if (summaryInfo.amountInfo) {
  189. summaryInfo.amountInfo += ' = ' + amount + '(元)'
  190. summaryInfo.amount = amount;
  191. }
  192. // 积分转成现金
  193. let integralRateVal = Number((_this.data.integral / _this.data.integralTacticItem.exchangeRate).toFixed(2))
  194. // 折扣--数据库的值不能超过10
  195. let discount = _this.data.couponUse.discount ? _this.data.couponUse.discount / 10 : 1
  196. if (_this.data.integral > Math.ceil(_this.data.integralTacticItem.exchangeRate * summaryInfo.amount)) {
  197. _this.setData({
  198. integral: Math.ceil(_this.data.integralTacticItem.exchangeRate * summaryInfo.amount)
  199. })
  200. summaryInfo.amount = 0.00
  201. } else {
  202. summaryInfo.amount = Number((summaryInfo.amount - integralRateVal) * discount.toFixed(2))
  203. }
  204. this.setData({
  205. summaryInfo: summaryInfo
  206. })
  207. // 统计两端用户数
  208. this.countStaffInfo();
  209. },
  210. /**
  211. * @desc : 获取标准版的价格显示
  212. * @author : 周兴
  213. * @date : 2024/4/1
  214. */
  215. countSummaryAmountSTD() {
  216. let _this = this
  217. let item = this.data.curentAdItem;
  218. let vipTable = this.data.vipTable
  219. let summaryInfo = this.data.summaryInfo
  220. let amount = 0;
  221. // 先清空
  222. summaryInfo.amountInfo = '';
  223. let extendDays = null;
  224. // 服务器的时间
  225. let nowDate = new Date(this.data.currentDate.toDateStr());
  226. extendDays = new Date(summaryInfo.userEndDate).dayDiff(nowDate) + 1;
  227. if (summaryInfo.wxMaxNum >= 0) {
  228. // 购买授权
  229. if (this.data.buyUser) {
  230. summaryInfo.amountInfo += item.wxPrice + '(元) '
  231. } else {
  232. summaryInfo.amountInfo += item.wxPrice + '(元) ' +
  233. ' * 1(年) * ' + summaryInfo.wxMaxNum + '(个)'
  234. }
  235. amount += item.wxPrice * summaryInfo.wxMaxNum
  236. }
  237. // vip报表
  238. if (vipTable && vipTable.length > 0) {
  239. vipTable.forEach(vipItem => {
  240. if (vipItem.chooseVipFlag) {
  241. summaryInfo.amountInfo += ' + ' + vipItem.wxPrice + '(元/' + vipItem.activityItemDescribe + ') ';
  242. summaryInfo.amountInfo = '( ' + summaryInfo.amountInfo + ' ) ';
  243. amount += vipItem.wxPrice;
  244. }
  245. })
  246. }
  247. // 购买授权
  248. if (this.data.buyUser) {
  249. summaryInfo.amountInfo += ' / 365(天) * ' + extendDays + '(天) * ' + summaryInfo.wxMaxNum + '(个)'
  250. if (summaryInfo.amountInfo) {
  251. amount = (amount / 365 * extendDays).toFixed(2);
  252. summaryInfo.amountInfo += ' = ' + amount + '(元)'
  253. summaryInfo.amount = amount;
  254. }
  255. this.setData({
  256. userEndDate: summaryInfo.userEndDate
  257. })
  258. } else {
  259. // 续费
  260. if (summaryInfo.amountInfo) {
  261. amount = (amount).toFixed(2);
  262. summaryInfo.amountInfo += ' = ' + amount + '(元)'
  263. summaryInfo.amount = amount;
  264. }
  265. let userEndDate = new Date(summaryInfo.userEndDate).addMonths(12).addDays(-1)
  266. this.setData({
  267. userEndDate: userEndDate.toDateStr()
  268. })
  269. }
  270. // 积分转成现金
  271. let integralRateVal = Number((_this.data.integral / _this.data.integralTacticItem.exchangeRate).toFixed(2))
  272. // 折扣--数据库的值不能超过10
  273. let discount = _this.data.couponUse.discount ? _this.data.couponUse.discount / 10 : 1
  274. if (_this.data.integral > Math.ceil(_this.data.integralTacticItem.exchangeRate * summaryInfo.amount)) {
  275. _this.setData({
  276. integral: Math.ceil(_this.data.integralTacticItem.exchangeRate * summaryInfo.amount)
  277. })
  278. summaryInfo.amount = 0.00
  279. } else {
  280. summaryInfo.amount = Number((summaryInfo.amount - integralRateVal) * discount.toFixed(2))
  281. }
  282. // 计算一授权一天的单价
  283. if (summaryInfo.userEndDate) {
  284. let price = (summaryInfo.amount / summaryInfo.wxMaxNum / extendDays).toFixed(2);
  285. summaryInfo.priceInfo = price
  286. summaryInfo.extendDays = extendDays
  287. }
  288. this.setData({
  289. summaryInfo: summaryInfo
  290. })
  291. },
  292. /**
  293. * @desc : 统计电脑端和手机端的用户数
  294. * @author : 周兴
  295. * @date : 2024/4/1
  296. */
  297. countStaffInfo() {
  298. let summaryInfo = this.data.summaryInfo;
  299. let staffCount = this.data.staffCount;
  300. if (!staffCount) {
  301. return;
  302. }
  303. let webNum = staffCount.webMaxNum + staffCount.maxNum
  304. let wxNum = staffCount.wxMaxNum + staffCount.maxNum
  305. summaryInfo.staffInfo = '可配置手机端授权' + wxNum + '个;电脑端授权' + webNum + '个(包含当前用户)'
  306. summaryInfo.webMaxNum = webNum
  307. summaryInfo.wxMaxNum = wxNum
  308. // 升级从当天算
  309. if (this.data.upgradeFlag) {
  310. summaryInfo.buyBeginDate = new Date().addDays(1).toDateStr();
  311. summaryInfo.extendDays = new Date(summaryInfo.endDate).dayDiff(new Date().addDays(1));
  312. } else {
  313. summaryInfo.buyBeginDate = new Date(this.data.cpEndDate).addDays(1).toDateStr();
  314. summaryInfo.extendDays = new Date(summaryInfo.endDate).dayDiff(new Date(this.data.cpEndDate).addDays(1));
  315. }
  316. // 计算一授权一天的单价
  317. let price = (summaryInfo.amount / (webNum + wxNum) / summaryInfo.extendDays).toFixed(2);
  318. summaryInfo.priceInfo = price
  319. this.setData({
  320. summaryInfo: summaryInfo
  321. })
  322. },
  323. /**
  324. * @desc : 修改用户数
  325. * @author : 周兴
  326. * @date : 2024/4/1
  327. */
  328. changeStaffCount(e) {
  329. let staffCount = this.data.staffCount
  330. let ds = e.currentTarget.dataset
  331. if (ds.type == 'wx') {
  332. staffCount.wxMaxNum = e.detail
  333. } else if (ds.type == 'web') {
  334. staffCount.webMaxNum = e.detail
  335. } else {
  336. staffCount.maxNum = e.detail
  337. }
  338. this.setData({
  339. staffCount: staffCount
  340. })
  341. // 计算金额
  342. this.countSummaryAmount();
  343. },
  344. /**
  345. * @desc : 保存
  346. * @author : 周兴
  347. * @date : 2024/4/1
  348. */
  349. handleSave() {
  350. let summaryInfo = this.data.summaryInfo;
  351. let currentUserCount = this.data.currentUserCount
  352. if (!currentUserCount) {
  353. return;
  354. }
  355. if (this.data.gradeCode == Constants.gradeCode.STD) {
  356. // 必须要选择一个授权
  357. if (Number(summaryInfo.wxMaxNum) <= 0 && this.data.buyUser) {
  358. util.showToast('请选择一个授权');
  359. return false
  360. }
  361. // 功能包
  362. let chooseVipFlag = false
  363. this.data.vipTable.forEach(it => {
  364. if (it.chooseVipFlag) {
  365. chooseVipFlag = true
  366. return
  367. }
  368. })
  369. if (Number(summaryInfo.wxMaxNum) <= 0 && !this.data.buyUser && !chooseVipFlag) {
  370. util.showToast('请选择一个授权或功能包');
  371. return false
  372. }
  373. // 判断数量是否超出续约授权
  374. if (currentUserCount.wxNum > summaryInfo.wxMaxNum && summaryInfo.reCountFlag
  375. && currentUserCount.wxNum > 1 && currentUserCount.wxNum - summaryInfo.wxMaxNum > 1) {
  376. let staffInfo = [{ wxMaxNum: Number(this.data.wxMaxNum), title: '当前授权', wxTitle: '手机授权', code: 'current', userTitle: '当前用户' }, { wxMaxNum: this.data.buyUser ? summaryInfo.wxMaxNum : summaryInfo.wxMaxNum + 1, title: '续费授权', wxTitle: '手机授权', code: 'renew' }]
  377. this.save({ saveFlag: false, url: '/package-basic-data/pages/activity/detail/detail?staffInfo=' + JSON.stringify(staffInfo) });
  378. } else {
  379. this.save({});
  380. }
  381. } else {
  382. // 判断数量是否超出续约授权
  383. if (currentUserCount.wxNum > summaryInfo.wxMaxNum || currentUserCount.webNum > summaryInfo.webMaxNum) {
  384. let staffInfo = [{ wxMaxNum: this.data.wxMaxNum, webMaxNum: this.data.webMaxNum, title: '当前授权', wxTitle: '手机授权', webTitle: (app.globalData.company.gradeCode == Constants.gradeCode.STD) ? '' : '电脑授权', code: 'current', userTitle: '当前用户' }, { wxMaxNum: summaryInfo.wxMaxNum, webMaxNum: summaryInfo.webMaxNum, title: '续费授权', wxTitle: '手机授权', webTitle: '电脑授权', code: 'renew' }]
  385. this.save({ saveFlag: false, url: '/package-basic-data/pages/activity/detail/detail?staffInfo=' + JSON.stringify(staffInfo) });
  386. } else {
  387. this.save({});
  388. }
  389. }
  390. },
  391. /**
  392. * @desc : 改变用户授权数
  393. * @author : 周兴
  394. * @date : 2024/4/1
  395. */
  396. changeUserSTD(e) {
  397. let summaryInfo = this.data.summaryInfo
  398. summaryInfo.wxMaxNum = e.detail
  399. this.setData({
  400. summaryInfo: summaryInfo
  401. })
  402. wx.nextTick(() => {
  403. // 计算金额
  404. this.countSummaryAmountSTD();
  405. });
  406. },
  407. /**
  408. * @desc : 校验
  409. * @author : 周兴
  410. * @date : 2024/4/1
  411. */
  412. validData() {
  413. // 专业版校验
  414. if (this.data.gradeCode == Constants.gradeCode.PRO) {
  415. // if (!this.data.readFlag) {
  416. // util.showToast('请勾选阅读须知');
  417. // return false;
  418. // }
  419. let curentAdItem = this.data.curentAdItem;
  420. if (!curentAdItem) {
  421. util.showToast('请选择活动');
  422. return false
  423. }
  424. // 必须要选择一个授权
  425. let staffCount = this.data.staffCount
  426. if (!staffCount.maxNum && !staffCount.webMaxNum && !staffCount.wxMaxNum) {
  427. util.showToast('请选择一个授权');
  428. return false
  429. }
  430. } else {
  431. let curentAdItem = this.data.curentAdItem;
  432. if (!curentAdItem) {
  433. util.showToast('请选择活动');
  434. return false
  435. }
  436. }
  437. return true;
  438. },
  439. /**
  440. * @desc : 设置保存参数
  441. * @author : 周兴
  442. * @date : 2024/4/1
  443. */
  444. setParams(params) {
  445. let summaryInfo = this.data.summaryInfo
  446. let curentAdItem = this.data.curentAdItem
  447. let cpEndDate = this.data.cpEndDate
  448. if (!summaryInfo || !cpEndDate) return;
  449. params.endDate = summaryInfo.endDate
  450. params.userEndDate = summaryInfo.userEndDate
  451. params.gradeCode = this.data.gradeCode
  452. params.cpId = app.globalData.company.cpId
  453. params.tradeNo = this.generateRandomNo();
  454. params.wxUserId = app.globalData.user.userId
  455. params.tradeAmount = summaryInfo.amount
  456. params.buyBeginDate = summaryInfo.buyBeginDate;
  457. params.buyEndDate = summaryInfo.endDate
  458. params.extendDays = summaryInfo.extendDays;
  459. if (this.data.gradeCode == Constants.gradeCode.STD) {
  460. params.buyEndDate = summaryInfo.userEndDate
  461. params.endDate = app.globalData.company.endDate
  462. params.wxMaxNum = summaryInfo.wxMaxNum
  463. if (!summaryInfo.reCountFlag && summaryInfo.wxMaxNumSocial) {
  464. params.wxMaxNum = summaryInfo.wxMaxNum + summaryInfo.wxMaxNumSocial
  465. }
  466. let funPackage = app.globalData.company.funPackage ? [...app.globalData.company.funPackage] : []
  467. params.funPackage = funPackage
  468. // 选中的功能包的数据
  469. let activityIds = []
  470. let itemIds = []
  471. this.data.vipTable.forEach(it => {
  472. if (it.chooseVipFlag) {
  473. activityIds.push(it.activityId)
  474. itemIds.push(it.itemId)
  475. }
  476. })
  477. if (activityIds.length > 0) {
  478. params.activityIds = activityIds
  479. params.activityItemIds = itemIds
  480. }
  481. // 续费的时候需要传
  482. // 购买授权
  483. if (this.data.buyUser) {
  484. params.reNew = app.globalData.company.reNew
  485. } else {
  486. let funPackages = []
  487. this.data.vipTable.forEach(it => {
  488. if (it.chooseVipFlag) {
  489. funPackages.push({
  490. activityId: it.activityId,
  491. funUuids: it.funUuids
  492. })
  493. }
  494. })
  495. let renew = {
  496. "user_end_date": this.data.userEndDate,
  497. "wx_max_num": summaryInfo.wxMaxNum + 1,
  498. "fun_package": funPackages.length > 0 ? funPackages : null,
  499. }
  500. params.reNew = renew
  501. // 续费时候保持原来的 微信人数
  502. params.wxMaxNum = summaryInfo.wxMaxNumSocial
  503. }
  504. params.webMaxNum = 0
  505. params.remarks = summaryInfo.amountInfo
  506. // 交易类型-续费
  507. params.tradeType = '交易类型-续费'
  508. } else {
  509. params.webMaxNum = summaryInfo.webMaxNum
  510. params.wxMaxNum = summaryInfo.wxMaxNum
  511. }
  512. params.buyLong = curentAdItem.activityItemName
  513. // 操作员
  514. params.staffNameFrom = app.globalData.user.staffName
  515. // 优惠券使用id 金额大于0
  516. params.couponUseId = this.data.couponUse.useId && Number(summaryInfo.amount) > 0
  517. ? this.data.couponUse.useId : null
  518. params.integral = this.data.integral
  519. return params;
  520. },
  521. /**
  522. * @desc : 保存数据
  523. * @author : 周兴
  524. * @date : 2024/5/17
  525. */
  526. saveData(params) {
  527. return this.excute(this.data.service, this.data.service.reNewCompany, this.data.params).then(res => {
  528. if (res.data.code == Constants.SUCESS_CODE && Number(this.data.summaryInfo.amount) > 0) {
  529. // 成功后跳转支付
  530. this.toPay(res.data.data);
  531. }
  532. })
  533. },
  534. /**
  535. * @desc : 查询当前用户授权数
  536. * @author : 周兴
  537. * @date : 2024/4/1
  538. */
  539. getStaffCount() {
  540. let service = app.globalData['commonService']
  541. this.excute(service, service.selectUserCount, {}).then(res => {
  542. if (res.data.code == Constants.SUCESS_CODE) {
  543. if (res.data && res.data.data) {
  544. let currentUserCount = res.data.data;
  545. this.setData({
  546. currentUserCount: currentUserCount,
  547. //服务器的时间
  548. currentDate: new Date(currentUserCount.currentDate)
  549. })
  550. }
  551. }
  552. this.setData({
  553. loadFlag: true
  554. })
  555. });
  556. },
  557. /**
  558. * @desc : 关闭所有的tip
  559. * @date : 2024/5/24 15:49
  560. * @author : 王英杰
  561. */
  562. closeAllTips() {
  563. this.closeTips(['tipIntegral'])
  564. },
  565. /**
  566. * @desc : 优惠劵数量获取 积分策略 积分
  567. * @author : 刘尧
  568. * @date : 2024/7/29 15:54
  569. */
  570. getCouponUse() {
  571. let _this = this
  572. this.setData({
  573. loading: true
  574. })
  575. let params = {
  576. couponStatus: Constants.couponStatus.unused,
  577. flgValid: true,
  578. cpId: app.globalData.company.cpId,
  579. }
  580. let service = app.globalData['couponUseService']
  581. this.excute(service, service.listByCondUse, params).then(res => {
  582. if (res.data && res.data.data) {
  583. // 优惠劵数量获取
  584. if (res.data.data.list && res.data.data.list.length > 0) {
  585. this.setData({
  586. couponList: res.data.data.list,
  587. couponUse: res.data.data.list[0],
  588. viewHeight: this.data.viewHeight + 45
  589. })
  590. }
  591. // 积分
  592. if (res.data.data.integral) {
  593. this.setData({
  594. integral: res.data.data.integral,
  595. viewHeight: this.data.viewHeight + 45
  596. })
  597. }
  598. // 积分策略
  599. if (res.data.data.listIntegralTactic && res.data.data.listIntegralTactic.length > 0) {
  600. this.setData({
  601. integralTacticItem: res.data.data.listIntegralTactic[0],
  602. })
  603. }
  604. }
  605. // 获取活动
  606. _this.getActivity()
  607. });
  608. },
  609. /**
  610. * @desc : 查询活动
  611. * @author : 周兴
  612. * @date : 2024/4/1
  613. */
  614. getActivity() {
  615. let params = {
  616. appCode: Constants.APP_CODE,
  617. activityStatus: Constants.kindCode.activityStatus,
  618. cpId: app.globalData.company.cpId,
  619. gradeCode: this.data.gradeCode
  620. }
  621. // 标准版
  622. if (this.data.gradeCode == Constants.gradeCode.STD) {
  623. if (this.data.buyUser) {
  624. params.activityTypeList = [Constants.kindCode.activityGrade];
  625. } else {
  626. params.activityTypeList = [Constants.kindCode.activityGrade, Constants.kindCode.activityFunc];
  627. }
  628. } else {
  629. params.activityTypeList = [Constants.kindCode.activityGrade, Constants.kindCode.activityVip];
  630. }
  631. let service = app.globalData['activityService']
  632. this.excute(service, service.selectActivityItems, params).then(res => {
  633. if (res.data.code == Constants.SUCESS_CODE) {
  634. if (res.data && res.data.data) {
  635. let activityTable = res.data.data;
  636. // 如果是标准版,需要进行截止日期的处理
  637. if (this.data.gradeCode == Constants.gradeCode.STD) {
  638. this.setData({
  639. activityTable: activityTable.filter(it => it.activityType == Constants.kindCode.activityGrade),
  640. vipTable: activityTable.filter(it => it.activityType == Constants.kindCode.activityFunc),
  641. })
  642. this.handleDataStd(activityTable);
  643. } else {
  644. this.setData({
  645. activityTable: activityTable
  646. })
  647. }
  648. }
  649. }
  650. this.setData({
  651. loading: false
  652. })
  653. });
  654. },
  655. /**
  656. * @desc : 标准版处理数据
  657. * @author : 周兴
  658. * @date : 2024/4/1
  659. */
  660. handleDataStd(activityTable) {
  661. if (activityTable && activityTable.length > 0) {
  662. let item = activityTable[0]
  663. this.setData({
  664. curentAdItem: item
  665. })
  666. let summaryInfo = this.data.summaryInfo
  667. let months = item.validLong + item.extraLong
  668. //服务器的时间
  669. let endDate = this.data.currentDate.addMonths(months).addDays(-1)
  670. let dayDiffs = null;
  671. if (summaryInfo.userEndDate) {
  672. dayDiffs = new Date(summaryInfo.userEndDate).dayDiff(this.data.currentDate)
  673. }
  674. // 如果截止日期是空,就取活动中的截止日期
  675. if (!summaryInfo.userEndDate || !dayDiffs || dayDiffs < 0) {
  676. summaryInfo.userEndDate = endDate.toDateStr();
  677. // 重新统计,到期续费或者第一次购买用户
  678. summaryInfo.reCountFlag = true;
  679. summaryInfo.wxMaxNum = summaryInfo.wxMaxNumSocial
  680. this.setData({
  681. showVip: true
  682. })
  683. } else {
  684. // 如果没有购买,需要显示
  685. if (!app.globalData.company.vip) {
  686. this.setData({
  687. showVip: true
  688. })
  689. }
  690. }
  691. summaryInfo.buyBeginDate = this.data.currentDate.toDateStr();
  692. this.setData({
  693. summaryInfo: summaryInfo
  694. })
  695. wx.nextTick(() => {
  696. // 计算金额
  697. this.countSummaryAmountSTD();
  698. });
  699. }
  700. },
  701. /**
  702. * 生命周期函数--监听页面加载
  703. */
  704. onLoad(options) {
  705. // 升级
  706. if (options && options.upgrade) {
  707. wx.setNavigationBarTitle({
  708. title: mixins.$t('updateSpecialized'),
  709. })
  710. this.setData({
  711. gradeCode: Constants.gradeCode.PRO,
  712. upgradeFlag: true
  713. })
  714. } else {
  715. // 购买授权 和续费
  716. if (options.buyUser) {
  717. wx.setNavigationBarTitle({
  718. title: mixins.$t('buyUser'),
  719. })
  720. } else {
  721. wx.setNavigationBarTitle({
  722. title: mixins.$t('reNew'),
  723. })
  724. }
  725. this.setData({
  726. gradeCode: app.globalData.company.gradeCode,
  727. buyUser: options.buyUser
  728. })
  729. }
  730. this.setData({
  731. companyName: app.globalData.company.cpName,
  732. cpManager: app.globalData.company.cpManager,
  733. cpPhone: app.globalData.company.cpPhone,
  734. cpEndDate: app.globalData.company.endDate,
  735. webMaxNum: app.globalData.company.webMaxNum,
  736. wxMaxNum: app.globalData.company.wxMaxNum,
  737. })
  738. // 如果是标准版,需要获取用户授权数(手机)
  739. let summaryInfo = {}
  740. if (app.globalData.company.gradeCode == Constants.gradeCode.STD && !options.buyUser) {
  741. summaryInfo.wxMaxNum = app.globalData.company.wxMaxNum
  742. summaryInfo.reCountFlag = true
  743. } else {
  744. summaryInfo.wxMaxNum = 1
  745. }
  746. summaryInfo.wxMaxNumSocial = this.data.wxMaxNum
  747. // 续费用户到期日期
  748. summaryInfo.userEndDate = app.globalData.company.userEndDate
  749. this.setData({
  750. summaryInfo: summaryInfo,
  751. })
  752. // 获取活动
  753. // this.getActivity();
  754. // 获取当前用户授权数
  755. this.getStaffCount();
  756. // 优惠劵数量获取 积分策略 积分
  757. this.getCouponUse()
  758. },
  759. /**
  760. * 六大功能的切换
  761. */
  762. funcClick(e) {
  763. let funcMenuFlg = !this.data.funcMenuFlg
  764. if (funcMenuFlg) {
  765. this.setData({
  766. funcMenu: [
  767. {
  768. title: '订单开单',
  769. icon: 'btn-account-receivable.png',
  770. },
  771. {
  772. title: '销售出库',
  773. icon: 'btn-shipped.png',
  774. },
  775. {
  776. title: '销售退货',
  777. icon: 'btn-stored.png',
  778. },
  779. {
  780. title: '销售跟踪',
  781. icon: 'btn-shipped-out.png',
  782. },
  783. {
  784. title: '采购订单',
  785. icon: 'btn-account-receivable.png',
  786. },
  787. {
  788. title: '采购入库',
  789. icon: 'btn-shipped.png',
  790. },
  791. {
  792. title: '采购退货',
  793. icon: 'btn-stored.png',
  794. },
  795. {
  796. title: '以销定采',
  797. icon: 'btn-shipped-out.png',
  798. },
  799. {
  800. title: '库存查询',
  801. icon: 'btn-account-receivable.png',
  802. },
  803. {
  804. title: '入库办理',
  805. icon: 'btn-shipped.png',
  806. },
  807. {
  808. title: '出库办理',
  809. icon: 'btn-stored.png',
  810. },
  811. {
  812. title: '库存盘点',
  813. icon: 'btn-shipped-out.png',
  814. },
  815. {
  816. title: '资金账户',
  817. icon: 'btn-account-receivable.png',
  818. },
  819. {
  820. title: '资金转账',
  821. icon: 'btn-shipped.png',
  822. },
  823. {
  824. title: '收款单',
  825. icon: 'btn-stored.png',
  826. },
  827. {
  828. title: '付款单',
  829. icon: 'btn-shipped-out.png',
  830. },
  831. {
  832. title: '日结对账',
  833. icon: 'btn-account-receivable.png',
  834. },
  835. {
  836. title: '资金日记账',
  837. icon: 'btn-shipped.png',
  838. },
  839. {
  840. title: '供应商往来',
  841. icon: 'btn-stored.png',
  842. },
  843. ],
  844. })
  845. } else {
  846. this.setData({
  847. funcMenu: [
  848. {
  849. title: '订单开单',
  850. icon: 'btn-account-receivable.png',
  851. },
  852. {
  853. title: '销售出库',
  854. icon: 'btn-shipped.png',
  855. },
  856. {
  857. title: '销售退货',
  858. icon: 'btn-stored.png',
  859. },
  860. {
  861. title: '销售跟踪',
  862. icon: 'btn-shipped-out.png',
  863. },
  864. {
  865. title: '采购订单',
  866. icon: 'btn-account-receivable.png',
  867. },
  868. {
  869. title: '采购入库',
  870. icon: 'btn-shipped.png',
  871. },
  872. {
  873. title: '采购退货',
  874. icon: 'btn-stored.png',
  875. },
  876. {
  877. title: '以销定采',
  878. icon: 'btn-shipped-out.png',
  879. },
  880. ],
  881. })
  882. }
  883. this.setData({
  884. funcMenuFlg
  885. })
  886. },
  887. })