<template>
  <div class="app-container">
    <div>
      <div class="set-item">
        <span class="label">月销量显示:</span>
        <el-switch
          v-model="saleShow"
          active-text="是"
          inactive-text="否"
          @change="setSetting"
        />
      </div>
      <div class="set-item-info">
        <i class="el-icon-info">是否在app中显示商品月销量</i>
      </div>
    </div>
    <div v-if="loading" v-loading="loading" class="loadingShade" />
  </div>
</template>

<script>

import {
  filterSet
} from '@/filters/systemSet'

export default {
  data() {
    return {
      saleShow: false,
      saleShow_keys: 'sales_month',
      loading: false,
      loadingTime: 1
    }
  },
  methods: {
    // 获取所有设置
    async getSetting() {
      try {
        const setting = await this.$store.dispatch('system/get')
        // 设置月销量显示
        let saleStatus = filterSet(setting, 'sales_month').values
        saleStatus = saleStatus === '1'
        this.saleShow = saleStatus
      } catch (e) {
        this.$message.error(e)
      }
    },
    // 设置销量显示
    setSetting() {
      this.$store.dispatch('system/set', this.saleShow_keys).then((msg) => {
        this.$message.success(msg)
      }).catch(e => {
        this.$message.error(e)
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
