// 中成药
<template>
  <div>
    <div class="chinese_medicine">
      <div class="clearer flex-center" @click="clearData()">清空</div>
      <!-- 中成药 -->
      <!-- fixed="left" -->
      <div class="c-m-table">
        <el-table :data="tableData3" style="width:100%;" :span-method="arraySpanMethod">
          <el-table-column prop="id" label="序号" width="50" fixed="left">
            <template slot-scope="scope">
              <div v-if="!scope.row.name" class="flex-vertical-between">
                <div style="width:110px;" class="operate2" id="operate2">
                  <el-input
                    :value="scope.row.key"
                    :id="'searchD1'+scope.row.id"
                    size="mini"
                    placeholder="请输入..."
                    @input="searchDrug($event,scope)"
                    @blur="drugBlur($event,scope)"
                    @keydown.down.native="drugDown($event,scope)"
                    @keydown.up.native="drugUp($event,scope)"
                    @keydown.enter.native="drugEnter(scope)"
                  ></el-input>

                  <div class="table-choose3" v-if="scope.row.key">
                    <div class="table-choose-h flex-vertical-between">
                      <div class="flex-center">药品名称</div>
                      <div class="flex-center">规格</div>
                      <div class="flex-center">产地</div>
                      <div class="flex-center">库存</div>
                    </div>

                    <div
                      class="t-c-b infinite-list"
                      v-infinite-scroll="load"
                      :infinite-scroll-immediate="false"
                      :id="'infiniteList'+scope.row.id"
                      :ref="'infiniteList'+scope.row.id"
                      style="overflow:auto"
                    >
                      <div
                        class="infinite-list-item flex-vertical-between"
                        :style="scope.row.search_i===index1?'background:#F3FFFB;':''"
                        @click="chooseDis3(scope,index1,item1)"
                        v-for="(item1,index1) in scope.row.drugList"
                        :key="index1"
                      >
                        <p class="flex-center">{{item1.ypmc}}</p>
                        <p class="flex-center">{{item1.gg}}</p>
                        <p class>{{item1.cdmc}}</p>
                        <p class="flex-center">{{item1.kc}}</p>
                      </div>
                    </div>
                  </div>
                </div>

                <div class="operate1" v-if="scope.row.id!==tableData3.length && !scope.row.name">
                  <img src="../assets/delete1.png" alt @click="deleteDis1(scope)" />
                </div>
              </div>
              <!-- -->
              <div v-else>{{scope.row.id}}</div>
            </template>
          </el-table-column>
          <el-table-column prop="name" label="药品名称" width="80" fixed="left">
            <template slot-scope="scope">
              <div
                @click="clickName(scope)"
                v-if="!scope.row.showSearch"
                :style="{'color':scope.row.color?scope.row.color:''}"
              >{{scope.row.name}}</div>
              <div v-else class="flex-vertical-between">
                <div style="width:110px;">
                  <el-input
                    :value="scope.row.key"
                    :id="'searchD1'+scope.row.id"
                    size="mini"
                    :placeholder="scope.row.name"
                    @input="searchDrug($event,scope)"
                    @blur="drugBlur1($event,scope)"
                    @keydown.down.native="drugDown($event,scope)"
                    @keydown.up.native="drugUp($event,scope)"
                    @keydown.enter.native="drugEnter(scope)"
                    :disabled="recipe_tabs[recipe_tabs_c].disable"
                  ></el-input>
                  <!-- v-model="scope.row.key" -->
                  <div class="table-choose3" v-if="scope.row.key">
                    <div class="table-choose-h flex-vertical-between">
                      <div class="flex-center">药品名称</div>
                      <div class="flex-center">规格</div>
                      <div class="flex-center">产地</div>
                      <div class="flex-center">库存</div>
                    </div>
                    <!--  -->
                    <div
                      class="t-c-b infinite-list"
                      v-infinite-scroll="load"
                      :infinite-scroll-immediate="false"
                      :id="'infiniteList'+scope.row.id"
                      :ref="'infiniteList'+scope.row.id"
                      style="overflow:auto"
                    >
                      <div
                        class="infinite-list-item flex-vertical-between"
                        :style="scope.row.search_i===index1?'background:#F3FFFB;':''"
                        @click="chooseDis3(scope,index1,item1)"
                        v-for="(item1,index1) in scope.row.drugList"
                        :key="index1"
                      >
                        <p class="flex-center">{{item1.ypmc}}</p>
                        <p class="flex-center">{{item1.gg}}</p>
                        <p class>{{item1.cdmc}}</p>
                        <p class="flex-center">{{item1.kc}}</p>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="spec" label="规格" width="50"></el-table-column>
          <el-table-column prop="dose" label="剂量" width="50">
            <template slot-scope="scope" v-if="scope.row.name">
              <!-- <div class="t_dose">
                                <el-input :value="scope.row.dose" @input="countDoseMoney($event,scope)" size="mini">
                                </el-input>
              </div>-->
              <div class="t_dose">
                <el-input
                  :value="scope.row.dose"
                  size="mini"
                  @input="countDoseMoney($event,scope)"
                  :id="'dose1'+scope.row.id"
                  @keydown.enter.native="doseEnter(scope)"
                ></el-input>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="unit" label="单位" width="50"></el-table-column>
          <el-table-column prop="usage" label="用法" width="100">
            <template slot-scope="scope" v-if="scope.row.name">
              <el-select v-model="scope.row.usage" placeholder="请选择" size="mini">
                <el-option
                  :label="item.value"
                  :value="item.key"
                  v-for="(item,index) in scope.row.usageList"
                  :key="index"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column prop="nums" label="频次" width="100">
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.nums"
                placeholder="请选择"
                size="mini"
                @change="numsChange($event,scope)"
                v-if="scope.row.name"
              >
                <el-option
                  :label="item.value"
                  :value="item.key"
                  v-for="(item,index) in scope.row.numList"
                  :key="index"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column prop="timesQuan" label="次用量" width="80">
            <template slot-scope="scope" v-if="scope.row.name">
              <div class="flex-vertical-between">
                <div class="input t_dose">
                  <el-input
                    v-model="scope.row.timesQuan"
                    size="mini"
                    @input="timesQuanC($event,scope)"
                  ></el-input>
                </div>
                <div class="unit">{{scope.row.usage=='2'?'ml':'克'}}</div>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="time" label="服药时间" width="100">
            <template slot-scope="scope" v-if="scope.row.name">
              <el-select
                v-model="scope.row.time"
                placeholder="请选择"
                size="mini"
                @change="timeC($event,scope)"
              >
                <el-option
                  :label="item.value"
                  :value="item.key"
                  v-for="(item,index) in scope.row.timeList"
                  :key="index"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column prop="from" label="产地" width="80"></el-table-column>
          <el-table-column prop="price" label="单价" width="50"></el-table-column>
          <el-table-column prop="total" label="计价总额" width="80"></el-table-column>
          <el-table-column prop="inventory" label="库存" width="50"></el-table-column>
          <el-table-column label="操作" fixed="right">
            <template slot-scope="scope">
              <div class="operate" v-if="scope.row.name">
                <div>
                  <img src="../assets/add.png" alt @click="addDrug3(scope)" />
                </div>
                <div>
                  <img src="../assets/delete1.png" alt @click="deleteDrug3(scope)" />
                </div>
                <div>
                  <img src="../assets/find.png" alt @click="findDrug(scope)" />
                </div>
              </div>
              <div class="operate" v-else-if="scope.row.id==tableData3.length && !scope.row.name">
                <div style="opacity:0;">
                  <img src="../assets/find.png" alt />
                </div>
              </div>

              <div v-else class="operate">
                <div v-if="scope.row.id!==tableData3.length">
                  <img src="../assets/delete1.png" alt @click="deleteDrug3(scope)" />
                </div>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <!-- 底部处方 -->
    <div class="table-bottom">
      <div class="table-b-header">
        <div v-if="bottom_form.usege=='xz'" class="header-about">
          <div class="item flex-vertical-center-l">
            <span>操作指南：</span>
            <div style="flex:1;">
              <el-input size="medium" placeholder="请输入" v-model="bottom_form.caozuo"></el-input>
            </div>
          </div>
        </div>

        <div class="header-about">
          <div class="item flex-vertical-center-l">
            <span>嘱托：</span>
            <div style="flex:1;">
              <el-input size="medium" placeholder="请输入" v-model="bottom_form.zhutuo"></el-input>
            </div>
          </div>
        </div>
        <div class="header-about flex-vertical-center-l flex-wrap" v-if="container_i!=2">
          <div class="item flex-vertical-center-l">
            <span>配送：</span>
            <div class="div1">
              <el-radio-group v-model="bottom_form.radio" @change="getAdd">
                <el-radio label="0">是</el-radio>
                <el-radio label="1">否</el-radio>
              </el-radio-group>
            </div>
          </div>
          <div class="item flex-vertical-center-l" v-if="bottom_form.radio==0">
            <span>收货人姓名：</span>
            <div class="div1">
              <el-input size="small" placeholder="请输入" v-model="bottom_form.saveName"></el-input>
            </div>
          </div>
          <div class="item flex-vertical-center-l" v-if="bottom_form.radio==0">
            <span>收货人电话：</span>
            <div class="div1">
              <el-input size="small" placeholder="请输入" v-model="bottom_form.phone"></el-input>
            </div>
          </div>
          <div class="item flex-vertical-center-l flex-wrap" v-if="bottom_form.radio==0">
            <span>收货地址：</span>
            <div class="city1 city">
              <el-select size="small" v-model="province" placeholder="选择省" @change="proC($event)">
                <el-option
                  :label="item.name"
                  :value="item.code"
                  v-for="(item,index) in provinceList"
                  :key="index"
                ></el-option>
              </el-select>
            </div>
            <div class="city1 city">
              <el-select size="small" v-model="city" placeholder="选择市" @change="cityC($event)">
                <el-option
                  :label="item.name"
                  :value="item.code"
                  v-for="(item,index) in cityList"
                  :key="index"
                ></el-option>
              </el-select>
            </div>
            <div class="city1 city">
              <el-select size="small" v-model="area" placeholder="选择区">
                <el-option
                  :label="item.name"
                  :value="item.code"
                  v-for="(item,index) in areaList"
                  :key="index"
                ></el-option>
              </el-select>
            </div>
            <div class="div4">
              <el-input size="small" placeholder="请输入详细地址" v-model="bottom_form.address"></el-input>
            </div>
          </div>

          <div
            class="right flex-center"
            v-if="bottom_form.radio==0"
            @click="getAddressForHospital"
          >寄到本院</div>
        </div>
      </div>
    </div>
    <!-- 留在这个页面 -->
    <div class="table-b-bottom flex-vertical-between">
      <div class="t-b-b-left flex-vertical-center-l flex-wrap">
        <div class="t-b-l-item">
          当前处方金额:
          <span>{{nowRecipeMoney}}元</span>
        </div>
        <div class="t-b-l-item" v-if="container_i==0">
          单剂金额:
          <span>10元</span>
        </div>
        <div class="t-b-l-item" v-if="bottom_form.daijian && bottom_form.doseType=='tj'">
          代煎费:
          <span>10元</span>
        </div>
        <div class="t-b-l-item" v-if="bottom_form.radio==0" v-show="moneyMsg.deliveryPrice">
          配送费:
          <span>{{moneyMsg.deliveryPrice}}元</span>
        </div>
        <div class="t-b-l-item" v-if="bottom_form.doseType=='gj'">
          制膏费:
          <span>10元</span>
        </div>
        <div class="t-b-l-item">
          合计费用:
          <span>{{allMoney}}元</span>
        </div>
      </div>
      <div class="t-b-b-right flex-vertical-center-r">
        <div class="flex-center bg-green" @click="submit()" v-if="showSubmit">提交处方</div>
      </div>
    </div>
  </div>
</template>
<script>
import {
  getProver,
  getArea,
  getSelectType,
  getPharmacyMsg,
  getPatAddress
} from "@/api/city.js";
import {
  getTableDrug,
  getAddressForHospital,
  getPharmacyID,
  customerQuery
} from "@/api/diagnosis.js";
import { debounce } from "@/utils/format.js";
import { mapState, mapGetters, mapActions, mapMutations } from "vuex";
export default {
  name: "medandchinese",
  props: {
    container_i: {
      type: Number,
      default: 1
    },
    showSubmit: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      name: "中药制剂",
      tableData3: [
        {
          id: 1,
          key: "",
          drugList: [],
          search_i: 0,
          showSearch: false,
          page: 1,
          loadMore: true,
          usageList: [],
          numList: [],
          timeList: []
        }
      ],
      page: 1,
      // 底部表单
      bottom_form: {
        doseNum: "",
        doseType: "",
        usege: "",
        num: "",
        daijian: "",
        nongjian: "",
        time: "",
        caozuo: "",
        zhutuo: "",
        radio: "1",
        saveName: "", // 收货人
        address: "",
        phone: "",
        doseType1: "zc",
        doseNum: ""
      },
      pharmacyID: "", // 药房id
      province: "",
      city: "",
      area: "",
      provinceList: [],
      cityList: [],
      areaList: [],
      moneyMsg: {},
      nowRecipeMoney: 0, // 当前处方金额
      allMoney: 0, // 合计金额
      index: 0
    };
  },
  created() {
    // this.getTableDrug(,'1)
    this.getProver();
    // this.getPharmacyMsg(1)
    this.getSelectType("中药制剂药品用法", 0);
    this.getSelectType("中药制剂服药时间", 0);
    this.getSelectType("中药制剂频次", 0);
    this.getPharmacyID();
    this.customerQuery();
  },
  methods: {
    // 获取地址
    getAdd(e) {
      if (e == 1) {
        this.province = "";
        this.city = "";
        this.area = "";
        this.bottom_form.saveName = "";
        this.bottom_form.phone = "";
        this.bottom_form.address = "";
      } else {
        this.getPatAddress();
      }
      this.countNowRecipeMoney();
    },
    findDrug(scope) {
      this.$emit("find", scope);
    },
    // 频次改变
    numsChange(e, scope) {
      let item = scope.row;
      item.nums = e;

      this.$set(this.tableData3, scope.$index, item);
    },
    // 渲染次用量
    timesQuanC(e, scope) {
      let item = scope.row;
      item.timesQuan = e;

      this.$set(this.tableData3, scope.$index, item);
    },
    // 渲染服药时间
    timeC(e, scope) {
      let item = scope.row;
      item.time = e;

      this.$set(this.tableData3, scope.$index, item);
    },
    // 计算当前处方金额
    countNowRecipeMoney() {
      let data = this.tableData3;
      let total = 0;
      data.forEach(item => {
        if (item.total) {
          total += Number(item.total);
        }
      });

      this.nowRecipeMoney = total.toFixed(2);
      // 是否配送
      let isDelivery = this.bottom_form.radio;
      //配送费
      let deliveryPrice =
        isDelivery == 0 ? this.moneyMsg.deliveryPrice || 0 : 0;

      this.allMoney = Number(total.toFixed(2)) + Number(deliveryPrice);
      this.$emit("update:totalAllMoney", this.allMoney);
    },
    countDoseMoney(e, scope) {
      scope.row.dose = e;

      scope.row.total = (
        Number(this.tableData3[scope.$index].dose) *
        Number(this.tableData3[scope.$index].price)
      ).toFixed(2);

      // setTimeout(() => {
      //     document.querySelectorAll('#dose' + scope.row.id)[0].value = e
      // }, 200)
      this.$set(this.tableData3, scope.$index, scope.row);

      this.countNowRecipeMoney();
    },
    // 清空按钮点击
    clearData() {
      this.tableData3 = [];
      this.tableData3.push({
        id: 1,
        key: "",
        drugList: [],
        search_i: 0,
        showSearch: false,
        page: 1,
        loadMore: true
      });
      this.page = 1;
      this.countNowRecipeMoney();
    },
    load() {
      let key = this.tableData3[this.index].key;
      let page = this.tableData3[this.index].page;
      let loadMore = this.tableData3[this.index].loadMore;
      let index = this.tableData3[this.index].id - 1;
      if (loadMore) {
        page += 1;
      }
      // console.log('思辨')

      this.getTableDrug(key, page, index, loadMore);
    },
    // 搜索展示药品
    searchDrug(e, scope) {
      this.tableData3[scope.$index].key = e;

      this.page = scope.row.page;

      // debounce(this.getTableDrug(e, 1, scope.$index), 1000)
      debounce(this.getTableDrug(scope.row.key, 1, scope.row.id - 1), 10000);

      this.index = scope.row.id - 1;
    },
    // 药品名称 输入框失去焦点
    drugBlur(e, scope) {
      setTimeout(() => {
        this.tableData3[scope.row.id - 1].key = "";

        let ids = document.querySelectorAll("#operate2");
        ids.forEach((item, index) => {
          item.style["z-index"] = "99";
        });

        this.tableData3.filter((item, index) => {
          return (item.id = index + 1);
        });
      }, 500);
    },
    drugBlur1(e, scope) {
      setTimeout(() => {
        this.tableData3[scope.row.id - 1].key = "";
        this.tableData3[scope.row.id - 1].showSearch = false;
        let ids = document.querySelectorAll("#operate2");
        ids.forEach((item, index) => {
          item.style["z-index"] = "99";
        });

        this.tableData3.filter((item, index) => {
          return item.id % 2 != 0;
        });
      }, 500);
    },
    // 监听键盘事件
    drugDown(e, scope) {
      let totalData = this.tableData3;
      // 如果到最后一个 判断是否需要分页
      if (
        totalData[scope.row.id - 1].search_i ==
        totalData[scope.row.id - 1].drugList.length - 1
      ) {
        // totalData[scope.$index].search_i
        if (totalData[scope.row.id - 1].loadMore) {
          totalData[scope.row.id - 1].page += 1;
          this.getTableDrug(
            totalData[scope.row.id - 1].key,
            totalData[scope.row.id - 1].page,
            scope.row.id - 1,
            totalData[scope.row.id - 1].loadMore
          );

          totalData[scope.row.id - 1].search_i += 1;
        }
      } else {
        totalData[scope.row.id - 1].search_i += 1;
      }

      // 表格 fixed 时 去 下标 为 1

      if (totalData[scope.row.id - 1].drugList.length > 5) {
        document.querySelectorAll(
          `#infiniteList${scope.row.id}`
        )[1].scrollTop += 36;

        console.log(
          document.querySelectorAll(`#infiniteList${scope.row.id}`)[1]
            .scrollTop,
          "top"
        );
      }
      this.tableData3 = totalData.filter((item, index) => {
        // this.getSelectType('中药药品用法', index)
        return (item.id = index + 1);
      });

      this.$forceUpdate();
    },
    drugUp(e, scope) {
      let totalData = this.tableData3;
      // 如果到最后一个 判断是否需要分页
      if (totalData[scope.row.id - 1].search_i == 0) {
        // totalData[scope.$index].search_i
      } else {
        totalData[scope.row.id - 1].search_i -= 1;
      }

      if (
        document.querySelectorAll(`#infiniteList${scope.row.id}`)[1].scrollTop >
        0
      ) {
        document.querySelectorAll(
          `#infiniteList${scope.row.id}`
        )[1].scrollTop -= 36;
      }

      this.tableData3 = totalData.filter((item, index) => {
        // this.getSelectType('中药药品用法', index)
        return (item.id = index + 1);
      });
    },
    drugEnter(scope) {
      this.chooseDis3(
        scope,
        scope.row.search_i,
        scope.row.drugList[scope.row.search_i]
      );
    },
    clickName(scope) {
      this.tableData3[scope.row.id - 1].showSearch = !this.tableData3[
        scope.row.id - 1
      ].showSearch;

      this.tableData3[scope.row.id - 1].key = scope.row.name;
      this.tableData3[scope.row.id - 1].search_i = 0;

      debounce(this.getTableDrug(scope.row.key, 1, scope.row.id - 1), 10000);
      setTimeout(() => {
        console.log(document.querySelectorAll("#searchD1" + scope.row.id));
        document.querySelectorAll("#searchD1" + scope.row.id)[1].focus();
      }, 500);
    },
    doseEnter(scope) {
      if (scope.row.id == this.tableData3.length - 1) {
        // console.log(document.querySelectorAll('#searchD1' + (scope.row.id + 1)), '啦啦啦')
        document.querySelectorAll("#searchD1" + (scope.row.id + 1))[1].focus();
      } else {
        try {
          this.tableData3.forEach(item => {
            if (item.name && !item.dose && scope.row.id < item.id) {
              document.querySelectorAll("#dose1" + item.id)[0].focus();
              throw Error();
            }
            if (!item.name) {
              // console.log(document.querySelectorAll('#searchD1' + item.id), '啦啦啦')
              document.querySelectorAll("#searchD1" + item.id)[1].focus();
              throw Error();
            }
          });
        } catch (error) {}
      }
    },
    // 选中中成药方
    chooseDis3(scope, index, item) {
      let obj = {
        id: scope.row.id,
        name: item.ypmc,
        spec: item.gg, // 规格
        dose: "", // 剂量
        // unit: item.dw, // 单位
        unit: item.bzdw, // 单位
        // usage: item.usagestr, // 用法
        usage: "",
        // price: item.lsjg,
        price: item.price,
        total: 0,
        inventory: item.kc, // 库存
        key: "",
        showSearch: false,
        search_i: 0,
        showSearch: false,
        medid: item.pid, // 药品id
        originname: item.cdmc // 产地名称
      };
      Object.assign(obj, this.tableData3[scope.$index]);
      // 调用 父级合理用药接口
      let father = this.$parent;
      father.getRationalMed(obj.medid);
      let data = this.tableData3;
      this.tableData3[scope.$index] = obj;

      if (scope.$index == this.tableData3.length - 1) {
        this.tableData3.push({
          search_i: 0,
          key: "",
          page: 1,
          drugList: [],
          usageList: [],
          numList: [],
          timeList: [],
          loadMore: true
        });
      }

      this.tableData3.filter((item, index) => {
        this.getSelectType("中药制剂药品用法", index);
        this.getSelectType("中药制剂服药时间", index);
        this.getSelectType("中药制剂频次", index);
        return (item.id = index + 1);
      });
      setTimeout(() => {
        let ids = document.querySelectorAll("#dose1" + scope.row.id);
        // console.log(ids, 'ids');
        // ids[0].style.color = 'red'
        document.querySelectorAll("#dose1" + scope.row.id)[0].focus();
      }, 500);
    },

    // 表三 添加
    addDrug3(scope) {
      let tableData3 = this.tableData3;
      if (scope.$index == tableData3.length - 1) {
        this.tableData3.push({
          key: "",
          page: 1,
          drugList: [],
          usageList: [],
          numList: [],
          timeList: [],
          loadMore: true,
          search_i: 0,
          showSearch: false
        });
        this.getSelectType("中药制剂药品用法", this.tableData3.length - 1);
        this.getSelectType("中药制剂服药时间", this.tableData3.length - 1);
        this.getSelectType("中药制剂频次", this.tableData3.length - 1);
      } else {
        let data = tableData3.splice(scope.row.id);

        tableData3.push({
          id: 2,
          drugList: [],
          page: 1,
          key: "",
          usageList: [],
          numList: [],
          timeList: [],
          loadMore: true,
          search_i: 0,
          showSearch: false
        });
        tableData3 = tableData3.concat(data);

        this.tableData3 = tableData3;

        this.getSelectType("中药制剂药品用法", scope.$index + 1);
        this.getSelectType("中药制剂服药时间", scope.$index + 1);
        this.getSelectType("中药制剂频次", scope.$index + 1);
      }

      this.tableData3.filter((item, index) => {
        return (item.id = index + 1);
      });
    },
    // 表三 删除
    deleteDrug3(scope) {
      if (this.tableData3.length > 1) {
        this.tableData3.splice(scope.$index, 1);
        this.tableData3.filter((item, index) => {
          return (item.id = index + 1);
        });

        this.countNowRecipeMoney();
      }
    },
    // 修改省的数据
    proC(e) {
      // console.log(e)
      this.city = "";
      this.area = "";
      this.getArea(e, 1);
    },
    cityC(e) {
      this.area = "";
      this.getArea(e, 2);
    },
    // 合并表格
    arraySpanMethod({ row, column, rowIndex, columnIndex }) {
      // if (!row.name) {
      //     return [1, 14]
      // }
    },
    submit() {
      this.$emit("submit");
    },
    // 通过中药类型获取药房id
    async getPharmacyID() {
      let res = await getPharmacyID({
        type: "5"
      });
      if (res.ResultCode == 0) {
        if (res.ResultInfo == "") {
          this.$message({
            showClose: true,
            message: "当前类型无法开药,请切换类型",
            type: "error"
          });
          return;
        }
        this.pharmacyID = res.ResultInfo;
        // this.changePharmacy()
        this.getPharmacyMsg(res.ResultInfo);
      }
    },
    async customerQuery() {
      let res = await customerQuery({
        type: 1
      });
      if (res.ResultCode == 0) {
        this.pharmacyID = res.Data[0].pid;
      }
    },
    async getAddressForHospital() {
      let res = await getAddressForHospital({});
      if (res.ResultCode == 0) {
        this.bottom_form.province = res.Data.province;
        this.bottom_form.city = res.Data.city;
        this.bottom_form.area = res.Data.district;
        this.bottom_form.address = res.Data.adressdetail;

        this.getArea(res.Data.province, 1);
        this.getArea(res.Data.city, 2);
      }
    },
    // 获取表格药品列表
    async getTableDrug(key, page, index, load = true) {
      if (!load) return;
      let params = {
        key: key,
        limit: 5,
        page: page,
        type: 4,
        pharmacyid: this.pharmacyID
      };
      let res = await getTableDrug(params);
      if (res.ResultCode == 0) {
        res.Data.Items.filter(item => {
          return (item.price = Number(Number(item.price).toFixed(3)));
        });
        if (page <= res.Data.TotalPageCount) {
          if (page == 1) {
            this.tableData3[index].drugList = res.Data.Items;
          } else {
            this.tableData3[index].drugList = [
              ...this.tableData3[index].drugList,
              ...res.Data.Items
            ];
            this.tableData3[index].page += 1;
          }
        } else {
          this.tableData3[index].loadMore = false;
        }
      }
    },
    // 获取省数据
    async getProver() {
      let res = await getProver();
      if (res.ResultCode == 0) {
        this.provinceList = res.Data;
      }
    },
    // 获取市数据
    async getArea(code, type) {
      let res = await getArea(code);
      if (res.ResultCode == 0) {
        if (type == 1) {
          this.cityList = res.Data;
        } else {
          this.areaList = res.Data;
        }
      }
    },
    // 根据表格获取数据类型
    async getSelectType(data, index) {
      let res = await getSelectType(data);

      if (data == "中药制剂药品用法") {
        this.tableData3[index].usageList = res.Data;
      } else if (data == "中药制剂服药时间") {
        this.tableData3[index].timeList = res.Data;
      } else if (data == "中药制剂频次") {
        this.tableData3[index].numList = res.Data;
      }
    },
    // 获取制膏费用
    async getPharmacyMsg(data) {
      let res = await getPharmacyMsg(data);
      if (res.ResultCode == 0) {
        this.moneyMsg = res.Data;
      }
    },
    // 获取患者地址信息
    async getPatAddress() {
      if (!this.getPatiensInfo.basisPatient.pid) return;
      let res = await getPatAddress({
        patId: this.getPatiensInfo.basisPatient.pid
      });
      if (res.ResultCode == 0) {
        this.bottom_form.address = res.Data.detailadress;
        this.bottom_form.saveName = res.Data.name;
        this.bottom_form.phone = res.Data.phone;
        this.province = res.Data.province;
        this.city = res.Data.city;
        this.area = res.Data.district;

        this.getArea(res.Data.province, 1);
        this.getArea(res.Data.city, 2);
      }
    }
  },
  computed: {
    ...mapGetters(["getuserinfo", "getPatiensInfo"])
  }
};
</script>
<style lang="scss" scoped>
@import "../style/common.scss";

.center-table {
  border: 2px solid #dedede;
  padding: 7px 0 0;
  // min-height: 600px;
  // position: relative;

  .table-header {
    padding-bottom: 7px;
    border-bottom: 2px solid #dedede;

    .table-label {
      .label-item {
        cursor: pointer;
        width: 134px;
        border-right: 2px solid #eaeaea;

        div {
          color: #666;
          transform: rotate(45deg);
          font-size: 28px;
          margin-left: 12px;
          margin-top: 1px;
        }
      }

      span {
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: 400;
        color: #666666;
      }

      .l_active {
        color: #5386f6;
      }
    }
  }

  .add-presc {
    width: 70px;
    height: 26px;
    background: #ffae45;
    border-radius: 4px;
    font-size: 12px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #ffffff;
    cursor: pointer;
    margin-right: 20px;
  }

  .table-container {
    padding: 37px 10px;

    .t-con-header {
      margin-bottom: 20px;

      .t-con-radio {
        flex: 1;
      }

      .t-radio-title {
        width: 82px;
        font-size: 16px;
        font-family: PingFang SC;
        font-weight: 400;
        color: #333333;
      }

      .t-radio-group {
        flex: 1;
      }

      .add-presc1 {
        width: 84px;
        height: 34px;
        background: #ffae45;
        border-radius: 4px;
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #ffffff;
      }
    }
  }

  .table-show {
    width: 100%;

    // background: #5386F6;
    // overflow: hidden;

    .table-left-body {
      width: 49.5%;
      position: relative;
      perspective: 100px;
      padding-bottom: 53px;
    }

    .table-left {
      width: 100%;
      overflow-y: auto;
      border: 1px solid #dedede;
      box-sizing: border-box;

      .table-l-hader {
        white-space: nowrap;

        div {
          display: inline-block;
          // padding: 15px 10px;
          background: #f3fffb;
          text-align: center;
          height: 48px;
          line-height: 48px;
          border: 1px solid #dedede;
          border-bottom: 0 !important;
          // border-top: 0 !important;
        }

        .med-name {
          margin-left: 50px;
        }

        .kucun {
          padding-right: 120px;
        }

        .fixed-r {
          position: fixed;
          right: 0;
        }

        .fixed-left {
          position: fixed;
          left: 0;
        }
      }

      .table-l-item {
        white-space: nowrap;

        .bg-green {
          .div1 {
            background: #f3fffb;
            border: 1px solid #dedede;
          }
        }

        .div1 {
          display: inline-block;
          // padding: 15px 10px;
          background: #ffffff;
          text-align: center;
          height: 53px;
          line-height: 53px;
          border: 1px solid #dedede;
          z-index: 9999;
          border-top: 0 !important;
        }

        .med-name {
          margin-left: 50px;
        }

        .kucun {
          padding-right: 120px;
          border-right: 1px solid #dedede;
        }

        .fixed-r {
          position: fixed;
          right: 0;
        }

        .fixed-left {
          position: fixed;
          left: 0;
          // border-left: 1px solid #DEDEDE;
        }

        .no-data {
          width: 100%;
          box-sizing: border-box;
          // border-top: 1px solid #DEDEDE;
          position: relative;
          left: 0;
          right: 0;
          bottom: 0px;
          // float: left;
        }
      }
    }
  }

  .operate {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-around;

    img {
      width: 16px;
    }
  }

  .operate2 {
    position: absolute;
    z-index: 99;
  }

  .bottom-input {
    background: #fff;
    padding: 12.5px 30px 12.5px 52px;
    position: relative;
    // z-index: 999;
    // perspective: 100px;

    .div {
      width: 154px;
    }

    .table-choose {
      z-index: 9999;
      width: 332px;
      height: 221px;
      background: #ffffff;
      border: 2px solid #d8d8d8;
      position: relative;
      top: 2px;
      left: -48px;
      overflow: auto;

      .table-choose-h {
        background: #f3fffb;

        div {
          height: 36px;
          width: 73px;
        }

        div:first-child {
          width: 115px;
        }
      }

      .t-c-b {
        cursor: pointer;
        height: 180px;

        .td {
          background: #f3fffb;
        }

        p {
          border: 1px solid #ededed;
          height: 36px;
          width: 73px;
          // flex: 1;
          box-sizing: border-box;
        }

        p:first-child {
          width: 115px;
        }
      }
    }
  }

  .table-bottom {
    // position: absolute;
    // bottom: 0;
    // right: 0;
    // left: 0;\
    padding: 0 37px;
    margin-top: 241px;
    // margin-top: 66px;

    .header-about {
      .item {
        margin-right: 20px;
        margin-bottom: 10px;

        span {
          font-size: 16px;
          font-family: PingFang SC;
          font-weight: 400;
          color: #333333;
        }

        .div1 {
          width: 120px;
        }

        .div2 {
          width: 74px;
        }

        .city1 {
          width: 120px;
        }

        .div3 {
          width: 92px;
        }

        .div4 {
          width: 160px;
        }

        .input-suffix {
          line-height: 36px;
        }
      }

      .right {
        width: 70px;
        height: 26px;
        background: #ffae45;
        border-radius: 4px;
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: 400;
        color: #ffffff;
        margin-bottom: 10px;
        cursor: pointer;
      }
    }
  }

  .table-b-bottom {
    padding: 10px 27px;
    border-top: 2px solid #dedede;
    margin-top: 10px;

    .t-b-l-item {
      font-size: 16px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #333333;
      margin-right: 20px;

      span {
        color: #ff6245;
      }
    }

    .t-b-b-right {
      div {
        width: 130px;
        height: 46px;
        background: #ffae45;
        border-radius: 4px;
        font-size: 16px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #ffffff;
        cursor: pointer;
      }

      .bg-green {
        background: #5386f6;
        margin-left: 20px;
      }
    }
  }

  // 中成药 和适宜技术配方
  .chinese_medicine {
    padding: 0 37px;

    .clearer {
      width: 84px;
      height: 34px;
      background: #ffae45;
      border-radius: 4px;
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: bold;
      color: #ffffff;
      cursor: pointer;
      margin-bottom: 20px;
    }

    .c-m-table {
      width: 100%;
      overflow: hidden;
      border: 1px solid #dedede;

      .unit {
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: 400;
        color: #000000;
        // margin-left: 10px;
      }

      .input {
        width: 40px;
      }
    }
  }
}

.table-show {
  width: 100%;

  // background: #5386F6;
  // overflow: hidden;

  .table-left-body {
    width: 49.5%;
    position: relative;
    perspective: 100px;
    padding-bottom: 53px;
  }

  .table-left {
    width: 100%;
    overflow-y: auto;
    border: 1px solid #dedede;
    box-sizing: border-box;

    .table-l-hader {
      white-space: nowrap;

      div {
        display: inline-block;
        // padding: 15px 10px;
        background: #f3fffb;
        text-align: center;
        height: 48px;
        line-height: 48px;
        border: 1px solid #dedede;
        border-bottom: 0 !important;
        // border-top: 0 !important;
      }

      .med-name {
        margin-left: 50px;
      }

      .kucun {
        padding-right: 120px;
      }

      .fixed-r {
        position: fixed;
        right: 0;
      }

      .fixed-left {
        position: fixed;
        left: 0;
      }
    }

    .table-l-item {
      white-space: nowrap;

      .bg-green {
        .div1 {
          background: #f3fffb;
          border: 1px solid #dedede;
        }
      }

      .div1 {
        display: inline-block;
        // padding: 15px 10px;
        background: #ffffff;
        text-align: center;
        height: 53px;
        line-height: 53px;
        border: 1px solid #dedede;
        z-index: 9999;
        border-top: 0 !important;
      }

      .med-name {
        margin-left: 50px;
      }

      .kucun {
        padding-right: 120px;
        border-right: 1px solid #dedede;
      }

      .fixed-r {
        position: fixed;
        right: 0;
      }

      .fixed-left {
        position: fixed;
        left: 0;
        // border-left: 1px solid #DEDEDE;
      }

      .no-data {
        width: 100%;
        box-sizing: border-box;
        // border-top: 1px solid #DEDEDE;
        position: relative;
        left: 0;
        right: 0;
        bottom: 0px;
        // float: left;
      }
    }
  }
}

.operate {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-around;

  img {
    width: 16px;
  }
}

.bottom-input {
  background: #fff;
  padding: 12.5px 30px 12.5px 52px;
  position: relative;
  // z-index: 999;
  // perspective: 100px;

  .div {
    width: 154px;
  }

  .table-choose {
    z-index: 9999;
    width: 332px;
    height: 221px;
    background: #ffffff;
    border: 2px solid #d8d8d8;
    position: relative;
    top: 2px;
    left: -48px;
    overflow: auto;

    .table-choose-h {
      background: #f3fffb;

      div {
        height: 36px;
        width: 73px;
      }

      div:first-child {
        width: 115px;
      }
    }

    .t-c-b {
      cursor: pointer;
      height: 180px;

      .td {
        background: #f3fffb;
      }

      p {
        border: 1px solid #ededed;
        height: 36px;
        width: 73px;
        // flex: 1;
        box-sizing: border-box;
      }

      p:first-child {
        width: 115px;
      }
    }
  }
}

.table-bottom {
  // position: absolute;
  // bottom: 0;
  // right: 0;
  // left: 0;\
  padding: 0 37px;
  margin-top: 241px;

  .header-about {
    .item {
      margin-right: 20px;
      margin-bottom: 10px;

      span {
        font-size: 16px;
        font-family: PingFang SC;
        font-weight: 400;
        color: #333333;
      }

      .div1 {
        width: 120px;
      }

      .div2 {
        width: 74px;
      }

      .city1 {
        width: 120px;
      }

      .div3 {
        width: 92px;
      }

      .div4 {
        width: 160px;
      }

      .input-suffix {
        line-height: 36px;
      }
    }

    .right {
      width: 70px;
      height: 26px;
      background: #ffae45;
      border-radius: 4px;
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #ffffff;
      margin-bottom: 10px;
      cursor: pointer;
    }
  }
}

.table-b-bottom {
  padding: 10px 27px;
  border-top: 2px solid #dedede;
  margin-top: 10px;

  .t-b-l-item {
    font-size: 16px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #333333;
    margin-right: 20px;

    span {
      color: #ff6245;
    }
  }

  .t-b-b-right {
    div {
      width: 130px;
      height: 46px;
      background: #ffae45;
      border-radius: 4px;
      font-size: 16px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #ffffff;
      cursor: pointer;
    }

    .bg-green {
      background: #5386f6;
      margin-left: 20px;
    }
  }
}

.table-choose3 {
  z-index: 999999 !important;
  width: 332px;
  height: 221px;
  background: #ffffff;
  border: 2px solid #d8d8d8;
  // position: absolute;
  position: fixed;

  margin-top: 19px;
  left: 318px;
  overflow: auto;
  // z-index: 999 !important;

  .table-choose-h {
    background: #f3fffb;

    div {
      height: 36px;
      width: 73px;
    }

    div:first-child {
      width: 115px;
    }
  }

  .t-c-b {
    cursor: pointer;
    height: 180px;
    width: 100%;

    .td {
      background: #f3fffb;
    }

    p {
      border: 1px solid #ededed;
      height: 36px;
      width: 73px;
      // flex: 1;
      box-sizing: border-box;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    p:first-child {
      width: 115px;
    }

    p:nth-child(3) {
      // color: red;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      text-align: left;
      line-height: 36px;
    }
  }
}

.collapse ::v-deep .el-collapse-item__content {
  padding-bottom: 5px;
}

.c-m-table::v-deep .el-table .cell {
  text-align: center;
}

.table-show::v-deep .el-table .cell {
  text-align: center;
}

.c-m-table::v-deep .el-select input {
  padding: 0 15px 0 5px;
}

.table-show ::v-deep .el-select input {
  padding: 0 15px 0 5px;
}

.t_dose::v-deep .el-input__inner {
  // text-align: left;
  padding: 0 5px !important;
}

.city::v-deep .el-select input {
  padding: 0 20px 0 10px;
  // height: 32px;
}

.xuewei::v-deep .el-select {
  width: 100%;
}
</style>