mixin.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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=' + encodeURIComponent(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. authenticateInterceptor: function (callback) {
  131. if (this.user.logged) {
  132. callback.call(this)
  133. } else {
  134. this.login(window.location.href)
  135. }
  136. }
  137. },
  138. filters: {
  139. time: function (time) {
  140. if (typeof time === 'number') {
  141. if (!time) {
  142. return '无'
  143. } else {
  144. let d = new Date(time)
  145. let year = d.getFullYear()
  146. let month = d.getMonth() + 1
  147. let day = d.getDate() < 10 ? '0' + d.getDate() : '' + d.getDate()
  148. let hour = d.getHours() < 10 ? '0' + d.getHours() : '' + d.getHours()
  149. let minutes = d.getMinutes() < 10 ? '0' + d.getMinutes() : '' + d.getMinutes()
  150. let seconds = d.getSeconds() < 10 ? '0' + d.getSeconds() : '' + d.getSeconds()
  151. return year + '-' + month + '-' + day + ' ' + hour + ':' + minutes + ':' + seconds
  152. }
  153. }
  154. },
  155. priceFilter: function (num) {
  156. if (num === 0) {
  157. return num
  158. }
  159. if (typeof num === 'number') {
  160. if (num <= 0.000001) {
  161. num = 0.000001
  162. } else {
  163. if (num.toString().indexOf('.') === -1) {
  164. num += '.00'
  165. } else {
  166. let inputStr = num.toString()
  167. let arr = inputStr.split('.')
  168. let floatNum = arr[1]
  169. if (floatNum.length > 6) {
  170. num = inputStr.substring(0, arr[0].length + 7)
  171. if (Number(floatNum.charAt(6)) > 4) {
  172. num = (Number(num) * 1000000 + 1) / 1000000
  173. }
  174. } else if (floatNum.length === 1) {
  175. num = num + '0'
  176. }
  177. }
  178. }
  179. }
  180. return num
  181. },
  182. currencyFilter: function (val) {
  183. return val ? val === 'RMB' ? '¥' : '$' : ''
  184. },
  185. telHideFilter: function (val) {
  186. return val ? val.slice(0, 3) + '****' + val.slice(7, 11) : ''
  187. },
  188. storeTypeFilter: function (type) {
  189. let tmp = ''
  190. switch (type) {
  191. case 'CONSIGNMENT':
  192. tmp = '寄售'
  193. break
  194. case 'DISTRIBUTION':
  195. tmp = '经销'
  196. break
  197. case 'AGENCY':
  198. tmp = '代理'
  199. break
  200. case 'ORIGINAL_FACTORY':
  201. tmp = '原厂'
  202. break
  203. }
  204. return tmp
  205. },
  206. deliveryRuleFilter: function (type) {
  207. let tmp = ''
  208. switch (type) {
  209. case 1301:
  210. tmp = '第三方配送'
  211. break
  212. case 1302:
  213. tmp = '卖家配送'
  214. break
  215. case 1303:
  216. tmp = '上门自提'
  217. break
  218. }
  219. return tmp
  220. },
  221. invoiceTypeFilter: function (type) {
  222. let tmp = ''
  223. switch (type) {
  224. case 1205:
  225. tmp = '普票'
  226. break
  227. case 1206:
  228. tmp = '专票'
  229. break
  230. }
  231. return tmp
  232. }
  233. }
  234. })