<template>
  <!-- 弹出框表单 -->
  <el-drawer
    :title="title"
    :visible.sync="open"
    :direction="direction"
    :destroy-on-close="true"
    size="50%"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-row>
        <Field
          :span="20"
          label="备注："
          prop="remark"
          v-model="form.remark"
          type="textarea"
          :rows="10"
          placeholder="请输入备注"
        />
      </el-row>

      <form-buttons
        @submit="submitForm"
        v-if="pageInfo.type != 'view'"
        noCancelBtn
      />
    </el-form>
  </el-drawer>
</template>

<script>
import form from "@/assets/mixins/formdialog";
export default {
  name: "StaffDetail",
  mixins: [form],
  components: {},
  created() {
    this.changePath("staff");
  },
  data() {
    var checkEmail = (rule, value, callback) => {
      let mailReg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
      if (!value) {
        //如果输入为空直接返回
        callback();
      } else {
        //如果字符串 string 中含有与 RegExpObject 匹配的文本，则返回 true，否则返回 false。
        if (mailReg.test(value)) {
          //匹配成功返回
          callback();
        } else {
          //匹配不成功返回错误显示
          callback(
            new Error("邮箱格式:xx@xx.xx，只含数字、大小写字母、下划线、横杠")
          );
        }
      }
    };
    var checkPhone = (rule, value, callback) => {
      let phoneReg = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
      if (!value) {
        callback();
      } else {
        if (phoneReg.test(value)) {
          callback();
        } else {
          callback(new Error("请输入正确格式的11位电话号码"));
        }
      }
    };
    return {
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "备注",
      // 是否显示弹出层
      open: false,
      direction: "rtl",
      // 表单校验
      rules: {},
    };
  },

  methods: {
    /** 编辑 */
    edit(row) {
      this.reset();
      this.query = { id: row.id };
      this.urls.currUrl = "bussinesscard/record/edit";
      this.getData();
      this.pageInfo.type = "edit";
      this.title = "备注";
    },

    /**取消按钮 */
    cancel() {
      this.open = false;
    },
    /**获取数据后弹框 */
    afterRender(data) {
      this.open = true;
    },

    beforeSubmit(data) {
      return data;
    },

    afterSubmit(data) {
      this.open = false;
      this.$emit("ok");
    },

    // 表单重置
    reset() {
      this.form = {
        id: null,
        createUserId: null,
        createTime: null,
        realName: "",
        nickName: "",
        mobile: "",
        email: "",
        companyName: "",
        bussinesscardId: null,
        viewId: null,
        viewName: "",
        sumViews: null,
        remark: "",
        viewTime: null,
        photoPath: "",
      };
      this.resetForm("form");
    },
    resetForm(refName) {
      if (this.$refs[refName]) {
        this.$refs[refName].resetFields();
      }
    },
  },
};
</script>
