| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- /* 目前nuxt 版本如果不高于 1.0.0 并不支持vuex的方法,因此获取相对于的东西只能通过this.$store.state来获取
- 如果nuxt框架为 1.0.0以上,vuex属性状态这里可以优化
- */
- import BScroll from 'better-scroll'
- import Vue from 'vue'
- import baseUtils from '~utils/baseUtils'
- import baseUrls from '~utils/baseUrls'
- // import { mapState } from 'vuex'
- Vue.mixin({
- data () {
- return {
- initScroll: null
- }
- },
- computed: {
- user() {
- return this.$store.state.option.user
- },
- sortEnterprises () {
- if (this.user.data.enterprises) {
- let ens = this.user.data.enterprises.slice()
- if (ens && ens.length) {
- ens.sort(function (a, b) {
- return b.lastLoginTime - a.lastLoginTime
- })
- }
- return ens
- } else {
- return ''
- }
- },
- // 判断是否erp嵌入
- isInFrame () {
- if (this.$route.query.type === 'erp') {
- this.$store.commit('option/ADD_COOKIES', 'type=erp;')
- return true
- } else {
- let cookies = this.$store.state.option.cookies
- let cookieArr = cookies.split(';')
- let cookieObj = {}
- for (let i = 0; i < cookieArr.length; i++) {
- if (cookieArr[i].indexOf('=') > -1) {
- let tmpArr = cookieArr[i].split('=')
- cookieObj[tmpArr[0].trim()] = tmpArr[1].trim()
- }
- }
- return cookieObj.type === 'erp'
- }
- },
- currentEnName () {
- if (this.user.data.enterprise) {
- return this.user.data.enterprise.uu ? this.user.data.enterprise.enName : this.user.data.userName + '(个人账户)'
- } else {
- return {}
- }
- },
- baseUtils () {
- return baseUtils
- },
- baseUrls () {
- return baseUrls
- },
- isMobile () {
- return this.$store.state.option.isMobile
- },
- // 账户安全状态
- accountInvalid () {
- return !this.user.data.pwdEnable || !this.user.data.haveUserQuestion || !this.user.data.emailValidCode || this.user.data.emailValidCode !== 2
- }
- },
- methods: {
- goLastPage: function () {
- window.history.back(-1)
- },
- preventTouchMove (e) {
- e.preventDefault()
- },
- stopPropagation: function (e) {
- if (e) {
- e.stopPropagation()
- }
- },
- _initscroll() {
- if (this.$refs.mobileModalBox) {
- if (!this.initScroll) {
- this.initScroll = new BScroll(this.$refs.mobileModalBox, {
- click: true
- })
- } else {
- this.initScroll.destroy()
- this.initScroll = new BScroll(this.$refs.mobileModalBox, {
- click: true
- })
- }
- }
- },
- login: function (url) {
- this.$router.push(`/auth/login${url ? '?returnUrl=' + url : ''}`)
- },
- goStoreApply: function () {
- if (this.user.logged) {
- if (this.user.data.enterprise.uu) {
- if (this.user.data.enterprise.isVendor === 313) {
- this.$http.get('/basic/vendor/transactionInfo').then(response => {
- if (response.data.isOpenStore) {
- window.location.href = '/vendor#/store/maintain'
- } else {
- window.location.href = '/vendor#/store-apply'
- }
- }, err => {
- this.$message.error('获取开店信息失败')
- console.log(err)
- })
- } else {
- this.$router.push('/register-saler')
- }
- } else {
- this.$router.push('/personalMaterial')
- }
- } else {
- this.login()
- }
- },
- authorityInterceptor: function (url, callback) {
- this.baseUtils.getAuthority(this, url, callback, this.isMobile)
- }
- },
- filters: {
- time: function (time) {
- if (typeof time === 'number') {
- if (!time) {
- return '无'
- } else {
- let d = new Date(time)
- let year = d.getFullYear()
- let month = d.getMonth() + 1
- let day = d.getDate() < 10 ? '0' + d.getDate() : '' + d.getDate()
- let hour = d.getHours() < 10 ? '0' + d.getHours() : '' + d.getHours()
- let minutes = d.getMinutes() < 10 ? '0' + d.getMinutes() : '' + d.getMinutes()
- let seconds = d.getSeconds() < 10 ? '0' + d.getSeconds() : '' + d.getSeconds()
- return year + '-' + month + '-' + day + ' ' + hour + ':' + minutes + ':' + seconds
- }
- }
- },
- priceFilter: function (num) {
- if (num === 0) {
- return num
- }
- if (typeof num === 'number') {
- if (num <= 0.000001) {
- num = 0.000001
- } else {
- if (num.toString().indexOf('.') === -1) {
- num += '.00'
- } else {
- let inputStr = num.toString()
- let arr = inputStr.split('.')
- let floatNum = arr[1]
- if (floatNum.length > 6) {
- num = inputStr.substring(0, arr[0].length + 7)
- if (Number(floatNum.charAt(6)) > 4) {
- num = (Number(num) * 1000000 + 1) / 1000000
- }
- } else if (floatNum.length === 1) {
- num = num + '0'
- }
- }
- }
- }
- return num
- },
- currencyFilter: function (val) {
- return val ? val === 'RMB' ? '¥' : '$' : ''
- },
- telHideFilter: function (val) {
- return val ? val.slice(0, 3) + '****' + val.slice(7, 11) : ''
- },
- storeTypeFilter: function (type) {
- let tmp = ''
- switch (type) {
- case 'CONSIGNMENT':
- tmp = '寄售'
- break
- case 'DISTRIBUTION':
- tmp = '经销'
- break
- case 'AGENCY':
- tmp = '代理'
- break
- case 'ORIGINAL_FACTORY':
- tmp = '原厂'
- break
- }
- return tmp
- },
- deliveryRuleFilter: function (type) {
- let tmp = ''
- switch (type) {
- case 1301:
- tmp = '第三方配送'
- break
- case 1302:
- tmp = '卖家配送'
- break
- case 1303:
- tmp = '上门自提'
- break
- }
- return tmp
- },
- invoiceTypeFilter: function (type) {
- let tmp = ''
- switch (type) {
- case 1205:
- tmp = '普票'
- break
- case 1206:
- tmp = '专票'
- break
- }
- return tmp
- }
- }
- })
|