<template>
  <app-dialog v-model="visible" :loading="loading" :title="title" append-to-body class="detail-dialog" width="550px" @cancel="onCancel" @confirm="onConfirm">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-row :gutter="15">
        <app-filter-item :span="24" label="共享资源名称" prop="name">
          <el-input v-model="form.name" clearable placeholder="请输入" />
        </app-filter-item>

        <app-filter-item :span="24" label="共享资源代码" prop="code">
          <el-input v-model="form.code" clearable placeholder="请输入" />
        </app-filter-item>

        <app-filter-item :span="24" label="共享方式" prop="shared">
          <el-input v-model="form.shared" clearable placeholder="请输入" />
        </app-filter-item>
        <app-filter-item :span="24" label="共享资源类型" prop="typed">
          <el-input v-model="form.typed" clearable placeholder="请输入" />
        </app-filter-item>

        <app-filter-item :span="24" label="资源描述" prop="resourceDescription">
          <el-input v-model="form.resourceDescription" clearable placeholder="请输入" />
        </app-filter-item>

        <!--        <app-filter-item :span="24" label="资源项更新周期">-->
        <!--          <el-radio-group v-model="form.updateRate">-->
        <!--            <el-radio-button v-for="(radio, index) in rateList" :key="index" :label="radio" class="mb-10">{{ radio }} </el-radio-button>-->
        <!--          </el-radio-group>-->
        <!--        </app-filter-item>-->
      </el-row>
    </el-form>
  </app-dialog>
</template>

<script>
import dialogMixin from '@/mixins/dialog.js';

export default {
  name: 'CompanyDialog',
  mixins: [dialogMixin],
  props: {
    selectedRows: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      form: {
        sourceType: '1',
      },
      createdList: ['发布', '未发布'],
      tableNameList: ['是', '否'],
      // rateList: ['仅一次', '实时', '每天', '每周', '每月', '每季度', '每年'],
      rules: {
        name: [{ required: true, message: '资源编码不能为空' }],
        code: [{ required: true, message: '资源名称不能为空' }],
        query: [{ required: true, message: '请选择是否开启离线文件共享方式' }],
        status: [{ required: true, message: '请选择接口状态' }],
      },
      loading: false,
    };
  },
  mounted() {},
  methods: {
    /**
     * @description: dialog每次显示时触发的init方法
     * @param {*} data 传入data
     * @return {*}
     */
    initData(data) {
      const orgForm = this.$options.data().form;
      this.form = { ...orgForm, ...data };
      this.$nextTick(() => {
        this.$refs.form.clearValidate();
      });
    },
    onCancel() {
      this.visible = false;
    },
    onConfirm() {
      this.$refs.form.validate(async valid => {
        if (valid) {
          // const params = this.handleParams()
          // try {
          //   this.loading = true
          //   if (this.data?.id) {
          //     await updateData(params)
          //   } else {
          //     await dataAdd(params)
          //   }
          //   this.$message.success('操作成功')
          //   this.onCancel()
          this.$emit('confirm', { ...this.form });
          // } finally {
          //   this.loading = false
          // }
        }
      });
    },
  },
};
</script>

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