<template>
  <div>
    <van-button @click="get()" type="primary">获取列表</van-button>
    <van-cell-group inset>
      <van-cell
        v-for="(item, index) in departments"
        :key="index"
        :title="item.name"
      >
        <template>
          <van-checkbox-group v-model="radio">
            <van-cell-group>
                <van-cell
                  v-for="(user, index2) in departmentlist[index]"
                  :key="index2"
                >
                  <van-checkbox :name="user.userid">{{
                    user.name
                  }}</van-checkbox>
                </van-cell>
            </van-cell-group>
          </van-checkbox-group>
        </template>
      </van-cell>
    </van-cell-group>
    <van-field
      v-model="title"
      rows="2"
      autosize
      label="标题"
      type="textarea"
      maxlength="50"
      placeholder="请输入消息标题"
      show-word-limit
    />
    <van-field
      v-model="message"
      rows="2"
      autosize
      label="内容"
      type="textarea"
      maxlength="50"
      placeholder="请输入消息内容"
      show-word-limit
    />
    <van-uploader v-model="fileList" multiple :max-count="1" />
    <van-cell>
        <van-button @click="postMessage()" type="primary">发送消息</van-button>
    </van-cell>
    <van-cell></van-cell>
  </div>
</template>

<script>
import apiFunc from "@/apis/api";

export default {
  name: "index",
  data() {
    return {
      departments: [],
      departmentlist: [],
      radio: [],
      groupradio: [],
      message:"",
      title:"",
      fileList:[]
    };
  },
  methods: {
    get() {
      let that = this;
      apiFunc.getdepartments().then((res) => {
        that.departments = res.data.result;
        for (let i = 0; i < that.departments.length; i++) {
          apiFunc.getdepartmentlist(that.departments[i].id).then((res) => {
            that.departmentlist.push([]);
            that.departmentlist[i] = res.data.result;
          });
        }
      });
    },
    postMessage() {
        apiFunc.postMessages(this.radio,this.message,this.title).then((res) => {
          console.log(res);
      });
    },
  },
};
</script>
