Facebook
From Denim Camel, 6 Years ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 235
  1. <template lang="jade">
  2. div#vue-market
  3.         div.market-menager
  4.                 h3 Market manager ({{outSize}})
  5.                 header
  6.                         input(type="text" v-model="sort.name" placeholder="Nazwa przedmiotu")
  7.                         input(type="text" v-model="sort.priceMin" placeholder="Cena min")
  8.                         input(type="text" v-model="sort.priceMax" placeholder="Cena max")
  9.                         select-template(:selected.sync="sort.price" v-bind:list="['min - max','max - min']"  placeholder="Sortowanie ceny")
  10.                         select-template(:selected.sync="sort.available" v-bind:list="['włączone','wyłączone']"  placeholder="Dortowanie dostępności")
  11.                         select-template(:selected.sync="sort.error" v-bind:list="['Alert api','Alert ceny','Alert Brak']"  placeholder="Sortowanie Alertów")
  12.                 header
  13.                         button.gradient(@click="setAllProfile({allow_in_case: 1})") Włącz wszystkie
  14.                         button.gradient(@click="setAllProfile({allow_in_case: 0})") Wyłącz wszystkie
  15.                         button.gradient(@click="UpdateAllProfilePrice") Aktualizuj ceny
  16.                 nav
  17.                         select-template(:selected.sync="page.limit" v-bind:list="['5','10','20']" placeholder="Sztuk")
  18.                         i.fas.fa-angle-left(v-on:click="page.active--")
  19.                         div
  20.                                 input(v-model="page.active" type="number")
  21.                                 p {{page.count}}
  22.                         i.fas.fa-angle-right(v-on:click="page.active++")
  23.                 section
  24.                         item(v-for="profile in out" v-bind:profile="profile" @edit="setProfile")
  25.        
  26. </template>
  27.  
  28. <script>
  29.  
  30.  
  31.  
  32.  
  33. import mySelect from "../../../../components/select.vue";
  34. import item from "./item.vue";
  35. export default {
  36.   name: "market-manager",
  37.   data() {
  38.     return {
  39.                 query:{where:{market_hash_name:[],current_price:[],allow_in_case:[]}},
  40.     sort: { // wortości sortowań profili
  41.         price:'',
  42.         name:'',
  43.                 available: '',
  44.                 error: '',
  45.                 priceMin: '',
  46.                 priceMax: ''
  47.         },
  48.         page: {
  49.                 count: 0,
  50.                 limit: null,
  51.                 active: 1
  52.         },
  53.     profiles:[], // Wszystkie profile
  54.     out:[], // Wyjściowe profile pod widok
  55.         outSize: 0,
  56.         temp: 0
  57.     }},
  58.     created() {
  59.  
  60.         this.getProfiles(); // Pierwsze pobieranie profili
  61.         },
  62.         watch: {
  63.                 'sort.available': function() {this.renderProfiles()},
  64.                 'sort.price': function() {this.renderProfiles()},
  65.                 'sort.name': function() {this.renderProfiles()},
  66.                 'sort.error': function() {this.renderProfiles()},
  67.                 'sort.priceMin': function() {this.renderProfiles()},
  68.                 'sort.priceMax': function() {this.renderProfiles()},
  69.                 'page.limit': function() {this.renderProfiles()},
  70.                 'page.priceMin': function() {this.renderProfiles()},
  71.                 'page.priceMax': function() {this.renderProfiles()},
  72.                 'page.active': function(n,p) {
  73.                         if(n < 1 || n > this.page.count) {
  74.                                 this.page.active = p
  75.                         } else {
  76.                                 this.renderProfiles()
  77.                         }
  78.                        
  79.                 }
  80.         },
  81.         components: {
  82.                 "select-template": mySelect,
  83.                 'item': item
  84.         },
  85.  
  86.         methods: {
  87.                 setProfile(data) {
  88.                         let params = {id:data.id,edit:data.edit,query:this.query};
  89.                         Server.CallEvent("@Admin->editMarketProfiles",params,this.getProfiles);
  90.                 },
  91.                 setAllProfile(edit) {
  92.                         let ids = [];
  93.                         this.out.forEach((v)=>{ids.push(v.id)})
  94.                         let params = {edit: edit,query: {whereIn:{id:ids}}};
  95.                         if(ids.length != 0) {
  96.                                 Server.CallEvent("@Admin->editMarketProfiles", params,this.getProfiles);
  97.                         }
  98.                 },
  99.                 UpdateAllProfilePrice() {
  100.                         let index = 0;
  101.                         this.out.forEach((v)=>{
  102.                                 if(v.api != 0) {
  103.                                         let params = {id:v.id,edit:{current_price: v.api},query:this.query};
  104.                                         Server.CallEvent("@Admin->editMarketProfiles",params,()=>{
  105.                                                 index++
  106.                                                 if(index == this.outSize) {this.getProfiles();}
  107.                                         });
  108.                                 } else {
  109.                                         index++;
  110.                                         if(index == this.outSize) {this.getProfiles();}
  111.                                 }
  112.  
  113.                         })
  114.  
  115.                 },
  116.                 getProfiles() {
  117.                         let params = {query:this.query}
  118.                         Server.CallEvent("@Admin->getMarketProfiles",params,(e,profiles)=>{
  119.                                 if(e==null) {
  120.                                         Server.CallEvent("@Admin->getSteamPrices",(er,apiPrice)=> {
  121.                                                 profiles.forEach((profile,index)=>{
  122.                                                         if(apiPrice[profile.market_hash_name]) {
  123.                                                                 profile.api = apiPrice[profile.market_hash_name];
  124.                                                         }
  125.                                                         else {
  126.                                                                 profile.api = 0;
  127.                                                         }
  128.                                                         profile.newPrice = profile.current_price;
  129.                                                         profile.status = false
  130.                                                         profile.error = this.getError(profile)
  131.                                                 })
  132.                                                 this.profiles = profiles;
  133.                                                 this.renderProfiles();
  134.                                         })
  135.  
  136.                                 }
  137.                         });
  138.                 },
  139.                 getError(profile) {
  140.                         if (profile.api == 0) {
  141.                                 return 'Alert api'
  142.                         }
  143.                         else  if (Math.abs(profile.api - profile.current_price) > 0.5 && Math.abs(profile.api - profile.current_price) * 100 / profile.api > 10) {
  144.                                 return 'Alert ceny'
  145.                         }
  146.                         else {
  147.                                 return 'Alert Brak'
  148.                         }
  149.                 },
  150.  
  151.                 renderProfiles() {
  152.                         // var start = +new Date();  // log start timestamp
  153.                         let list = Object.assign([],this.profiles);
  154.                         if(this.sort.available != '' & this.sort.available != null) { list = this.sortByAvailable(list) }
  155.                         if(this.sort.error != '' & this.sort.error != null) { list = this.sortByError(list) }
  156.                         if(this.sort.name != '' & this.sort.name != null) { list = this.sortByName(list) }
  157.                         if(this.sort.price != '' & this.sort.price != null) { list = this.sortByPrice(list) }
  158.                         if(this.sort.priceMin != '' || this.sort.priceMax != '') { list = this.sortByPriceMinMax(list) }
  159.                         list = this.sortByPage(list);
  160.                         this.out = list
  161.                         this.outSize = list.length
  162.                         // var end =  +new Date();  // log end timestamp
  163.                         // var diff = end - start;
  164.                         // alert('Time: ' + diff + 'ms.');
  165.                         },
  166.  
  167.                 sortByPrice(props){
  168.                         let list = Object.assign([],props);
  169.                         let out = list.sort((a,b)=>{
  170.                                 if(this.sort.price == 'min - max') {
  171.                                         return parseFloat(a.current_price) - parseFloat(b.current_price)
  172.                                 }
  173.                                 else if(this.sort.price == 'max - min') {
  174.                                         return parseFloat(b.current_price) - parseFloat(a.current_price)
  175.                                 }
  176.                                        
  177.                         })
  178.                         return out
  179.                 },
  180.                 sortByName(props){
  181.                         let reg = new RegExp(this.sort.name.toUpperCase());
  182.                         let list = Object.assign([],props)
  183.                         let out = [];
  184.                         list.forEach((v,i,a)=>{
  185.                                 let name = v.market_hash_name.toUpperCase()
  186.                                 if (reg.test(name)) { out.push(v) }
  187.                         })
  188.                         return out
  189.                 },
  190.                 sortByAvailable(props){
  191.                         let list = Object.assign([],props)
  192.                         let out = [];
  193.                         list.forEach((v,i,a)=>{
  194.                                 let available = v.allow_in_case
  195.                                 let number = 1;
  196.                                 if(this.sort.available == 'włączone') {number = 1}
  197.                                 if(this.sort.available == 'wyłączone') {number = 0}
  198.                                 if (available == number) {
  199.                                         out.push(v)
  200.                                 }
  201.                         })
  202.                         return out      
  203.                 },
  204.                 sortByPriceMinMax(props){
  205.                         console.log(12)
  206.                         let list = Object.assign([],props);
  207.                         let min = this.sort.priceMin==''?0:this.sort.priceMin;
  208.                         let max = this.sort.priceMax==''?Infinity:this.sort.priceMax;
  209.                         let out = [];
  210.                         list.forEach((v,i,a)=>{
  211.                                 let price = parseFloat(v.current_price)
  212.                                 if (price >= min & price <= max) {
  213.                                         out.push(v)
  214.                                 }
  215.                         })
  216.                         return out      
  217.                 },
  218.                 sortByError(props){
  219.                         let list = Object.assign([],props)
  220.                         let out = [];
  221.                         list.forEach((v,i,a)=>{
  222.                                 if (this.sort.error == v.error) {
  223.                                         out.push(v)
  224.                                 }
  225.                         })
  226.                         return out      
  227.                 },
  228.                 sortByPage(props){
  229.                         let list = Object.assign([],props)
  230.                         if(this.page.limit == null) {
  231.                                 this.page.count = 1;
  232.                                 this.page.active = 1;
  233.                                 return list
  234.                         }
  235.                         else {
  236.                                 this.page.count = Math.ceil(list.length / this.page.limit)
  237.                                 let tempSite = (parseInt(this.page.active)-1) * parseInt(this.page.limit);
  238.                                 let tempLimit = parseInt(this.page.limit);
  239.                                 let out = list.splice(tempSite, tempLimit);
  240.                                 return out
  241.                         }
  242.      
  243.                 }
  244.         }
  245.  
  246. };
  247. </script>
  248.  
  249.  
  250.