<!--
  @description:
  @author: zxl
  @routerPath:
  @date: 2022-12-28 15:21
-->
<template>
  <div>
    <el-dialog
      v-dialogDrag
      :visible.sync="dialogData.flag"
      :close-on-click-modal="false"
      title="平台信息"
      width="40vw"
      custom-class="el-dialog__body-p0"
      top="10vh"
    >
      <div class="p16">
        <el-form
          ref="form"
          :model="formData"
          :rules="rules"
          :inline-message="true"
        >
          <table class="from_table">
            <tr>
              <td>
                <el-form-item label="消息标题" prop="msgTitle" />
              </td>
              <td colspan="3">
                <el-input v-model="formData.msgTitle" maxlength="200" show-word-limit />
              </td>
            </tr>
            <tr>
              <td>
                <el-form-item label="消息类型" prop="msgType" />
              </td>
              <td colspan="3">
                <el-radio-group v-model="formData.msgType">
                  <el-radio label="01">
                    公开消息
                  </el-radio>
                  <el-radio label="02">
                    指定消息
                  </el-radio>
                </el-radio-group>
              </td>
            </tr>
            <tr>
              <td>
                <el-form-item label="消息源地址" prop="msgUrl" />
              </td>
              <td colspan="3">
                <el-input v-model="formData.msgUrl" maxlength="200" show-word-limit />
              </td>
            </tr>

            <tr>
              <td>
                <el-form-item label="消息发起人" prop="msgUserName" />
              </td>
              <td>
                <el-input v-model="formData.msgUserName" maxlength="50" show-word-limit />
              </td>
              <!--              <td colspan="3">
                <el-input
                  v-model="formData.platformDesc"
                  :autosize="{ minRows: 2, maxRows: 4 }"
                  type="textarea"
                  placeholder="请输入内容"
                />
              </td>-->
            </tr>
            <!--            <tr>
              <td>
                <el-form-item label="消息发送人id" prop="msgUserId" />
              </td>
              <td colspan="3">
                <el-input v-model="formData.msgUserId" maxlength="32" show-word-limit />
              </td>
            </tr>
            <tr>
              <td>
                <el-form-item label="消息发起单位id" prop="msgDepartId" />
              </td>
              <td colspan="3">
                <el-input v-model="formData.msgDepartId" maxlength="32" show-word-limit />
              </td>
            </tr>-->
            <tr>
              <td>
                <el-form-item label="消息发起单位名称" prop="msgDepartName" />
              </td>
              <td colspan="3">
                <el-input v-model="formData.msgDepartName" maxlength="100" show-word-limit />
              </td>
            </tr>
            <tr>
              <td>
                <el-form-item label="接收人用户名" :prop="formData.msgType==='01'?'':'receiveUser'" />
              </td>
              <td colspan="3">
                <el-input v-model="formData.receiveUser" maxlength="32" show-word-limit />
              </td>
            </tr>
            <tr>
              <td>
                <el-form-item label="消息内容" prop="msgContent" />
              </td>
              <td colspan="3">
                <el-input
                  v-model="formData.msgContent"
                  :autosize="{ minRows: 2, maxRows: 4 }"
                  type="textarea"
                  placeholder="请输入内容"
                  maxlength="10000"
                />
              </td>
            </tr>
          </table>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button :loading="confirmLoading" type="primary" @click="sure()">
          确认
        </el-button>
        <el-button @click="dialogData.flag=false">
          取消
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import { publishMsg } from '../../../api/appManagement/msg'

export default {
  components: {

  },
  props: {
    dialogData: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      formData: {
        id: '',
        msgTitle: '', //  消息标题
        msgContent: '', // 消息内容
        msgType: '01', // 消息类型
        msgUrl: '', // 消息源地址
        msgUserName: '', // 消息发起人
        msgUserId: '', // 消息发送人id
        msgDepartId: '', // 消息发起单位id
        msgDepartName: '', // 消息发起单位名称
        receiveUser: ''// 接收人用户名

      },
      rules: {
        msgTitle: [{ required: true, message: '不能为空', trigger: 'blur' }],
        msgContent: [{ required: true, message: '不能为空', trigger: 'blur' }],
        msgType: [{ required: true, message: '请选择', trigger: 'blur' }],
        receiveUser: [{ required: true, message: '请输入', trigger: 'blur' }]
      },
      confirmLoading: false
    }
  },
  created() {
    if (this.dialogData.row) {
      this.formData = this.dialogData.row
    }
  },
  methods: {
    // 附件上传
    changeFile(file, fileList) {
      const f = fileList[0]
      console.log('ffffff', f)
      if (f?.fileData?.fileId) {
        /* this.formData.fileId = f?.fileData?.fileId*/
      }
    },
    sure() {
      // 校验输入内容
      this.$refs['form'].validate((valid, field) => {
        if (valid) { // 校验通过
          this.confirmLoading = true
          publishMsg(this.formData).then(res => {
            this.confirmLoading = false
            this.$message({
              type: 'success',
              message: '操作成功'
            })
            this.$emit('change', true)
            this.dialogData.flag = false
          }).catch(() => {
            this.confirmLoading = false
          })
        }
      })
    }
  }

}
</script>

<style scoped>

</style>
