
<template>
    <el-dialog
      :visible.sync="showDialog"
      :title="title"
      :modal-append-to-body="false"
      style="text-align: left"
      @close="closeDialog"
      :close-on-click-modal="false"
      width="1000px"
    >
      <div class="user-panel" v-loading="loading">
        <el-descriptions class="margin-top" :column="3"  border>
            <el-descriptions-item>
            <template slot="label">
                流水号
            </template>
            {{formModel.wishInfoUserRecord.num}}
            </el-descriptions-item>
            <el-descriptions-item>
            <template slot="label">
                爱心人士
            </template>
            {{formModel.wishInfoUserRecord.regUserName}}
            </el-descriptions-item>
            <el-descriptions-item>
            <template slot="label">
                是否现场互换心愿
            </template>
            <span v-if="formModel.wishInfoUserRecord.isSpot">是</span>
            <span v-else>否</span>
            </el-descriptions-item>
            <el-descriptions-item>
            <template slot="label">

                学生心愿
            </template>
            篮球
            </el-descriptions-item>
            <el-descriptions-item span="2">
            <template slot="label">
                作品图片
            </template>
            <el-link :href="formModel.wishInfo.image" target="blank_"  :underline="false">
                <el-image
                    style="width: 100px; height: 100px"
                    :src="formModel.wishInfo.image">
                </el-image>
            </el-link>
            </el-descriptions-item>
            <el-descriptions-item>
            <template slot="label">
                学生姓名
            </template>
            {{formModel.wishInfo.studentName}}
            </el-descriptions-item>
            <el-descriptions-item>
            <template slot="label">
                学生类型
            </template>
            {{formModel.wishInfo.studentType}}
            </el-descriptions-item>
            <el-descriptions-item>
            <template slot="label">
                互换状态
            </template>
            {{formModel.wishInfoUserRecord.statusN}}
            </el-descriptions-item>
            <el-descriptions-item>
            <template slot="label">
                收件人
            </template>
            {{formModel.wishInfoUserRecord.recipients}}
            </el-descriptions-item>
            <el-descriptions-item span="2">
            <template slot="label">
                收件人电话
            </template>
            {{formModel.wishInfoUserRecord.recipientsPhone}}
            </el-descriptions-item>
            <el-descriptions-item span="3">
            <template slot="label">
                收件人地址
            </template>
            {{formModel.wishInfoUserRecord.recipientsAddress}}
            </el-descriptions-item>

            <el-descriptions-item>
            <template slot="label">
                寄件人
            </template>
            {{formModel.wishInfoUserRecord.sender}}
            </el-descriptions-item>
            <el-descriptions-item span="2">
            <template slot="label">
                寄件人电话
            </template>
            {{formModel.wishInfoUserRecord.senderPhone}}
            </el-descriptions-item>
            <el-descriptions-item>
            <template slot="label">
                寄件人地址
            </template>
            {{formModel.wishInfoUserRecord.senderAddress}}
            </el-descriptions-item>
        </el-descriptions>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="closeDialog">取 消</el-button>
      </span>
    </el-dialog>
  </template>
  <script>
  import Constant from "@/constant";
  import { getToken } from "@/utils/auth"; // get token from cookie
  import wishInfoUserRecordApi from "@/api/base/wishInfoUserRecord";
  import dataDictionaryApi from "@/api/sys/dataDictionary";
  
  export default {
    props: ["businessKey", "title"],
    data() {
      return {
        showPwd: true,
        ruleValidate: {
          category: [
            { required: true, message: "类型不能为空", trigger: "blur" },
          ],
          title: [
            { required: true, message: "标题不能为空", trigger: "blur" },
          ],
          amount: [
            { required: true, message: "数量不能为空", trigger: "blur" },
          ],
          studentName: [
            { required: true, message: "学生姓名不能为空", trigger: "blur" },
          ],
          studentType: [
            { required: true, message: "学生类型不能为空", trigger: "blur" },
          ],
        },
        roleList: [],
        formModel: {
            wishInfoUserRecord:[],
            wishInfo:[]
        },
        showDialog: true,
        loading: false,
        submitting: false,
        categoryList:[],
        //上传地址
        uploadUrl: Constant.serverUrl + "/uploadPicture",
        uploadData: {
            subFolder: "love-donation",
        },
        fileUrl: "",
        fileUrl1: "",
        headers: {
            Authorization: getToken(),
        },
        uploadUrl1: Constant.serverUrl + "/tinymce/upload?token=" + getToken(),
      };
    },
    created() {
      dataDictionaryApi.findByCatalogName({catalogName: "心愿类型",})
        .then((response) => {
            var jsonData = response.data;
            this.categoryList = jsonData.data;
      });
    },
    methods: {
      closeDialog() {
        this.$emit("close", false);
      },
      handleSubmit() {
        var self = this;
  
        this.$refs["form"].validate((valid) => {
          if (valid) {
            (function () {
              var id = self.formModel.id;
  
              if (id == null || id.length == 0) {
                return wishInfoUserRecordApi.add(self.formModel);
              } else {
                self.formModel.password = null;
                return wishInfoUserRecordApi.update(self.formModel);
              }
            })().then(function (response) {
              var jsonData = response.data;
  
              if (jsonData.result) {
                self.$message({
                  message: "保存成功!",
                  type: "success",
                });
  
                self.$emit("close", true);
              } else {
                self.$message({
                  message: jsonData.message + "",
                  type: "warning",
                });
  
                self.$emit("close", false);
              }
            });
          }
        });
      },
      handleAvatarSuccess(res, file) {
          var self = this;
          self.formModel.image = res.data;
  
          self.fileUrl =
            res.data + "?x-oss-process=image/resize,m_lfit,h_300,w_300";
      },
    },
    async mounted() {
      var self = this;
      self.loading = true;
  
      (function () {
        if (self.businessKey != null && self.businessKey.length > 0) {
          return wishInfoUserRecordApi.edit(self.businessKey);
        } else {
          return wishInfoUserRecordApi.create();
        }
      })()
        .then((response) => {
          var jsonData = response.data;
  
          if (jsonData.result) {
            self.formModel = jsonData.data;

            //alert(JSON.stringify(self.formModel))

            self.showModal = true;
  
            let image = self.formModel.image;
              if (image != null) {
                  self.fileUrl = image 
              }
  
            if (self.formModel.introduction != null) {
              self.$refs.editor.setContent(self.formModel.introduction);
            }
  
          } else {
            self.$message.error(jsonData.message + "");
          }
  
          self.loading = false;
        })
        .catch((error) => {
          self.$message.error(error + "");
          self.loading = false;
        });
    },
    components: {
    },
  };
  </script>
  <style scoped>
  .user-panel {
    margin: 10px auto;
  }
  .avatar-uploader .el-upload {
      border: 1px dashed #d9d9d9;
      border-radius: 6px;
      cursor: pointer;
      position: relative;
      overflow: hidden;
    }
    .avatar-uploader .el-upload:hover {
      border-color: #409EFF;
    }
    .avatar-uploader-icon {
      font-size: 28px;
      color: #8c939d;
      width: 178px;
      height: 178px;
      line-height: 178px;
      text-align: center;
    }
    .avatar {
      width: 178px;
      height: 178px;
      display: block;
    }
  </style>