<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24">
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </el-col>
    </el-row>

    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <h1>公司信息</h1>
      <el-row>
        <el-col :span="8">
          <el-form-item label="公司名称" prop="companyName">
            <el-input v-model="form.companyName" placeholder="请输入公司名称"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="传真号码" prop="faxNumber">
            <el-input v-model="form.faxNumber" placeholder="请输入传真号码"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="品牌名称" prop="brandName">
            <el-input v-model="form.brandName" placeholder="请输入品牌名称"/>
          </el-form-item>
        </el-col>
      </el-row>
      <h1>询盘联系方式</h1>
      <el-row>
        <el-col :span="8">
          <el-form-item label="手机号码" prop="tel">
            <div style="display: flex;justify-content: start;align-items: center">
              <el-input v-model="form.tel" placeholder="请输入手机号码"/>
              <el-tooltip class="item" effect="dark" content="发询盘短信要用到,格式:+8618612345678 或者 +886970123456" placement="bottom">
                <i class="el-icon-question"></i>
              </el-tooltip>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="Email" prop="email">
            <el-input v-model="form.email" placeholder="请输入Email"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="Teams账号" prop="teams">
            <el-input v-model="form.teams" placeholder="请输入Teams账号"/>
          </el-form-item>
        </el-col>
      </el-row>
      <h1>站点信息</h1>
      <el-row>
        <el-col :span="8">
          <el-form-item label="站点icon" prop="icon">
            <image-upload v-model="form.icon"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="站点logo" prop="logo">
            <image-upload v-model="form.logo"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="站点二维码" prop="qrCode">
            <image-upload v-model="form.qrCode"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="版权文字" prop="copyright">
            <el-input v-model="form.copyright" placeholder="请输入版权文字"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系地址" prop="address">
            <el-input v-model="form.address" placeholder="请输入联系地址"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="站点联系方式html" prop="contactUs">
            <editor v-model="form.contactUs" :min-height="192"/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-button type="primary" @click="submitForm">确 定</el-button>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from '@/api/base/info'

export default {
  name: 'Info',
  data() {
    return {
      // 表单参数
      form: {
        id: null,
        companyName: null,
        faxNumber: null,
        brandName: null,
        tel: null,
        email: null,
        teams: null,
        copyright: null,
        address: null,
        icon: null,
        logo: null,
        qrCode: null,
        contactUs: null,
        tenantId: null,
        creator: null,
        createTime: null,
        updater: null,
        updateTime: null,
        delFlag: null
      },
      // 表单校验
      rules: {
        companyName: [
          { required: true, message: '请输入公司名称', trigger: 'blur' },
        ],
        tel: [
          { required: true, message: '请输入手机号码', trigger: 'blur' },
        ],
        email: [
          { required: true, message: '请输入Email账号', trigger: 'blur' },
          { type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur' }
        ],
        teams: [
          { required: true, message: '请输入Teams账号', trigger: 'blur' },
        ],
        icon: [
          { required: true, message: '请上传站点icon', trigger: 'blur' },
        ],
        logo: [
          { required: true, message: '请上传站点logo', trigger: 'blur' },
        ],
        qrCode: [
          { required: true, message: '请上传站点二维码', trigger: 'blur' },
        ],
      }
    }
  },
  created() {
  },
  methods: {
    /** 查询站点基础信息列表 */
    getList() {
      this.loading = true
      listInfo(this.queryParams).then(response => {
        this.infoList = response.data.records
        this.total = response.data.total
        this.loading = false
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
  }
}
</script>
