| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524 |
- var _request = require('../../../../utils/request.js')
- var _handle = require('../../../../utils/handle.js')
- Page({
- data: {
- page: 1,
- per_page: 10,
- curItem: {},
- radishCount: 0,
- checkIntegral: {},
- companyList: [],
- more: true,
- showPanel: false,
- showPwdDialog: false,
- ydCodeDialog: false,
- ydExchangeDialog: false,
- clogo: '',
- integralTotal: 0,
- originInToTal: 0,
- countdown: 0,
- servicePwd: '',
- phoneCode: '',
- useIntegral: 0,
- panelId: '',
- show: false,
- imgUrls: [
- ],
- indicatorDots: true,
- autoplay: true,
- interval: 5000,
- duration: 1000,
- circular: true,
- bindTel: false,
- checkData: {},
- lock: false
- },
- onLoad: function () {
- // this.getBalanceInfo()
- this.getCompanyList()
- this.check()
- this.getBanners()
- },
- onReachBottom: function () {
- if (this.data.more) {
- var page = this.data.page + 1
- this.setData({
- page: page
- })
- this.getCompanyList()
- }
- },
- getCode () {
- var that = this
- var url = 'v1/platforms/yidong/send_code'
- var params = {
- }
- var success = function (res) {
- wx.setStorageSync('sms_request_time', Date.now())
- that.startCountdown()
- }
- _request.$get(url, params, success)
- },
- startCountdown: function () {
- var smsRequestTime = wx.getStorageSync('sms_request_time')
- if (smsRequestTime) {
- var count = parseInt((60000 - (new Date() - smsRequestTime)) / 1000)
- this.setData({
- countdown: count
- })
- if (this.data.countdown > 0) {
- var timer = setInterval(() => {
- var countdown = this.data.countdown - 1
- this.setData({
- countdown: countdown
- })
- if (this.data.countdown <= 0) {
- clearInterval(timer)
- }
- }, 1000)
- }
- }
- },
- getBalanceInfo: function () {
- var that = this
- var url = "v1/user/balance/info";
- var params = {}
- var success = function (val) {
- that.setData({
- balanceInfo: val.data,
- bindTel : true
- });
- }
- _request.$get(url, params, success)
- },
- getCompanyList: function () {
- var that = this
- var url = "v1/platforms";
- var params = {
- page: that.data.page,
- per_page: that.data.per_page,
- cache: false
- }
- var success = function (res) {
- var result = that.data.companyList.concat(res.data.list || [])
- console.log(result)
- that.setData({
- companyList: result
- })
- var listMore = res.data.list_count > that.data.companyList.length
- that.setData({
- more: listMore
- })
- }
- _request.$get(url, params, success)
- },
- radishCountInput: function (e) {
- var that = this
- var item = that.data.curItem
- if (e.detail.value) {
- that.data.radishCount = Number(e.detail.value)
- that.data.integralTotal = (that.data.originInToTal - ((e.detail.value * item.p_count) / item.labi_count)).toFixed(2)
- } else if (e.detail.value === '') {
- that.data.integralTotal = 0
- }
- if ((that.data.originInToTal - that.data.integralTotal) * 100 % 100 === 0) {
- that.data.useIntegral = that.data.originInToTal - that.data.integralTotal
- } else {
- that.data.useIntegral = (that.data.originInToTal - that.data.integralTotal).toFixed(2)
- }
- this.setData({
- integralTotal: that.data.integralTotal,
- useIntegral: that.data.useIntegral
- })
- },
- checkUserIntegral: function (tag) {
- var that = this
- var url
- if (tag === 'liantong' || tag === 'yidong' || tag === 'yizhifu' ) {
- url = "v1/platform/" + tag + "/check";
- } else {
- url = "v1/platform/" + that.data.curItem.id + "/check";
- }
- var params
- if (tag === 'yidong') {
- params = {
- code: that.data.phoneCode
- }
- } else {
- params = {}
- }
- var success = function (val) {
- var integral
- var item = that.data.curItem
- that.data.originInToTal = val.data.total
- if (val.data.total >= 0 && that.data.curItem.tag === 'yidong') {
- that.ydDialog()
- that.setData({
- showPanel: that.data.showPanel,
- panelId: that.data.curItem.id,
- clogo: that.data.curItem.logo
- })
- }
- if (val.data.total) {
- // integral = item.p_start_count * item.labi_count / item.p_count
- // that.data.integralTotal = val.data.total - ((integral * item.p_count) / item.labi_count)
- integral = Math.floor(val.data.total / item.p_count) * item.labi_count
- that.data.integralTotal = (val.data.total - (integral * item.p_count / item.labi_count)).toFixed(2)
- that.data.radishCount = integral
- } else {
- integral = 0
- that.data.integralTotal = 0
- }
- if ((that.data.originInToTal - that.data.integralTotal) * 100 % 100 === 0) {
- that.data.useIntegral = that.data.originInToTal - that.data.integralTotal
- } else {
- that.data.useIntegral = (that.data.originInToTal - that.data.integralTotal).toFixed(2)
- }
- that.setData({
- checkIntegral: val.data,
- integralTotal: that.data.integralTotal,
- useIntegral: that.data.useIntegral,
- radishCount: integral,
- originInToTal: val.data.total
- });
- }
- _request.$get(url, params, success)
- },
- exchange: function (e) {
- _handle.setFormId(e)
- var that = this
- that.data.lock = true
- var ratio = e.detail.target.dataset.ratio
- var url = "v1/platform/" + e.detail.target.dataset.id + "/exchange"
- var params = {
- count: that.data.radishCount
- }
- var success = function (val) {
- that.data.lock = false
- wx.redirectTo({
- url: '/packageUser/pages/user/exchangeSuccess/exchangeSuccess'
- })
- }
- if (that.data.radishCount) {
- if (e.detail.target.dataset.tag === 'yizhifu') {
- that.getdianxin()
- } else {
- if (that.data.integralTotal >= 0) {
- if (that.data.radishCount % that.data.curItem.labi_range === 0) {
- if (e.detail.target.dataset.tag === 'liantong') {
- that.showDialog()
- } else if (e.detail.target.dataset.tag === 'yidong') {
- that.data.ydExchangeDialog = !that.data.ydExchangeDialog
- that.setData({
- ydExchangeDialog: that.data.ydExchangeDialog
- })
- } else {
- if (that.data.lock) {
- _request.$post(url, params, success)
- }
- }
- } else {
- wx.showToast({
- title: '请以' + that.data.curItem.labi_range + '的倍数输入代金券数',
- icon: 'none',
- duration: 2000
- })
- }
- } else {
- wx.showToast({
- title: '代金券余额不足~',
- icon: 'none',
- duration: 2000
- })
- }
- }
- } else {
- wx.showToast({
- title: '请输入兑换的代金券~',
- icon: 'none',
- duration: 2000
- })
- }
- },
- getdianxin () {
- var that = this
- var url = 'v1/pf/yizhifu/page/exchange'
- var params = {
- count: that.data.radishCount
- }
- var success = function (val) {
- console.log(val)
- wx.navigateTo({
- url: '/pages/web/web?id=' + val.result_str
- })
- }
- _request.$post(url, params, success)
- },
- servicePwdInput (e) {
- var that = this
- that.data.servicePwd = e.detail.value
- },
- phoneCodeInput (e) {
- var that = this
- that.data.phoneCode = e.detail.value
- },
- checkYDIntegral () {
- var that = this
- if (that.data.phoneCode) {
- that.openPanelTwo()
- } else {
- wx.showToast({
- title: '验证码不能为空',
- icon: 'none',
- duration: 1000
- })
- }
- },
- sumbit () {
- var that = this
- var url = "v1/platform/liantong/exchange"
- var params = {
- count: that.data.radishCount,
- pwd: that.data.servicePwd
- }
- var success = function (val) {
- wx.redirectTo({
- url: '/packageUser/pages/user/exchangeSuccess/exchangeSuccess'
- })
- }
- _request.$post(url, params, success)
- },
- sumbitYD () {
- var that = this
- var url = "v1/platform/yidong/exchange"
- var params = {
- count: that.data.radishCount,
- code: that.data.phoneCode
- }
- var success = function (val) {
- wx.redirectTo({
- url: '/packageUser/pages/user/exchangeSuccess/exchangeSuccess'
- })
- }
- if (that.data.phoneCode) {
- _request.$post(url, params, success)
- } else {
- wx.showToast({
- title: '验证码不能为空',
- icon: 'none',
- duration: 1000
- })
- }
- },
- openPanel (e) {
- var that = this
- that.data.curItem = e.currentTarget.dataset.item
- if (e.currentTarget.dataset.item.tag === 'yidong') {
- if (that.data.curItem.state === 1) {
- if (!that.data.showPanel) {
- that.ydDialog()
- that.setData({
- clogo: that.data.curItem.logo
- })
- } else {
- that.data.showPanel = !that.data.showPanel
- that.setData({
- showPanel: that.data.showPanel,
- transferR: 90,
- radishCount: 0,
- originInToTal: 0,
- integralTotal: 0
- })
- }
- }
- } //else if (e.currentTarget.dataset.item.tag === 'yizhifu') {
- // that.data.showPanel = !that.data.showPanel
- // that.data.show = !that.data.show
- // that.setData({
- // showPanel: that.data.showPanel,
- // show : that.data.show
- // })
- // }
- else {
- that.openPanelTwo()
- }
- },
- openPanelTwo () {
- var that = this
- if (that.data.curItem.state === 1) {
- that.data.showPanel = !that.data.showPanel
- if (that.data.showPanel) {
- that.checkUserIntegral(that.data.curItem.tag)
- if (that.data.curItem.tag === 'yizhifu') {
- that.setData({
- show: true
- })
- }
- that.setData({
- transferR: -90,
- // show: false
- })
- } else {
- that.setData({
- transferR: 90,
- radishCount: 0,
- originInToTal: 0,
- integralTotal: 0,
- show: false,
- })
- }
- if (that.data.curItem.tag !== 'yidong') {
- that.setData({
- showPanel: that.data.showPanel,
- panelId: that.data.curItem.id,
- clogo: that.data.curItem.logo,
- })
- }
- // if (that.data.curItem.tag === 'yizhifu') {
- // console.log(4444)
- // that.setData({
- // showPanel: that.data.showPanel,
- // panelId: that.data.curItem.id,
- // clogo: that.data.curItem.logo,
- // })
- // }
- }
- },
- showDialog () {
- var that = this
- that.data.showPwdDialog = !that.data.showPwdDialog
- that.setData({
- showPwdDialog: that.data.showPwdDialog
- })
- },
- ydDialog () {
- var that = this
- that.data.ydCodeDialog = !that.data.ydCodeDialog
- that.setData({
- ydCodeDialog: that.data.ydCodeDialog
- })
- },
- ydExDialog () {
- var that = this
- that.data.ydExchangeDialog = !that.data.ydExchangeDialog
- if (!that.data.ydExchangeDialog) {
- that.data.showPanel = !that.data.showPanel,
- that.setData({
- showPanel: that.data.showPanel,
- ydExchangeDialog: that.data.ydExchangeDialog
- })
- } else {
- that.setData({
- ydExchangeDialog: that.data.ydExchangeDialog
- })
- }
- },
- minus () {
- var that = this
- var item = that.data.curItem
- var minRadishCount = item.p_start_count * item.labi_count / item.p_count
- var left = that.data.radishCount - item.labi_range
- if (left >= minRadishCount) {
- that.data.radishCount = left
- that.data.integralTotal = (that.data.checkIntegral.total - ((that.data.radishCount * item.p_count) / item.labi_count)).toFixed(2)
- if ((that.data.originInToTal - that.data.integralTotal) * 100 % 100 === 0) {
- that.data.useIntegral = that.data.originInToTal - that.data.integralTotal
- } else {
- that.data.useIntegral = (that.data.originInToTal - that.data.integralTotal).toFixed(2)
- }
- that.setData({
- radishCount: that.data.radishCount,
- integralTotal: that.data.integralTotal,
- useIntegral: that.data.useIntegral
- })
- } else {
- wx.showToast({
- title: '兑换代金券数量不对',
- icon: 'none',
- duration: 2000
- })
- }
- },
- plus () {
- var that = this
- var item = that.data.curItem
- that.data.radishCount = that.data.radishCount + item.labi_range
- that.data.integralTotal = (that.data.checkIntegral.total - ((that.data.radishCount * item.p_count) / item.labi_count)).toFixed(2)
- if ((that.data.originInToTal - that.data.integralTotal) * 100 % 100 === 0) {
- that.data.useIntegral = that.data.originInToTal - that.data.integralTotal
- } else {
- that.data.useIntegral = (that.data.originInToTal - that.data.integralTotal).toFixed(2)
- }
- that.setData({
- radishCount: that.data.radishCount,
- integralTotal: that.data.integralTotal,
- useIntegral: that.data.useIntegral
- })
- },
- toUrl () {
- var that = this
- if (that.data.curItem.get_url_type === 'internal') {
- wx.navigateTo({
- url: that.data.curItem.get_url
- })
- } else if (that.data.curItem.get_url_type === 'external') {
- wx.navigateTo({
- url: '/pages/web/web?id=' + that.data.curItem.get_url
- })
- } else {
- wx.showToast({
- title: '未设置链接',
- icon: 'none',
- duration: 2000
- })
- }
- },
- check () {
- var that = this
- var url = 'v1/user/check'
- var params = {
- }
- var success = function (res) {
- if (res.data.wx_user_id <= 0) {
- wx.login({
- success: res => {
- _request.login(res)
- }
- })
- } else {
- that.setData({
- checkData: res.data
- })
- if (that.data.checkData.merchant_id > 0) {
- // that.getmerchant()
- }
- if (res.data.user_id > 0 && !that.data.bindTel) {
- that.setData({
- bindTel: true
- })
- that.getBalanceInfo()
- }
- }
- }
- _request.$get(url, params, success)
- },
- getBanners () {
- var item = 'lol'
- var that = this
- var url = 'v1/ad/' + item + '/items'
- var params = {
- }
- var success = function (res) {
- that.setData({
- imgUrls: res.data
- })
- }
- _request.$get(url, params, success)
- },
- onShareAppMessage: function (val) {
- return _request.share({
- sc: 'xcx_user_exchange'
- })
- }
- })
|