<template>
  <!--批量新增-->
  <div class="main-contain">
    <div class="app-container">
      <div class="bannar_list">
        <div class="banner_left">
          <div>
            透析模式:
            <el-select
              v-model="modeOptions_value"
              placeholder="请选择"
              @change="changemode"
            >
              <el-option
                v-for="item in modeOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </div>
          <div>
            新增类型:
            <el-select
              v-model="new_type"
              placeholder="请选择"
              @change="changetype"
            >
              <el-option
                v-for="item in options"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </div>
          <div>
            是否选择所有患者:
            <el-select
              v-model="patient_value"
              placeholder="请选择"
              @change="changelist"
            >
              <el-option
                v-for="item in options_patient"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </div>
        </div>

        <button @click="lili">调试</button>
        <el-button @click="save">保存</el-button>
      </div>

      <el-container>
        <div style="width: 211px">
          <el-table
            border
            height="550"
            ref="multipleTable"
            :data="tableData"
            tooltip-effect="dark"
            style="width: 100%"
            @selection-change="handleSelectionChange"
            :row-style="{ color: '#303133' }"
            :header-cell-style="{
              backgroundColor: 'rgb(245, 247, 250)',
              color: '#606266',
            }"
          >
            <el-table-column type="selection" width="55"> </el-table-column>
            <el-table-column label="患者姓名" width="155">
              <template slot-scope="scope">{{ scope.row.name }}</template>
            </el-table-column>
          </el-table>
        </div>

        <el-main>
          <el-tabs
            v-model="editableTabsValue"
            type="border-card"
            editable
            @tab-click="dian"
            @edit="handleTabsEdit"
          >
            <el-tab-pane
              v-for="(item, index) in editableTabs"
              :key="index"
              :label="item.title"
              :name="item.name"
            >
              <el-select
                v-model="item.patient_value"
                placeholder="请选择"
                @change="changelist"
                style="width: 50%"
              >
                <el-option
                  v-for="item in options_2"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>

              <el-table
                v-if="new_type == 1"
                :data="item.tableDatas"
                style="width: 100%"
                max-height="250"
                border
                :row-style="{ color: '#303133' }"
                :header-cell-style="{
                  backgroundColor: 'rgb(245, 247, 250)',
                  color: '#606266',
                }"
              >
                <el-table-column fixed label="新增药品名称" width="230">
                  <template slot-scope="scope">
                    <el-select
                      filterable
                      v-model="scope.row.drug_name"
                      placeholder="请选择"
                      @focus="clicktmp(item.patient_value, scope.row)"
                      @change="changeid(scope.row, scope.$index)"
                    >
                      <el-option
                        v-for="item in tmplist"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                      >
                      </el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column label="单次用量" width="200">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.single_dose"
                      placeholder="请输入"
                      style="width: 75px"
                    ></el-input>
                    <el-select
                      v-model="scope.row.single_dose_unit"
                      placeholder="请选择"
                      style="width: 90px"
                    >
                      <el-option
                        v-for="item in unit"
                        :key="item.name"
                        :label="item.name"
                        :value="item.name"
                      >
                      </el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column label="用法" width="125">
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.delivery_way"
                      placeholder="请选择"
                    >
                      <el-option
                        v-for="item in usage"
                        :key="item.name"
                        :label="item.name"
                        :value="item.name"
                      >
                      </el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column label="频率" width="120">
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.execution_frequency"
                      placeholder="请选择"
                    >
                      <el-option
                        v-for="item in frequency"
                        :key="item.name"
                        :label="item.name"
                        :value="item.name"
                      >
                      </el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column label="天数" width="115">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.day"
                      placeholder="请输入"
                      style="width: 75px"
                    ></el-input
                    >天
                  </template>
                </el-table-column>
                <el-table-column label="总量" width="200">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.prescribing_number"
                      placeholder="请输入"
                      style="width: 75px"
                    ></el-input>
                    <el-select
                      v-model="scope.row.prescribing_number_unit"
                      placeholder="请选择"
                      style="width: 90px"
                    >
                      <el-option
                        v-for="item in unit"
                        :key="item.name"
                        :label="item.name"
                        :value="item.name"
                      >
                      </el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column label="单价" width="120">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.price"
                      style="width: 80px"
                    ></el-input
                    >元
                  </template>
                </el-table-column>
                <el-table-column label="备注" width="120">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.remark"
                      placeholder=""
                    ></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="操作" width="120">
                  <template slot-scope="scope">
                    <el-button
                      @click.native.prevent="
                        addRow(scope.$index, item.tableDatas)
                      "
                      type="text"
                      size="small"
                      style="width: 30px; height: 30px"
                    >添加
<!--                      <i class="el-icon-circle-plus-outline"></i>-->
                    </el-button>
                    <el-button
                      style="width: 30px; height: 30px"
                      @click.native.prevent="
                        deleteRow(scope.$index, item.tableDatas)
                      "
                      type="text"
                      size="small"
                    >移除
<!--                      <i class="el-icon-remove-outline"></i>-->
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>

              <el-table
                v-if="new_type == 2"
                :data="item.project"
                style="width: 100%"
                max-height="250"
                border
                :row-style="{ color: '#303133' }"
                :header-cell-style="{
                  backgroundColor: 'rgb(245, 247, 250)',
                  color: '#606266',
                }"
              >
                <el-table-column fixed label="新增项目名称" width="230">
                  <template slot-scope="scope">
                    <el-select
                      filterable
                      v-model="scope.row.drug_name"
                      placeholder="请选择"
                      @focus="clicktmp(item.patient_value, scope.row)"
                      @change="changeid2(scope.row, scope.$index)"
                    >
                      <el-option
                        v-for="item in tmplist"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                      >
                      </el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column label="组" width="120">
                  <template slot-scope="scope">
                    {{ scope.row.translate }}
                  </template>
                </el-table-column>
                <el-table-column label="单次用量" width="200">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.single_dose"
                      placeholder="请输入内容"
                    ></el-input>
                    {{ scope.row.unit }}
                  </template>
                </el-table-column>
                <el-table-column label="用法" width="120">
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.delivery_way"
                      placeholder="请选择"
                    >
                      <el-option
                        v-for="item in usage"
                        :key="item.name"
                        :label="item.name"
                        :value="item.name"
                      >
                      </el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column label="频率" width="120">
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.execution_frequency"
                      placeholder="请选择"
                    >
                      <el-option
                        v-for="item in frequency"
                        :key="item.name"
                        :label="item.name"
                        :value="item.name"
                      >
                      </el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column label="天数" width="110">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.day"
                      placeholder="请输入"
                      style="width: 75px"
                    ></el-input
                    >天
                  </template>
                </el-table-column>
                <el-table-column label="总量" width="200">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.prescribing_number"
                      placeholder="请输入"
                      style="width: 75px"
                    ></el-input>
                    {{ scope.row.unit }}
                  </template>
                </el-table-column>
                <el-table-column label="单价" width="120">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.price"
                      style="width: 80px"
                    ></el-input
                    >元
                  </template>
                </el-table-column>
                <el-table-column label="备注" width="120">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.remark"
                      placeholder=""
                    ></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="推送频率" width="120" v-if="1==2">
                  <template slot-scope="scope">
                    <div v-if="scope.row.frequency_type == 1">
                      {{ "每次必推" }}
                    </div>
                    <div v-if="scope.row.frequency_type == 2">
                      {{ scope.row.day_count }}天/次
                    </div>
                    <div v-if="scope.row.frequency_type == 3">
                      {{ scope.row.week_days }}
                    </div>
                  </template>
                </el-table-column>
                <el-table-column fixed="right" label="操作" width="102">
                  <template slot-scope="scope">
<!--                    <el-button-->
<!--                      @click.native.prevent="addopen(scope.$index)"-->
<!--                      type="text"-->
<!--                      size="small">-->
<!--                      推送-->
<!--                    </el-button>-->
                    <el-button
                      @click.native.prevent="
                        addRow2(scope.$index, item.project)
                      "
                      type="text"
                      size="small"
                    >
                      添加
                    </el-button>
                    <el-button
                      @click.native.prevent="
                        deleteRow(scope.$index, item.project)
                      "
                      type="text"
                      size="small"
                    >
                      移除
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>

              <!--              <el-table-->
              <!--                v-if="new_type == 2"-->
              <!--                :data="item.project"-->
              <!--                style="width: 100%"-->
              <!--                max-height="250"-->
              <!--              >-->
              <!--                <el-table-column fixed label="新增项目名称" width="250">-->
              <!--                  <template slot-scope="scope2">-->
              <!--                    <el-select-->
              <!--                      v-model="scope2.row.drug_name"-->
              <!--                      placeholder="请选择"-->
              <!--                      @focus="clicktmp(item.patient_value,scope2.row,item)"-->
              <!--                      @change="changeid2(scope2.row,scope2.$index)"-->
              <!--                    >-->
              <!--                      <el-option-->
              <!--                        v-for="item in tmplist"-->
              <!--                        :key="item.id"-->
              <!--                        :label="item.name"-->
              <!--                        :value="item.id"-->
              <!--                      >-->
              <!--                      </el-option>-->
              <!--                    </el-select>-->
              <!--                  </template>-->
              <!--                </el-table-column>-->
              <!--                <el-table-column label="组" width="120">-->
              <!--                  <template slot-scope="scope2" width="100">-->
              <!--                    {{scope2.row.translate}}-->
              <!--                  </template>-->
              <!--                </el-table-column>-->
              <!--                <el-table-column label="单次用量" width="120">-->
              <!--                  <template slot-scope="scope2">-->
              <!--                    <el-input-->
              <!--                      v-model="scope2.row.single_dose"-->
              <!--                      placeholder="请输入内容"-->
              <!--                    ></el-input>-->
              <!--                    {{ scope2.row.unit }}-->
              <!--                  </template>-->
              <!--                </el-table-column>-->
              <!--                <el-table-column label="用法" width="120">-->
              <!--                  <template slot-scope="scope2">-->
              <!--                    <el-select-->
              <!--                      v-model="scope2.row.delivery_way"-->
              <!--                      placeholder="请选择"-->
              <!--                    >-->
              <!--                      <el-option-->
              <!--                        v-for="item in usage"-->
              <!--                        :key="item.id"-->
              <!--                        :label="item.name"-->
              <!--                        :value="item.id"-->
              <!--                      >-->
              <!--                      </el-option>-->
              <!--                    </el-select>-->
              <!--                  </template>-->
              <!--                </el-table-column>-->
              <!--                <el-table-column label="频率" width="120">-->
              <!--                  <template slot-scope="scope2">-->
              <!--                    <el-select-->
              <!--                      v-model="scope2.row.execution_frequency"-->
              <!--                      placeholder="请选择"-->
              <!--                    >-->
              <!--                      <el-option-->
              <!--                        v-for="item in frequency"-->
              <!--                        :key="item.id"-->
              <!--                        :label="item.name"-->
              <!--                        :value="item.id"-->
              <!--                      >-->
              <!--                      </el-option>-->
              <!--                    </el-select>-->
              <!--                  </template>-->
              <!--                </el-table-column>-->
              <!--                <el-table-column label="天数" width="120">-->
              <!--                  <template slot-scope="scope2">-->
              <!--                    <el-input-->
              <!--                      v-model="scope2.row.day"-->
              <!--                      placeholder="请输入内容"-->
              <!--                    ></el-input-->
              <!--                    >天-->
              <!--                  </template>-->
              <!--                </el-table-column>-->
              <!--                <el-table-column label="总量" width="120">-->
              <!--                  <template slot-scope="scope2">-->
              <!--                    <el-input-->
              <!--                      v-model="scope2.row.prescribing_number"-->
              <!--                      placeholder="请输入内容"-->
              <!--                    ></el-input>-->
              <!--                    {{ scope.row.unit }}-->
              <!--                  </template>-->
              <!--                </el-table-column>-->
              <!--                <el-table-column label="单价" width="120">-->
              <!--                  <template slot-scope="scope2">&lt;!&ndash;:disabled="true"&ndash;&gt;-->
              <!--                    <el-input-->
              <!--                      v-model="scope2.row.price"-->
              <!--                    ></el-input-->
              <!--                    >元-->
              <!--                  </template>-->
              <!--                </el-table-column>-->
              <!--                <el-table-column label="备注" width="120">-->
              <!--                  <template slot-scope="scope2">-->
              <!--                    <el-input-->
              <!--                      v-model="scope2.row.remark"-->
              <!--                      placeholder=""-->
              <!--                    ></el-input>-->
              <!--                  </template>-->
              <!--                </el-table-column>-->
              <!--                <el-table-column fixed="right" label="操作" width="120">-->
              <!--                  <template slot-scope="scope2">-->
              <!--                    <el-button-->
              <!--                      @click.native.prevent="addopen(scope2.$index)"-->
              <!--                      type="text"-->
              <!--                      size="small">-->
              <!--                      推送-->
              <!--                    </el-button>-->
              <!--                    <el-button-->
              <!--                      @click.native.prevent="-->
              <!--                        addRow2(scope2.$index, item.project)-->
              <!--                      "-->
              <!--                      type="text"-->
              <!--                      size="small"-->
              <!--                    >-->
              <!--                      添加-->
              <!--                    </el-button>-->
              <!--                    <el-button-->
              <!--                      @click.native.prevent="-->
              <!--                        deleteRow(scope2.$index, item.project)-->
              <!--                      "-->
              <!--                      type="text"-->
              <!--                      size="small"-->
              <!--                    >-->
              <!--                      移除-->
              <!--                    </el-button>-->
              <!--                  </template>-->
              <!--                </el-table-column>-->
              <!--              </el-table>-->
            </el-tab-pane>
            <el-tab-pane name="more" closable v-if="dayorMonth == 'day'"><span slot="label"><i
                                class="el-icon-plus"
                                @click="addTab"></i></span>
                        </el-tab-pane>
          </el-tabs>
        </el-main>
      </el-container>
    </div>
    <el-dialog
      title="推送频率设置"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <span>周期提醒</span>
      <el-radio-group v-model="frequency_type">
        <el-radio :label="1">每次必推</el-radio>
        <el-radio :label="2">天数频率</el-radio>
        <el-radio :label="3">星期频率</el-radio>
      </el-radio-group>
      <div v-if="frequency_type == 2">
        <el-input style="width: 50px" v-model="day_count"></el-input>&nbsp;
        天/一次
      </div>
      <div v-if="frequency_type == 3">
        <el-checkbox-group v-model="week_days">
          <el-checkbox label="周一" name="周一" key="1">周一</el-checkbox>
          <el-checkbox label="周二" name="周二" key="2">周二</el-checkbox>
          <el-checkbox label="周三" name="周三" key="3">周三</el-checkbox>
          <el-checkbox label="周四" name="周四" key="4">周四</el-checkbox>
          <el-checkbox label="周五" name="周五" key="5">周五</el-checkbox>
          <el-checkbox label="周六" name="周六" key="6">周六</el-checkbox>
          <el-checkbox label="周日" name="周日" key="7">周日</el-checkbox>
        </el-checkbox-group>
      </div>

      <span slot="footer" class="dialog-footer">
        <!--        <button @click="lili">调试</button>-->
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="baocun">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { gethisusertoalive } from "@/api/deposit";
import {
  getdialysismodename,
  getdrugsname,
  getmodeconfigs,
  getdrugsinformation,
  prescriptiontemplate,
} from "@/api/batch/batch";

export default {
  data() {
    return {
      dialogVisible: false,
      patientList: [{ id: 1, name: "张三" }],
      tableList: [],
      editableTabsValue: "1",
      modeOptions: {},
      editableTabs: [
        {
          title: "处方1",
          name: "1",
          patient_value: 1,
          tableDatas: [
            {
              id: "",
              drug_name: "",
              single_dose: "",
              single_dose_unit: "",
              delivery_way: "",
              execution_frequency: "",
              day: "",
              prescribing_number: "",
              prescribing_number_unit: "",
              price: "",
              remark: "",
            },
          ],
          project: [
            {
              id: "",
              drug_name: "",
              translate: "",
              single_dose: "",
              unit: "",
              delivery_way: "",
              execution_frequency: "",
              day: "",
              prescribing_number: "",
              price: "",
              remark: "",
              frequency_type: 1,
              day_count: "",
              week_days: "",
            },
          ],
        },
      ],
      tabIndex: 2,
      modeOptions_value: 1, //透析模式
      multipleSelection: [], //选中的患者
      tableData: [],
      options: [
        { id: 1, name: "药品" },
        { id: 2, name: "项目" },
      ],
      options_patient: [
        { id: 1, name: "是" },
        { id: 2, name: "否" },
      ],
      options_2: [
        { id: 1, name: "普通门诊" },
        { id: 2, name: "门诊特殊病" },
      ],
      new_type: 1, //新增类型
      patient_value: 1, //是否选择所有患者
      druglist: [], //药品规格_门诊特殊
      druglist2: [], //药品规格_普通
      projectlist: [], //项目规格—特俗
      projectlist2: [], //项目规格——普通
      tmplist: [], //临时
      unit: [
        { id: 1, name: "g" },
        { id: 2, name: "mg" },
        { id: 3, name: "u" },
        { id: 4, name: "ml" },
        { id: 5, name: "万U" },
        { id: 6, name: "枚" },
        { id: 7, name: "粒" },
        { id: 8, name: "片" },
        { id: 9, name: "支" },
        { id: 10, name: "μg" },
        { id: 11, name: "iu" },
        { id: 12, name: "包" },
        { id: 13, name: "袋" },
        { id: 14, name: "万" },
        { id: 15, name: "万iu" },
        { id: 16, name: "丸" },
        { id: 17, name: "盒" },
        { id: 18, name: "瓶" },
        { id: 19, name: "瓶（袋）" },
        { id: 20, name: "次" },
      ],
      usage: [], //用法
      frequency: [], //频率
      frequency_type: "", //周期提醒
      day_count: "", //周期提醒天
      week_days: [], //周期提醒星期
      tabhang: 0, //tab的下标
      hang: 0, //行数
    };
  },
  created() {
    // console.log("this.$store.getters.treatment_mode",this.$store.getters.treatment_mode)
    for (let key in this.$store.getters.treatment_mode) {
      this.modeOptions[key] = this.$store.getters.treatment_mode[key];
    }
    // console.log("this.modeOptions",this.modeOptions)
    this.getusernames();
    this.getthisdrugname();
    this.getdrugconfigs();
  },
  methods: {
    save() {
      var tmp = this.modeOptions[this.modeOptions_value].name;
      var tmp2 = "";
      for (let i = 0; i < this.editableTabs.length; i++) {
        console.log("for");
        for (let j = 0; j < this.editableTabs[i].project.length; j++) {
          if (this.editableTabs[i].project[j].id != "") {
            if (this.projectlist != null) {
              for (let p1 = 0; p1 < this.projectlist.length; p1++) {
                if (
                  this.editableTabs[i].project[j].id == this.projectlist[p1].id
                ) {
                  tmp2 = tmp2 + this.projectlist[p1].name + ",";
                }
              }
            }
            if (this.projectlist2 != null) {
              for (let p2 = 0; p2 < this.projectlist2.length; p2++) {
                if (
                  this.editableTabs[i].project[j].id == this.projectlist2[p2].id
                ) {
                  tmp2 = tmp2 + this.projectlist2[p2].name + ",";
                }
              }
            }
          }
        }
        for (let x = 0; x < this.editableTabs[i].tableDatas.length; x++) {
          if (this.editableTabs[i].tableDatas[x].id != "") {
            if (this.druglist != null) {
              console.log(
                "for" + i + "",
                this.editableTabs[i].tableDatas[x].id
              );
              for (let d1 = 0; d1 < this.druglist.length; d1++) {
                console.log("循环" + d1 + "", this.druglist[d1].id);
                if (
                  this.editableTabs[i].tableDatas[x].id == this.druglist[d1].id
                ) {
                  tmp2 = tmp2 + this.druglist[d1].name + ",";
                }
              }
            }
            if (this.druglist2 != null) {
              console.log(
                "for" + i + "",
                this.editableTabs[i].tableDatas[x].id
              );
              for (let d2 = 0; d2 < this.druglist2.length; d2++) {
                console.log("循环" + d2 + "", this.druglist2[d2].id);
                if (
                  this.editableTabs[i].tableDatas[x].id == this.druglist2[d2].id
                ) {
                  tmp2 = tmp2 + this.druglist2[d2].name + ",";
                }
              }
            }
          }
        }
      }
      console.log("tmp2", tmp2);
      this.$confirm(
        "注：该操作将会把所选患者的" +
          tmp +
          "透析模式中的新增" +
          tmp2 +
          "，请确定是否保存?",
        "",
        {
          confirmButtonText: "确 定",
          cancelButtonText: "取 消",
          type: "warning",
        }
      ).then(() => {
        if (this.multipleSelection.length == 0) {
          this.$message.error("没有选中有效信息");
          return;
        }
        let st = "";
        for (let i = 0; i < this.multipleSelection.length; i++) {
          st = st + this.multipleSelection[i].id + ",";
        }
        let params = {
          mode_id: this.modeOptions_value,
          patient_id: st,
          type: this.new_type,
        };
        let data = {
          prescriptions: this.editableTabs,
        };
        prescriptiontemplate(params, data).then((res) => {
          if (res.data.state == 1) {
            this.$message.success("保存成功");
          } else {
            this.$message.error(res.data.msg);
          }
        });
      });
    },

    lili() {
      console.log("this.editableTabs", this.editableTabs);
      // console.log("this.druglist2",this.druglist2)
      // console.log("this.projectlist",this.projectlist)
      // console.log("this.projectlist2",this.projectlist2)
      // console.log("patient_value",this.patient_value)
    },
    addopen(hang) {
      this.hang = hang;
      //清空
      this.week_days = [];
      this.day_count = "";
      this.frequency_type = 1;
      this.dialogVisible = true;
    },
    changetype() {
      console.log(">>>>>>>", this.new_type);
      this.editableTabs = [
        {
          title: "处方1",
          name: "1",
          patient_value: 1,
          tableDatas: [
            {
              id: "",
              drug_name: "",
              single_dose: "",
              single_dose_unit: "",
              delivery_way: "",
              execution_frequency: "",
              day: "",
              prescribing_number: "",
              prescribing_number_unit: "",
              price: "",
              remark: "",
            },
          ],
          project: [
            {
              id: "",
              drug_name: "",
              translate: "",
              single_dose: "",
              unit: "",
              delivery_way: "",
              execution_frequency: "",
              day: "",
              prescribing_number: "",
              price: "",
              remark: "",
              frequency_type: 1,
              day_count: "",
              week_days: "",
            },
          ],
        },
      ];
    },
    baocun() {
      let tmp = "";
      for (let i = 0; i < this.week_days.length; i++) {
        tmp = tmp + "," + this.week_days[i];
      }
      console.log("tmp", tmp);
      this.editableTabs[this.tabhang].project[this.hang].frequency_type =
        this.frequency_type;
      this.editableTabs[this.tabhang].project[this.hang].day_count =
        this.day_count;
      this.editableTabs[this.tabhang].project[this.hang].week_days = tmp;
      this.dialogVisible = false;
    },
    dian(tab, event) {
      console.log("tabtabtabtab", tab.index);
      this.tabhang = tab.index;
    },
    changeid(item, index) {
      console.log("this.tabhang1", this.tabhang);
      console.log("this.hang", this.hang);
      this.hang = index;
      item.id = item.drug_name;
      var params = {
        id: item.id,
      };
      getdrugsinformation(params).then((res) => {
        if (res.data.state == 1) {
          console.log("res??", res);
          this.editableTabs[this.tabhang].tableDatas[this.hang].single_dose =
            res.data.data.list[0].single_dose;
          this.editableTabs[this.tabhang].tableDatas[
            this.hang
          ].single_dose_unit = res.data.data.list[0].single_dose_unit;
          this.editableTabs[this.tabhang].tableDatas[this.hang].delivery_way =
            res.data.data.list[0].delivery_way;
          this.editableTabs[this.tabhang].tableDatas[
            this.hang
          ].execution_frequency = res.data.data.list[0].execution_frequency;
          this.editableTabs[this.tabhang].tableDatas[this.hang].day =
            res.data.data.list[0].drug_day;
          this.editableTabs[this.tabhang].tableDatas[
            this.hang
          ].prescribing_number = res.data.data.list[0].prescribing_number;
          this.editableTabs[this.tabhang].tableDatas[
            this.hang
          ].prescribing_number_unit =
            res.data.data.list[0].prescribing_number_unit;
          this.editableTabs[this.tabhang].tableDatas[this.hang].price =
            res.data.data.list[0].retail_price;
          this.editableTabs[this.tabhang].tableDatas[this.hang].remark =
            res.data.data.list[0].remark;
        }
      });
    },
    changeid2(item, index) {
      console.log("this.tabhang2", this.tabhang);
      console.log("this.hang???", this.hang);
      this.hang = index;
      item.id = item.drug_name;
      var params = {
        id: item.id,
      };
      getdrugsinformation(params).then((res) => {
        if (res.data.state == 1) {
          console.log("res??", res);
          this.editableTabs[this.tabhang].project[this.hang].single_dose =
            res.data.data.list[0].single_dose;
          this.editableTabs[this.tabhang].project[this.hang].translate =
            res.data.data.list[0].translate;
          this.editableTabs[this.tabhang].project[this.hang].delivery_way =
            res.data.data.list[0].delivery_way;
          this.editableTabs[this.tabhang].project[
            this.hang
          ].execution_frequency = res.data.data.list[0].execution_frequency;
          this.editableTabs[this.tabhang].project[this.hang].day =
            res.data.data.list[0].day;
          this.editableTabs[this.tabhang].project[
            this.hang
          ].prescribing_number = res.data.data.list[0].prescribing_number;
          this.editableTabs[this.tabhang].project[this.hang].unit =
            res.data.data.list[0].unit;
          this.editableTabs[this.tabhang].project[this.hang].price =
            res.data.data.list[0].retail_price;
          this.editableTabs[this.tabhang].project[this.hang].remark =
            res.data.data.list[0].remark;
        }
      });
    },
    clicktmp(tmp, ite, item) {
      console.log("？？？？？？？hatmp", tmp);
      console.log("？？？？？？hscope2.rowitem", ite);
      console.log("？？？？？？item", item);
      if (this.new_type == 1) {
        if (tmp == 2) {
          this.tmplist = this.druglist;
        } else {
          this.tmplist = this.druglist2;
        }
      } else {
        if (tmp == 2) {
          this.tmplist = this.projectlist;
        } else {
          this.tmplist = this.projectlist2;
        }
      }
    },
    changelist() {
      console.log("patient_value", this.patient_value);
      if (this.patient_value == 1) {
        this.getusernames();
      }
      if (this.patient_value == 2) {
        this.qieusername();
      }
    },
    changemode() {
      if (this.patient_value == 2) {
        this.qieusername();
      }
    },
    deleteRow(index, rows) {
      console.log("index",index)
      console.log("rows",rows)
      if(rows.length == 1){
        this.$message.error("最后一条处方，不能删除")
        return
      }
      rows.splice(index, 1);
    },
    addRow(index, rows) {
      rows.splice(index + 1, 0, {
        id: "",
        drug_name: "",
        single_dose: "",
        single_dose_unit: "",
        delivery_way: "",
        execution_frequency: "",
        day: "",
        prescribing_number: "",
        prescribing_number_unit: "",
        price: "",
        remark: "",
      });
    },
    addRow2(index, rows) {
      rows.splice(index + 1, 0, {
        id: "",
        drug_name: "",
        single_dose: "",
        unit: "",
        delivery_way: "",
        execution_frequency: "",
        day: "",
        prescribing_number: "",
        price: "",
        remark: "",
        frequency_type: "",
        day_count: "",
        week_days: "",
      });
    },
    qieusername() {
      var params = {
        mode: this.modeOptions_value,
      };
      getdialysismodename(params).then((res) => {
        if (res.data.state == 1) {
          this.tableData = res.data.data.list;
        }
      });
    },
    getusernames() {
      var params = {};
      gethisusertoalive(params).then((res) => {
        console.log("this.res", res);
        if (res.data.state == 1) {
          this.tableData = res.data.data.list;
          console.log("this.tableData", this.tableData);
        }
      });
    },
    getthisdrugname() {
      var params = {
        addtype: 1,
      };
      getdrugsname(params).then((res) => {
        if (res.data.state == 1) {
          this.druglist = res.data.data.list;
          this.druglist2 = res.data.data.list2;
        }
      });
      var params2 = {
        addtype: 2,
      };
      getdrugsname(params2).then((res) => {
        if (res.data.state == 1) {
          this.projectlist = res.data.data.list;
          this.projectlist2 = res.data.data.list2;
        }
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleTabsEdit(targetName, action,tab) {
      this.tabhang = this.editableTabs.length
      console.log("this.tabhang3",this.tabhang)
      if (action === "add") {
        let newTabName = ++this.tabIndex + "";
        let tmp = this.editableTabs.length + 1;
        this.editableTabs.push({
          title: "处方" + tmp,
          name: newTabName,
          patient_value: 1,
          tableDatas: [
            {
              id: "",
              drug_name: "",
              single_dose: "",
              single_dose_unit: "",
              delivery_way: "",
              execution_frequency: "",
              day: "",
              prescribing_number: "",
              prescribing_number_unit: "",
              price: "",
              remark: "",
            },
          ],
          project: [
            {
              id: "",
              drug_name: "",
              single_dose: "",
              unit: "",
              delivery_way: "",
              execution_frequency: "",
              day: "",
              prescribing_number: "",
              price: "",
              remark: "",
              frequency_type: "",
              day_count: "",
              week_days: "",
            },
          ],
        });
        this.editableTabsValue = newTabName;
      }
      if (action === "remove") {
        if(this.editableTabs.length == 1){
          this.$message.error("最后一条处方，不能删除")
          return
        }
        let tabs = this.editableTabs;
        let activeName = this.editableTabsValue;
        if (activeName === targetName) {
          tabs.forEach((tab, index) => {
            if (tab.name === targetName) {
              let nextTab = tabs[index + 1] || tabs[index - 1];
              if (nextTab) {
                activeName = nextTab.name;
              }
            }
          });
        }

        this.editableTabsValue = activeName;
        this.editableTabs = tabs.filter((tab) => tab.name !== targetName);
      }
    },
    getdrugconfigs() {
      var params = {};
      getmodeconfigs(params).then((res) => {
        if (res.data.state == 1) {
          this.frequency = res.data.data.efs;
          this.usage = res.data.data.drugways;
        }
      });
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
  },
};
</script>



<style lang="scss" scoped>
.app-container {
  background: #f6f8f9;
  .el-container {
    -webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27),
      0 0 60px rgba(0, 0, 0, 0.06) inset;
  }
}
::v-deep .el-table__body-wrapper {
  height: 500px;
  overflow-y: scroll;
}
.bannar_list {
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  .banner_left {
    width: 1000px;
    display: flex;
    justify-content: space-around;
    div {
      white-space: nowrap;
      font-size: 14px;
      color: #606266;
    }
  }
}
.zone {
  //  margin-left: 30px;
  //  text-align: left;
  width: 70px;
  display: inline-block;
  color: #606266;
}
.disinfect {
  position: relative;
  .newButton {
    // position: absolute;
    // right: 2%;
    // top:4px;
    // z-index: 9;
    margin-bottom: 10px;
    margin-left: 90%;
  }
}
.disinfectOne {
  position: relative;
  .newButtonOne {
    position: absolute;
    right: 0;
    top: -10;
    z-index: 18;
  }
}
.but {
  width: 200px;
  height: 50px;
  // border: solid 1px red;
  margin-left: 77%;
}
.clearn {
  width: 460px;
  height: 50px;
  // border:solid 1px red;
  margin-left: 650px;
}

.zClass {
  width: 200px;
  height: 200px;
  // border:solid 1px red;
  margin-left: 450px;
  margin-top: 200px;
}
.warn {
  color: red;
  font-size: 14px;
  width: 100%;
  display: inline-block;
  margin-left: 96px;
}

.userbutton {
  margin-bottom: 10px;
  margin-left: 82%;
}
</style>
<style lang="scss" >
.a {
  margin-bottom: 10px;
  margin-top: 6px;
}

.b {
  .el-button {
    margin-left: 90%;
    margin-bottom: 10px;
  }
}

.stoppage {
  .el-form-item__label {
    width: 190px;
  }
}
.st {
  .el-form-item__label {
    width: -10px;
  }
}
.main {
  position: relative;
  .newButtonOne {
    position: absolute;
    right: 0;
    z-index: 2;
  }
}

.elbutton {
  // border: solid 1px red;
  height: 50px;
  width: 400px;
  margin-left: 650px;
}
// .el-form-item__label {
//   width: 130px;
//   font-size: 14px;
// }
.el-form-item__error {
  margin-left: 130px;
}

.el-upload-list__item-name {
  color: #606266;
  display: block;
  margin-right: 40px;
  overflow: hidden;
  padding-left: 4px;
  text-overflow: ellipsis;
  transition: color 0.3s;
  white-space: nowrap;
}
.el-main {
  padding-top: 0px;
}
.newMain {
  .el-form-item__label {
    width: 104px;
  }
}
.newDisinfectOne {
  .el-input--prefix .el-input__inner {
    padding-left: 15px;
  }
}
.stoppage {
  .el-form-item__label {
    width: 18%;
  }
}
.newItem {
  .el-form-item__label {
    width: 130px;
  }
}
.formItem {
  .el-form-item__label {
    width: 104px;
    line-height: 30px;
  }
}
.newname {
  .el-form-item__label {
    width: 60px;
  }
}
::-webkit-scrollbar {
  height: 20px;
}

.el-button {
  color: #fff;
  background-color: #409eff;
  border-color: #409eff;
}
.el-table td .cell {
  padding: 0 10px;
}
</style>
