<template>
  <div>
    <el-button size="small" @click="classificationOpen = true" style="width: 200px;font-size:14px;text-align:left"
      :style="handleselectName ? 'color:black' : 'color:#C0C4CC'">{{ handleselectName ? handleselectName :
        '请选择专病管理路径' }}</el-button>
    <el-dialog title="专病管理路径选择" :visible.sync="classificationOpen" width="70%" :before-close="classificationOpenfalse">
      <el-row :gutter="20">
        <el-col :span="6">
          <div class="left" ref="box">
            <div class="name">科室名称</div>
            <div style="padding: 10px 0;">
              <el-input v-model="departmentName" placeholder="请输入科室名称" clearable @keyup.enter.native="handleQuery" />
            </div>
            <div class="listitem" v-for="(item, index) in DepartmentoList" :key="index"
              @click="clickDepartmenitem(item)">
              <div :class="queryParams.departmentId == item.id ? 'allactive' : 'all'">
                {{ item.departmentName }}
              </div>
              <span class="count">{{ item.countNum }}</span>
            </div>
          </div>
        </el-col>
        <el-col :span="18">
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
            label-width="68px">
            <el-form-item label="路径名称" prop="routeName">
              <el-input v-model="queryParams.routeName" placeholder="请输入路径名称" clearable
                @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="路径分类" prop="routeClassify">
              <el-select v-model="queryParams.routeClassify" placeholder="请选择">
                <el-option label="全部" value="ALL" />
                <el-option label="科室管理路径" value="DEPARTMENT_MANAGE_PATH" />
                <el-option label="专病管理路径" value="SPECIAL_DIEASE_MANAGE_PATH" />
              </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-table v-loading="loading" :data="specialDiseaseRouteList" @selection-change="handleSelectionChange"
            @row-dblclick="handleselect">
            <el-table-column label="序号" type="index" width="55" align="center" />
            <el-table-column label="路径名称" align="center" prop="routeName" />
            <el-table-column label="版本号" align="center" prop="version" />
            <el-table-column label="路径分类" align="center" prop="routeClassify">
              <template slot-scope="scope">
                {{ scope.row.routeClassify == 'DEPARTMENT_MANAGE_PATH' ? '科室管理路径' : '' }}
                {{ scope.row.routeClassify == 'SPECIAL_DIEASE_MANAGE_PATH' ? '专病管理路径' : '' }}
              </template>
            </el-table-column>
            <el-table-column label="病种名称" align="center" prop="diseaseTypeName" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button size="mini" type="text" @click="handleselect(scope.row)"
                  v-if="handleselectId != scope.row.id">选择</el-button>
                <el-button size="mini" type="text" @click="nohandleselect(scope.row)"
                  v-if="handleselectId == scope.row.id">取消选择</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-col>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import {
  listSpecialDiseaseRoute,
  selectDiseaseCount,
} from "@/api/system/specialDiseaseRoute";
export default {
  props: ['routeId', 'routeName', 'servicePackageId'],
  name: "SpecialDiseaseRoute",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 专病路径信息表格数据
      specialDiseaseRouteList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      classificationOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        departmentId: null,
        departmentName: null,
        diseaseTypeId: null,
        diseaseTypeName: null,
        routeName: null,
        routeCode: null,
        version: null,
        routeClassify: null,
        releaseStatus: 'PUBLISHED',
        suitRange: null,
        routeSort: null,
        routeRemark: null,
        servicePackageId: null,
      },
      // 表单校验
      rules: {},
      DepartmentoList: [],
      departmentName: '',
      handleselectName: '',
      handleselectId: '',
    };
  },
  created() {
    this.queryParams.servicePackageId = this.servicePackageId
    this.getList();
  },
  mounted() {
    this.handleselectId = this.routeId
    this.handleselectName = this.routeName
  },
  watch: {
    departmentName(val) {
      this.infolists();
    },
    routeId(newValue, oldValue) {
      this.handleselectId = newValue;
    },
    servicePackageId(newValue, oldValue) {
      if (newValue) {
        this.queryParams.servicePackageId = newValue;
        this.getList();
      }
    },
    routeName(newValue, oldValue) {
      this.handleselectName = newValue;
    }
  },
  methods: {
    nohandleselect() {
      this.handleselectId = ''
      this.handleselectName = ''
      this.$emit("on-template", { routeId: '', routeName: '' });
    },
    handleselect(item) {
      this.handleselectId = item.id
      this.handleselectName = item.routeName
      this.$emit("on-template", { routeId: item.id, routeName: item.routeName });
      this.classificationOpen = false
    },
    clickDepartmenitem(item) {
      this.loading = true;
      this.queryParams.departmentId = item.id;
      this.getList();
    },
    //科室
    infolists() {
      selectDiseaseCount(this.departmentName, 'PUBLISHED', this.queryParams.servicePackageId).then((res) => {
        this.DepartmentoList = res.data;
      });
    },
    /** 查询专病路径信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.releaseStatus = 'PUBLISHED'
      listSpecialDiseaseRoute(this.queryParams).then(response => {
        this.specialDiseaseRouteList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      this.infolists();
    },
    // 取消按钮
    cancel() {
      this.classificationOpen = false;
    },
    /** 搜索按钮操作 */
    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
    },
    classificationOpenfalse() {
      this.classificationOpen = false
    },
  }
};
</script>
<style scoped lang="scss">
.left {
  height: 500px;
  overflow: auto;

  .name {
    font-weight: 700;
    margin-bottom: 10px;
  }

  .listitem {
    width: 100%;
    height: 50px;
    border-bottom: 1px solid #dcdfe6;
    position: relative;

    .count {
      display: inline-block;
      position: absolute;
      left: 210px;
      color: #a4a6aa;
      top: 50%;
      transform: translateY(-50%);
      font-size: 13px;
    }

    .all {
      height: 50px;
      line-height: 50px;
      padding-left: 13px;
    }

    .allactive {
      background: #e8f4ff;
      height: 50px;
      line-height: 50px;
      padding-left: 13px;
      border-left: 3px solid #4d9de7;
    }
  }
}
</style>
