<template>
  <div class="page">
    <LayoutTable
      ref="layouttable"
      :data="tableData"
      :config="tableConfig"
      notDel
      notAdd
    >
      <div slot="table-search-left" class="daterange">
        <el-date-picker
          v-model="daterange"
          type="daterange"
          @change="handleDateChange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </div>
    </LayoutTable>

    <drawer-show ref="drawerform" @ok="getData" />
  </div>
</template>

<script>
/** 表单弹出框模式需引入 */
import drawerShow from "./drawershow";
import table from "@/assets/mixins/table";
export default {
  name: "recordList",
  components: {
    drawerShow,
  },
  mixins: [table],
  created() {},
  mounted() {
    // 重写搜索清除
    this.$refs.layouttable.$refs.searchform.cleanForm = this.cleanForm;
  },
  methods: {
    /** 重写新增方法 */
    toAdd(row) {
      this.$refs.drawerform.add(row);
    },
    /** 重写编辑方法 */
    toEdit(row) {
      this.$refs.drawerform.edit(row);
    },
    /** 重写查看方法 */
    toView(row) {
      this.$refs.drawerform.view(row);
    },
    // 日期范围选择事件
    handleDateChange() {
      this.daterange && this.daterange.length > 0
        ? (this.$refs.layouttable.$refs.searchform.form.viewTimeStart =
            this.daterange[0])
        : (this.$refs.layouttable.$refs.searchform.form.viewTimeStart = "");
      this.daterange && this.daterange.length > 0
        ? (this.$refs.layouttable.$refs.searchform.form.viewTimeEnd =
            this.daterange[1])
        : (this.$refs.layouttable.$refs.searchform.form.viewTimeEnd = "");
    },
    // 重写搜索清除
    cleanForm() {
      this.daterange = "";
      this.$refs.layouttable.$refs.searchform.form.viewTimeStart = undefined;
      this.$refs.layouttable.$refs.searchform.form.viewTimeEnd = undefined;
      this.$forceUpdate();
      this.$refs.layouttable.$refs.searchform.clean();
      this.$refs.layouttable.$refs.searchform.onSubmit();
    },
  },
  data() {
    return {
      daterange: "",
      isreply: false,
      config: {
        search: [
          {
            name: "query",
            type: "text",
            label: "姓名或手机号",
            fuzzy: true,
          },
        ],
        columns: [
          { type: "index", label: "序号", width: 50 },

          { label: "昵称", prop: "nickName", formatter: this.formatters },

          {
            label: "头像",
            prop: "photoPath",
            formatter: (row) => {
              return row.photoPath != "" ? (
                <el-image
                  style="width: 70px; height: 70px"
                  src={row.photoPath}
                  preview-src-list={[row.photoPath]}
                >
                  <div
                    slot="error"
                    class="image-slot"
                    style="width: 70px; height: 70px;display:flex;justify-content: center;align-items: center;"
                  >
                    <i
                      class="el-icon-picture-outline"
                      style="font-size:26px"
                    ></i>
                  </div>
                </el-image>
              ) : (
                "--"
              );
            },
            width: 100,
          },

          {
            label: "第一次打开时间",
            prop: "createTime",
            formatter: this.formatterDate,
            width: 140,
          },

          {
            label: "真实姓名",
            prop: "realName",
            formatter: this.formatters,
            width: 120,
          },
          {
            label: "联系电话",
            prop: "mobile",
            formatter: this.formatters,
            width: 140,
          },
          {
            label: "邮箱地址",
            prop: "email",
            formatter: this.formatters,
            width: 150,
          },
          {
            label: "单位名称",
            prop: "companyName",
            formatter: this.formatters,
          },
          {
            label: "最近一次打开时间",
            prop: "viewTime",
            formatter: this.formatterDate,
            width: 150,
          },
          {
            label: "备注",
            prop: "remark",
            formatter: this.formatters,
          },
          {
            label: "操作",
            width: 100,
            formatter: (row) => {
              return (
                <div>
                  <span
                    onClick={() => {
                      this.toEdit(row);
                    }}
                    style="color:#409EFF;"
                  >
                    备注
                  </span>
                </div>
              );
            },
          },
        ],
      },
    };
  },
};
</script>
<style lang="less" scoped>
.daterange {
  height: 32px;
  /deep/.el-range-editor.el-input__inner {
    height: 100%;
    margin-top: 1px;
    margin-right: 10px;
  }
}
/deep/.el-date-editor .el-range-separator {
  width: 10%;
  line-height: 25px;
}
</style>
