<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="110px"
    >
      <el-form-item label="护理站名称" prop="nurseStationId" label-width="100px">
        <el-select v-model="queryParams.nurseStationId" placeholder="请选择护理站" @change="handleQuery">
          <el-option
            v-for="item in handstationlist"
            :key="item.id"
            :label="item.nurseStationName"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="护理项目编号" prop="nurseItemCode">
        <el-input
          v-model="queryParams.nurseItemCode"
          placeholder="请输入护理项目编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="护理项目名称" prop="nurseItemName">
        <el-input
          v-model="queryParams.nurseItemName"
          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="['system:stationItem: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="['system:stationItem: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="['system:stationItem:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:stationItem:importStationItem']"
        >导入</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="nurseItemList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="护理时长" style="margin-left: 120px">
              <div
                v-for="(item, index) in props.row.nurseStationItemPrices"
                :key="index"
                style="display: block"
              >{{ item.serveDurationUnit }}</div>
            </el-form-item>
            <el-form-item label="价格(元)" style="margin-left: 30px">
              <div
                v-for="(item, index) in props.row.nurseStationItemPrices"
                :key="index"
                style="display: block"
              >{{ item.price }}</div>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="所属护理站" align="center" prop="nurseStationName" />
      <!-- <el-table-column label="护理类型" align="center" prop="nurseTypeName" /> -->
      <el-table-column label="护理项目编号" align="center" prop="nurseItemCode" />
      <el-table-column label="护理项目名称" align="center" prop="nurseItemName" />
      <el-table-column label="护理项目分类名称" align="center" prop="classifyName" />
      <el-table-column label="上架状态" align="center" prop="whetherShelf">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.shelfStatus"
            active-color="#13ce66"
            inactive-color="#ff4949"
            @change="upwhetherShelf(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:stationItem:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:stationItem:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改护理站护理项目对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1120px"
      append-to-body
      :before-close="cancel"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="130px" :inline="true">
        <el-form-item label="所属护理站" required>
          <template>
            <el-button
              @click="nurseStationshow = true"
              style="
                width: 208px;
                text-align: left;
                height: 36px;
                color: #c0c4cc;
              "
              v-if="
                this.form.nurseStationItem.nurseStationName ==
                '请选择所属护理站'
              "
            >{{ form.nurseStationItem.nurseStationName }}</el-button>
            <el-button
              disabled
              v-else
              style="
                width: 208px;
                text-align: left;
                height: 36px;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
              "
            >{{ form.nurseStationItem.nurseStationName }}</el-button>
          </template>
        </el-form-item>
        <el-form-item label="护理项目分类">
          <template>
            <el-button
              style="
                width: 208px;
                text-align: left;
                height: 36px;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
                color: #c0c4cc;
              "
              @click="clickClassifyshow"
              v-if="form.nurseStationItem.classifyName == '请选择护理项目分类'"
            >{{ form.nurseStationItem.classifyName }}</el-button>
            <el-button
              style="
                width: 208px;
                text-align: left;
                height: 36px;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
              "
              @click="clickClassifyshow"
              v-else
            >{{ form.nurseStationItem.classifyName }}</el-button>
          </template>
        </el-form-item>
        <el-form-item label="护理项目名称" prop="nurseStationItem.nurseItemName">
          <el-input
            v-model="form.nurseStationItem.nurseItemName"
            placeholder="请输入护理项目名称"
            maxlength="50"
          />
        </el-form-item>
        <el-form-item label="提前预约时长" prop="nurseStationItem.advanceAppointDuration">
          <el-select
            v-model.number="form.nurseStationItem.advanceAppointDuration"
            placeholder="请选择提前预约时长"
            style="width:208px"
            clearable
          >
            <el-option
              style="width:208px"
              v-for="item in optionlist"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="预约人数上限" prop="nurseStationItem.appointmentLimitCount">
          <el-input
            placeholder="请输入预约人数上限"
            v-model="form.nurseStationItem.appointmentLimitCount"
            oninput="value=value.replace(/[^\d]/g,'')"
            maxlength="8"
          />
        </el-form-item>
        <el-form-item label="预约时间间隔" prop="nurseStationItem.appointmentTimeInterval">
          <el-select
            style="width:208px"
            v-model="form.nurseStationItem.appointmentTimeInterval"
            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="nurseStationItem.sort">
          <el-input
            placeholder="请输入排序"
            v-model.number="form.nurseStationItem.sort"
            maxlength="10"
            oninput="value=value.replace(/[^\d]/g,'')"
          />
        </el-form-item>
        <el-form-item label="项目头像" prop="nurseStationItem.itemPictureUrl">
          <stationAcatar
            style="width: 208px"
            @imgUrl="imgUrl"
            :img="form.nurseStationItem.itemPictureUrl"
            :type="'itemPictureUrl'"
          />
        </el-form-item>
        <el-form-item label="项目内容简介" prop="nurseStationItem.nurseItemContent">
          <editor
            @imgs="imgs"
            :min-height="82"
            style="width: 90%"
            maxlength="300"
            v-model="form.nurseStationItem.nurseItemContent"
          ></editor>
        </el-form-item>
        <el-form-item label="项目时长和价格" required>
          <el-table
            ref="nurseStationItemPrices"
            :data="form.nurseStationItemPrices"
            style="margin-top: 20px; width: 900px"
          >
            <el-table-column property="serveDurationUnit" label="服务时长和单位" align="center">
              <template slot-scope="scope">
                <el-input v-model="scope.row.serveDurationUnit" maxlength="6"></el-input>
              </template>
            </el-table-column>
            <el-table-column property="price" label="价格" align="center">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.price"
                  placeholder="小数点后两位(元)"
                  min="0"
                  type="number"
                  oninput="if(value.indexOf('.')>0){value=value.slice(0,value.indexOf('.')+3)} if(value.length>6){value=value.slice(0,6)}"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column property="description" label="描述" align="center">
              <template slot-scope="scope">
                <el-input v-model="scope.row.description" maxlength="300"></el-input>
              </template>
            </el-table-column>
            <el-table-column property="description" label="佣金金额" align="center">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.commissionAmount"
                  maxlength="300"
                  placeholder="最多小数点后两位(元)"
                  @input="commissionAmountinput(scope.row)"
                  type="number"
                  min="0"
                  oninput="if (value.indexOf('.') > 0) { value = value.slice(0, value.indexOf('.') + 3)}  if (value.length > 6) { value = value.slice(0, 6) }"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column property="description" label="佣金比例(%)" align="center">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.commissionRate"
                  maxlength="300"
                  @input="commissionRateoninput(scope.row)"
                  placeholder="最多小数点后两位(%)"
                  type="number"
                  min="0"
                  oninput="if (value.indexOf('.') > 0) { value = value.slice(0, value.indexOf('.') + 3)}  if (value.length > 6) { value = value.slice(0, 6) }"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="100">
              <template slot-scope="scope">
                <el-button size="mini" type="text" @click="addnurseStationItemPrices">新增</el-button>
                <el-button size="mini" type="text" @click="delnurseStationItemPrices(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>

        <el-form-item label="护理项目耗材">
          <el-button type="primary" size="small" plain @click="listStationConsumableinfo">添加护理项目耗材</el-button>
          <el-table
            ref="singleTable"
            :data="form.nurseStationItemConsumables"
            style="margin-top: 20px; width: 900px"
          >
            <el-table-column property="nurseStationConsumableId" label="耗材包名称" align="center">
              <template slot-scope="scope">{{ scope.row.consumableDetail }}</template>
            </el-table-column>

            <el-table-column property="consumableCount" label="耗材包数量" align="center">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.consumableCount"
                  maxlength="9"
                  oninput="value=value.replace(/[^\d]/g,'')"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column property="consumablePrice" label="耗材包单位" align="center">
              <template slot-scope="scope">{{ scope.row.consumableUnit }}</template>
            </el-table-column>
            <el-table-column property="consumablePrice" label="耗材包单价" align="center">
              <template slot-scope="scope">{{ scope.row.consumablePrice }}</template>
            </el-table-column>
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button size="mini" type="text" @click="delConsumable(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </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-dialog
      title="选择护理项目分类"
      :visible.sync="Classifyshow"
      width="1100px"
      append-to-body
      :before-close="cancelClassifyshow"
    >
      <el-form :model="classifyquery" label-width="150px" :inline="true">
        <el-form-item label="护理项目分类编码" prop="classifyCode">
          <el-input v-model="classifyquery.classifyCode" placeholder="请输入护理项目分类编码" />
        </el-form-item>
        <el-form-item label="护理项目分类名称" prop="classifyName">
          <el-input v-model="classifyquery.classifyName" placeholder="请输入护理项目分类名称" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="classifylistInfo">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="classifylistcancel">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="classifylist" @cell-dblclick="choiceclassify">
        <el-table-column label="请选择" width="70" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              style="width: 15px; height: 15px"
              circle
              @click="choiceclassify(scope.row)"
              v-if="form.nurseStationItem.nurseClassifyId == scope.row.id"
            ></el-button>

            <el-button
              style="width: 15px; height: 15px"
              circle
              v-else
              @click="choiceclassify(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column property="classifyCode" label="护理项目分类编码" align="center"></el-table-column>
        <el-table-column property="classifyName" label="护理项目分类名称" align="center"></el-table-column>
      </el-table>
      <pagination
        v-show="classifytotal > 0"
        :total="classifytotal"
        :page.sync="classifyquery.pageNum"
        :limit.sync="classifyquery.pageSize"
        @pagination="classifylistInfo"
      />
    </el-dialog>
    <!-- 护理站 -->
    <el-dialog
      title="选择护理站"
      :visible.sync="nurseStationshow"
      width="1100px"
      append-to-body
      :before-close="clicknurseStationshow"
    >
      <el-form ref="form" :model="getListByUserquery" label-width="110px" :inline="true">
        <el-form-item label="护理站编码" prop="nurseStationCode">
          <el-input v-model="getListByUserquery.nurseStationCode" placeholder="请输入护理站编码" />
        </el-form-item>
        <el-form-item label="护理站名称" prop="nurseStationName">
          <el-input v-model="getListByUserquery.nurseStationName" placeholder="请输入护理站名称" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery2">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="stationcancel">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="nurseStationlist" @cell-dblclick="choicestationid">
        <el-table-column label="请选择" width="70" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              style="width: 15px; height: 15px"
              circle
              @click="choicestationid(scope.row)"
              v-if="form.nurseStationItem.nurseStationId == scope.row.id"
            ></el-button>

            <el-button
              style="width: 15px; height: 15px"
              circle
              v-else
              @click="choicestationid(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column property="nurseStationCode" label="护理站编码" align="center"></el-table-column>
        <el-table-column property="nurseStationName" label="护理站名称" align="center"></el-table-column>
        <el-table-column property="phone" label="联系电话" align="center"></el-table-column>
        <el-table-column
          property="address"
          label="护理站地址"
          align="center"
          :show-overflow-tooltip="true"
        ></el-table-column>
      </el-table>

      <pagination
        v-show="total4 > 0"
        :total="total4"
        :page.sync="getListByUserquery.pageNum"
        :limit.sync="getListByUserquery.pageSize"
        @pagination="getList"
      />
    </el-dialog>
    <!-- 耗材弹框 -->
    <el-dialog
      title="添加护理项目耗材"
      :visible.sync="stationConsumableshow"
      width="1100px"
      append-to-body
      :before-close="clickstationConsumableshow"
    >
      <el-form ref="form" :model="StationConsumablequeryParams" label-width="110px" :inline="true">
        <el-form-item label="耗材包名称" prop="nurseStationId">
          <el-input v-model="StationConsumablequeryParams.consumableDetail" placeholder="请输入耗材包名称" />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="listStationConsumableinfo"
          >搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="listStationConsumableinfocancel">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table
        v-loading="loading"
        :data="stationConsumableList"
        @cell-dblclick="cellchoiceConsumable"
      >
        <el-table-column label="请选择" width="70" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              style="width: 15px; height: 15px"
              circle
              @click="delConsumable(scope.row)"
              v-if="
                form.nurseStationItemConsumables.find(
                  (e) => e.id == scope.row.id
                )
              "
            ></el-button>

            <el-button
              style="width: 15px; height: 15px"
              circle
              v-else
              @click="choiceConsumable(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column label="护理站名称" align="center" prop="nurseStationName" />
        <el-table-column label="耗材包编号" align="center" prop="consumableCode" />
        <el-table-column label="耗材包名称" align="center" prop="consumableDetail" />
        <el-table-column label="耗材包单位" align="center" prop="consumableUnit" />
        <el-table-column label="耗材包价格" align="center" prop="consumablePrice" />
      </el-table>
      <el-button
        type="primary"
        size="mini"
        @click="clickstationConsumableshow"
        style="
          margin-top: 20px;
          margin-left: 85%;
          width: 100px;
          height: 40px;
          font-size: 15px;
        "
      >选择完成</el-button>
      <pagination
        v-show="total3 > 0"
        :total="total3"
        :page.sync="StationConsumablequeryParams.pageNum"
        :limit.sync="StationConsumablequeryParams.pageSize"
        @pagination="listStationConsumable"
      />
    </el-dialog>
    <!-- //导入 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link
            type="primary"
            :underline="false"
            style="font-size: 12px; vertical-align: baseline"
            @click="importTemplate"
          >下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStationConsumable } from "@/api/system/stationConsumable";
import stationAcatar from "../stationAvatar/index.vue";
import { listInfo } from "@/api/system/classifyItem.js";
import {
  list,
  getNurseItem,
  delNurseItem,
  addNurseItem,
  updateNurseItem,
  updatePicture,
  updateShelfStatus
} from "@/api/system/nurseItem";
import { getToken } from "@/utils/auth";
import { getListByUser } from "@/api/system/userlist.js";

export default {
  components: { stationAcatar },
  name: "NurseItem",
  data() {
    return {
      imgsurl: { pictureUrlList: [] },
      imageUrl: "",
      imgone: "",
      handstationlist: [],
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/stationItem/importData"
      },
      // 遮罩层
      loading: true,
      stationConsumableshow: false,
      nurseStationshow: false,
      Classifyshow: false,
      // 选中数组
      ids: [],
      idd: 99999999,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total2: 0,
      total3: 0,
      total4: 0,
      options: [
        {
          value: "HALF_HOUR",
          label: "半小时"
        },
        {
          value: "ONE_HOUR",
          label: "一小时"
        },
        {
          value: " NINETY_MINUTES",
          label: "九十分钟"
        },
        {
          value: "TWO_HOUR",
          label: "两小时"
        }
      ],
      value: "",
      optionlist: [
        {
          value: "HALF_DAY",
          label: "半天"
        },
        {
          value: "ONE_DAY",
          label: "一天"
        }
      ],
      //耗材
      stationConsumableList: [],
      // 护理站护理项目表格数据
      nurseItemList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //权限查询
      nurseStationlist: [],
      nurseStationlist2: [],
      getListByUserquery: {
        pageNum: 1,
        pageSize: 10
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nurseStationId: null,
        nurseTypeId: null,
        userId: null,
        nurseItemCode: null,
        nurseItemName: null,
        nurseItemContent: null,
        advanceAppointDuration: null,
        sort: null
      },
      // 查询参数
      StationConsumablequeryParams: {
        pageNum: 1,
        pageSize: 10,
        nurseStationId: null,
        consumableDetail: null
      },
      // 表单参数
      form: {
        nurseStationItem: {
          nurseTypeId: null,
          nurseItemName: null,
          nurseItemContent: "",
          advanceAppointDuration: null,
          itemPictureUrl: null,
          sort: null,
          nurseStationName: "请选择所属护理站",
          classifyName: "请选择护理项目分类",
          nurseClassifyId: null,
          appointmentLimitCount: null,
          appointmentTimeInterval: null
        }
      },
      // 表单校验
      rules: {
        "nurseStationItem.nurseItemName": [
          { required: true, message: "护理项目名称不能为空", trigger: "blur" }
        ],
        "nurseStationItem.nurseItemContent": [
          { required: true, message: "项目内容简介不能为空", trigger: "blur" }
        ],
        "nurseStationItem.sort": [
          { required: true, message: "排序不能为空", trigger: "blur" }
        ],
        // "nurseStationItem.advanceAppointDuration": [
        //             { required: true, message: "提前预约时长不能为空", trigger: "blur" },
        //         ],
        //          // }, ],
        "nurseStationItem.appointmentTimeInterval": [
          {
            required: true,
            trigger: "blur",
            message: "请选择预约时间点间隔"
          }
        ],
        // "nurseStationItem.advanceAppointDuration": [
        //   { required: true, message: "提前预约时长不能为空", trigger: "blur" },
        // ],
        "nurseStationItem.itemPictureUrl": [
          {
            required: true,
            trigger: "blur",
            message: "请选择项目头像"
          }
        ],
        nurseStationId: [
          { required: true, trigger: "blur", message: "请选择所属护理站" }
        ],
        nurseTypeId: [
          { required: true, message: "请选择护理类型", trigger: "blur" }
        ]
      },
      classifyquery: {
        pageNum: 1,
        pageSize: 10,
        classifyCode: null,
        classifyName: null
      },
      classifylist: [],
      classifytotal: 0
    };
  },
  created() {
    this.info();
    this.infos();
    // this.getList();
    this.classifylistInfo();
  },
  methods: {
    commissionAmountinput(e) {
      if (e.commissionRate) {
        e.commissionAmount = null;
      }
    },
    commissionRateoninput(e) {
      if (e.commissionAmount) {
        e.commissionRate = null;
      }
    },
    //点击上架
    upwhetherShelf(row) {
      let shelfStatus = null;
      if (row.shelfStatus == false) {
        shelfStatus = "NOT_SHELF";
      } else if (row.shelfStatus == true) {
        shelfStatus = "SHELF";
      }
      updateShelfStatus(row.id, shelfStatus).then(res => {
        if (row.shelfStatus == false) {
          this.$modal.msgSuccess("已修改上架状态为未上架");
        } else {
          this.$modal.msgSuccess("已修改上架状态为上架");
        }
        this.getList();
      });
    },
    //// //护理项目list
    //打开遮罩层
    clickClassifyshow() {
      this.Classifyshow = true;
      this.classifylistcancel();
    },
    //关闭遮罩层
    cancelClassifyshow() {
      this.Classifyshow = false;
    },
    //选中或者取消选中
    choiceclassify(e) {
      if (this.form.nurseStationItem.nurseClassifyId == e.id) {
        this.form.nurseStationItem.nurseClassifyId = null;
        this.form.nurseStationItem.classifyName = null;
      } else {
        this.form.nurseStationItem.nurseClassifyId = e.id;
        this.form.nurseStationItem.classifyName = e.classifyName;
      }
      this.Classifyshow = false;
    },
    //重置
    classifylistcancel() {
      this.classifyquery = {
        pageNum: 1,
        pageSize: 10,
        classifyCode: null,
        classifyName: null
      };
      this.classifylistInfo();
    },
    //搜索
    classifylistInfo() {
      listInfo(this.classifyquery).then(res => {
        this.classifylist = res.rows;
        this.classifytotal = res.total;
      });
    },
    imgs(item) {
      this.imgsurl.pictureUrlList.push(item);
    },
    imgUrl(imgUrl) {
      this.form.nurseStationItem.itemPictureUrl = imgUrl;
    },
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download(
        "/system/stationItem/downloadTemplate?fileType=1",
        {},
        `护理站项目信息导入模板.xlsx`
      );
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(
        "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
          response.msg +
          "</div>",
        "导入结果",
        { dangerouslyUseHTMLString: true }
      );
      this.getList();
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    //耗材包选择完成
    stationConsumablechoiceok() {
      this.form.nurseStationItemConsumables.forEach(e => {
        e.nurseStationConsumableId = e.id;
      });
      this.stationConsumableshow = false;
    },
    //删除已经选择的耗材包
    delConsumable(item) {
      this.form.nurseStationItemConsumables = this.form.nurseStationItemConsumables.filter(
        e => e.id != item.id
      );
    },
    //双击耗材包
    cellchoiceConsumable(item) {
      if (this.form.nurseStationItemConsumables.find(e => e.id == item.id)) {
        this.form.nurseStationItemConsumables = this.form.nurseStationItemConsumables.filter(
          e => e.id != item.id
        );
      } else {
        this.form.nurseStationItemConsumables.push(item);
      }
    },
    //选择耗材宝
    choiceConsumable(item) {
      this.form.nurseStationItemConsumables.push(item);
    },
    //护理站页面选择护理站
    choicestationid(item) {
      this.form.nurseStationItem.nurseStationId = item.id;
      // this.form.nurseStationId = item.id;
      this.form.nurseStationItem.nurseStationName = item.nurseStationName;
      this.StationConsumablequeryParams.nurseStationId = item.id;
      this.nurseStationshow = false;
      this.stationcancel();
    },
    //关闭护理站页面
    clicknurseStationshow() {
      this.stationcancel();
      this.nurseStationshow = false;
    },
    //耗材包关闭
    clickstationConsumableshow() {
      this.listStationConsumableinfocancel();
      this.stationConsumableshow = false;
    },
    // 耗材重置
    listStationConsumableinfocancel() {
      this.StationConsumablequeryParams.consumableDetail = null;
      this.StationConsumablequeryParams.pageNum = 1;
      this.StationConsumablequeryParams.pageSize = 10;
      this.listStationConsumable();
    },
    //护理站重置
    stationcancel() {
      this.getListByUserquery = {
        pageNum: 1,
        pageSize: 10
      };
      this.info();
    },
    //护理站搜索
    handleQuery2() {
      this.loading = true;
      this.getListByUserquery.pageNum = 1;
      this.info();
    },
    /** 耗材列表 */
    listStationConsumable() {
      listStationConsumable(this.StationConsumablequeryParams).then(
        response => {
          this.stationConsumableList = response.rows;
          this.total3 = response.total;
        }
      );
    },
    listStationConsumableinfo() {
      if (this.form.nurseStationItem.nurseStationId != null) {
        listStationConsumable(this.StationConsumablequeryParams).then(
          response => {
            this.stationConsumableList = response.rows;
            this.total3 = response.total;
            this.stationConsumableshow = true;
          }
        );
      } else {
        this.$message.error("请先选择护理站");
      }
    },
    /** 查询护理站护理项目列表 */
    getList() {
      this.loading = true;
      list(this.queryParams).then(response => {
        response.rows.forEach(e => {
          if (e.shelfStatus == "SHELF") {
            e.shelfStatus = true;
          } else {
            e.shelfStatus = false;
          }
        });
        this.nurseItemList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      var obj = { pictureUrlList: [] };
      if (this.imgone != this.form.nurseStationItem.itemPictureUrl) {
        obj.pictureUrlList.push(this.form.nurseStationItem.itemPictureUrl);
      }
      if (obj.pictureUrlList.length > 0) {
        updatePicture(obj).then(res => {});
      }
      if (this.imgsurl.pictureUrlList.length > 0) {
        updatePicture(this.imgsurl).then(res => {});
      }
      this.imgsurl = { pictureUrlList: [] };
      this.open = false;
      this.reset();
    },
    //时长价格
    addnurseStationItemPrices(item, index) {
      if (this.form.nurseStationItemPrices.length == 5) {
        this.$message.error("最多只能5条");
      } else {
        this.idd++;
        var obj = {
          serveDurationUnit: "",
          price: "",
          description: "",
          idd: this.idd
        };
        this.form.nurseStationItemPrices.push(obj);
      }
    },
    delnurseStationItemPrices(item) {
      if (item.idd && !item.nurseItemPriceId) {
        if (this.form.nurseStationItemPrices.length == 1) {
          this.$message.error("最后一条不可删除");
        } else {
          this.form.nurseStationItemPrices = this.form.nurseStationItemPrices.filter(
            e => e.idd != item.idd
          );
        }
      } else if (!item.idd && item.nurseItemPriceId) {
        if (this.form.nurseStationItemPrices.length == 1) {
          this.$message.error("最后一条不可删除");
        } else {
          this.form.nurseStationItemPrices = this.form.nurseStationItemPrices.filter(
            e => e.nurseItemPriceId != item.nurseItemPriceId
          );
        }
      }
    },
    // 表单重置
    reset() {
      this.form = {
        nurseStationItem: {
          nurseTypeId: null,
          nurseItemName: null,
          nurseItemContent: null,
          advanceAppointDuration: null,
          itemPictureUrl: null,
          sort: null,
          nurseStationName: "请选择所属护理站",
          classifyName: "请选择护理项目分类",
          nurseClassifyId: null,
          appointmentLimitCount: null
        },
        nurseStationItemConsumables: [
          // {
          //   nurseStationConsumableId: "",
          //   consumableCount: "",
          //   consumablePrice: "",
          // },
        ],
        nurseStationItemPrices: [
          {
            serveDurationUnit: null,
            price: null,
            description: null,
            idd: this.idd
          }
        ]
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      if (this.nurseStationlist[0]) {
        this.queryParams.pageNum = 1;
        this.queryParams.pageSize = 10;
        this.queryParams.nurseItemCode = null;
        this.queryParams.nurseItemName = null;
      }
      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.StationConsumablequeryParams.nurseStationId = null;
      this.title = "添加护理站护理项目";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.StationConsumablequeryParams.nurseStationId = null;
      const id = row.id || this.ids;
      getNurseItem(id).then(response => {
        if (response.data.nurseStationItemConsumables) {
          response.data.nurseStationItemConsumables.forEach(e => {
            e.id = e.nurseStationConsumableId;
          });
        } else {
          response.data.nurseStationItemConsumables = [];
        }
        this.form = response.data;
        this.StationConsumablequeryParams.nurseStationId =
          response.data.nurseStationItem.nurseStationId;
        this.imgone = this.form.nurseStationItem.itemPictureUrl;
        if (this.form.nurseStationItemPrices.length == 0) {
          var obj = {
            serveDurationUnit: "",
            price: "",
            description: "",
            idd: this.idd
          };
          this.form.nurseStationItemPrices.push(obj);
        }
        this.open = true;
        this.title = "修改护理站护理项目";
      });
    },
    /** 提交按钮 */
    submitForm() {
      if (!this.form.nurseStationItem.appointmentLimitCount) {
        this.form.nurseStationItem.appointmentLimitCount = null;
      }
      if (this.form.nurseStationItemConsumables.length > 0) {
        this.form.nurseStationItemConsumables.forEach(e => {
          e.nurseStationConsumableId = e.id;
          e.consumableCount = Number(e.consumableCount);
        });
      }
      if (this.form.nurseStationItemPrices.length > 0) {
        this.form.nurseStationItemPrices.forEach(e => {
          if (!e.commissionAmount || e.commissionAmount == "") {
            e.commissionAmount = null;
          }
          if (!e.commissionRate || e.commissionRate == "") {
            e.commissionRate = null;
          }
        });
      }
      this.form.nurseStationItem.nurseTypeId = this.form.nurseTypeId;
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.nurseStationItem.id != null) {
            this.form.nurseStationItemPrices.forEach(e => {
              e.nurseStationItemId = this.form.nurseStationItem.id;
            });
            var obj = { pictureUrlList: [] };
            if (this.imgone != this.form.nurseStationItem.itemPictureUrl) {
              obj.pictureUrlList.push(this.imgone);
            }
            if (obj.pictureUrlList.length > 0) {
              updatePicture(obj).then(res => {});
            }
            this.imgsurl = { pictureUrlList: [] };
            this.form.nurseStationItemPrices.forEach(e => {
              e.price = Number(e.price);
            });
            updateNurseItem(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.nurseStationItemPrices.forEach(e => {
              e.price = Number(e.price);
            });
            addNurseItem(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.$forceUpdate();
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    infos() {
      var queryFor = {
        pageNum: 1,
        pageSize: 9999
      };
      getListByUser(queryFor).then(res => {
        this.handstationlist = res.rows;
        this.queryParams.nurseStationId = res.rows[0].id;
        this.getList();
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除此护理站护理项目？")
        .then(function() {
          return delNurseItem(ids);
        })
        .then(() => {
          var obj = { pictureUrlList: [] };
          obj.pictureUrlList.push(row.itemPictureUrl);
          updatePicture(obj).then(res => {});
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导入按钮操作 */
    handleExport() {
      this.upload.title = "护理站护理项目导入";
      this.upload.open = true;
    },

    //权限列表
    info() {
      getListByUser(this.getListByUserquery).then(res => {
        this.total4 = res.total;
        this.nurseStationlist = res.rows;
      });
    }
  }
};
</script>
<style lang="scss" scoped>
::v-deep .el-table__cell .el-form-item--medium .el-form-item__content {
  display: block;
}
// ::v-deep .el-form-item__label {
//   font-weight: 550;
// }
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
