<template>
  <div class="app-container">
    <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-input
          v-model="queryParams.whetherRelease"
          placeholder="请输入是否发布，0：否，1：是"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
      </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>

    <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="['manage:servicepackage: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="['manage:servicepackage: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="['manage:servicepackage:remove']"
          >删除</el-button
        >
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['manage:servicepackage:export']"
          >导出</el-button
        >
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-row :gutter="20">
      <el-col :span="5">
        <div class="leftserv" ref="box">
          <div class="name">科室名称</div>
          <div>
            <el-input
              v-model="name"
              placeholder="请输入科室名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </div>
          <div class="listitem">
            <div
              :class="itemname == null ? 'allactive' : 'all'"
              @click="itemdata()"
            >
              全部
            </div>
            <span class="count">{{ count }}</span>
          </div>
          <div
            class="listitem"
            v-for="(item, index) in DepartmentoList"
            :key="index"
            @click="itemdata(item)"
          >
            <div :class="itemname == item.id ? 'allactive' : 'all'">
              {{ item.departmentName }}
            </div>
            <span class="count">{{ item.countNum }}</span>
          </div>
        </div>
      </el-col>
      <el-col :span="19">
        <el-table
          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">
              {{ scope.row.whetherRelease == "0" ? "否" : "" }}
              {{ scope.row.whetherRelease == "1" ? "是" : "" }}
            </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>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </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
            type=""
            v-if="departmentName == '请选择科室'"
            @click="clickinnerVisible()"
            style="
              width: 204px;
              text-align: left;
              height: 36px;
              color: #c0c4cc;
              overflow: hidden;
            "
            >{{ departmentName }}</el-button
          >
          <el-button
            @click="clickinnerVisible()"
            type=""
            v-else
            style="
              width: 204px;
              text-align: left;
              height: 36px;
              padding-left: -10px;
              overflow: hidden;
            "
            >{{ departmentName }}</el-button
          >
        </el-form-item>
        <el-form-item label="病种名称" prop="diseaseTypeName">
          <el-button
            type=""
            v-if="diseaseTypeName == '请选择病种'"
            @click="clickdisease()"
            style="
              width: 204px;
              text-align: left;
              height: 36px;
              color: #c0c4cc;
              overflow: hidden;
            "
            >{{ diseaseTypeName }}</el-button
          >
          <el-button
            @click="clickdisease()"
            type=""
            v-else
            style="
              width: 204px;
              text-align: left;
              height: 36px;
              padding-left: -10px;
              overflow: hidden;
            "
            >{{ 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>
      <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"
      />
    </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>

          <!-- <span class="container" v-tooltip="formdetail.packageName">{{ formdetail.packageName }}</span> -->
          <!-- <span class="container">
                <el-tooltip>

                          <template slot="title">
                                {{ formdetail.packageName ? formdetail.packageName : '-' }}
                          </template>

                      {{ formdetail.packageName ? formdetail.packageName : '-' }}
                        </el-tooltip>
         </span> -->
        </el-form-item>
        <!-- <el-form-item label="服务包名称:" prop="packageVersion">
          <span
            >{{ formdetail.packageName }}</span
          >
        </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";

export default {
  name: "Servicepackage",
  data() {
    return {
      itemname: null,
      departmentName: null,
      diseaseTypeName: null,
      name: '',
      departmentId: null,
      count: '',//全部
      DepartmentoList: [],//左侧数组
      // 左侧传值
      querydepartmen: {
        departmentName: "",
        // pageNum: 1,
        // pageSize: 10,

      },


      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();
    this.Departmentlist();
  },
  methods: {
    changepackageTermUnit(e) {

      this.$set(this.form, 'packageTermUnit', e);
      // 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);
      // console.log(this.form.voList,'[[[[]]]]')
      // console.log(this.optionscontent)
      var optionscontentPlus = []
      this.optionscontent[index] = []
      for (var i = 0; i < 5; i++) {
        if (this.optionscontent[i] != []) {
          optionscontentPlus.push(this.optionscontent[i])
        }
      }
      // console.log(optionscontentPlus,'打印optionscontentPlus')
      // console.log(this.optionscontent,'optionscontent')
      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);
        // console.log(this.form)
      }
    },
    /** 查询服务包基础信息列表 */
    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
        }
      })
    },

    // 左侧科室列表
    Departmentlist() {
      this.loading = true;
      listServicePackageNum(this.querydepartmen).then(response => {
        this.DepartmentoList = response.data;
        let sum = 0;
        this.DepartmentoList.forEach((item) => {
          if (item.countNum != null) {
            sum += item.countNum;
          }
          this.count = sum;
        });
        this.loading = false;
      });
    },
    // 左侧科室
    itemdata(item) {
      if (item) {
        this.itemname = item.id
        this.departmentName = item.departmentName
        this.loading = true;
        this.queryParams.departmentId = item.id
        this.getList()
      } else {
        this.queryParams.departmentId = ''
        this.itemname = null
        this.getList()
      }
    },
    // 点击科室
    clickinnerVisible() {
      this.innerVisibleshow = true;
      if (this.itemname) {
        this.informationqueryParams.departmentId = this.itemname

      } else {
        this.informationqueryParams.departmentId = null
      }
      this.informationInfoinfo();
    },
    // 科室列表
    informationInfoinfo() {
      department(this.informationqueryParams).then((response) => {
        this.infolist = response.rows;
        this.totaldepartment = response.total;
        this.loading = false;
      });
      // this.informationqueryParams.page = 1;
    },
    // 科室名称重置
    addresetQuerylist() {
      this.informationqueryParams = {
        pageNum: 1,
        pageSize: 10,
      };
      this.informationInfoinfo();
    },
    innerVisiblecancel() {
      this.innerVisibleshow = false;
    },
    // 科室名称圆点按钮
    nurseclick(row) {
      this.form.departmentId = row.id;
      this.departmentName = row.departmentName;
      this.form.diseaseTypeId = '';
      this.diseaseTypeName = '请选择病种';
      this.innerVisibleshow = false;
      // this.form.diseaseTypeId = null;
      // this.diseaseTypeName = '请选择科室';
    },

    // 病种列表
    infodisease() {
      listDisease(this.querydisease).then((response) => {
        this.listdisease = response.rows;
        this.diseasetotal = response.total;
        this.loading = false;
      });
    },
    // 点击病种
    clickdisease() {
      if (this.departmentName == '请选择科室') {
        this.$modal.msgError("请先选择科室");
      } else {
        this.diseaseshowst = true;
        this.querydisease.departmentId = this.form.departmentId
        this.infodisease()
      }
    },
    // 病种名称圆点按钮
    nurseclickdisease(row) {
      this.form.diseaseTypeId = row.id;
      this.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.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,
          },
        ],
      };
      this.form.whetherRelease = 0
      this.form.packageTermUnit = '年'
      if (this.itemname) {
        this.form.departmentName = this.departmentName
        this.form.departmentId = this.itemname
      } else if (this.itemname == null) {
        this.departmentName = "请选择科室"
      }
      else {
        this.departmentName = "请选择科室"
      }
      this.diseaseTypeName = "请选择病种"

      this.open = true;
      this.title = "添加服务包基础信息";
    },
    // 修改
    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
          }
        })
        if (!response.data.diseaseTypeName || response.data.diseaseTypeName == "") {
          this.diseaseTypeName = "请选择病种"
        } else {
          this.diseaseTypeName = response.data.diseaseTypeName
        }
        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.diseaseTypeName = response.data.diseaseTypeName
        this.departmentName = response.data.departmentName
        this.open = true;
        this.title = "复制服务包基础信息";
        this.Departmentlist();
      });
    },
    // 复制确定
    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.diseaseTypeName == "请选择病种") {
        this.form.diseaseTypeName == null
      } else {
        this.form.diseaseTypeName = this.diseaseTypeName
      }
      if (this.itemname) {

        this.form.departmentName = this.departmentName
        this.form.departmentId = this.itemname

      } else {
        this.form.departmentName = this.departmentName

      }
      addServicepackage(obj).then(response => {
        this.$modal.msgSuccess("复制成功");
        this.open = false;
        this.getList();
        this.getlistcount()
      });

    },
    // 提交
    submitForm() {
      // return
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            this.form.departmentName = this.departmentName
            if (this.diseaseTypeName == "请选择病种") {
              this.form.diseaseTypeName = null
            } else {
              this.form.diseaseTypeName = this.diseaseTypeName
            }
            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.diseaseTypeName == "请选择病种") {
              this.form.diseaseTypeName = null
            } else {
              this.form.diseaseTypeName = this.diseaseTypeName
            }
            if (this.itemname) {
              this.form.departmentName = this.departmentName
              this.form.departmentId = this.itemname

            } else {
              this.form.departmentName = this.departmentName
            }
            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();
                this.Departmentlist()
              });

            }
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除该服务包基础信息？').then(function () {
        return delServicepackage(ids);
      }).then(() => {
        this.getList();
        this.Departmentlist();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('manage/servicepackage/export', {
        ...this.queryParams
      }, `servicepackage_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss" scope>
::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;

// }
.leftserv {
  height: 857px;
  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;
    }
  }
}
</style>
