<template>
  <div class="app-container">
    <base-header title="外勤签到设置" />
    <div class="container">
      <mt-cell title="是否启用照片上传功能">
        <mt-switch v-model="usePhoto" @change="setConfig" />
      </mt-cell>
    </div>
  </div>
</template>

<script>
  import {LegworkGetConfig, LegworkSetConfig} from 'API/oa/legwork'
  export default {
    name: 'LegworkSetting',
    beforeRouteEnter(to, from, next) {
      next(vm => {
        vm.getConfig()
      })
    },
    data() {
      return {
        usePhoto: false
      }
    },
    methods: {
      getConfig() {
        LegworkGetConfig().then(res => {
          this.usePhoto = res === 1
        }).catch()
      },
      setConfig() {
        LegworkSetConfig({
          status: this.usePhoto ? 1 : 0
        }).then(() => {
          this.$toast('修改成功')
        }).catch()
      }
    }
  }
</script>

<style scoped lang="scss">
  .app-container {
    .container {
      .mint-cell {
        margin-top: 20px;
        padding: 0 32px;
      }

      ::v-deep .mint-switch-core {
        width: 80px;
        height: 40px;
        border-radius: 40px;
        &:before, &:after {
          top: 1px;
          width: 36px;
          height: 36px;
          border-radius: 36px;
        }
      }
      ::v-deep .mint-switch-core {
        background-color: #E6E6E6;
        border-color: #E6E6E6;
      }
      ::v-deep .mint-switch-input:checked + .mint-switch-core::after {
        transform: translateX(44px);
      }
      ::v-deep .mint-switch-input:checked + .mint-switch-core {
        border-color: $theme-color;
        background-color: $theme-color;
      }
      ::v-deep .mint-cell-value {
        margin-right: 0;
      }
    }
  }
</style>
