<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <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="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入用户电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="加密号码" prop="phoneMk">
        <el-input
          v-model="queryParams.phoneMk"
          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-option
            v-for="dict in sexOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </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-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['his:healthTongue:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="healthTongueList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户电话" align="center" prop="phone" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="sex">
        <template slot-scope="scope">
          <dict-tag :options="sexOptions" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="年龄" align="center" prop="age" />

      <el-table-column label="体质" align="center" prop="typeName" />

      <el-table-column label="剥苔" align="center" prop="botai" >
        <template slot-scope="scope">
          <dict-tag :options="orOptions" :value="scope.row.botai"/>
        </template>
      </el-table-column>

      <el-table-column label="齿痕" align="center" prop="chihen" >
        <template slot-scope="scope">
          <dict-tag :options="orOptions" :value="scope.row.chihen"/>
        </template>
      </el-table-column>

      <el-table-column label="裂纹" align="center" prop="liewen">
        <template slot-scope="scope">
          <dict-tag :options="orOptions" :value="scope.row.liewen"/>
        </template>
      </el-table-column>

      <el-table-column label="舌脉" align="center" prop="shemianName" />

      <el-table-column label="苔色" align="center" prop="taiseName" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
             size="mini"
             type="text"
             @click="handledetails(scope.row)"
             >详情
          </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="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="状态" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入状态" />
        </el-form-item>
        <el-form-item label="状态" prop="patientId">
          <el-input v-model="form.patientId" placeholder="请输入状态" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option
              v-for="dict in sexOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="parseInt(dict.dictValue)"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="舌苔图片" prop="tongueUrl">
          <el-input v-model="form.tongueUrl" placeholder="请输入舌苔图片" />
        </el-form-item>
        <el-form-item label="舌苔id" prop="tongueId">
          <el-input v-model="form.tongueId" placeholder="请输入舌苔id" />
        </el-form-item>
        <el-form-item label="体质" prop="typeName">
          <el-input v-model="form.typeName" placeholder="请输入体质" />
        </el-form-item>
        <el-form-item label="体质解析" prop="typeJson">
          <el-input v-model="form.typeJson" placeholder="请输入体质解析" />
        </el-form-item>
        <el-form-item label="剥苔" prop="botai">
          <el-input v-model="form.botai" placeholder="请输入剥苔" />
        </el-form-item>
        <el-form-item label="剥苔详细" prop="botaiDesc">
          <el-input v-model="form.botaiDesc" placeholder="请输入剥苔详细" />
        </el-form-item>
        <el-form-item label="齿痕" prop="chihen">
          <el-input v-model="form.chihen" placeholder="请输入齿痕" />
        </el-form-item>
        <el-form-item label="齿痕详细" prop="chihenDesc">
          <el-input v-model="form.chihenDesc" placeholder="请输入齿痕详细" />
        </el-form-item>
        <el-form-item label="裂纹" prop="liewen">
          <el-input v-model="form.liewen" placeholder="请输入裂纹" />
        </el-form-item>
        <el-form-item label="裂纹详细" prop="liewenDesc">
          <el-input v-model="form.liewenDesc" placeholder="请输入裂纹详细" />
        </el-form-item>
        <el-form-item label="舌脉" prop="shemianName">
          <el-input v-model="form.shemianName" placeholder="请输入舌脉" />
        </el-form-item>
        <el-form-item label="舌脉详细" prop="shemianDesc">
          <el-input v-model="form.shemianDesc" placeholder="请输入舌脉详细" />
        </el-form-item>
        <el-form-item label="苔色" prop="taiseName">
          <el-input v-model="form.taiseName" placeholder="请输入苔色" />
        </el-form-item>
        <el-form-item label="苔色详细" prop="taiseDesc">
          <el-input v-model="form.taiseDesc" 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>

       <el-drawer
    	:with-header="false"
            size="75%"
             :title="show.title" :visible.sync="show.open">
         <healthTongueDetails  ref="Details" />
       </el-drawer>

  </div>
</template>

<script>
import { listHealthTongue, getHealthTongue, delHealthTongue, addHealthTongue, updateHealthTongue, exportHealthTongue } from "@/api/his/healthTongue";
import healthTongueDetails from '../../components/his/healthTongueDetails.vue';
export default {
  name: "HealthTongue",
  components: { healthTongueDetails },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      show:{
              title:"详情",
              open:false,
            },
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 舌苔表格数据
      healthTongueList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 性别字典
      sexOptions: [],
      // 状态字典
      statusOptions: [],
      orOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        patientId: null,
        name: null,
        sex: null,
        age: null,
        status: null,
        tongueUrl: null,
        tongueId: null,
        typeName: null,
        typeJson: null,
        botai: null,
        botaiDesc: null,
        chihen: null,
        chihenDesc: null,
        liewen: null,
        phone:null,
        phoneMk:null,
        liewenDesc: null,
        shemianName: null,
        shemianDesc: null,
        taiseName: null,
        taiseDesc: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_sex").then(response => {
      this.sexOptions = response.data;
    });
    this.getDicts("sys_company_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("sys_company_or").then(response => {
      this.orOptions = response.data;
    });

  },
  methods: {
    /** 查询舌苔列表 */
    getList() {
      this.loading = true;
      listHealthTongue(this.queryParams).then(response => {
        this.healthTongueList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handledetails(row){
            this.show.open=true;
            setTimeout(() => {
                 this.$refs.Details.getDetails(row.id);
            }, 1);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        patientId: null,
        name: null,
        sex: null,
        age: null,
        status: 0,
        tongueUrl: null,
        tongueId: null,
        typeName: null,
        typeJson: null,
        botai: null,
        botaiDesc: null,
        chihen: null,
        chihenDesc: null,
        liewen: null,
        liewenDesc: null,
        shemianName: null,
        shemianDesc: null,
        taiseName: null,
        taiseDesc: null,
        createTime: 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
      getHealthTongue(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) {
            updateHealthTongue(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addHealthTongue(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除舌苔编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delHealthTongue(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有舌苔数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportHealthTongue(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
