<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24">
        <el-button type="primary" @click="submitForm">保 存</el-button>
      </el-col>
    </el-row>
    <el-divider></el-divider>
    <!-- 添加或修改在线询盘设置对话框 -->
    <el-form ref="form" :model="form" :rules="rules" label-width="200px">
      <el-row>
        <el-col :span="12">
          <el-form-item prop="company">
            <template v-slot:label>
              <span>公司名称</span>
              <el-tooltip class="item" effect="dark" content="开启后代表客户可以填写公司名称" placement="bottom">
                <i class="el-icon-question"></i>
              </el-tooltip>
            </template>
            <el-switch
              v-model="form.company"
              active-text="开启"
              inactive-text="关闭"
            ></el-switch>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="公司名称是否必填">
            <el-switch
              v-model="form.companyMust"
              active-text="必填"
              inactive-text="非必填"
            >
            </el-switch>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="tel">
            <template v-slot:label>
              <span>电话/WhatsApp</span>
              <el-tooltip class="item" effect="dark" content="开启后代表客户可以填写电话/WhatsApp" placement="bottom">
                <i class="el-icon-question"></i>
              </el-tooltip>
            </template>
            <el-switch
              v-model="form.tel"
              active-text="开启"
              inactive-text="关闭"
            ></el-switch>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="电话/WhatsApp是否必填">
            <el-switch
              v-model="form.telMust"
              active-text="必填"
              inactive-text="非必填"
            >
            </el-switch>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item  prop="title">
            <template v-slot:label>
              <span>标题</span>
              <el-tooltip class="item" effect="dark" content="开启后代表客户可以填写标题" placement="bottom">
                <i class="el-icon-question"></i>
              </el-tooltip>
            </template>
            <el-switch
              v-model="form.title"
              active-text="开启"
              inactive-text="关闭"
            ></el-switch>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="标题是否必填">
          <el-switch
            v-model="form.titleMust"
            active-text="必填"
            inactive-text="非必填"
          >
          </el-switch>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="name">
            <template v-slot:label>
              <span>姓名</span>
              <el-tooltip class="item" effect="dark" content="开启后代表客户可以填写姓名" placement="bottom">
                <i class="el-icon-question"></i>
              </el-tooltip>
            </template>
            <el-switch
              v-model="form.name"
              active-text="开启"
              inactive-text="关闭"
            ></el-switch>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="标题是否必填">
          <el-switch
            v-model="form.nameMust"
            active-text="必填"
            inactive-text="非必填"
          >
          </el-switch>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="提示文字" prop="content">
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入提示文字"
              v-model="form.content"
            >
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-divider></el-divider>
    <el-button type="primary" @click="submitForm">保 存</el-button>
  </div>
</template>

<script>
import { listInquiry, getInquiry, delInquiry, addInquiry, updateInquiry } from '@/api/base/inquiry'

export default {
  name: 'Inquiry',
  data() {
    return {
      // 表单参数
      form: {
        id: null,
        company: null,
        companyMust: null,
        tel: null,
        telMust: null,
        title: null,
        titleMust: null,
        name: null,
        nameMust: null,
        content: null,
        tenantId: null,
        creator: null,
        createTime: null,
        updater: null,
        updateTime: null,
        delFlag: null
      },
      // 表单校验
      rules: {}
    }
  },
  onCreate(){
    debugger
    console.log("onCreate")
    this.getDataInfo()
  },
  created() {
    this.getDataInfo()
  },
  methods: {
    /** 查询在线询盘设置 */
    getDataInfo() {
      getInquiry({}).then(response => {
        if(200==response.code && response.data){
          this.form = response.data
        }
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInquiry(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addInquiry(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },

  }
}
</script>
