mixin.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. priceFilter: function (num) {
  146. if (num === 0) {
  147. return num
  148. }
  149. if (typeof num === 'number') {
  150. if (num <= 0.000001) {
  151. num = 0.000001
  152. } else {
  153. if (num.toString().indexOf('.') === -1) {
  154. num += '.00'
  155. } else {
  156. let inputStr = num.toString()
  157. let arr = inputStr.split('.')
  158. let floatNum = arr[1]
  159. if (floatNum.length > 6) {
  160. num = inputStr.substring(0, arr[0].length + 7)
  161. if (Number(floatNum.charAt(6)) > 4) {
  162. num = (Number(num) * 1000000 + 1) / 1000000
  163. }
  164. } else if (floatNum.length === 1) {
  165. num = num + '0'
  166. }
  167. }
  168. }
  169. }
  170. return num
  171. },
  172. currencyFilter: function (val) {
  173. return val ? val === 'RMB' ? '¥' : '$' : ''
  174. },
  175. telHideFilter: function (val) {
  176. return val ? val.slice(0, 3) + '****' + val.slice(7, 11) : ''
  177. },
  178. storeTypeFilter: function (type) {
  179. let tmp = ''
  180. switch (type) {
  181. case 'CONSIGNMENT':
  182. tmp = '寄售'
  183. break
  184. case 'DISTRIBUTION':
  185. tmp = '经销'
  186. break
  187. case 'AGENCY':
  188. tmp = '代理'
  189. break
  190. case 'ORIGINAL_FACTORY':
  191. tmp = '原厂'
  192. break
  193. }
  194. return tmp
  195. },
  196. deliveryRuleFilter: function (type) {
  197. let tmp = ''
  198. switch (type) {
  199. case 1301:
  200. tmp = '第三方配送'
  201. break
  202. case 1302:
  203. tmp = '卖家配送'
  204. break
  205. case 1303:
  206. tmp = '上门自提'
  207. break
  208. }
  209. return tmp
  210. },
  211. invoiceTypeFilter: function (type) {
  212. let tmp = ''
  213. switch (type) {
  214. case 1205:
  215. tmp = '普票'
  216. break
  217. case 1206:
  218. tmp = '专票'
  219. break
  220. }
  221. return tmp
  222. }
  223. }
  224. })