<template>
  <el-dialog v-model="props.modelValue" title="产品详情" width="900px" @closed="closeDialog" @open="openDialog">
    <el-form ref="formRef" :model="formData" :rules="rules" :disabled="true">
      <el-row>
        <el-col :lg="24">
          <el-form-item :label-width="labelWidth" label="产品类目" prop="product_type_guid">
            <el-cascader class="w100" filterable :options="dataList"
              :props="{ checkStrictly: false, value: 'product_type_guid', label: 'product_type_name', emitPath: false }"
              clearable v-model="formData.product_type_guid">
              <template #default="{ node, data }">
                <span>{{ data.product_type_name }}</span>
                <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
              </template>
            </el-cascader>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>

        <el-col :span="12">
          <el-form-item :label-width="labelWidth" label="产品名称" prop="product_name">
            <el-input v-model='formData.product_name' type="text"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span='24'>
          <el-form-item :label-width='labelWidth' label='产品图片' prop='product_img'>
            <UploadImage ref='uploadRef' v-model='formData.product_img' :data=uoloadData :limit='5' :fileSize='5'
              :drag='true' :isDisabled="true" :isShowTip='false' />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item :label-width="labelWidth" label="产品排序" prop="product_sort">
            <el-input-number v-model='formData.product_sort' controls-position='right' :min='1'></el-input-number>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item :label-width="labelWidth" label="跳转链接" prop="product_link">
            <el-input v-model='formData.product_link' type="text"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label-width="labelWidth" label="产品描述" prop="product_description">
            <el-input v-model='formData.product_description' type="textarea" :rows="5"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item :label-width="labelWidth" label="产品详情" prop="product_details">
            <RichText v-model='formData.product_details' :min-height='196'></RichText>
          </el-form-item>
        </el-col>

      </el-row>
    </el-form>
  </el-dialog>
</template>

<script setup>
import { reactive, ref, watch } from "vue";
import { isEmptyObject } from "~/utils/index";
import { getProductTypeTree } from "~/service/product_type";


// --业务参数



// --业务方法
const dataList = ref();
async function getList() {
  getProductTypeTree().then((res) => {
    if (res.code == 0) {
      dataList.value = res.data
    }
  })
}



// --基础参数
const formRef = ref();
const labelWidth = 100;

const props = defineProps({
  modelValue: Boolean,
  data: Object,
  done: Function,
});
const emits = defineEmits(["update:modelValue"]);
const formData = ref({
  ...props.data,
});


// --基础方法
watch(props, (v) => {
  formData.value = v.data;


});

// 打开弹窗时执行
const openDialog = async () => {

  await getList()

};

const closeDialog = () => {
  emits("update:modelValue", false);
};
</script>

<style lang="less" scoped></style>
