<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=""
        v-if="nurseStationlist.find((e) => e.isAdmin == '1')"
      >
        <el-select
          v-model="queryParams.nurseStationId"
          clearable
          placeholder="请选择护理站"
          v-loadmore="loadMore"
        >
          <el-option
            v-for="item in nurseStationlist"
            :key="item.id"
            :label="item.nurseStationName"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="护理站名称" prop="" v-else>
        <el-select
          v-model="queryParams.nurseStationId"
          placeholder="请选择护理站"
          v-loadmore="loadMore"
        >
          <el-option
            v-for="item in nurseStationlist"
            :key="item.id"
            :label="item.nurseStationName"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="耗材包编号" prop="consumableCode">
        <el-input
          v-model="queryParams.consumableCode"
          placeholder="请输入耗材包编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="耗材包详情" prop="consumableDetail">
        <el-input
          v-model="queryParams.consumableDetail"
          placeholder="请输入服务项目耗材包详情"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="耗材包单位" prop="consumableUnit">
        <el-input
          v-model="queryParams.consumableUnit"
          placeholder="请输入耗材包单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="耗材包价格(元)" prop="consumablePrice">
        <el-input
          v-model="queryParams.consumablePrice"
          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="sresetQuery"
          >重置</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:stationConsumable: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:stationConsumable: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:stationConsumable:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleport"
          >导入</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="stationConsumableList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="护理站名称"
        align="center"
        prop="nurseStationName"
        :show-overflow-tooltip="true"
      />
      <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-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:stationConsumable:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:stationConsumable: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="listStationConsumableinfo"
    />
    <!-- 修改护理站耗材信息对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="xgopen"
      width="500px"
      append-to-body
      :before-close="cancel"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="所属护理站">
          <el-button
            disabled
            style="width: 360px; text-align: left; height: 36px; color: #c0c4cc"
            @click="open3 = true"
            v-if="form.nurseStationName == '请选择所属护理站'"
          >
            {{ form.nurseStationName }}
          </el-button>
          <el-button
            disabled
            style="width: 360px; text-align: left; height: 36px"
            @click="open3 = true"
          >
            {{ form.nurseStationName }}
          </el-button>
        </el-form-item>
        <el-form-item label="耗材包详情" prop="consumableDetail">
          <el-input
            v-model="form.consumableDetail"
            placeholder="请输入服务项目耗材包详情"
            maxlength="100"
          />
        </el-form-item>
        <el-form-item label="耗材包单位" prop="consumableUnit">
          <el-input
            v-model="form.consumableUnit"
            placeholder="请输入耗材包单位"
            maxlength="10"
          />
        </el-form-item>
        <el-form-item label="耗材包价格(元)" prop=" ">
          <el-input
            v-model="form.consumablePrice"
            placeholder="请输入耗材包价格" 
            type="number"
            oninput="if(value.indexOf('.')>0){value=value.slice(0,value.indexOf('.')+3)} if(value.length>7){value=value.slice(0,7)}"
            min="0"
          />
        </el-form-item>
        <el-form-item label="排序" prop="sort">
          <el-input
            v-model="form.sort"
            placeholder="不可输入小数点"
            type="number"
            min="0"
            oninput="if(value.indexOf('.')>0){value=value.slice(0,value.indexOf('.')+0)} if(value.length>10){value=value.slice(0,10)}"
          />
        </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="title"
      :visible.sync="open"
      width="1200px"
      append-to-body
      :before-close="cancel"
      ><el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="120px"
        :inline="true"
      >
        <div
          v-for="(item, index) in form.nurseStationConsumables"
          :key="index"
          style="margin-top: 20px; border-bottom: 1px solid #f3f3f3"
        >
          <el-form-item
            label="所属护理站"
            :rules="rules.nurseStationConsumables.nurseStationId"
            :prop="`nurseStationConsumables.${index}.nurseStationId`"
          >
            <el-button
              style="
                width: 208px;
                text-align: left;
                height: 36px;
                color: #c0c4cc;
                overflow: hidden;
              "
              @click="choicenurseStation(item, index)"
              v-if="item.nurseStationName == '请选择所属护理站'"
            >
              {{ item.nurseStationName }}
            </el-button>
            <el-button
              style="
                width: 208px;
                text-align: left;
                height: 36px;
                overflow: hidden;
              "
              @click="choicenurseStation(item, index)"
              v-else
            >
              {{ item.nurseStationName }}
            </el-button>
          </el-form-item>
          <el-form-item
            label="耗材包详情"
            :rules="rules.nurseStationConsumables.consumableDetail"
            :prop="`nurseStationConsumables.${index}.consumableDetail`"
          >
            <el-input
              v-model="item.consumableDetail"
              placeholder="请输入服务项目耗材包详情"
              maxlength="50"
            />
          </el-form-item>
          <el-form-item
            label="耗材包单位"
            :rules="rules.nurseStationConsumables.consumableUnit"
            :prop="`nurseStationConsumables.${index}.consumableUnit`"
          >
            <el-input
              v-model="item.consumableUnit"
              placeholder="请输入耗材包单位"
              maxlength="10"
            />
          </el-form-item>
          <el-form-item
            label="耗材包价格(元)"
            :rules="rules.nurseStationConsumables.consumablePrice"
            :prop="`nurseStationConsumables.${index}.consumablePrice`"
          >
            <el-input
              v-model="item.consumablePrice"
              placeholder="保留小数点后两位"
              type="number"
              min="0"
              oninput="if(value.indexOf('.')>0){value=value.slice(0,value.indexOf('.')+3)} if(value.length>7){value=value.slice(0,7)}"
            />
          </el-form-item>
          <el-form-item
            label="排序"
            :rules="rules.nurseStationConsumables.sort"
            :prop="`nurseStationConsumables.${index}.sort`"
          >
            <el-input
              v-model="item.sort"
              placeholder="不可输入小数点"
              type="number"
              min="0"
              oninput="if(value.indexOf('.')>0){value=value.slice(0,value.indexOf('.')+0)} if(value.length>10){value=value.slice(0,10)}"
            />
          </el-form-item>
          <el-button
            type="primary"
            circle
            plain
            icon="el-icon-circle-plus-outline"
            style="margin-left: 400px"
            v-if="index == 0"
            @click="addnurseStationConsumables"
          ></el-button>
          <el-button
            type="danger"
            icon="el-icon-delete"
            circle
            plain
            @click="delnurseStationConsumables(index)"
            style="margin-left: 400px"
            v-if="index != 0"
          ></el-button>
        </div>
      </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>
    <!-- xg//选择所属护理站 -->
    <el-dialog
      width="1150px"
      title="选择所属护理站"
      :visible.sync="open3"
      append-to-body
      :before-close="cancel2"
    >
      <el-form
        :model="getListByUserquery"
        ref="queryForm"
        size="small"
        :inline="true"
        label-width="90px"
      >
        <el-form-item label="护理站名称">
          <el-input
            style="width: 180px"
            v-model="getListByUserquery.nurseStationName"
            placeholder="请输入项目名称"
            clearable
            @keyup.enter.native="handleQuery2"
          />
        </el-form-item>
        <el-form-item label="护理站编号">
          <el-input
            style="width: 180px"
            v-model="getListByUserquery.nurseStationCode"
            placeholder="请输入护理站编号"
            clearable
            @keyup.enter.native="handleQuery2"
          />
        </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="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        v-loading="loading"
        :data="nurseStationlist"
        @cell-dblclick="clicknurseStation2"
      >
        <el-table-column width="60" align="center" label="请选择">
          <template slot-scope="scope">
            <el-button
              type="primary"
              style="width: 15px; height: 15px"
              circle
              @click="clicknurseStation2(scope.row)"
              v-if="form.nurseStationId == scope.row.id"
            ></el-button>
            <el-button
              style="width: 15px; height: 15px"
              @click="clicknurseStation2(scope.row)"
              circle
              v-else
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column
          label="护理站名称"
          align="center"
          prop="nurseStationName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="护理站编号"
          align="center"
          prop="nurseStationCode"
        />
        <el-table-column label="护理站经度" align="center" prop="longitude" />
        <el-table-column label="护理站纬度" align="center" prop="latitude" />
        <el-table-column label="联系电话" align="center" prop="phone" />
        <el-table-column
          label="护理站地址"
          align="center"
          prop="address"
          :show-overflow-tooltip="true"
        />
        <el-table-column label="负责人" align="center" prop="dutyPerson" />
        <el-table-column label="负责人电话" align="center" prop="dutyPhone" />
      </el-table>

      <pagination
        v-show="total3 > 0"
        :total="total3"
        :page.sync="getListByUserquery.pageNum"
        :limit.sync="getListByUserquery.pageSize"
        @pagination="info"
      />
    </el-dialog>
    <!-- add//选择所属护理站 -->
    <el-dialog
      width="1150px"
      title="选择所属护理站"
      :visible.sync="open2"
      append-to-body
      :before-close="cancel2"
    >
      <el-form
        :model="getListByUserquery"
        ref="queryForm"
        size="small"
        :inline="true"
        label-width="90px"
      >

        <el-form-item label="护理站编码" prop="nurseStationCode">
          <el-input
            style="width: 180px"
            v-model="getListByUserquery.nurseStationCode"
            placeholder="请输入护理站编码"
            clearable
            @keyup.enter.native="handleQuery2"
          />
        </el-form-item>
         <el-form-item label="护理站名称" prop="nurseStationName">
          <el-input
            style="width: 180px"
            v-model="getListByUserquery.nurseStationName"
            placeholder="请输入项目名称"
            clearable
            @keyup.enter.native="handleQuery2"
          />
        </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="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        v-loading="loading"
        :data="nurseStationlist"
        @cell-dblclick="clicknurseStation"
      >
        <el-table-column width="60" align="center" label="请选择">
          <template slot-scope="scope">
            <el-button
              type="primary"
              style="width: 15px; height: 15px"
              circle
              @click="clicknurseStation(scope.row)"
              v-if="
                form.nurseStationConsumables[index].nurseStationId ==
                scope.row.id
              "
            ></el-button>

            <el-button
              style="width: 15px; height: 15px"
              @click="clicknurseStation(scope.row)"
              circle
              v-else
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column
          label="护理站编码"
          align="center"
          prop="nurseStationCode"
        />
        <el-table-column
          label="护理站名称"
          align="center"
          prop="nurseStationName"
          :show-overflow-tooltip="true"
        />


        <el-table-column label="联系电话" align="center" prop="phone" />
        <el-table-column
          label="护理站地址"
          align="center"
          prop="address"
          :show-overflow-tooltip="true"
        />

      </el-table>

      <pagination
        v-show="total3 > 0"
        :total="total3"
        :page.sync="getListByUserquery.pageNum"
        :limit.sync="getListByUserquery.pageSize"
        @pagination="info"
      />
    </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,
  getStationConsumable,
  delStationConsumable,
  addStationConsumable,
  updateStationConsumable,
  list,
} from "@/api/system/stationConsumable";
import { getListByUser } from "@/api/system/userlist.js";
import { getToken } from "@/utils/auth";
export default {
  name: "StationConsumable",
  data() {
    return {
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url:
          process.env.VUE_APP_BASE_API + "/system/stationConsumable/importData",
      },
      value: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total2: 0,
      total3: 0,
      // 护理站耗材信息表格数据
      stationConsumableList: [],
      nurseStationlist: [],
      nurseStationlist2: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open2: false,
      open3: false,
      xgopen: false,
      index: "",
      //权限查询
      getListByUserquery: {
        pageNum: 1,
        pageSize: 10,
      },
      // 查询参数
      nurseStationqueryParams: {
        pageNum: 1,
        pageSize: 10,
        areaCode: null,
        userId: null,
        nurseStationCode: null,
        nurseStationName: null,
        nurseStationType: null,
        agencyIntroduce: null,
        nurseStationDescription: null,
        longitude: null,
        latitude: null,
        phone: null,
        address: null,
        dutyPerson: null,
        dutyPhone: null,
        stationPictureUrl: null,
        sort: null,
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nurseStationId: "",
        userId: null,
        consumableCode: null,
        consumableDetail: null,
        consumableUnit: null,
        consumablePrice: null,
        sort: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        nurseStationId: [
          {
            required: true,
            message: "请选择所属护理站",
            trigger: "blur",
          },
        ],
        consumableDetail: [
          {
            required: true,
            message: "请输入耗材包详情",
            trigger: "blur",
          },
        ],
        consumableUnit: [
          {
            required: true,
            message: "请输入耗材包单位",
            trigger: "blur",
          },
        ],
        consumablePrice: [
          {
            required: true,
            message: "请输入耗材包价格",
            trigger: "blur",
          },
        ],
        sort: [
          {
            required: true,
            message: "请输入排序",
            trigger: "blur",
          },
        ],
        nurseStationConsumables: {
          consumableDetail: [
            {
              required: true,
              message: "请输入耗材包详情",
              trigger: "blur",
            },
          ],
          nurseStationId: [
            {
              required: true,
              message: "请选择所属护理站",
              trigger: "blur",
            },
          ],
          consumableUnit: [
            {
              required: true,
              message: "请输入耗材包单位",
              trigger: "blur",
            },
          ],
          consumablePrice: [
            {
              required: true,
              message: "请输入耗材包价格",
              trigger: "blur",
            },
          ],
          sort: [
            {
              required: true,
              message: "请输入排序",
              trigger: "blur",
            },
          ],
        },
      },
    };
  },
  created() {
    this.getList();
    this.info();
    // this.listinfo();
  },
  methods: {
    /** 下载模板操作 */
    importTemplate() {
      this.download(
        "/system/stationItem/downloadTemplate?fileType=2",
        {},
        `护理站耗材信息导入模板.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;
    },
    delnurseStationConsumables(index) {
      this.form.nurseStationConsumables.splice(index, 1);
      console.log(this.form.nurseStationConsumables);
    },
    addnurseStationConsumables() {
      var obj = {
        nurseStationId: "",
        consumableUnit: null,
        sort: "",
        consumablePrice: "",
        consumableDetail: null,
        nurseStationName: "请选择所属护理站",
      };
      if (this.form.nurseStationConsumables.length == 5) {
        this.$message.error("最多只能5条");
      } else {
        this.form.nurseStationConsumables.push(obj);
      }
    },
    choicenurseStation(item, index) {
      console.log(item);
      this.index = index;
      this.open2 = true;
    },

    //点击护理站左侧按钮
    clicknurseStation2(item) {
      this.form.nurseStationId = item.id;
      this.form.nurseStationName = item.nurseStationName;
      this.open3 = false;
      this.reset2();
    },
    clicknurseStation(item) {
      console.log(item);
      console.log(this.index);
      console.log(this.form);
      this.form.nurseStationConsumables[this.index].nurseStationId = item.id;
      this.form.nurseStationConsumables[this.index].nurseStationName =
        item.nurseStationName;
      this.open2 = false;
      this.reset2();
    },
    /** 查询护理站耗材信息列表 */
    getList() {
      this.loading = true;
      this.listStationConsumableinfo();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.xgopen = false;
      this.nurseStationName = "请选择所属护理站";
      this.reset();
    },
    cancel2() {
      this.open2 = false;
      this.open3 = false;
      this.reset2();
    },
    // 表单重置
    reset2() {
      this.getListByUserquery = {
        pageNum: 1,
        pageSize: 10,
        areaCode: null,
        userId: null,
        nurseStationCode: null,
        nurseStationName: null,
        nurseStationType: null,
        agencyIntroduce: null,
        nurseStationDescription: null,
        longitude: null,
        latitude: null,
        phone: null,
        address: null,
        dutyPerson: null,
        dutyPhone: null,
        stationPictureUrl: null,
        sort: null,
      };
    },
    reset() {
      this.form = {
        id: null,
        consumablePrice: null,
        sort: null,
        nurseStationId: "",
        nurseStationConsumables: [
          {
            nurseStationId: "",
            consumableUnit: null,
            sort: "",
            consumablePrice: "",
            consumableDetail: null,
            nurseStationName: "请选择所属护理站",
          },
        ],
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    listStationConsumableinfo() {
      listStationConsumable(this.queryParams).then((response) => {
        this.stationConsumableList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleQuery() {
      this.loading = true;
      this.queryParams.pageNum = 1;
      this.listStationConsumableinfo();
    },
    //护理站分页
    // listinfo() {
    //   list(this.nurseStationqueryParams).then((res) => {
    //     this.nurseStationlist2 = res.rows;
    //     console.log(this.nurseStationlist2);
    //     this.total2 = res.total;
    //   });
    // },
    //护理站搜索
    handleQuery2() {
      this.getListByUserquery.pageNum = 1;
      getListByUser(this.getListByUserquery).then((res) => {
        this.nurseStationlist = res.rows;
        this.total3 = res.total;
      });
    },
    /** 重置按钮操作 */
    sresetQuery() {
      if (this.nurseStationlist[0].isAdmin == "1") {
        this.resetForm("queryForm");
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          nurseStationId: "",
          userId: null,
          consumableCode: null,
          consumableDetail: null,
          consumableUnit: null,
          consumablePrice: null,
          sort: null,
        };
        this.handleQuery();
      } else {
        this.queryParams.pageNum = 1;
        this.queryParams.consumableCode = null;
        this.queryParams.consumableDetail = null;
        this.queryParams.consumableUnit = null;
        this.queryParams.consumablePrice = null;
        this.handleQuery();
      }
    },
    //护理站重置
    resetQuery() {
      this.reset2();
      this.handleQuery2();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加护理站耗材信息";
      this.cancel2();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids;
      getStationConsumable(id).then((response) => {
        this.form = response.data;
        this.xgopen = true;
        this.title = "修改护理站耗材信息";
        this.loading = false;
      });
    },
    /** 提交按钮 */
    submitForm() {
      console.log(this.form);
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateStationConsumable(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.xgopen = false;
              this.getList();
            });
          } else {
            addStationConsumable(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.nurseStationName = "请选择所属护理站";
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          return delStationConsumable(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/stationConsumable/export",
        {
          ...this.queryParams,
        },
        `stationConsumable_${new Date().getTime()}.xlsx`
      );
    },
    /** 导入按钮操作 */
    handleport() {
      this.upload.title = "护理站耗材导入";
      this.upload.open = true;
    },
    //权限列表
    info() {
      getListByUser(this.getListByUserquery).then((res) => {
        console.log(res);
        if (res.rows[0].isAdmin == "1") {
          console.log(true);
          this.nurseStationlist = res.rows;
          this.total3 = res.total;
        } else {
          this.total3 = res.total;
          this.nurseStationlist = res.rows;
          this.queryParams.nurseStationId = res.rows[0].id;
          this.handleQuery();
        }
      });
    },

    loadMore() {
      console.log(1);
      var a = Math.ceil(this.total3 / 10);
      if (this.nurseStationlist.length + 1 >= this.total3) {
      } else {
        if (this.getListByUserquery.pageNum >= a) {
        } else {
          this.getListByUserquery.pageNum++;
          getListByUser(this.getListByUserquery).then((res) => {
            console.log(res);
            res.rows.forEach((e) => {
              this.nurseStationlist.push(e);
            });
          });
        }
      }
    },
  },
};
</script>
