mixin.js 6.3 KB

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