<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      @submit.native.prevent
    >
      <el-form-item label="企业名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入企业名称"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属站点" prop="tenant_id" v-if="is_super">
        <SiteOptions v-model="queryParams" />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="数据编号" prop="id" align="center" />
      <el-table-column label="专家名称" prop="title" align="center" />
      <el-table-column label="专家姓名" prop="local" align="center" />
      <el-table-column label="联系方式" prop="is_multiple" align="center" />
      <el-table-column label="所属站点" prop="area" align="center" />
      <el-table-column label="创建时间" prop="created_at" align="center">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.created_at) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleUpdate(scope.row)"
            >查看</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.page_num"
      :limit.sync="queryParams.page_size"
      @pagination="getList"
    />
    <!-- 添加或修改对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px">
      <el-form
        ref="form"
        disabled
        :model="form"
        :rules="rules"
        label-width="100px"
      >
        <el-form-item label="所属站点:" prop="tenant_id" v-if="is_super">
          <SiteOptions v-model="form" />
        </el-form-item>
        <el-form-item label="企业名称:" prop="title">
          <el-input v-model="form.title" placeholder="请输入企业名称" />
        </el-form-item>
        <el-form-item label="专家姓名:" prop="size">
          <el-input v-model="form.size" placeholder="请输入专家姓名" />
        </el-form-item>
        <el-form-item label="联系电话:" prop="images">
          <el-input v-model="form.images" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="备注:">
          <el-input
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 6 }"
            v-model="form.images"
            placeholder="请输入备注"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
        <el-button type="primary" @click="cancel">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  bannerList,
  bannerAdd,
  bannerEdit,
  bannerDelete,
} from "@/api/website/siteSet";
export default {
  data() {
    return {
      is_super: this.$store.getters.is_super,
      loading: true,
      queryParams: {
        title: undefined,
        mode: undefined,
        tenant_id: undefined,
        page_num: 1,
        page_size: 10,
      },
      total: 0,
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      restaurants: [],
      // 表单参数
      form: {},
      rules: {
        tenant_id: [
          {
            required: true,
            message: "所属站点不能为空",
            trigger: ["blur", "change"],
          },
        ],
        title: [
          { required: true, message: "企业名称不能为空", trigger: "blur" },
        ],
        size: [
          { required: true, message: "专家姓名不能为空", trigger: "blur" },
        ],
        images: [
          { required: true, message: "联系电话不能为空", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleQuery() {
      this.queryParams.page_num = 1;
      this.getList();
    },
    getList() {
      this.loading = true;
      this.dataList = [1];
      this.total = 15;
      this.loading = false;
      // bannerList(this.queryParams).then((res) => {
      //   this.dataList = res.data.data;
      //   this.total = res.data.count;
      //   this.loading = false;
      // });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.memberOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        tenant_id: undefined,
        title: undefined,
        local: undefined,
        size: undefined,
        domains: [],
        images: undefined,
        is_multiple: 0,
      };
      this.resetForm("form");
    },
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "新增";
    },
    handleUpdate(row) {
      this.reset();
      this.form = Object.assign({}, this.form, row);
      this.open = true;
      this.title = "详情";
    },
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != undefined) {
            // bannerEdit(this.form).then((response) => {
            //   this.$modal.msgSuccess("修改成功");
            //   this.open = false;
            //   this.getList();
            // });
          } else {
            // bannerAdd(this.form).then((response) => {
            //   this.$modal.msgSuccess("新增成功");
            //   this.open = false;
            //   this.getList();
            // });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal
        .confirm('是否确认删除编号为"' + row.id + '"的数据项？')
        .then(function () {
          // return bannerDelete({ id: row.id });
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
  created() {
    this.getList();
  },
};
</script>