<!--
 * @Descripttion: (客户关注/tb_customer_follow 添加弹窗)
 * @version: (1.0)
 * @Author: (lwh)
 * @Date: (2023-11-24)
 * @LastEditors: (lwh)
 * @LastEditTime: (2023-11-24)
-->
<template>
  <el-dialog v-model="props.modelValue" title="添加客户关注信息" width="900px" @closed="closeDialog" @open="openDialog">
    <el-form ref="formRef" :model="formData" :rules="rules">
      <el-row :gutter="20">


               <el-col :lg="12">
            <el-form-item :label-width="labelWidth" label="客户Guid" prop="customerGuid">
              <el-input v-model="formData.customerGuid" placeholder="请输入客户Guid" />
            </el-form-item>
          </el-col>
       <el-col :lg="12">
            <el-form-item :label-width="labelWidth" label="表格数据Guid" prop="tableDataGuid">
              <el-input v-model="formData.tableDataGuid" placeholder="请输入表格数据Guid" />
            </el-form-item>
          </el-col>

      </el-row>
    </el-form>

    <template #footer>
      <div key="dialog-footer">
        <el-button type="primary" @click="handleAddClick(formRef)" :loading="loadingStatus">添加</el-button>
        <el-button @click="handleResetClick(formRef)">重置</el-button>
      </div>
    </template>
  </el-dialog>
</template>


<script setup>
import { reactive, ref, watch } from "vue";
import { ElMessage } from 'element-plus'
import modal from '@/plugins/modal.js'
import {  addOrUpdateCustomerFollow } from '@/api/business/TableDataManage/CustomerFollows/customerFollow.js';


// 打开弹窗时回调
const openDialog = async () => {


}

// -业务参数


// -业务方法



// -基础参数
const loadingStatus = ref(false)
const labelWidth = 100;
const formRef = ref();
const { proxy } = getCurrentInstance()
const emits = defineEmits(["update:modelValue"]);
const formData = reactive({
});
const props = defineProps({
  modelValue: Boolean,
  done: Function,
});
const imgData = ref({
  fileDir: "CustomerFollow"
})

// 验证
const rules = reactive({
    customerFollowGuid: [{ required: true, message: "不能为空", trigger: "blur", type: "number" }],
    customerGuid: [{ required: true, message: "客户Guid不能为空", trigger: "blur", type: "number" }],
    tableDataGuid: [{ required: true, message: "表格数据Guid不能为空", trigger: "blur", type: "number" }],
});

// -基础方法

// 提交
const handleAddClick = async (formEl) => {
  if (!formEl) return;
  formEl.validate(async (valid) => {
    if (!valid) {
      return;
    }
    loadingStatus.value = true


    const { code } = await addOrUpdateCustomerFollow(formData);
    if (code == 200) {
      modal.msgSuccess('添加成功')
      closeDialog();
      loadingStatus.value = false
    }
  });
};
const closeDialog = () => {
  handleResetClick(formRef.value);
  props.done();
  emits("update:modelValue", false);
};
const handleResetClick = async (formEl) => {
  if (!formEl) return;
  formEl.resetFields();
};
</script>