<template>
  <div class="app-container" ref="layout">
    <el-row :gutter="20">
      <el-col :span="5">
        <DepartmentList ref="DepartmentList" @clickdepartment="clickdepartment" :methods="'listServicePackageNum'">
        </DepartmentList>
      </el-col>
      <el-col :span="19" :xs="24">
        <div ref="topform" class="form">
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
            label-width="90px">
            <el-form-item label="病种名称" prop="diseaseTypeName">
              <el-input v-model="queryParams.diseaseTypeName" placeholder="请输入病种名称" clearable
                @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="服务包名称" prop="packageName">
              <el-input v-model="queryParams.packageName" placeholder="请输入服务包名称" clearable
                @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="服务包版本" prop="packageVersion">
              <el-input v-model="queryParams.packageVersion" placeholder="请输入服务包版本" clearable
                @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="是否发布" prop="whetherRelease">
              <el-select v-model="queryParams.whetherRelease" placeholder="请选择">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="服务包价格" prop="packagePrice">
              <el-input oninput="value=value.replace(/[^\d.]/g,'')" v-model="queryParams.packagePrice"
                placeholder="请输入服务包价格" clearable @keyup.enter.native="handleQuery" />
            </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>
        </div>
        <div ref="mb8" class="mb8">
          <el-row :gutter="10" class="">
            <el-col :span="1.5">
              <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                :disabled="queryParams.hospitalAgencyId ? false : true"
                v-hasPermi="['manage:servicepackage:add']">新增服务包</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
          </el-row>
        </div>
        <div ref="table">
          <el-table :max-height="maxTableHeight" v-loading="loading" :data="servicepackageList"
            @selection-change="handleSelectionChange">
            <el-table-column label="序号" align="center" type="index" />
            <el-table-column label="服务包名称" align="center" prop="packageName" :show-overflow-tooltip="true" />
            <el-table-column label="版本号" align="center" prop="packageVersion" />
            <el-table-column label="服务期限" align="center" prop="packageTermAndUnit" />
            <el-table-column label="服务包简介" align="center" prop="packageIntroduction" :show-overflow-tooltip="true" />
            <el-table-column label="备注" align="center" prop="packageRemark" />
            <el-table-column label="是否发布" align="center" prop="whetherRelease">
              <template slot-scope="scope">
                <el-tag type="warning" v-if="scope.row.whetherRelease == '0'">未发布</el-tag>
                <el-tag type="success" v-else-if="scope.row.whetherRelease == '1'">已发布</el-tag>
              </template>
            </el-table-column>
            <el-table-column label="病种名称" align="center" prop="diseaseTypeName" />
            <el-table-column width="180" label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button size="mini" type="text" icon="el-icon-s-open" @click="copy(scope.row)">复制</el-button>
                <el-button size="mini" type="text" icon="el-icon-s-promotion" @click="release(scope.row)"
                  v-if="scope.row.whetherRelease == 0">发布</el-button>
                <el-button size="mini" type="text" icon="el-icon-notebook-2" @click="detail(scope.row)">详情</el-button>
                <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                  v-hasPermi="['manage:servicepackage:edit']">修改</el-button>
                <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                  v-hasPermi="['manage:servicepackage:remove']">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize" @pagination="getList" /> -->
        <myPagination v-show="total > 0" :total="total" :pageSize="queryParams.pageSize"
          :indexFromWrap="queryParams.pageNum" @updateCPage="updateCPage"></myPagination>
      </el-col>
    </el-row>
    <!-- 添加或修改服务包基础信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px" :inline="true">
        <el-form-item label="科室名称" prop="departmentId">
          <el-button @click="clickinnerVisible()" style="
              width: 379px;
              text-align: left;
              height: 36px;
              overflow: hidden;
            " :style="form.departmentName == '请选择科室' ? 'color: #c0c4cc;' : ''">{{ form.departmentName }}</el-button>
        </el-form-item>
        <el-form-item label="病种名称" prop="diseaseTypeName">
          <el-button type="" @click="clickdisease()" :style="form.diseaseTypeName == '请选择病种' ? 'color: #c0c4cc;' : ''"
            style="
              width: 206px;
              text-align: left;
              height: 36px;
              overflow: hidden;
            ">{{ form.diseaseTypeName }}</el-button>
        </el-form-item>
        <el-form-item label="服务包名称" prop="packageName">
          <el-input v-model="form.packageName" placeholder="请输入服务包名称" />
        </el-form-item>
        <el-form-item label="服务包简介" prop="packageIntroduction">
          <el-input v-model="form.packageIntroduction" placeholder="请输入服务包简介" />
        </el-form-item>
        <el-form-item label="服务包价格" prop="packagePrice">
          <el-input oninput="value=value.replace(/[^\d.]/g,'')" v-model="form.packagePrice" placeholder="请输入服务包价格"
            style="width: 204px">
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="服务包版本" prop="packageVersion">
          <el-input v-model="form.packageVersion" placeholder="请输入服务包版本" />
        </el-form-item>
        <el-form-item label="硬件类型" prop="hardwareType">
          <el-select v-model="form.hardwareType" placeholder="请选择硬件类型" style="width: 204px">
            <el-option v-for="item in optionstype" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="服务包期限" prop="packageTerm">
          <el-input v-model="form.packageTerm" placeholder="请输入服务包期限" style="width: 208px">
            <el-select style="width: 60px" slot="append" v-model="form.packageTermUnit" placeholder="请选择"
              @change="$forceUpdate()">
              <el-option v-for="item in optionstime" :key="item.value" :label="item.label" :value="item.label">
              </el-option>
            </el-select>
          </el-input>
        </el-form-item>
        <br />
        <div v-for="(aitem, index) in form.voList" :key="index">
          <el-form-item label="服务包内容" :rules="rules.voList.serviceWayName" :prop="`voList.${index}.serviceWayName`">
            <el-select v-model="aitem.serviceWayName" placeholder="请选择服务方式" @change="changeway($event, index)">
              <el-option v-for="item in optionsway" :key="item.id" :label="item.serviceWayName"
                :value="item.serviceWayName">
              </el-option>
            </el-select>
            <el-form-item label="" :rules="rules.voList.serviceContent" :prop="`voList.${index}.serviceContent`">
              <el-select style="margin-left: 10px" v-model="aitem.serviceContent" placeholder="请选择服务内容"
                @change="changcontent($event, index)">
                <el-option v-for="item in optionscontent[index]" :key="item.id" :label="item.serviceContent"
                  :value="item.serviceContent">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="" :rules="rules.voList.serviceFrequencyText"
              :prop="`voList.${index}.serviceFrequencyText`">
              <el-select v-model="aitem.serviceFrequencyText" placeholder="请选择服务频次">
                <el-option v-for="item in optionsfrequency[index]" :key="item.id" :label="item.serviceFrequencyText"
                  :value="item.serviceFrequencyText">
                </el-option>
              </el-select>
            </el-form-item>
          </el-form-item>
          <el-button type="primary" plain icon="el-icon-circle-plus-outline" style="margin-top: 2px; margin-left: 6px"
            v-if="index == 0" @click="addnurseClassifyitem"></el-button>
          <!-- circle -->
          <el-button type="danger" icon="el-icon-delete" plain style="margin-top: 2px; margin-left: 6px"
            v-if="index != 0" @click="delnurseClassifyitem(index)"></el-button>
        </div>
        <br />
        <el-form-item label="服务包备注" prop="packageRemark">
          <el-input style="width: 835px" type="textarea" v-model="form.packageRemark" placeholder="请输入服务包备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormadd" v-if="title == '复制服务包基础信息'">确 定</el-button>
        <el-button type="primary" @click="submitForm" v-else>确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 科室弹框 -->
    <el-dialog title="" :visible.sync="innerVisibleshow" width="1000px" append-to-body
      :before-close="innerVisiblecancel">
      <el-form ref="queryForm" :model="informationqueryParams" :rules="rules" label-width="80px" :inline="true">
        <el-form-item label="科室名称" prop="departmentName" label-width="120">
          <el-input v-model="informationqueryParams.departmentName" placeholder="请输入科室名称" clearable />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="informationInfoinfo">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="addresetQuerylist">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="infolist" @cell-dblclick="nurseclick" v-loading="loading">
        <el-table-column label="请选择" width="100" align="center">
          <template slot-scope="scope">
            <el-button type="primary" style="width: 15px; height: 15px" v-if="form.departmentId == scope.row.id" circle
              @click="nurseclick(scope.row)"></el-button>
            <el-button v-else style="width: 15px; height: 15px" circle @click="nurseclick(scope.row)"></el-button>
          </template>
        </el-table-column>
        <el-table-column property="departmentName" label="科室名称" align="center" :show-overflow-tooltip="true">
        </el-table-column>
      </el-table>
      <myPagination v-show="totaldepartment > 0" :total="totaldepartment" :pageSize="informationqueryParams.pageSize"
        :indexFromWrap="informationqueryParams.pageNum" @updateCPage="updateCPagetwo"></myPagination>
      <!-- <pagination v-show="totaldepartment > 0" :total="totaldepartment" :page.sync="informationqueryParams.pageNum"
        :limit.sync="informationqueryParams.pageSize" @pagination="informationInfoinfo" /> -->
    </el-dialog>
    <!-- 病种弹框 -->
    <el-dialog title="" :visible.sync="diseaseshowst" width="1000px" append-to-body :before-close="canceldiseases">
      <el-form ref="queryForm" :model="querydisease" :rules="rules" label-width="80px" :inline="true">
        <el-form-item label="病种名称" prop="diseaseTypeName" label-width="120">
          <el-input v-model="querydisease.diseaseTypeName" placeholder="请输入病种名称" clearable />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="infodisease">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetdisease">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="listdisease" @cell-dblclick="nurseclickdisease" v-loading="loading">
        <el-table-column label="请选择" width="100" align="center">
          <template slot-scope="scope">
            <el-button type="primary" style="width: 15px; height: 15px" v-if="form.diseaseTypeId == scope.row.id" circle
              @click="nurseclickdisease(scope.row)"></el-button>
            <el-button v-else style="width: 15px; height: 15px" circle
              @click="nurseclickdisease(scope.row)"></el-button>
          </template>
        </el-table-column>
        <el-table-column property="diseaseTypeName" label="病种名称" align="center" :show-overflow-tooltip="true">
        </el-table-column>
      </el-table>
      <!-- <pagination v-show="diseasetotal > 0" :total="diseasetotal" :page.sync="querydisease.pageNum"
        :limit.sync="querydisease.pageSize" @pagination="infodisease" /> -->
      <myPagination v-show="diseasetotal > 0" :total="diseasetotal" :pageSize="querydisease.pageSize"
        :indexFromWrap="querydisease.pageNum" @updateCPage="updateCPagethree"></myPagination>
    </el-dialog>
    <!-- 详情弹框 -->
    <el-dialog title="详情" :visible.sync="detailshow" width="50%" :before-close="handleClose">
      <el-form ref="form" :model="formdetail" label-width="150px" :inline="true">
        <el-form-item label="病种名称:" prop="packageVersion">
          <span style="display: inline-block; width: 80px">
            {{ formdetail.diseaseTypeName }}</span>
        </el-form-item>
        <el-form-item label="服务包名称:" prop="packageVersion">
          <div class="container">
            <el-tooltip class="item" effect="dark" :content="formdetail.packageName" placement="top-start">
              <span>{{ formdetail.packageName }}</span>
            </el-tooltip>
          </div>
        </el-form-item>
        <el-form-item label="价格:" prop="packageVersion">
          <span>{{ formdetail.packagePrice }}元</span>
        </el-form-item>
        <br />
        <el-form-item label="服务期限:" prop="packageVersion">
          <span style="display: inline-block; width: 80px">
            {{ formdetail.packageTermAndUnit }}
          </span>
        </el-form-item>
        <el-form-item label="硬件类型:" prop="packageVersion">
          <span>
            {{ formdetail.hardwareType == "BLOOD_PRESSURE" ? "血压仪" : "" }}
          </span>
          <span>
            {{ formdetail.hardwareType == "GLUCOSE_METER" ? "血糖仪" : "" }}
          </span>
          <span>
            {{ formdetail.hardwareType == "ELECTROCARDIOGRA" ? "心电仪" : "" }}
          </span>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="datailList">
        <el-table-column label="序号" type="index" />
        <el-table-column label="服务方式" align="center" prop="serviceWayName" />
        <el-table-column label="服务内容" align="center" prop="serviceContent" :show-overflow-tooltip="true" />
        <el-table-column label="服务频次" align="center" prop="serviceFrequencyText" />
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="detailshow = false">关闭</el-button>
      </span>
    </el-dialog>
    <!-- 发布弹框 -->
    <el-dialog title="提示" :visible.sync="dialogexamine" width="30%" :before-close="amineClose" center>
      <span style="font-size: 18px; margin-left: 55px">是否同意发布？</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelamine">同意</el-button>
        <el-button type="primary" @click="submitamine">不同意</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { listServicepackage, getServicepackage, delServicepackage, addServicepackage, updateServicepackage, serviceWayList, serviccontent, editReleaseStatus, listServicePackageNum } from "@/api/manage/servicepackage";
import { department, listDisease } from "@/api/manage/script";
import DepartmentList from '../../components/DepartmentList.vue'
export default {
  components: {
    DepartmentList,
  },
  name: "Servicepackage",
  data() {
    return {
      departmentName: null,
      diseaseTypeName: null,
      name: '',
      departmentId: null,
      count: '',//全部
      DepartmentoList: [],//左侧数组
      // 左侧传值
      querydepartmen: {
        departmentName: "",
        // pageNum: 1,
        // pageSize: 10,
      },
      maxTableHeight: undefined,
      innerVisibleshow: false, //科室弹框
      // 科室
      informationqueryParams: {
        pageNum: 1,
        pageSize: 10,
        departmentName: null,
      },
      infolist: [],
      totaldepartment: 0,
      diseaseshowst: false,//病种弹框
      querydisease: {
        pageNum: 1,
        pageSize: 10,
        diseaseTypeName: null,
        departmentId: null,
      },
      listdisease: [],
      diseasetotal: 0,
      options: [{
        value: '0',
        label: '否'
      }, {
        value: '1',
        label: '是'
      },],
      value1: '',
      value2: '',
      value3: '',
      // 服务方式
      optionsway: [],
      // 服务内容

      optionscontent: {
        '0': [],
        '1': [],
        '2': [],
        '3': [],
        '4': [],
      },
      // 服务频次
      optionsfrequency: {
        '0': [],
        '1': [],
        '2': [],
        '3': [],
        '4': [],
      },
      // optionsfrequency: [
      // {
      //   value: '',
      //   label: ''
      // }
      // ],

      optionstype: [{
        value: 'BLOOD_PRESSURE',
        label: '血压仪'
      }, {
        value: 'GLUCOSE_METER',
        label: '血糖仪'
      }, {
        value: 'ELECTROCARDIOGRA',
        label: '心电仪'
      },],
      optionstime: [
        {
          value: 'year',
          label: '年'
        }, {
          value: 'mouth',
          label: '月'
        }, {
          value: 'day',
          label: '日'
        },
      ],
      value: 'year',
      detailshow: false,
      datailList: [],
      dialogexamine: false,//发布
      examineid: null,//发布id
      idd: 0,
      select: '',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 服务包基础信息表格数据
      servicepackageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        departmentId: null,
        departmentName: null,
        diseaseTypeId: null,
        diseaseTypeName: null,
        packageName: null,
        packageIntroduction: null,
        packageVersion: null,
        packageTerm: null,
        packageTermUnit: null,
        packagePrice: null,
        packageRemark: null,
        hardwareType: null,
        whetherRelease: null,
      },

      // 表单参数
      form: {},
      formdetail: {},
      // 表单校验
      rules: {
        departmentId: [
          { required: true, message: "科室名称不能为空", trigger: "blur" }
        ],
        packageIntroduction: [
          { required: true, message: "服务包简介不能为空", trigger: "blur" }
        ],
        packagePrice: [
          { required: true, message: "服务包价格不能为空", trigger: "blur" }
        ],
        packageVersion: [
          { required: true, message: "服务包版本不能为空", trigger: "blur" }
        ],
        // packageVersion:[
        // ],
        packageName: [
          { required: true, message: "服务包名称不能为空", trigger: "blur" }
        ],
        packageTerm: [
          { required: true, message: "服务包期限不能为空", trigger: "blur" }
        ],
        voList: {
          serviceWayName: [
            {
              required: true,
              message: "请选择服务方式",
              trigger: "blur",
            },
          ],
          serviceContent: [
            {
              required: true,
              message: "请选择服务内容",
              trigger: "blur",
            },
          ],
          serviceFrequencyText: [
            {
              required: true,
              message: "请选择服务频次",
              trigger: "blur",
            },
          ]
        },
      },
      serviceWayId: '',
    };
  },
  created() {
    this.getList();
  },
  mounted() {
    this.getMaxTableHeight()
    this.screenChange()
  },
  methods: {
    //接收科室列表传值
    clickdepartment(item) {
      this.queryParams.hospitalAgencyId = item.hospitalAgencyId
      this.queryParams.hospitalAgencyName = item.hospitalAgencyName
      this.queryParams.departmentId = item.itemid
      this.departmentName = item.itemName
      this.informationqueryParams.hospitalAgencyId = item.hospitalAgencyId
      if (item.hospitalAgencyId) {
        this.getList();
      }
      this.$forceUpdate()
    },
    changepackageTermUnit(e) {
      this.$set(this.form, 'packageTermUnit', e);
    },
    // 详情
    detail(row) {
      this.detailshow = true
      getServicepackage(row.id).then(response => {
        this.formdetail = response.data;
        this.datailList = response.data.voList
        this.datailList.forEach(el => {
          if (el.serviceFrequencyEnd) {
            el.serviceFrequencyText = el.serviceFrequencyStart + '~' + el.serviceFrequencyEnd
          } else {
            el.serviceFrequencyText = el.serviceFrequencyText
          }
        })
      });
    },
    // 详情关闭
    handleClose() {
      this.detailshow = false
    },
    // 发布
    release(row) {
      this.examineid = row.id
      this.dialogexamine = true
    },
    // 发布同意按钮
    cancelamine() {
      var propagandaStatus = 1
      editReleaseStatus(this.examineid, propagandaStatus).then(response => {
        this.$message({
          type: "success",
          message: "发布成功"
        });
        this.getList()
      });
      this.dialogexamine = false
    },
    // 发布关闭按钮
    amineClose() {
      this.dialogexamine = false
    },
    // 发布不同意按钮
    submitamine() {
      var propagandaStatus = 0
      editReleaseStatus(this.examineid, propagandaStatus).then(response => {
        this.$message({
          type: "success",
          message: "发布不通过"
        });
        this.getList()
      });
      this.dialogexamine = false
    },
    //添加时删除item
    delnurseClassifyitem(index) {
      this.form.voList.splice(index, 1);
      var optionscontentPlus = []
      this.optionscontent[index] = []
      for (var i = 0; i < 5; i++) {
        if (this.optionscontent[i] != []) {
          optionscontentPlus.push(this.optionscontent[i])
        }
      }
      this.optionscontent = {
        '0': [],
        '1': [],
        '2': [],
        '3': [],
        '4': [],
      }
      for (var j = 0; j < optionscontentPlus.length; j++) {
        this.optionscontent[j] = optionscontentPlus[j]
      }
      var optionsfrequencyPlus = []
      this.optionsfrequency[index] = []
      for (var i = 0; i < 5; i++) {
        if (this.optionsfrequency[i] != []) {
          optionsfrequencyPlus.push(this.optionsfrequency[i])
        }
      }
      this.optionsfrequency = {
        '0': [],
        '1': [],
        '2': [],
        '3': [],
        '4': [],
      }
      for (var j = 0; j < optionsfrequencyPlus.length; j++) {
        this.optionsfrequency[j] = optionsfrequencyPlus[j]
      }
    },
    //添加时新增item
    addnurseClassifyitem() {
      this.idd++;
      var obj = {
        serviceWayName: null,
        serviceContent: null,
        serviceFrequencyText: null,
        idd: this.idd
      };
      if (this.form.voList.length == 5) {
        this.$message.error("最多批量添加5条");
      } else {
        this.form.voList.push(obj);
      }
    },
    /** 查询服务包基础信息列表 */
    getList() {
      this.loading = true;
      listServicepackage(this.queryParams).then(response => {
        this.servicepackageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 查询服务方式
    getserviceWayList() {
      serviceWayList().then(response => {
        this.optionsway = response.data;
      });
    },
    // 服务方式点击事件
    changeway(e, index) {
      this.serviceWayId = this.optionsway.find(f => f.serviceWayName == e).id
      serviccontent(this.serviceWayId).then(response => {
        this.optionscontent[index] = response.rows;
      });
      this.form.voList[index].serviceContent = null
      this.form.voList[index].serviceFrequencyText = null
    },
    // 服务内容点击事件
    changcontent(e, index) {
      var id = null
      this.form.voList[index].serviceFrequencyText = null
      id = this.optionscontent[index].find(f => f.serviceContent == e).id
      this.optionsfrequency[index] = this.optionscontent[index].find(f => f.id == id).serviceWayFrequencyList
      this.optionsfrequency[index].forEach(el => {
        if (el.serviceFrequencyType == "DIGIT") {
          el.serviceFrequencyText = el.serviceFrequencyStart + '~' + el.serviceFrequencyEnd
        }
        else if (el.serviceFrequencyType == "serviceFrequencyType") {
          this.optionsfrequency[index] = this.optionscontent[index].find(f => f.id == e).serviceWayFrequencyList
        }
      })
    },
    // 点击科室
    clickinnerVisible() {
      this.innerVisibleshow = true;
      this.informationInfoinfo();
    },
    // 科室列表
    informationInfoinfo() {
      department(this.informationqueryParams).then((response) => {
        this.infolist = response.rows;
        this.totaldepartment = response.total;
        this.loading = false;
      });
    },
    // 科室名称重置
    addresetQuerylist() {
      this.informationqueryParams = {
        pageNum: 1,
        pageSize: 10,
      };
      this.informationInfoinfo();
    },
    innerVisiblecancel() {
      this.innerVisibleshow = false;
    },
    updateCPage(index, size) {
      this.queryParams.pageNum = index
      this.queryParams.pageSize = size
      this.getList();
    },
    updateCPagetwo(index, size) {
      this.informationqueryParams.pageNum = index
      this.informationqueryParams.pageSize = size
      this.informationInfoinfo();
    },
    updateCPagethree(index, size) {
      this.querydisease.pageNum = index
      this.querydisease.pageSize = size
      this.infodisease();
    },
    // 科室名称圆点按钮
    nurseclick(row) {
      this.form.departmentId = row.departmentCode;
      this.form.departmentName = row.departmentName;
      this.departmentName = row.departmentName;
      this.form.diseaseTypeId = '';
      this.form.diseaseTypeName = '请选择病种';
      this.innerVisibleshow = false;
    },
    // 病种列表
    infodisease() {
      listDisease(this.querydisease).then((response) => {
        this.listdisease = response.rows;
        this.diseasetotal = response.total;
        this.loading = false;
      });
    },
    // 点击病种
    clickdisease() {
      if (!this.form.departmentName) {
        this.$modal.msgError("请先选择科室");
      } else {
        this.querydisease.departmentId = this.form.departmentId
        this.infodisease()
        this.diseaseshowst = true;
      }
    },
    // 病种名称圆点按钮
    nurseclickdisease(row) {
      this.form.diseaseTypeId = row.id;
      this.form.diseaseTypeName = row.diseaseTypeName;
      this.diseaseshowst = false;
    },
    // 重置
    resetdisease() {
      this.querydisease = {
        pageNum: 1,
        pageSize: 10,
      };
      this.infodisease()
    },
    canceldiseases() {
      this.diseaseshowst = false;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        time: null,
        id: null,
        departmentId: null,
        departmentName: null,
        diseaseTypeId: null,
        diseaseTypeName: null,
        packageName: null,
        packageIntroduction: null,
        packageVersion: null,
        packageTerm: null,
        packageTermUnit: null,
        packagePrice: null,
        packageRemark: null,
        hardwareType: null,
        whetherRelease: 0,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.optionsway = [],
        // 服务内容
        // this.optionscontent = [],
        this.optionscontent = {
          '0': [],
          '1': [],
          '2': [],
          '3': [],
          '4': [],
        },
        this.optionsfrequency = {
          '0': [],
          '1': [],
          '2': [],
          '3': [],
          '4': [],
        }
      // 服务频次
      // this.optionsfrequency = [
      // {
      //   value: '',
      //   label: ''
      // }
      // ],
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.informationqueryParams.hospitalAgencyId = JSON.parse(localStorage.getItem('user')).hospitalAgencyId
      this.queryParams.hospitalAgencyId = JSON.parse(localStorage.getItem('user')).hospitalAgencyId
      this.$refs.DepartmentList.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.getserviceWayList()
      this.form.voList = [
        {
          serviceWayName: null,
          serviceContent: null,
          serviceFrequencyText: null,
          serviceFrequencyStart: null,
          serviceFrequencyEnd: null,
          idd: this.idd,
        },
      ]
      if (this.queryParams.departmentId) {
        this.form.departmentName = this.departmentName
        this.form.departmentId = this.queryParams.departmentId
      } else {
        this.form.departmentName = '请选择科室'
      }
      this.form.diseaseTypeName = "请选择病种"
      this.form.whetherRelease = 0
      this.form.packageTermUnit = '年'
      this.title = "添加服务包基础信息";
      this.open = true;
    },
    // 修改
    handleUpdate(row) {
      this.getserviceWayList()
      const id = row.id || this.ids
      getServicepackage(id).then(response => {
        this.form = response.data;
        this.form.voList.forEach(el => {
          if (!el.serviceFrequencyText) {
            el.serviceFrequencyText = el.serviceFrequencyStart + '~' + el.serviceFrequencyEnd
          } else {
            el.serviceFrequencyText = el.serviceFrequencyText
          }
        })
        this.departmentName = response.data.departmentName
        this.open = true;
        this.title = "修改服务包基础信息";
      });
    },
    // 复制
    copy(row) {
      const id = row.id || this.ids
      getServicepackage(id).then(response => {
        this.form = response.data;
        this.form.voList.forEach(el => {
          if (!el.serviceFrequencyText) {
            el.serviceFrequencyText = el.serviceFrequencyStart + '~' + el.serviceFrequencyEnd
          } else {
            el.serviceFrequencyText = el.serviceFrequencyText
          }
        })
        this.departmentName = response.data.departmentName
        this.open = true;
        this.title = "复制服务包基础信息";
      });
    },
    // 复制确定
    submitFormadd() {
      this.form.whetherRelease = 0
      var obj = JSON.parse(JSON.stringify(this.form))
      obj.voList.forEach(e => {
        if (e.serviceFrequencyText.includes('~')) {
          const str = e.serviceFrequencyText;
          const parts = str.split('~');
          e.serviceFrequencyStart = parts[0];
          e.serviceFrequencyEnd = parts[1];
          e.serviceFrequencyText = null
        } else {
          e.serviceFrequencyText = e.serviceFrequencyText
        }
      })
      if (this.form.diseaseTypeName == "请选择病种") {
        this.form.diseaseTypeName = null
      }
      addServicepackage(obj).then(response => {
        this.$modal.msgSuccess("复制成功");
        this.open = false;
        this.getList();
        this.getlistcount()
      });
    },
    // 提交
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            if (this.form.voList) {
              var obj = JSON.parse(JSON.stringify(this.form))
              obj.voList.forEach(e => {
                if (e.serviceFrequencyText.includes('~')) {
                  const str = e.serviceFrequencyText;
                  const parts = str.split('~');
                  e.serviceFrequencyStart = parts[0];
                  e.serviceFrequencyEnd = parts[1];
                  e.serviceFrequencyText = null
                } else {
                  e.serviceFrequencyText = e.serviceFrequencyText
                }
              })
              updateServicepackage(obj).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            }
          } else {
            if (this.form.voList) {
              var obj = JSON.parse(JSON.stringify(this.form))
              obj.voList.forEach(e => {
                if (e.serviceFrequencyText.includes('~')) {
                  const str = e.serviceFrequencyText;
                  const parts = str.split('~');
                  e.serviceFrequencyStart = parts[0];
                  e.serviceFrequencyEnd = parts[1];
                  e.serviceFrequencyText = null
                } else {
                  e.serviceFrequencyText = e.serviceFrequencyText
                }
              })
              addServicepackage(obj).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除该服务包基础信息？').then(function () {
        return delServicepackage(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('manage/servicepackage/export', {
        ...this.queryParams
      }, `servicepackage_${new Date().getTime()}.xlsx`)
    },
    // 获取表格最高高度
    getMaxTableHeight() {
      const windowInnerHeight = window.innerHeight // 屏幕可视高度
      const layoutDiv = this.$refs.layout
      const formDiv = this.$refs.topform
      const mb8Div = this.$refs.mb8
      this.maxTableHeight =
        windowInnerHeight - 134 -
        this.getBoxPadding(layoutDiv) -
        this.getBoxHeight(mb8Div) -
        this.getBoxHeight(formDiv)
    },
    // 屏幕resize监听
    screenChange() {
      // 屏幕resize监听事件：一旦屏幕宽高发生变化，就会执行resize
      window.addEventListener('resize', this.getMaxTableHeight, true)
      // 将屏幕监听事件移除
      // 这步是必须的。离开页面时不移除，再返回，或者进入到别的有相同元素的页面会报错
      // 或者将这里的方法直接写在beforeDestroy函数中也可以
      this.$once('hook:beforeDestroy', () => {
        window.removeEventListener('resize', this.getMaxTableHeight, true)
      })
    },
  }
};
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__body {
  padding-bottom: 60px !important;
}


::v-deep .el-input-group {
  width: 204px !important;
}

.container {
  display: inline-block;
  width: 80px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  // text-overflow:ellipsis
  //       white-space: nowrap;
  //       overflow: hidden;
}

// .container:hover {
//   text-overflow:inherit;
//     overflow: visible;
//     white-space: pre-line;

// }
.app-container {
  padding: 20px 0 0 20px !important;
}

::v-deep .el-row {
  height: 100% !important;
}

.leftserv {
  height: calc(100vh - 119px);
  overflow: auto;

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

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

    .count {
      display: inline-block;
      position: relative;
      // right: -172px;
      left: 210px;
      color: #a4a6aa;
      top: -35px;
      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;
    }
  }
}

.app-container {
  padding: 20px 0 0 20px !important;
}

::v-deep .el-row {
  height: 100% !important;
}
</style>
