|
@@ -0,0 +1,746 @@
|
|
|
+var vm = new Vue({
|
|
|
+ delimiters: ['${', '}'],
|
|
|
+ el: '#app',
|
|
|
+ data: function () {
|
|
|
+ return {
|
|
|
+ endTime: '',
|
|
|
+ endDay: -1,
|
|
|
+ sessKey: '$data-file-pack-buy',
|
|
|
+ preferentialShow: false,
|
|
|
+ specTitleShow: false,
|
|
|
+ buyType: 'buy', // buy购买, renew续费, upgrade升级
|
|
|
+ userInfo: {
|
|
|
+ phone: ''
|
|
|
+ },
|
|
|
+ // 已经购买的信息
|
|
|
+ alreadyBuyInfo: {
|
|
|
+ loaded: false,
|
|
|
+ ppstart: 0,
|
|
|
+ ppend: 0,
|
|
|
+ areanum: 0, // 可调整地区次数
|
|
|
+ provincenum: 0, // 已购买省份数量
|
|
|
+ area: {},
|
|
|
+ simulatedAmount: false, // 模拟金额(购买时候进入,省份数量不足购买条件,默认展示1个月价格)
|
|
|
+ },
|
|
|
+ // 选择的省份数量
|
|
|
+ areaInfo: '', // 空字符串或者null表示未选择省份,空对象表示全国/provinceMaxCount
|
|
|
+ priceInfo: {
|
|
|
+ provinceFreeCount: 1, // 免费省份数量
|
|
|
+ provinceMaxCount: 15, // 选择的大于15表示全国
|
|
|
+ month: {}
|
|
|
+ },
|
|
|
+ priceMap: {},
|
|
|
+ specActive: 1,
|
|
|
+ specList: [
|
|
|
+ {
|
|
|
+ cycleType: 1, // 月
|
|
|
+ label: '5个附件',
|
|
|
+ value: '1',
|
|
|
+ price: 0,
|
|
|
+ desc: '',
|
|
|
+ perDayPrice: 0,
|
|
|
+ productId: 1141,
|
|
|
+ id: 5
|
|
|
+ },
|
|
|
+ {
|
|
|
+ cycleType: 2, // 季
|
|
|
+ label: '10个附件',
|
|
|
+ value: '2',
|
|
|
+ price: 0,
|
|
|
+ desc: '',
|
|
|
+ perDayPrice: 0,
|
|
|
+ productId: 1142,
|
|
|
+ id: 10
|
|
|
+ },
|
|
|
+ {
|
|
|
+ cycleType: 3, // 年
|
|
|
+ label: '20个附件',
|
|
|
+ value: '3',
|
|
|
+ price: 0,
|
|
|
+ desc: '',
|
|
|
+ perDayPrice: 0,
|
|
|
+ productId: 1143,
|
|
|
+ id: 20
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ bottomConf: {
|
|
|
+ type: '',
|
|
|
+ initPrice: 0,
|
|
|
+ realPrice: 0,
|
|
|
+ disPrice: 0,
|
|
|
+ checkboxStatus: false,
|
|
|
+ hideCoupon: false,
|
|
|
+ links: [
|
|
|
+ {
|
|
|
+ text: '《剑鱼标讯线上购买与服务条款》',
|
|
|
+ url: '',
|
|
|
+ event: this.readEvent
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ buttons: {
|
|
|
+ submit: this.submitOrder
|
|
|
+ }
|
|
|
+ },
|
|
|
+ dialog: {
|
|
|
+ backTip: false,
|
|
|
+ backTipShowCount: 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ buyTypeText: function () {
|
|
|
+ if (this.buyType === 'upgrade') {
|
|
|
+ return '升级'
|
|
|
+ } else if (this.buyType === 'renew') {
|
|
|
+ return '续费'
|
|
|
+ } else {
|
|
|
+ return '购买'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ perMonthArea: function () {
|
|
|
+ var info = this.priceInfo
|
|
|
+ if (!info.month) return 0
|
|
|
+ if (!info.month.oneProvince_allBuyerClass) return 0
|
|
|
+ return info.month.oneProvince_allBuyerClass / 100
|
|
|
+ },
|
|
|
+ selectAreaText: function () {
|
|
|
+ var text = ''
|
|
|
+ if (this.areaInfo) {
|
|
|
+ var keys = Object.keys(this.areaInfo)
|
|
|
+ if (keys.length) {
|
|
|
+ text = keys.join('、')
|
|
|
+ } else {
|
|
|
+ text = '全国'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return text
|
|
|
+ },
|
|
|
+ // 选中的省份数量
|
|
|
+ selectAreaCount: function () {
|
|
|
+ var count = 0
|
|
|
+ if (this.areaInfo) {
|
|
|
+ var keyLength = Object.keys(this.areaInfo).length
|
|
|
+ if (keyLength === 0 || keyLength > this.priceInfo.provinceMaxCount) {
|
|
|
+ count = -1 // -1表示全国
|
|
|
+ } else {
|
|
|
+ count = keyLength
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return count
|
|
|
+ },
|
|
|
+ buyAreaText: function () {
|
|
|
+ var buyAreaCount = this.buyAreaCount
|
|
|
+ if (buyAreaCount === -1) {
|
|
|
+ return '全国'
|
|
|
+ } else {
|
|
|
+ return (buyAreaCount >= 0 ? buyAreaCount : 0) + ' 个省'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 购买的省份数量 = 选中数量 - 免费数量
|
|
|
+ buyAreaCount: function () {
|
|
|
+ if (this.buyType === 'renew') {
|
|
|
+ return this.renewAreaCount
|
|
|
+ } else {
|
|
|
+ var selectCount = this.selectAreaCount
|
|
|
+ if (selectCount === -1) {
|
|
|
+ return selectCount
|
|
|
+ } else {
|
|
|
+ var buyCount = selectCount - this.priceInfo.provinceFreeCount
|
|
|
+ return buyCount >= 0 ? buyCount : 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ renewAreaCount: function () {
|
|
|
+ var buyCount = this.alreadyBuyInfo.provincenum
|
|
|
+ if (buyCount) {
|
|
|
+ return buyCount
|
|
|
+ } else {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ },
|
|
|
+ upgradeAreaText: function () {
|
|
|
+ if (this.upgradeAreaCount === -1) {
|
|
|
+ return '全国'
|
|
|
+ } else {
|
|
|
+ return this.upgradeAreaCount + '个省'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 升级数量 = 选中数量 - 已购买数量 - 免费数量
|
|
|
+ upgradeAreaCount: function () {
|
|
|
+ var alreadyBuyCount = this.getAlreadyBuyCount()
|
|
|
+ return this.selectAreaCount - alreadyBuyCount - this.priceInfo.provinceFreeCount
|
|
|
+ },
|
|
|
+ // 选中的规格卡片info
|
|
|
+ selectedSpecItem: function () {
|
|
|
+ var _this = this
|
|
|
+ var t = {}
|
|
|
+ this.specList.some(function (item) {
|
|
|
+ var gotThis = item.cycleType == _this.specActive
|
|
|
+ if (gotThis) {
|
|
|
+ t = item
|
|
|
+ }
|
|
|
+ return gotThis
|
|
|
+ })
|
|
|
+ return t
|
|
|
+ },
|
|
|
+ // 手机号校验是否通过
|
|
|
+ validatorPhonePass: function () {
|
|
|
+ var phone = this.userInfo.phone
|
|
|
+ if (!phone) return true
|
|
|
+ return /^1\d{10}$/.test(phone)
|
|
|
+ },
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ validatorPhonePass: function () {
|
|
|
+ this.checkStatus()
|
|
|
+ },
|
|
|
+ },
|
|
|
+ created: function () {
|
|
|
+ this.getVipEndTime()
|
|
|
+ },
|
|
|
+ mounted: function () {
|
|
|
+ var restore = this.restoreState()
|
|
|
+ if (restore) {
|
|
|
+ this.getPrice()
|
|
|
+ } else {
|
|
|
+ this.getGoodsList()
|
|
|
+ this.getUserInfo()
|
|
|
+ this.getGiftInfo()
|
|
|
+ }
|
|
|
+ this.setTitle()
|
|
|
+ this.checkConfirmButtonDisabled()
|
|
|
+ utils.iosBackRefresh()
|
|
|
+ // if (this.buyType === 'buy') {
|
|
|
+ // this.addBackTip()
|
|
|
+ // }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ getMonthEndTime: function (date) {
|
|
|
+ var tempDate = new Date(date)
|
|
|
+ let month = tempDate.getMonth()
|
|
|
+ var new_year = tempDate.getFullYear(); //取当前的年份
|
|
|
+ var new_month = ++month; //取下一个月的第一天,方便计算(最后一天不固定)
|
|
|
+ if (month > 12) {
|
|
|
+ new_month -= 12; //月份减
|
|
|
+ new_year++; //年份增
|
|
|
+ }
|
|
|
+ var new_date = new Date(new_year, new_month, 1); //取当年当月中的第一天
|
|
|
+ return (new Date(new_date.getTime() - 1000));
|
|
|
+ },
|
|
|
+ getDayDiff: function (date1, date2, unit) {
|
|
|
+ var myDate1 = typeof date1 === 'string' && date1.includes('-') ? date1.replace(/-/g, '/') : date1;
|
|
|
+ var myDate2 = typeof date2 === 'string' && date2.includes('-') ? date2.replace(/-/g, '/') : date2;
|
|
|
+ var map = {
|
|
|
+ day: 1000 * 60 * 60 * 24,
|
|
|
+ hour: 1000 * 60 * 60,
|
|
|
+ minute: 1000 * 60,
|
|
|
+ second: 1000,
|
|
|
+ ms: 1,
|
|
|
+ };
|
|
|
+ return ((new Date(myDate2) - new Date(myDate1)) / (map[unit]));
|
|
|
+ },
|
|
|
+ getEndTime: function (vipEndTime) {
|
|
|
+ var nowDate = new Date().getTime()
|
|
|
+ var monthEndDate = this.getMonthEndTime(nowDate)
|
|
|
+ if (vipEndTime) {
|
|
|
+ var vipEndDate = new Date(vipEndTime)
|
|
|
+ if (vipEndDate.getTime() < monthEndDate.getTime()) {
|
|
|
+ monthEndDate = vipEndDate
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var diffDay = this.getDayDiff(nowDate, monthEndDate.getTime(), 'day')
|
|
|
+ const result = Math.ceil(diffDay)
|
|
|
+ this.endTime = monthEndDate.pattern('yyyy.MM.dd')
|
|
|
+ this.endDay = result
|
|
|
+ },
|
|
|
+ getVipEndTime: function () {
|
|
|
+ $.ajax({
|
|
|
+ url: '/subscribepay/vipsubscribe/getSubBuyMsg',
|
|
|
+ type: 'GET',
|
|
|
+ success: function (res) {
|
|
|
+ console.log(res)
|
|
|
+ if (res && res.data && res.data.endTime) {
|
|
|
+ this.getEndTime(res.data.endTime * 1000)
|
|
|
+ }
|
|
|
+ }.bind(this)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ showLoading: function () {
|
|
|
+ return this.$toast.loading({
|
|
|
+ duration: 0,
|
|
|
+ forbidClick: true,
|
|
|
+ message: 'loading...',
|
|
|
+ })
|
|
|
+ },
|
|
|
+ showToast: function (message) {
|
|
|
+ return this.$toast({
|
|
|
+ duration: 1500,
|
|
|
+ forbidClick: true,
|
|
|
+ message: message,
|
|
|
+ })
|
|
|
+ },
|
|
|
+ showDialog: function (conf) {
|
|
|
+ var defaultConf = {
|
|
|
+ title: '提示',
|
|
|
+ message: 'message',
|
|
|
+ className: 'j-confirm-dialog',
|
|
|
+ showConfirmButton: true,
|
|
|
+ showCancelButton: true,
|
|
|
+ confirmButtonColor: '#2abed1'
|
|
|
+ }
|
|
|
+ if (conf) {
|
|
|
+ Object.assign(defaultConf, conf)
|
|
|
+ }
|
|
|
+ return this.$dialog.confirm(defaultConf)
|
|
|
+ },
|
|
|
+ setTitle: function () {
|
|
|
+ var titleMap = {
|
|
|
+ buy: '附件下载包充值',
|
|
|
+ renew: '续费省份订阅包',
|
|
|
+ upgrade: '升级省份订阅包',
|
|
|
+ }
|
|
|
+ var title = titleMap[this.buyType]
|
|
|
+ document.title = title
|
|
|
+ try {
|
|
|
+ setHeaderTitle(title)
|
|
|
+ } catch (error) {}
|
|
|
+ },
|
|
|
+ getUrlArea: function () {
|
|
|
+ var area = utils.getParam('area')
|
|
|
+ if (area) {
|
|
|
+ var areaInfo = JSON.parse(decodeURIComponent(area))
|
|
|
+ if (!Array.isArray(areaInfo)) {
|
|
|
+ this.areaInfo = areaInfo
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getAlreadyBuyCount: function () {
|
|
|
+ var buyInfo = this.alreadyBuyInfo
|
|
|
+ if (!buyInfo) return 0
|
|
|
+ if (!buyInfo.provincenum) return 0
|
|
|
+ return buyInfo.provincenum
|
|
|
+ },
|
|
|
+ // 获取用户信息
|
|
|
+ getUserInfo: function () {
|
|
|
+ var _this = this
|
|
|
+ $.ajax({
|
|
|
+ url: '/jypay/user/getAccountInfo?t=' + Date.now(),
|
|
|
+ type: 'GET',
|
|
|
+ success: function (res) {
|
|
|
+ if (res && res.error_code === 0) {
|
|
|
+ Object.assign(_this.userInfo, res.data)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ getGoodsList: function () {
|
|
|
+ var _this = this
|
|
|
+ var loading = this.showLoading()
|
|
|
+ $.ajax({
|
|
|
+ url: '/jypay/resourcePack/price',
|
|
|
+ type: 'POST',
|
|
|
+ data: {
|
|
|
+ 'product': 'attachmentDownPack'
|
|
|
+ },
|
|
|
+ success: function (res) {
|
|
|
+ loading && loading.clear()
|
|
|
+ if (res && res.data) {
|
|
|
+
|
|
|
+ Object.assign(_this.priceMap, res.data)
|
|
|
+ // _this.getBuyInfo()
|
|
|
+ _this.getPrice()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: function () {
|
|
|
+ loading && loading.clear()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 获取已购买信息
|
|
|
+ getBuyInfo: function () {
|
|
|
+ var _this = this
|
|
|
+ var loading = this.showLoading()
|
|
|
+ $.ajax({
|
|
|
+ url: '/publicapply/free/subscribe',
|
|
|
+ type: 'POST',
|
|
|
+ success: function (res) {
|
|
|
+ loading && loading.clear()
|
|
|
+ _this.alreadyBuyInfo.loaded = true
|
|
|
+ if (res && res.error_code === 0) {
|
|
|
+ // _this.checkBuyStatus(res.data)
|
|
|
+ for (var key in res.data) {
|
|
|
+ _this.$set(_this.alreadyBuyInfo, key, res.data[key])
|
|
|
+ }
|
|
|
+ _this.getUrlArea()
|
|
|
+ if (!_this.areaInfo) {
|
|
|
+ _this.$set(_this, 'areaInfo', res.data.area)
|
|
|
+ }
|
|
|
+ _this.getPrice()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: function () {
|
|
|
+ loading && loading.clear()
|
|
|
+ _this.getPrice()
|
|
|
+ _this.alreadyBuyInfo.loaded = true
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 检查是否满足购买/续费/升级的条件
|
|
|
+ checkBuyStatus: function (data) {
|
|
|
+ if (!data) return
|
|
|
+ var buyCount = data.provincenum
|
|
|
+ if (buyCount === -1) {
|
|
|
+ if (this.buyType !== 'renew') {
|
|
|
+ this.buyType === 'renew'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 获取赠品信息
|
|
|
+ getGiftInfo: function () {
|
|
|
+ var _this = this
|
|
|
+ this.specList.forEach(function (spec) {
|
|
|
+ $.ajax({
|
|
|
+ url: '/jyCoupon/giveInfo',
|
|
|
+ type: 'POST',
|
|
|
+ data: {
|
|
|
+ useProduct: spec.productId,
|
|
|
+ useProductType: 0
|
|
|
+ },
|
|
|
+ success: function (res) {
|
|
|
+ if (res && res.error_code === 0) {
|
|
|
+ _this.$set(spec, 'giftList', res.data)
|
|
|
+ _this.renderGiftInfo(spec)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ renderGiftInfo: function (spec) {
|
|
|
+ var price = spec.price
|
|
|
+ var giftContent = this.calcGiftInfo(spec.giftList)
|
|
|
+ // 赠品信息展示
|
|
|
+ if (giftContent && price) {
|
|
|
+ var labelSubInfo = `  <span class="highlight-text">赠${giftContent.giveTimeText}</span>`
|
|
|
+ this.$set(spec, 'labelSubInfo', labelSubInfo)
|
|
|
+ this.$set(spec, 'discountId', giftContent.discountId)
|
|
|
+ } else {
|
|
|
+ this.$set(spec, 'labelSubInfo', '')
|
|
|
+ this.$set(spec, 'discountId', '')
|
|
|
+ }
|
|
|
+ },
|
|
|
+ calcGiftInfo: function (infoList) {
|
|
|
+ if (!Array.isArray(infoList) || infoList.length === 0) return
|
|
|
+ var info = infoList[0]
|
|
|
+ var timeType = ''
|
|
|
+ if (info.timeType == 1) {
|
|
|
+ timeType = '天'
|
|
|
+ } else if (info.timeType == 2) {
|
|
|
+ timeType = '月'
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ discountId: info.discountId,
|
|
|
+ giveTimeText: `${info.time}${timeType}`
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 通用计算价格方法
|
|
|
+ commonGetPrice: function (buyAreaCount, cycleType) {
|
|
|
+ var info = this.priceInfo
|
|
|
+ var isGreaterThanMaxArea = buyAreaCount === -1 // 是否购买全国
|
|
|
+ var priceInfo = {
|
|
|
+ price: 0,
|
|
|
+ perDayPrice: 0
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (cycleType) {
|
|
|
+ // 1个月
|
|
|
+ case 1: {
|
|
|
+ var monthPriceFen = isGreaterThanMaxArea ? info.month.allProvince_allBuyerClass : info.month.oneProvince_allBuyerClass * buyAreaCount
|
|
|
+ priceInfo.price = monthPriceFen / 100
|
|
|
+ priceInfo.perDayPrice = buyAreaCount === 0 ? 0 : (priceInfo.price / 30).toFixed(2)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ // 1个季度
|
|
|
+ case 2: {
|
|
|
+ var quarterPriceFen = isGreaterThanMaxArea ? info.quarter.allProvince_allBuyerClass : info.quarter.oneProvince_allBuyerClass * buyAreaCount
|
|
|
+ priceInfo.price = quarterPriceFen / 100
|
|
|
+ priceInfo.perDayPrice = buyAreaCount === 0 ? 0 : (priceInfo.price / (30 * 3)).toFixed(2)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ // 1年
|
|
|
+ case 3: {
|
|
|
+ var yearPriceFen = isGreaterThanMaxArea ? info.year.allProvince_allBuyerClass : info.year.oneProvince_allBuyerClass * buyAreaCount
|
|
|
+ priceInfo.price = yearPriceFen / 100
|
|
|
+ priceInfo.perDayPrice = buyAreaCount === 0 ? 0 : (priceInfo.price / 365).toFixed(2)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ default: {
|
|
|
+ return priceInfo
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return priceInfo
|
|
|
+ },
|
|
|
+ getUpgradePrice: function () {
|
|
|
+ var buyInfo = this.alreadyBuyInfo
|
|
|
+ // 获取剩余周期
|
|
|
+ var lastCycle = getDateSub(buyInfo.ppstart, buyInfo.ppend)
|
|
|
+ var lastYear = lastCycle[0]
|
|
|
+ var lastMonth = lastCycle[1]
|
|
|
+ console.log(`剩余周期:年:${lastYear},月:${lastMonth}`)
|
|
|
+
|
|
|
+ var beforePrice = 0
|
|
|
+ var newPrice = 0
|
|
|
+
|
|
|
+ var oldBuyAreaCount = this.alreadyBuyInfo.provincenum
|
|
|
+ var newBuyAreaCount = this.buyAreaCount
|
|
|
+
|
|
|
+ if (lastMonth !== 0) {
|
|
|
+ beforePrice += this.commonGetPrice(oldBuyAreaCount, this.specList[0].cycleType).price * lastMonth * 100
|
|
|
+ newPrice += this.commonGetPrice(newBuyAreaCount, this.specList[0].cycleType).price * lastMonth * 100
|
|
|
+ }
|
|
|
+
|
|
|
+ if (lastYear !== 0) {
|
|
|
+ beforePrice += this.commonGetPrice(oldBuyAreaCount, this.specList[2].cycleType).price * lastYear * 100
|
|
|
+ newPrice += this.commonGetPrice(newBuyAreaCount, this.specList[2].cycleType).price * lastYear * 100
|
|
|
+ }
|
|
|
+
|
|
|
+ var priceDiff = (newPrice - beforePrice) / 100
|
|
|
+ console.log('差价:' + priceDiff)
|
|
|
+ return priceDiff >= 0 ? priceDiff : 0
|
|
|
+ },
|
|
|
+ getPrice: function () {
|
|
|
+ this.sortPrice()
|
|
|
+ this.calcPrice()
|
|
|
+ },
|
|
|
+ // 根据请求返回值,计算卡片展示金额
|
|
|
+ sortPrice: function () {
|
|
|
+ var priceInfoArr = []
|
|
|
+
|
|
|
+ this.specList.forEach(function (spec) {
|
|
|
+ spec.price = this.priceMap[spec.id] / 100
|
|
|
+ this.renderGiftInfo(spec)
|
|
|
+ }.bind(this))
|
|
|
+ return priceInfoArr
|
|
|
+ },
|
|
|
+ // 计算支付总金额
|
|
|
+ calcPrice: function () {
|
|
|
+ var p = 0
|
|
|
+ if (this.buyType === 'buy' || this.buyType === 'renew') {
|
|
|
+ // 获取被选中的规格卡片info
|
|
|
+ var specItem = this.selectedSpecItem
|
|
|
+ this.bottomConf.type = 'filePack-' + specItem.value
|
|
|
+ p = specItem.price
|
|
|
+ } else {
|
|
|
+ p = this.getUpgradePrice()
|
|
|
+ }
|
|
|
+ this.updatePrice(p)
|
|
|
+ },
|
|
|
+ clickSpec: function (item) {
|
|
|
+ this.specActive = item.cycleType
|
|
|
+ this.calcPrice()
|
|
|
+ },
|
|
|
+ addBackTip: function () {
|
|
|
+ var _this = this
|
|
|
+ var pushContent = {
|
|
|
+ info: '购买省份订阅包返回',
|
|
|
+ url: '#tip'
|
|
|
+ }
|
|
|
+ if (!history.state && this.dialog.backTipShowCount < 1) {
|
|
|
+ history.pushState(pushContent, null, pushContent.url);
|
|
|
+ }
|
|
|
+ $(window).on('popstate', function () {
|
|
|
+ _this.dialog.backTip = true
|
|
|
+ _this.dialog.backTipShowCount++
|
|
|
+ })
|
|
|
+ },
|
|
|
+ toBuyArea: function () {
|
|
|
+ if (this.buyType === 'renew') return
|
|
|
+ this.savePageState()
|
|
|
+ location.href = './buy_area'
|
|
|
+ },
|
|
|
+ updateS: function (data) {
|
|
|
+ var check = data.check
|
|
|
+ var callback = data.callback
|
|
|
+ callback(this.checkSubmitStatus(check))
|
|
|
+ },
|
|
|
+ checkSubmitStatus: function (checkStatus) {
|
|
|
+ this.bottomConf.checkboxStatus = checkStatus
|
|
|
+ return checkStatus && this.validatorPhonePass && this.bottomConf.initPrice && !this.alreadyBuyInfo.simulatedAmount
|
|
|
+ },
|
|
|
+ // 保证mounted之后执行
|
|
|
+ checkConfirmButtonDisabled: function () {
|
|
|
+ var status = this.bottomConf.checkboxStatus && this.validatorPhonePass && this.bottomConf.initPrice && !this.alreadyBuyInfo.simulatedAmount
|
|
|
+ this.$refs.couponRef.submitStatus = !status
|
|
|
+ },
|
|
|
+ // 调用此方法,即可检测当前页面表单是否满足条件(可计算出提交按钮是否可用)
|
|
|
+ checkStatus: function () {
|
|
|
+ // 此处取反,因为在调用couponRef.chooseCheckbox时候,会对checkbox再次取反
|
|
|
+ this.bottomConf.checkboxStatus = !this.bottomConf.checkboxStatus
|
|
|
+ this.$refs.couponRef.chooseCheckbox()
|
|
|
+ },
|
|
|
+ readEvent: function () {
|
|
|
+ this.saveState()
|
|
|
+ if (utils.isWeiXinBrowser) {
|
|
|
+ location.href = '/front/staticPage/wx-serviceterms.html'
|
|
|
+ } else {
|
|
|
+ location.href = '/jyapp/front/staticPage/dataExport_serviceterms.html'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ submitOrder: function () {
|
|
|
+ var _this = this
|
|
|
+ var loading = this.showLoading()
|
|
|
+ var data = {
|
|
|
+ "product":"attachmentDownPack",
|
|
|
+ "data":{
|
|
|
+ "num": this.selectedSpecItem.id
|
|
|
+ },
|
|
|
+ order_phone: this.userInfo.phone,
|
|
|
+ lotteryId: this.$refs.couponRef.coupon.lotteryId,
|
|
|
+ useProduct: this.$refs.couponRef.getProductId(),
|
|
|
+ disWord: utils.getParam('disWord'),
|
|
|
+ discountId: this.selectedSpecItem.discountId
|
|
|
+ }
|
|
|
+ $.ajax({
|
|
|
+ url: '/jypay/resourcePack/createOrder',
|
|
|
+ contentType: "application/json;charset=UTF-8",
|
|
|
+ dataType: "json",
|
|
|
+ type: "post",
|
|
|
+ processData: false,
|
|
|
+ data: JSON.stringify(data),
|
|
|
+ success: function (res) {
|
|
|
+ loading && loading.clear()
|
|
|
+ if (res.status === 1) {
|
|
|
+ if (res.order_code) {
|
|
|
+ if (utils.isWeiXinBrowser) {
|
|
|
+ history.replaceState({}, '', '/weixin/common/filePack/orderDetail?order_code=' + res.order_code);
|
|
|
+ location.href = '/weixin/pay/checkout_filePack?orderCode=' + res.order_code
|
|
|
+ } else {
|
|
|
+ history.replaceState({}, '', '/jyapp/common/filePack/orderDetail?order_code=' + res.order_code);
|
|
|
+ location.href = "/jyapp/pay/checkout_filePack?orderCode=" + res.order_code + '&from=' + _this.buyType
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ _this.showToast(res.msg)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (res.msg) {
|
|
|
+ _this.showToast(res.msg)
|
|
|
+ } else {
|
|
|
+ _this.showToast('请稍后重试')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: function () {
|
|
|
+ loading && loading.clear()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ afterUpdateCoupon: function (coupon) {
|
|
|
+ // console.log('券后价:', this.$refs.couponRef.realPrice)
|
|
|
+ },
|
|
|
+ updatePrice: function (before) {
|
|
|
+ // console.trace()
|
|
|
+ this.bottomConf.initPrice = before;
|
|
|
+ this.$refs.couponRef.getCoupon()
|
|
|
+ },
|
|
|
+ restoreState: function () {
|
|
|
+ var $data = sessionStorage.getItem(this.sessKey)
|
|
|
+ if ($data) {
|
|
|
+ $data = JSON.parse($data)
|
|
|
+
|
|
|
+ Object.assign(this.dialog, $data.dialog)
|
|
|
+ this.$set(this, 'alreadyBuyInfo', $data.alreadyBuyInfo)
|
|
|
+ this.$set(this, 'areaInfo', $data.areaInfo)
|
|
|
+ this.$set(this, 'priceMap', $data.priceMap)
|
|
|
+ Object.assign(this.priceInfo, $data.priceInfo)
|
|
|
+ Object.assign(this.userInfo, $data.userInfo)
|
|
|
+ this.specActive = $data.specActive
|
|
|
+ this.giftInfo = $data.giftInfo
|
|
|
+ Object.assign(this.specList, $data.specList)
|
|
|
+ Object.assign(this.bottomConf, $data.bottomConf)
|
|
|
+
|
|
|
+ sessionStorage.removeItem(this.sessKey)
|
|
|
+ }
|
|
|
+ return !!$data
|
|
|
+ },
|
|
|
+ saveState: function () {
|
|
|
+ this.savePageState()
|
|
|
+ this.saveSubmitComponentState()
|
|
|
+ },
|
|
|
+ savePageState: function () {
|
|
|
+ var data = {
|
|
|
+ dialog: this.dialog,
|
|
|
+ alreadyBuyInfo: this.alreadyBuyInfo,
|
|
|
+ areaInfo: this.areaInfo,
|
|
|
+ priceInfo: this.priceInfo,
|
|
|
+ userInfo: this.userInfo,
|
|
|
+ specActive: this.specActive,
|
|
|
+ giftInfo: this.giftInfo,
|
|
|
+ specList: this.specList,
|
|
|
+ bottomConf: {
|
|
|
+ initPrice: this.bottomConf.initPrice,
|
|
|
+ realPrice: this.bottomConf.realPrice,
|
|
|
+ disPrice: this.bottomConf.disPrice,
|
|
|
+ checkboxStatus: this.bottomConf.checkboxStatus
|
|
|
+ },
|
|
|
+ priceMap: this.priceMap
|
|
|
+ }
|
|
|
+ sessionStorage.setItem(this.sessKey, JSON.stringify(data))
|
|
|
+ },
|
|
|
+ saveSubmitComponentState: function () {
|
|
|
+ this.$refs.couponRef.saveSelectedCoupon()
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+// 计算时间间隔差函数 [年个数, 月个数]
|
|
|
+function getDateSub (start, end) {
|
|
|
+ let startTime = new Date(start * 1000);
|
|
|
+ let endTime = new Date(end * 1000);
|
|
|
+
|
|
|
+ let startYear = startTime.getFullYear();
|
|
|
+ let startMonth = startTime.getMonth();
|
|
|
+ let startDay = startTime.getDate();
|
|
|
+
|
|
|
+ let endYear = endTime.getFullYear();
|
|
|
+ let endMonth = endTime.getMonth();
|
|
|
+ let endDay = endTime.getDate();
|
|
|
+
|
|
|
+ let finalMonthNum = 0;
|
|
|
+ let finalYearNum = 0;
|
|
|
+ if (startYear === endYear) {
|
|
|
+ if (startMonth === endMonth) {
|
|
|
+ finalMonthNum = 1;
|
|
|
+ } else {
|
|
|
+ if (endDay > startDay) {
|
|
|
+ finalMonthNum = endMonth - startMonth + 1;
|
|
|
+ } else {
|
|
|
+ finalMonthNum = endMonth - startMonth;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (startMonth === endMonth) {
|
|
|
+ if (endDay <= startDay) {
|
|
|
+ finalMonthNum = (endYear - startYear) * 12;
|
|
|
+ } else {
|
|
|
+ finalMonthNum = (endYear - startYear) * 12 + 1;
|
|
|
+ }
|
|
|
+ } else if (endMonth > startMonth) {
|
|
|
+ if (endDay <= startDay) {
|
|
|
+ finalMonthNum = (endYear - startYear) * 12 + (endMonth - startMonth);
|
|
|
+ } else {
|
|
|
+ finalMonthNum = (endYear - startYear) * 12 + (endMonth - startMonth) + 1;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (endDay <= startDay) {
|
|
|
+ finalMonthNum = (endYear - startYear - 1) * 12 + (12 - startMonth + endMonth);
|
|
|
+ } else {
|
|
|
+ finalMonthNum = (endYear - startYear - 1) * 12 + (12 - startMonth + endMonth) + 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ finalYearNum = Math.floor(finalMonthNum / 12);
|
|
|
+ if (finalYearNum > 0) {
|
|
|
+ finalMonthNum = finalMonthNum - finalYearNum * 12
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return [finalYearNum, finalMonthNum]
|
|
|
+}
|