<template>
  <div>
    <xy-dialog ref="dialog" :is-show.sync="isShow" :width='50' :type="'form'" :title="'督办提醒'"
      :form="form" :rules='rules' @submit="submit">
      <template v-slot:title>
        <div class="xy-table-item">
          <div class="xy-table-item-label" style="font-weight: bold">
            <span style="color: red;font-weight: bold;padding-right: 4px;">*</span>提醒内容：
          </div>
          <div class="xy-table-item-content">
            <el-input v-model="form.title" type="text"placeholder="请输入提醒内容" clearable
              style="width: 400px;"></el-input>
          </div>
        </div>
      </template>
      <template v-slot:users>
        <div class="xy-table-item">
          <div class="xy-table-item-label" style="font-weight: bold">
            <span style="color: red;font-weight: bold;padding-right: 4px;">*</span>接收人：
          </div>
          <div class="xy-table-item-content">
            <el-checkbox-group v-model="checkList">
                <el-checkbox v-for="item in checkArr" :label="item.accept_admin_id">{{item.accept_admin.name}}</el-checkbox>
              </el-checkbox-group>
          </div>
        </div>
      </template>

      <template v-slot:footerContent>
        <Button type="primary" style='margin-left:5px;margin-bottom:5px;'
          @click="submit">发送</Button>
        <Button type="primary" ghost style='margin-left:5px;margin-bottom:5px;' @click="isShow=false">取消</Button>
      </template>

    </xy-dialog>

  </div>
</template>

<script>
  import {
    Message
  } from 'element-ui'
  import {
    saveNotice
  } from '@/api/task/unit.js'
  import {deepCopy} from "@/utils/index.js"
  export default {
    components: {

    },
    data() {
      return {
        isShow: false,
        type: 'add',
        id: '',
        checkList:[],
        checkArr:[],
        formObj: {},
        form: {
          title:'',
          users:[]
        },
        rules: {
          // carry_type: [{
          //   required: true,
          //   message: '请选择'
          // }],
          // start_date: [{
          //   required: true,
          //   message: '请选择'
          // }],
          // end_date: [{
          //   required: true,
          //   message: '请选择'
          // }],
        }
      }
    },
    created() {
    },
    methods: {
      setForm(e) {
        if (e) {
          let arr = []
          let Arr = []
          this.form.mission_id = e.id
          e.mission_distribute.map(item=>{
            if(item.admin_type>1){
              arr.push(item.accept_admin_id)
              Arr.push(item)
            }
          })
          this.checkList = arr
          this.checkArr = Arr
        }
      },

      submit() {

        if(!this.form.title){
          this.$Message.warning("请输入提醒内容")
          return
        }
        if(this.checkList.length>0){
          this.checkList.map(item=>{
            this.form.users.push({
              user_id:item
            })
          })
        }else{
          this.$Message.warning("请选择接收人")
          return
        }
        saveNotice(this.form).then(res => {
          Message({
            type: 'success',
            message: '提交成功'
          })

          this.$emit('refresh')
          this.isShow = false

        })
      },
    },
    watch: {
      isShow(newVal) {
        if (newVal) {

        } else {
          this.id = ''
          this.$refs['dialog'].reset()
        }
      },
    }

  }
</script>

<style scoped lang="scss">
  ::v-deep .title,
  ::v-deep .users {
    flex-basis: 100%;
  }

  ::v-deep .el-form>div {
    align-items: flex-start !important;
  }

  .xy-table-item {
    padding-right: 0
  }

  ::v-deep .xy-table-item-label {
    padding-right: 0
  }
</style>
