<template>
  <div class="mall-section-container">
    <div class="mall-content-section">
      <div class="mall-content-title">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '' }"><a href="/report/#/memberSummary">首页</a></el-breadcrumb-item>
          <el-breadcrumb-item>积分商城</el-breadcrumb-item>
          <el-breadcrumb-item>设置</el-breadcrumb-item>
          <el-breadcrumb-item>常规设置</el-breadcrumb-item>
        </el-breadcrumb>
        <h3>
          <span>常规设置</span>
        </h3>
      </div>
      <div class="section">
        <el-form :model="form" ref="form" :rules="formRules" label-width="100px" class="demo-ruleForm" label-position="right">
          <el-form-item prop="cardType" label="积分消耗卡">
            <el-select v-model="form.cardType" placeholder="积分消耗卡">
              <el-option label="集团卡" :value="2"></el-option>
              <el-option label="品牌卡" :value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleSubmit('form')">确定</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
// import qs from 'qs';
import request from '../../service/request.js';
// import getInputVal from '../../utils/common.js';

export default {
  data() {
    return {
      form: {
        cardType: ''
      },
      formRules: {
        cardType: [{ required: true, message: '请选择积分消耗卡', trigger: 'change' }]
      }
    };
  },
  created() {
    this.getMess();
  },
  methods: {
    getMess() {
      request.get('/api-integral-mall/get-card-config').then(res => {
        if (res.data.errorCode === 0) {
          this.form.cardType = res.data.result.cardType || '';
        } else {
          this.$message.error(res.data.message);
        }
      });
    },
    handleSubmit(form) {
      this.$refs[form].validate(valid => {
        if (valid) {
          let params = {
            cardType: this.form.cardType
          };
          request.get('/api-integral-mall/save-card-config', { params }).then(res => {
            if (res.data.errorCode === 0) {
              this.getMess();
            } else {
              this.$message.error(res.data.message);
            }
          });
        } else {
          return false;
        }
      });
    }
  },
  components: {}
};
</script>
<style scoped>
.section {
  background: #fff;
  margin: 24px;
  padding: 24px;
}
</style>
