<template>
  <div>
    <div class="search-wrapper">
      <el-form
        :inline="true"
        :model="searchForm"
        class="search_form"
        style="text-align: left"
      >
        <el-form-item label="服务名称">
          <el-input
            v-model="searchForm.name"
            placeholder="请输入服务名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="服务类型">
          <el-select
            v-model="searchForm.typeId"
            placeholder="请选择服务类型"
            size="medium"
          >
            <el-option
              v-for="item in TypeList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="table-wrapper">
      <table-template
        :tableData="tableData"
        :tableColumns="tableColumns"
        :loading="loading"
        :pagination="pagination"
        @Jump="jumpPage"
      >
        <el-table-column slot="icon" label="服务图标" align="center">
          <template slot-scope="scope">
            <el-image
              style="width: 30px; height: 30px"
              :src="scope.row.icon"
              :preview-src-list="[scope.row.icon]"
            >
            </el-image>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="350" align="center">
          <template slot-scope="scope">
            <el-button
              type="success"
              size="mini"
              class="btn"
              round
              @click="view(scope.row)"
              >编辑</el-button
            >
            <el-popconfirm title="确定删除此数据吗？" @confirm="del(scope.row)">
              <el-button type="warning" size="mini" round slot="reference"
                >删除</el-button
              >
            </el-popconfirm>
          </template>
        </el-table-column>
      </table-template>
    </div>

    <el-dialog title="编辑" :visible.sync="dialogVisible" width="30%">
      <el-form
        :model="dataForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="服务名称" prop="name">
          <el-input v-model="dataForm.name"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import TableTemplate from "@/components/Table";

export default {
  components: { TableTemplate },

  data() {
    return {
      searchForm: {},
      TypeList: [],
      loading: false,
      tableData: [
        {
          name: "服务名称",
          type: "所属类型",
          icon: require("@/assets/1.png"),
          sort: "1",
        },
      ],
      tableColumns: [
        {
          key: "name",
          label: "服务名称",
        },
        {
          key: "type",
          label: "所属类型",
        },
        {
          key: "icon",
          label: "服务图标",
          type: "slot",
        },
        {
          key: "sort",
          label: "排序",
        },
      ],
      pagination: {
        total: 0,
        pageSize: 10,
        currentPage: 1,
      },
      rules: {
        name: [{ required: true, message: "请输入活动名称", trigger: "blur" }],
      },
      dataForm: {},
      dialogVisible: false,
    };
  },
  watch: {
    dialogVisible(val) {
      if (!val) {
        this.$refs.ruleForm.resetFields();
      }
    },
  },
  created() {
    this.init();
  },
  methods: {
    init() {},
    onSubmit() {},
    jumpPage() {
      this.init();
    },
    view() {
      this.dialogVisible = true;
    },
    del() {},
  },
};
</script>

<style lang="stylus" scoped>
@import '~@/stylus/common';
.btn{
    margin-right 10px
}
</style>
