<template>
  <div class="systemSettings">
    <van-nav-bar class="navBar" title="设置" left-arrow @click-left="onClickLeft" />
    <div class="content">
      <div class="module">
        <div class="title">拜访设置</div>
        <div class="box">
          <div class="label">允许拍照时缩放，但每张会保存到本地相册</div>
          <div class="value">
            <van-switch v-model="switchChecked" size="20" @change="change" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { mapState } from 'vuex';
import { setPhotoMethod } from '@/api/week';
import store from '@/store';
export default {
  name: 'systemSettings',
  computed: {
    ...mapState({
      userInfo: (state) => state.user.userInfo,
    }),
  },
  data() {
    return {
      switchChecked: false,
    };
  },
  created() {
    // 0=企业微信，1=H5相机
    this.switchChecked = this.userInfo.photoMethod == 0 ? false : true;
  },
  methods: {
    change(value) {
      console.log(value);
      this.toastLoading(0, '加载中...', true);
      setPhotoMethod({ photoMethod: value ? 1 : 0 }).then((res) => {
        this.toastLoading().clear();
        if (res.code == 200) {
          this.$toast('设置成功');
          // 获取移动端获取用户信息接口
          store.dispatch('getUserInfo');
        }
      });
    },
    onClickLeft() {
      this.$router.go(-1);
    },
  },
};
</script>
<style lang="scss" scoped>
.systemSettings {
  width: 100%;
  height: 100%;
  .content {
    margin: 10px 16px;
    .module {
      margin-bottom: 10px;
      .title {
        font-size: 16px;
        padding: 10px 0;
      }
      .box {
        background: #fff;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px;
        font-size: 16px;
      }
    }
  }
}
</style>
