mixin.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. export default {
  2. onShow() {
  3. this.setNavigationBarTitleText();
  4. },
  5. methods: {
  6. /**
  7. * 设置页面标题
  8. */
  9. setNavigationBarTitleText() {
  10. let pages = getCurrentPages();
  11. let currentPage = pages[pages.length - 1];
  12. if (currentPage && currentPage.$holder && currentPage.$holder.navigationBarTitleText) {
  13. let title = currentPage.$holder.navigationBarTitleText;
  14. if (this.storeInfo) title += '-' + this.storeInfo.store_name;
  15. if (title != currentPage.$holder.navigationBarTitleText) uni.setNavigationBarTitle({
  16. title: title
  17. })
  18. } else {
  19. setTimeout(() => {
  20. this.setNavigationBarTitleText();
  21. }, 800)
  22. }
  23. }
  24. },
  25. filters: {
  26. /**
  27. * 金额格式化
  28. * @param {Object} money
  29. */
  30. moneyFormat(money) {
  31. if (isNaN(money)) return money;
  32. return parseFloat(money).toFixed(2);
  33. },
  34. /**
  35. * 时间格式化
  36. * @param {Object} time 时间戳
  37. * @param {Object} format 输出格式
  38. */
  39. timeFormat(time, format = 'y-m-d h:i:s') {
  40. var date = new Date();
  41. date.setTime(time * 1000);
  42. var y = date.getFullYear();
  43. var m = date.getMonth() + 1;
  44. var d = date.getDate();
  45. var h = date.getHours();
  46. var i = date.getMinutes();
  47. var s = date.getSeconds();
  48. format = format.replace('y', y);
  49. format = format.replace('m', (m < 10 ? '0' + m : m));
  50. format = format.replace('d', (d < 10 ? '0' + d : d));
  51. format = format.replace('h', (h < 10 ? '0' + h : h));
  52. format = format.replace('i', (i < 10 ? '0' + i : i));
  53. format = format.replace('s', (s < 10 ? '0' + s : s));
  54. return format;
  55. },
  56. /**
  57. * 刷新会员信息
  58. */
  59. refreshMemberInfo() {
  60. if (this.memberInfo) {
  61. this.$api.sendRequest({
  62. url: '/cashier/storeapi/member/info',
  63. data: {
  64. member_id: this.memberInfo.member_id
  65. },
  66. success: res => {
  67. if (res.code == 0 && res.data) {
  68. this.$store.commit('setMemberInfo', res.data);
  69. }
  70. }
  71. })
  72. }
  73. }
  74. },
  75. computed: {
  76. getRootFontSize() {
  77. return this.$store.state.rootSize;
  78. },
  79. siteInfo() {
  80. return this.$store.state.siteInfo;
  81. },
  82. storeInfo() {
  83. return this.$store.state.storeInfo;
  84. },
  85. memberInfo() {
  86. return this.$store.state.memberInfo;
  87. },
  88. defaultImg() {
  89. return this.$store.state.defaultImg;
  90. }
  91. },
  92. watch: {
  93. 'storeInfo.store_id': {
  94. handler(nval, oval) {
  95. if (oval && typeof this.switchStoreAfter == 'function') {
  96. this.switchStoreAfter();
  97. this.setNavigationBarTitleText();
  98. }
  99. },
  100. deep: true
  101. }
  102. }
  103. }