mixin.js 5.5 KB

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