mixin.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /* 目前nuxt 版本如果不高于 1.0.0 并不支持vuex的方法,因此获取相对于的东西只能通过this.$store.state来获取
  2. 如果nuxt框架为 1.0.0以上,vuex属性状态这里可以优化
  3. */
  4. import BScroll from 'better-scroll'
  5. import Vue from 'vue'
  6. import baseUtils from '~utils/baseUtils'
  7. import baseUrls from '~utils/baseUrls'
  8. // import { mapState } from 'vuex'
  9. Vue.mixin({
  10. data () {
  11. return {
  12. initScroll: null
  13. }
  14. },
  15. computed: {
  16. user() {
  17. return this.$store.state.option.user
  18. },
  19. currency() {
  20. return this.$store.state.option.currency
  21. },
  22. isAdmin () {
  23. let isAdmin = null
  24. if (this.user.data.enterprise) {
  25. this.user.data.enterprise.enAdminuu === this.user.data.userUU ? isAdmin = true : isAdmin = false
  26. } else {
  27. isAdmin = false
  28. }
  29. return isAdmin
  30. },
  31. sortEnterprises () {
  32. if (this.user.data.enterprises) {
  33. let ens = this.user.data.enterprises.slice()
  34. if (ens && ens.length) {
  35. ens.sort(function (a, b) {
  36. return b.lastLoginTime - a.lastLoginTime
  37. })
  38. }
  39. return ens
  40. } else {
  41. return ''
  42. }
  43. },
  44. // 判断是否erp嵌入
  45. isInFrame () {
  46. if (this.$route.query.type === 'erp') {
  47. if (this.$store.state.option.cookies.indexOf('type=erp') > -1) {
  48. return true
  49. }
  50. this.$store.commit('option/ADD_COOKIES', ';type=erp')
  51. return true
  52. } else {
  53. let cookies = this.$store.state.option.cookies
  54. let cookieArr = cookies.split(';')
  55. let cookieObj = {}
  56. for (let i = 0; i < cookieArr.length; i++) {
  57. if (cookieArr[i].indexOf('=') > -1) {
  58. let tmpArr = cookieArr[i].split('=')
  59. cookieObj[tmpArr[0].trim()] = tmpArr[1].trim()
  60. }
  61. }
  62. return cookieObj.type === 'erp'
  63. }
  64. },
  65. currentEnName () {
  66. if (this.user.data.enterprise) {
  67. return this.user.data.enterprise.uu ? this.user.data.enterprise.enName : this.user.data.userName + '(个人账户)'
  68. } else {
  69. return {}
  70. }
  71. },
  72. baseUtils () {
  73. return baseUtils
  74. },
  75. baseUrls () {
  76. return baseUrls
  77. },
  78. isMobile () {
  79. return this.$store.state.option.isMobile
  80. },
  81. // 账户安全状态
  82. accountInvalid () {
  83. return !this.user.data.pwdEnable || !this.user.data.haveUserQuestion || !this.user.data.emailValidCode || this.user.data.emailValidCode !== 2
  84. }
  85. },
  86. methods: {
  87. goLastPage: function () {
  88. window.history.back(-1)
  89. },
  90. preventTouchMove (e) {
  91. e.preventDefault()
  92. },
  93. stopPropagation: function (e) {
  94. if (e) {
  95. e.stopPropagation()
  96. }
  97. },
  98. _initscroll() {
  99. if (this.$refs.mobileModalBox) {
  100. if (!this.initScroll) {
  101. this.initScroll = new BScroll(this.$refs.mobileModalBox, {
  102. click: true
  103. })
  104. } else {
  105. this.initScroll.refresh()
  106. // this.initScroll.destroy()
  107. // this.initScroll = new BScroll(this.$refs.mobileModalBox, {
  108. // click: true
  109. // })
  110. }
  111. }
  112. },
  113. login: function (url) {
  114. this.$router.push(`/auth/login${url ? '?returnUrl=' + encodeURIComponent(url) : ''}`)
  115. },
  116. goStoreApply: function () {
  117. if (this.user.logged) {
  118. if (this.user.data.enterprise.uu) {
  119. if (this.user.data.enterprise.isVendor === 313) {
  120. this.$http.get('/basic/vendor/transactionInfo').then(response => {
  121. if (response.data.isOpenStore) {
  122. window.location.href = '/vendor#/store/maintain'
  123. } else {
  124. window.location.href = '/vendor#/store-apply'
  125. }
  126. }, err => {
  127. this.$message.error('获取开店信息失败')
  128. console.log(err)
  129. })
  130. } else {
  131. this.$router.push('/register-saler')
  132. }
  133. } else {
  134. this.$router.push('/personalMaterial')
  135. }
  136. } else {
  137. this.login()
  138. }
  139. },
  140. authorityInterceptor: function (url, callback) {
  141. this.baseUtils.getAuthority(this, url, callback, this.isMobile)
  142. },
  143. authenticateInterceptor: function (callback) {
  144. if (this.user.logged) {
  145. callback.call(this)
  146. } else {
  147. this.login(window.location.href)
  148. }
  149. },
  150. goRouter (url) {
  151. this.$router.push(url)
  152. }
  153. },
  154. filters: {
  155. time: function (time) {
  156. if (typeof time === 'number') {
  157. if (!time) {
  158. return '无'
  159. } else {
  160. let d = new Date(time)
  161. let year = d.getFullYear()
  162. let month = d.getMonth() + 1
  163. let day = d.getDate() < 10 ? '0' + d.getDate() : '' + d.getDate()
  164. let hour = d.getHours() < 10 ? '0' + d.getHours() : '' + d.getHours()
  165. let minutes = d.getMinutes() < 10 ? '0' + d.getMinutes() : '' + d.getMinutes()
  166. let seconds = d.getSeconds() < 10 ? '0' + d.getSeconds() : '' + d.getSeconds()
  167. return year + '-' + month + '-' + day + ' ' + hour + ':' + minutes + ':' + seconds
  168. }
  169. }
  170. },
  171. priceFilter: function (num) {
  172. if (num === 0) {
  173. return num
  174. }
  175. if (typeof num === 'number') {
  176. if (num <= 0.000001) {
  177. num = 0.000001
  178. } else {
  179. if (num.toString().indexOf('.') === -1) {
  180. num += '.00'
  181. } else {
  182. let inputStr = num.toString()
  183. let arr = inputStr.split('.')
  184. let floatNum = arr[1]
  185. if (floatNum.length > 6) {
  186. num = inputStr.substring(0, arr[0].length + 7)
  187. if (Number(floatNum.charAt(6)) > 4) {
  188. num = (Number(num) * 1000000 + 1) / 1000000
  189. }
  190. } else if (floatNum.length === 1) {
  191. num = num + '0'
  192. }
  193. }
  194. }
  195. }
  196. return num
  197. },
  198. currencyFilter: function (val) {
  199. return val ? val === 'RMB' ? '¥' : '$' : ''
  200. },
  201. telHideFilter: function (val) {
  202. return val ? val.slice(0, 3) + '****' + val.slice(7, 11) : ''
  203. },
  204. storeTypeFilter: function (type) {
  205. let tmp = ''
  206. switch (type) {
  207. case 'CONSIGNMENT':
  208. tmp = '寄售'
  209. break
  210. case 'DISTRIBUTION':
  211. tmp = '经销'
  212. break
  213. case 'AGENCY':
  214. tmp = '代理'
  215. break
  216. case 'ORIGINAL_FACTORY':
  217. tmp = '原厂'
  218. break
  219. }
  220. return tmp
  221. },
  222. deliveryRuleFilter: function (type) {
  223. let tmp = ''
  224. switch (type) {
  225. case 1301:
  226. tmp = '第三方配送'
  227. break
  228. case 1302:
  229. tmp = '卖家配送'
  230. break
  231. case 1303:
  232. tmp = '上门自提'
  233. break
  234. }
  235. return tmp
  236. },
  237. invoiceTypeFilter: function (type) {
  238. let tmp = ''
  239. switch (type) {
  240. case 1205:
  241. tmp = '普票'
  242. break
  243. case 1206:
  244. tmp = '专票'
  245. break
  246. }
  247. return tmp
  248. }
  249. }
  250. })