gen-purchase-ghs-panel.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. const fs = require('fs');
  2. const path = 'd:/front-end/hdApp/src/admin/home/workbench.vue';
  3. const lines = fs.readFileSync(path, 'utf8').split(/\r?\n/);
  4. let tpl = lines.slice(55, 234).join('\n');
  5. tpl = tpl.replace('<view class="order-page">', '<view class="purchase-ghs-panel">');
  6. const popups = lines.slice(240, 278).join('\n');
  7. const initBlock = lines.slice(470, 482).join('\n');
  8. const ghsMethods = lines.slice(492, 711).join('\n');
  9. let fixedMethods = (initBlock + '\n' + ghsMethods).replace(
  10. ' init() {\n this.getGHSList()',
  11. ' init() {\n return this.getGHSList()'
  12. );
  13. let styles = lines.slice(1377, 1493).join('\n') + '\n' + lines.slice(1494, 2009).join('\n');
  14. styles = styles.replace(/\.order-page/g, '.purchase-ghs-panel');
  15. const script = `<script>
  16. import { mapGetters } from "vuex";
  17. import { consoleIndex } from "@/api/workbench";
  18. import { ghsList } from "@/api/purchase";
  19. import { changeDelStatus, hasMoreGhs, searchNearbyGhs } from "@/api/ghs";
  20. import { currentShop } from "@/api/shop";
  21. import { hasNotice } from "@/api/admin";
  22. import permision from "@/utils/wa-permission_1.1/permission.js";
  23. import { iconSrc } from "@/utils/iconSrc";
  24. export default {
  25. name: "PurchaseGhsPanel",
  26. props: {
  27. statusBarHeight: { type: Number, default: 0 }
  28. },
  29. data() {
  30. return {
  31. constant: this.$constant,
  32. ad: [],
  33. isMini: 0,
  34. data: {
  35. admin: {},
  36. asset: {},
  37. notice: {},
  38. todayData: { income: 0.00, order: 0, custom: 0, expend: 0.00, visit: 0 },
  39. warning: ''
  40. },
  41. supplierList: [],
  42. currentGhs: {},
  43. displayGhsList: [],
  44. shopInfo: [],
  45. supplierSearchTime: 0,
  46. hasRequestApi: 0
  47. };
  48. },
  49. computed: {
  50. ...mapGetters({ loginInfo: "getLoginInfo" }),
  51. workbenchTitle() {
  52. if (this.shopInfo && this.shopInfo.shopName == '首店') {
  53. return this.shopInfo.merchantName || '进货'
  54. }
  55. const merchantName = (this.shopInfo && this.shopInfo.merchantName) ? this.shopInfo.merchantName : ''
  56. const shopName = (this.shopInfo && this.shopInfo.shopName) ? this.shopInfo.shopName : ''
  57. const title = merchantName + (shopName ? (' · ' + shopName) : '')
  58. return title || '进货'
  59. },
  60. isWithinTwoDays() {
  61. if (!this.supplierSearchTime) return false;
  62. const twoDays = 2 * 24 * 60 * 60 * 1000;
  63. return (Date.now() - this.supplierSearchTime) < twoDays;
  64. }
  65. },
  66. beforeDestroy() {
  67. this.handlePageUnload();
  68. },
  69. methods: {
  70. iconSrc,
  71. handlePageLoad() {},
  72. handlePageUnload() {},
  73. handlePageShow() {
  74. this.supplierSearchTime = uni.getStorageSync('supplier_search_time') || 0;
  75. this.init();
  76. this.toRemindCustom();
  77. },
  78. handlePullDownRefresh() {
  79. return Promise.resolve(this.init()).then(() => {
  80. uni.stopPullDownRefresh();
  81. });
  82. },
  83. getShareMessage(res) {
  84. if (res && res.from === 'button' && res.target && res.target.dataset && res.target.dataset.ghs) {
  85. const ghsInfo = res.target.dataset.ghs;
  86. const hdShopAdminId = this.loginInfo && this.loginInfo.shopAdminId ? this.loginInfo.shopAdminId : 0;
  87. const ghsShopAdminId = ghsInfo.shopAdminId || 0;
  88. const shopId = ghsInfo.shopId || 0;
  89. const fromGhsId = ghsInfo.id || 0;
  90. const fromCg = 1;
  91. const path = \`/pagesPurchase/ghsProduct?hdShopAdminId=\${hdShopAdminId}&ghsShopAdminId=\${ghsShopAdminId}&shopId=\${shopId}&id=0&fromGhsId=\${fromGhsId}&fromCg=\${fromCg}\`;
  92. return {
  93. title: ghsInfo.name,
  94. desc: "",
  95. path: path,
  96. imageUrl: ghsInfo.avatar || ghsInfo.smallAvatar || ''
  97. };
  98. }
  99. return null;
  100. },
  101. ${fixedMethods}
  102. }
  103. };
  104. </script>`;
  105. const out = `<template>\n${tpl}\n${popups}\n</template>\n${script}\n<style lang="scss" scoped>\n${styles}\n</style>\n`;
  106. fs.writeFileSync('d:/front-end/hdApp/src/admin/home/components/purchase-ghs-panel.vue', out);
  107. console.log('written', out.length);