<template>
  <el-form :model="supplierForm" ref="supplierForm" label-width="130px" v-loading="loading" style="width: 500px">
    <el-form-item label="默认商品图片" prop="default_sku_image">
      <el-upload class="site-logo" :action="MixinUploadApi" :show-file-list="false"
        :on-success="(res) => { supplierForm.default_sku_image = res.url }" :multiple="false">
        <img v-if="supplierForm.default_sku_image" :src="supplierForm.default_sku_image" class="site-logo-img">
        <i v-else class="el-icon-plus logo-uploader-icon"></i>
      </el-upload>
    </el-form-item>
    <el-form-item label="通知手机号" prop="notify_mobile">
      <el-input v-model="supplierForm.notify_mobile" maxlength="11"></el-input>
    </el-form-item>
    <el-form-item label="">
      <el-button type="primary" @click="submitForm">保存设置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import * as API_SystemSetting from '@/api/systemSetting'

export default {
  name: 'SystemSettingsSupplier',
  data() {
    return {
      loading: true,
      /** 站点设置 */
      supplierForm: {},
      siteTagInputVisible: false,
      siteTagInputValue: ''
    }
  },
  created() {
    API_SystemSetting.getSupplierSetting().then(response => {
      this.loading = false
      this.supplierForm = response
      this.supplierForm.keywords = response.keywords.split(',')
    }).catch(() => { this.loading = false })
  },
  watch: {
    'supplierForm.siteon': function(newVal) {
      this.siteRules.close_reson[0].required = newVal === 0
    }
  },
  methods: {
    submitForm() {
      this.$refs['supplierForm'].validate((valid) => {
        if (valid) {
          const params = this.MixinClone(this.supplierForm)
          API_SystemSetting.editSupplierSetting(params).then(() => {
            this.$message.success('修改成功！')
          })
        } else {
          this.$message.error('表单填写有误，请检查！')
          return false
        }
      })
    }
  }
}
</script>

<style type="text/scss" lang="scss" scoped>
.container {
  background-color: #fff;
  padding: 10px;
  position: relative;
}

.site-tag {
  margin: 0 3px;
}

.site-new-tag-input {
  width: 100px;
}

/deep/ .site-logo .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;

  &:hover {
    border-color: #409EFF;
  }
}

.logo-uploader-icon {
  font-size: 20px;
  color: #8c939d;
  width: 120px;
  height: 120px;
  line-height: 120px;
  text-align: center;
}

.site-logo-img {
  width: 120px;
  height: 120px;
  display: block;
}

.image-pane .el-input-group {
  width: 200px;
}

.point-pane .el-input-group {
  width: 200px;
}
</style>
