mixin.js 6.8 KB

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