<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-button type="" class="stationbtn" @click="ParamsStation(true)">{{
          queryParams.nurseStationName
        }}</el-button>
      </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"
          v-hasPermi="['system:stationConsumable:importStationConsumable']"
          >导入</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="请输入排序"
            oninput="value=value.replace(/[^\d]/g,'')"
            maxLength="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
              placeholder="请输入排序"
              v-model="item.sort"
              maxlength="10"
              oninput="value=value.replace(/[^\d]/g,'')"
            />
          </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.nurseStationCode"
            placeholder="请输入护理站编码"
            clearable
            @keyup.enter.native="handleQuery2"
          />
        </el-form-item>
        <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>
          <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="stationid == 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="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>
    <!-- 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 indexjs from "./indexjs.js";
export default indexjs;
</script>
<style lang="scss" scoped>
.stationbtn {
  width: 208px;
  text-align: left;
  height: 32px;
  overflow: hidden;
  font-size: 14px;
}
</style>
