<template>
  <el-dialog
    width="1260px"
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
    @close="handlereset"
    style="height: auto;"
  >
    <div style="margin-bottom: 60px;">
      <el-form
        style="height: auto;"
        class="addFormBox"
        :model="dataForm"
        :rules="dataRule"
        ref="dataForm"
        label-width="80px"
      >
        <el-form-item label="链接地址" prop="url">
          <el-input
            v-model="dataForm.url"
            placeholder="链接地址"
            :rows="3"
          ></el-input>
        </el-form-item>
      </el-form>
    </div>

    <span slot="footer" class="dialog-footer">
      <el-button @click="handlereset">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import global from "../../common/common.vue"; //引入共用组间
export default {
  data() {
    return {
      baseUrl: global.baseUrl,
      visible: false,
      dialogImageUrl: "",
      dialogVisible: false,
      dataForm: {
        id: null,
        title: '',
        url: ''
      },
      dataRule: {
        url: [
          { required: true, message: "链接地址不能为空", trigger: "blur" }
        ]
      },
      urlList: {
        info: "/master/message/getMessageById",
        add: "/common/wxPublicAccount/addWxPublicAccountArticle",
        update: "/common/wxPublicAccount/updateWxPublicAccountArticle"
      }
    };
  },
  methods: {
    init(row) {
      this.dataForm = {
        id: row && row.id || null,
        url: row && row.url || ''
      };
      this.visible = true;
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          // 这里应该是提交数据的逻辑
          this.$http
            .request({
              url: this.dataForm.id ? this.$http.adornUrl(this.urlList.update) : this.$http.adornUrl(this.urlList.add),
              method: "POST",
              data: this.dataForm,
              header: {
                //默认 无 说明：请求头
                "Content-Type": "application/json"
              }
            })
            .then(({ data }) => {
              if (data && data.code === 0) {
                this.$message({
                  message: "操作成功",
                  type: "success",
                  duration: 1500,
                  onClose: () => {
                    this.visible = false;
                    this.$emit("refreshDataList");
                  }
                });
              } else {
                this.$message.error(data.msg);
              }
            });
        }
      });
    },
    handlereset() {
      this.visible = false;
    }
  }
};
</script>

<style lang="scss" scoped>
/deep/ .addFormBox.el-form-item {
  margin-bottom: 10px !important;
}
</style>
