<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px" size="medium" class="ry_form">
      <!--      <el-form-item label="关联用户" prop="userId">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.userId"-->
      <!--          placeholder="请输入关联用户"-->
      <!--          clearable-->
      <!--          size="small"-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="审核状态" prop="status">-->
      <!--        <el-select v-model="queryParams.status" placeholder="请选择审核状态" clearable size="small">-->
      <!--          <el-option-->
      <!--            v-for="dict in dict.type.applet_state"-->
      <!--            :key="dict.value"-->
      <!--            :label="dict.label"-->
      <!--            :value="dict.value"-->
      <!--          />-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入身份证"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--      <el-form-item label="性别" prop="sex">-->
      <!--        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable size="small">-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--      <el-form-item label="养宠经验" prop="experience">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.experience"-->
      <!--          placeholder="请输入养宠经验"-->
      <!--          clearable-->
      <!--          size="small"-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="是否有专业执照" prop="isHave">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.isHave"-->
      <!--          placeholder="请输入是否有专业执照"-->
      <!--          clearable-->
      <!--          size="small"-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="个人宠物类型" prop="petType">-->
      <!--        <el-select v-model="queryParams.petType" placeholder="请选择个人宠物类型" clearable size="small">-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="审核状态" prop="status">-->
      <!--        <el-select v-model="queryParams.status" placeholder="请选择审核状态" clearable size="small">-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->




      <el-form-item class="flex_one tr">
        <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-row :gutter="10" class="mb8">-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="primary"-->
    <!--          plain-->
    <!--          icon="el-icon-plus"-->
    <!--          size="mini"-->
    <!--          @click="handleAdd"-->
    <!--          v-hasPermi="['model:AppletUsersTeacher:add']"-->
    <!--        >新增</el-button>-->
    <!--      </el-col>-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="success"-->
    <!--          plain-->
    <!--          icon="el-icon-edit"-->
    <!--          size="mini"-->
    <!--          :disabled="single"-->
    <!--          @click="handleUpdate"-->
    <!--          v-hasPermi="['model:AppletUsersTeacher:edit']"-->
    <!--        >修改</el-button>-->
    <!--      </el-col>-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="danger"-->
    <!--          plain-->
    <!--          icon="el-icon-delete"-->
    <!--          size="mini"-->
    <!--          :disabled="multiple"-->
    <!--          @click="handleDelete"-->
    <!--          v-hasPermi="['model:AppletUsersTeacher:remove']"-->
    <!--        >删除</el-button>-->
    <!--      </el-col>-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="warning"-->
    <!--          plain-->
    <!--          icon="el-icon-download"-->
    <!--          size="mini"-->
    <!--          :loading="exportLoading"-->
    <!--          @click="handleExport"-->
    <!--          v-hasPermi="['model:AppletUsersTeacher:export']"-->
    <!--        >导出</el-button>-->
    <!--      </el-col>-->
    <!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>-->
    <!--    </el-row>-->

    <el-table v-loading="loading" :data="AppletUsersTeacherList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--      <el-table-column label="标识" align="center" prop="id" />-->
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="审核状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.applet_state" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="关联用户" align="center" prop="userId" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="身份证" align="center" prop="idCard" />
      <!--      <el-table-column label="性别" align="center" prop="sex" />-->
      <el-table-column label="性别" align="center" prop="sex" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.applet_sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="养宠经验" align="center" prop="experience" />
      <el-table-column label="是否有专业执照" align="center" prop="isHave">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isHave" type="success">是</el-tag>
          <el-tag v-else type="danger">否</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="个人宠物类型" align="center" prop="petType" >
        <template slot-scope="scope">
          <el-tag v-for="item in scope.row.petType
          &&
          scope.row.petType.split(',')" 
          :key="item" type="success">{{ {
            '3': '猫',
            '4': '狗',
            '5': '异宠'
          }[item] }}</el-tag>
        </template>
      </el-table-column>
      <!--      <el-table-column label="审核状态" align="center" prop="status" />-->

      <el-table-column label="审核图片" align="center" prop="审核图片">
        <template slot-scope="{ row }">
          <el-image v-if="row.images" :src="row.images" :preview-src-list="[row.images]" class="small-img circle-img"/>
        </template>
      </el-table-column>
      <el-table-column label="所在地区" align="center" prop="area" />
      <el-table-column label="详细地址" align="center" prop="address" />
      <el-table-column label="经度" align="center" prop="longitude" />
      <!--      <el-table-column label="创建人" align="center" prop="createBy" />-->
      <el-table-column label="纬度" align="center" prop="latitude" />
      <!--      <el-table-column label="修改人" align="center" prop="updateBy" />-->


      <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-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['model:AppletUsersTeacher:edit']"
          >查看信息</el-button>
          <!--          <el-button-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            icon="el-icon-delete"-->
          <!--            @click="handleDelete(scope.row)"-->
          <!--            v-hasPermi="['model:AppletUsersTeacher:remove']"-->
          <!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改伴宠师认证表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="50%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="108px" >
        <el-form-item label="审核状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择审核状态">
            <el-option
              v-for="dict in dict.type.applet_state"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="关联用户" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入关联用户" disabled />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" disabled />
        </el-form-item>
        <el-form-item label="身份证" prop="idCard">
          <el-input v-model="form.idCard" placeholder="请输入身份证" disabled/>
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别" disabled>
            <el-option
              v-for="dict in dict.type.applet_sex"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号" disabled/>
        </el-form-item>
        <el-form-item label="养宠经验" prop="experience">
          <el-input v-model="form.experience" placeholder="请输入养宠经验" disabled />
        </el-form-item>
        <el-form-item label="是否有专业执照" prop="isHave">
          <el-select v-model="form.isHave" placeholder="请选择是否有专业执照">
            <el-option label="是" :value="1" />
            <el-option label="否" :value="0" />
          </el-select>
        </el-form-item>
        <el-form-item label="个人宠物类型" prop="petType">
          <el-select v-model="form.petType" placeholder="请选择个人宠物类型" multiple>
            <el-option label="猫" value="3" />
            <el-option label="狗" value="4" />
            <el-option label="异宠" value="5" />
          </el-select>
        </el-form-item>

        <el-form-item label="审核图片" >
          <!--          <imageUpload v-model="form.images"/>-->
          <oss-image-upload v-model="form.images" :limit="1"></oss-image-upload>
        </el-form-item>
        <el-form-item label="所在地区" prop="area">
          <el-input v-model="form.area" placeholder="请输入所在地区" disabled/>
        </el-form-item>
        <el-form-item label="详细地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入详细地址" disabled/>
        </el-form-item>
        <!--        <el-form-item label="经度" prop="longitude">-->
        <!--          <el-input v-model="form.longitude" placeholder="请输入经度" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="创建人" prop="create by">-->
        <!--          <el-input v-model="form.createBy" placeholder="请输入创建人" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="纬度" prop="latitude">-->
        <!--          <el-input v-model="form.latitude" placeholder="请输入纬度" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="修改人" prop="update by">-->
        <!--          <el-input v-model="form.updateBy" placeholder="请输入修改人" />-->
        <!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAppletUsersTeacher, getAppletUsersTeacher, delAppletUsersTeacher, addAppletUsersTeacher, updateAppletUsersTeacher, exportAppletUsersTeacher } from "@/api/model/AppletUsersTeacher";

export default {
  name: "AppletUsersTeacher",
  dicts: ['applet_sex', 'applet_state'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 伴宠师认证表格数据
      AppletUsersTeacherList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,

        name: null,

        idCard: null,

        sex: null,

        phone: null,

        experience: null,

        isHave: null,

        petType: null,

        status: 1,

        images: null,

      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      columns: [
        { key: 1, label: "关联用户", visible:  true  },
        { key: 2, label: "姓名", visible:  true  },
        { key: 3, label: "身份证", visible:  true  },
        { key: 4, label: "性别", visible:  true  },
        { key: 5, label: "手机号", visible:  true  },
        { key: 6, label: "养宠经验", visible:  true  },
        { key: 7, label: "是否有专业执照", visible:  true  },
        { key: 8, label: "个人宠物类型", visible:  true  },
        { key: 9, label: "审核状态", visible:  true  },
        { key: 10, label: "审核图片", visible:  false  },
      ],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询伴宠师认证列表 */
    getList() {
      this.loading = true;
      listAppletUsersTeacher(this.queryParams).then(response => {
        this.AppletUsersTeacherList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,

        userId: null,

        name: null,

        idCard: null,

        sex: null,

        phone: null,

        experience: null,

        isHave: null,

        petType: null,

        status: 1,

        images: null,

        createTime: null,

        updateTime: null,

      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加伴宠师认证";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAppletUsersTeacher(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改伴宠师认证";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAppletUsersTeacher(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAppletUsersTeacher(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除伴宠师认证编号为"' + ids + '"的数据项？').then(function() {
        return delAppletUsersTeacher(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有伴宠师认证数据项？').then(() => {
        this.exportLoading = true;
        return exportAppletUsersTeacher(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
