mixin.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. return this.user.data.sys
  24. },
  25. isRoleAdmin () {
  26. return this.user.data.roleAdmin
  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.refresh()
  103. // this.initScroll.destroy()
  104. // this.initScroll = new BScroll(this.$refs.mobileModalBox, {
  105. // click: true
  106. // })
  107. }
  108. }
  109. },
  110. login: function (url) {
  111. this.$router.push(`/auth/login${url ? '?returnUrl=' + encodeURIComponent(url) : ''}`)
  112. },
  113. goStoreApply: function () {
  114. if (this.user.logged) {
  115. if (this.user.data.enterprise.uu) {
  116. if (this.user.data.enterprise.isVendor === 313) {
  117. this.$http.get('/basic/vendor/transactionInfo').then(response => {
  118. if (response.data.isOpenStore) {
  119. window.location.href = '/vendor#/store/maintain'
  120. } else {
  121. window.location.href = '/vendor#/store-apply'
  122. }
  123. }, err => {
  124. this.$message.error('获取开店信息失败')
  125. console.log(err)
  126. })
  127. } else {
  128. this.$router.push('/register-saler')
  129. }
  130. } else {
  131. this.$router.push('/personalMaterial')
  132. }
  133. } else {
  134. this.login()
  135. }
  136. },
  137. authorityInterceptor: function (url, callback) {
  138. this.baseUtils.getAuthority(this, url, callback, this.isMobile)
  139. },
  140. authenticateInterceptor: function (callback) {
  141. if (this.user.logged) {
  142. callback.call(this)
  143. } else {
  144. this.login(window.location.href)
  145. }
  146. },
  147. goRouter (url) {
  148. this.$router.push(url)
  149. }
  150. },
  151. filters: {
  152. time: function (time) {
  153. if (typeof time === 'number') {
  154. if (!time) {
  155. return '无'
  156. } else {
  157. let d = new Date(time)
  158. let year = d.getFullYear()
  159. let month = d.getMonth() + 1
  160. let day = d.getDate() < 10 ? '0' + d.getDate() : '' + d.getDate()
  161. let hour = d.getHours() < 10 ? '0' + d.getHours() : '' + d.getHours()
  162. let minutes = d.getMinutes() < 10 ? '0' + d.getMinutes() : '' + d.getMinutes()
  163. let seconds = d.getSeconds() < 10 ? '0' + d.getSeconds() : '' + d.getSeconds()
  164. return year + '-' + month + '-' + day + ' ' + hour + ':' + minutes + ':' + seconds
  165. }
  166. }
  167. },
  168. priceFilter: function (num) {
  169. if (num === 0) {
  170. return num
  171. }
  172. if (typeof num === 'number') {
  173. if (num <= 0.000001) {
  174. num = 0.000001
  175. } else {
  176. if (num.toString().indexOf('.') === -1) {
  177. num += '.00'
  178. } else {
  179. let inputStr = num.toString()
  180. let arr = inputStr.split('.')
  181. let floatNum = arr[1]
  182. if (floatNum.length > 6) {
  183. num = inputStr.substring(0, arr[0].length + 7)
  184. if (Number(floatNum.charAt(6)) > 4) {
  185. num = (Number(num) * 1000000 + 1) / 1000000
  186. }
  187. } else if (floatNum.length === 1) {
  188. num = num + '0'
  189. }
  190. }
  191. }
  192. }
  193. return num
  194. },
  195. currencyFilter: function (val) {
  196. return val ? val === 'RMB' ? '¥' : '$' : ''
  197. },
  198. telHideFilter: function (val) {
  199. return val ? val.slice(0, 3) + '****' + val.slice(7, 11) : ''
  200. },
  201. storeTypeFilter: function (type) {
  202. let tmp = ''
  203. switch (type) {
  204. case 'CONSIGNMENT':
  205. tmp = '寄售'
  206. break
  207. case 'DISTRIBUTION':
  208. tmp = '经销'
  209. break
  210. case 'AGENCY':
  211. tmp = '代理'
  212. break
  213. case 'ORIGINAL_FACTORY':
  214. tmp = '原厂'
  215. break
  216. }
  217. return tmp
  218. },
  219. deliveryRuleFilter: function (type) {
  220. let tmp = ''
  221. switch (type) {
  222. case 1301:
  223. tmp = '第三方配送'
  224. break
  225. case 1302:
  226. tmp = '卖家配送'
  227. break
  228. case 1303:
  229. tmp = '上门自提'
  230. break
  231. }
  232. return tmp
  233. },
  234. invoiceTypeFilter: function (type) {
  235. let tmp = ''
  236. switch (type) {
  237. case 1205:
  238. tmp = '普票'
  239. break
  240. case 1206:
  241. tmp = '专票'
  242. break
  243. }
  244. return tmp
  245. }
  246. }
  247. })