<template>
  <div>
    <el-dialog
      width="500px"
      title="新建群聊"
      :visible.sync="lookVisible"
      :before-close="onClose"
    >
      <el-form :model="formes" label-width="120px" ref="eidtPostMsg">
        <el-form-item
          label="群聊名称"
          :rules="[{ required: true, message: '请输入群聊名称' }]"
          prop="groupName"
        >
          <el-input class="w100" v-model="formes.groupName"></el-input>
        </el-form-item>
        <el-form-item
          label="群聊类型"
          :rules="[{ required: true, message: '请选择群聊类型' }]"
          prop="groupType"
        >
          <el-select
            class="w100"
            v-model.trim="formes.groupType"
            clearable
            filterable
            placeholder="群聊类型"
          >
            <el-option
              v-for="(item, index) in catgGoupTypeList"
              :key="index"
              :value="item.value"
              :label="item.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="群类型"
          :rules="[{ required: true, message: '请选择群类型' }]"
          prop="groupType"
        >
          <el-select
            class="w100"
            v-model.trim="formes.type"
            clearable
            filterable
            placeholder="群聊类型"
          >
            <el-option
              v-for="(item, index) in catTypeList"
              :key="index"
              :value="item.value"
              :label="item.label"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="onClose">取 消</el-button>
        <el-button type="primary" @click="submitMsg">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { createGroup } from "../api";
import { catgGoupTypeList,catTypeList } from "@/utils/searchArray";
export default {
  name: "eidtPostMsg",
  data() {
    return {
      formes: {
        id: "",
        groupName: "",
        groupType: "",
        type:""
      },
      catgGoupTypeList,
      catTypeList,
      lookVisible: false,
      chioseIdList: null,
      activeRow: null,
      type: "",
      title: "",
    };
  },

  mounted() {
    this.init();
  },
  methods: {
    init() {},
    openDioag() {
      this.lookVisible = true;
    },
    openResetDioag(row, type) {
      this.type = type;
      if (type == "name") {
        this.title = "修改群聊名称";
      } else {
        this.title = "修改群聊类型";
      }
      // this.activeRow = row;
      this.formes = { ...row };
      this.lookVisible = true;
    },
    onClose() {
      this.formes = {
        name: "",
        groupType: "",
      };
      this.$refs["eidtPostMsg"].resetFields();
      this.lookVisible = false;
    },
    submitMsg() {
      this.$refs.eidtPostMsg.validate(async (flag) => {
        if (flag) {
          try {
            const res = await createGroup({ ...this.formes });
            this.$message.success("新增成功");
            this.$emit("getList");
            this.onClose();
          } catch (e) {
            console.log(e);
          }
        }
      });
    },
    getName(val) {
      this.formes.fileName = val.data.name;
    },
    payDate() {
      let self = this;
      return {
        firstDayOfWeek: 1,
        disabledDate(time) {
          return time.getTime() + 86400000 < new Date().getTime();
        },
      };
    },
  },
};
</script>
<style lang="scss" scoped>
.w100 {
  width: 100% !important;
}
</style>
