<template>
  <div class="page">
    <LayoutTable notAdd notDel :data="tableData" :config="tableConfig">
      <el-button
        slot="table-head-left2"
        icon="el-icon-tickets"
        size="mini"
        type="danger"
        @click="monitorWarn"
        >监测预警</el-button
      >
    </LayoutTable>

    <drawer-show ref="dataDrawerShow" />

    <dialog-show ref="dialogform" @ok="getData" />
  </div>
</template>

<script>
/** 表单弹出框模式需引入 */
import dialogShow from "./dialogshow";
import drawerShow from "./dataDrawerShow";
import table from "@/assets/mixins/table";
export default {
  name: "AppointmentRecordsList",
  components: {
    dialogShow,
    drawerShow,
  },
  mixins: [table],
  created() {},
  methods: {
    /** 重写新增方法 */
    toAdd(row) {
      this.$refs.dialogform.add(row);
    },
    /** 重写编辑方法 */
    toEdit(row) {
      this.$refs.dialogform.edit(row);
    },
    /** 重写查看方法 */
    toView(row) {
      this.$refs.dialogform.view(row);
    },
    /** 监测预警 */
    monitorWarn(row) {
      this.$refs.dataDrawerShow.view(row);
    },

    serviceConstraint(row) {
      let _this = this;
      this.$confirm(
        "服务约束后，系统将停止向该群众推送此项服务，是否确认？",
        "系统服务",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function() {
          //todo
          _this
            .$post("/appointment/records", { id: [row.id] })
            .then((res) => {
              if (res && res.code && res.code == 1) {
                _this.getList();
                _this.$message.success("停止服务成功");
              }
            })
            .catch((error) => {
              _this.$message.error(error.message);
            });
        })
        .then((response) => {});
    },
  },
  data() {
    return {
      config: {
        search: [
          {
            name: "device",
            type: "select",
            label: "监测设备",
          },

          {
            name: "monitorTimeStart",
            type: "datetime",
            label: "开始时间",
          },

          {
            name: "monitorTimeEnd",
            type: "datetime",
            label: "结束时间",
          },

          {
            name: "name",
            type: "text",
            label: "姓名",
            fuzzy: true,
          },
        ],
        columns: [
          { type: "index", label: "序号", width: 50 },

          { label: "姓名", prop: "name" },

          { label: "联系方式", prop: "contactInfo" },

          { label: "身份证号码", prop: "idNumber" },

          { label: "预约业务", prop: "reservationService" },

          { label: "预约编号", prop: "reservationNumber" },

          {
            label: "监测时间",
            prop: "monitorTime",
            formatter: this.formatterDate,
          },

          { label: "监测设备", prop: "monitorDevice" },

          {
            label: "签到方式",
            prop: "checkInMethod",
            formatter: this.formatter,
          },

          {
            label: "监测凭证",
            prop: "monitorCertificate",
            formatter: (row) => {
              return row.monitorCertificate != "" ? (
                <el-image
                  style="width: 70px; height: 70px"
                  src={row.monitorCertificate}
                  preview-src-list={[row.monitorCertificate]}
                ></el-image>
              ) : (
                "--"
              );
            },
          },
          {
            label: "操作",
            width: 240,
            formatter: (row) => {
              return (
                <div>
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-open"
                    onClick={() => {
                      this.serviceConstraint(row);
                    }}
                  >
                    服务约束
                  </el-button>
                </div>
              );
            },
          },
        ],
      },
    };
  },
};
</script>
