<template>
  <div class="accordEdit">
    <!-- <div class="flex-center back" @click="$router.back()" v-if='showBtn'>返回</div> -->
    <div style="margin-bottom:10px;">
      <el-button type="primary" size="mini" @click="$router.back()" v-if="showBtn">返回</el-button>
    </div>
    <div class="flex-vertical-center-l flex-wrap">
      <div class="item flex-vertical-center-l">
        <span>*</span>
        <div class="name">方名：</div>
        <div class="input">
          <el-input size="mini" v-model="form.name" placeholder="请输入" :disabled="type=='find'"></el-input>
        </div>
      </div>
      <div class="item flex-vertical-center-l">
        <span></span>
        <div class="name">功效与适应症：</div>
        <div class="input">
          <el-input size="mini" v-model="form.efficacy" placeholder="请输入" :disabled="type=='find'"></el-input>
        </div>
      </div>
      <div class="item flex-vertical-center-l">
        <span>*</span>
        <div class="name">剂型：</div>
        <div class="input">
          <el-select size="mini" v-model="form.doseType" placeholder="请选择" :disabled="type=='find'">
            <el-option
              :label="item.value"
              :value="item.key"
              v-for="(item,index) in doseTypeList"
              :key="index"
            ></el-option>
          </el-select>
        </div>
      </div>

      <!-- <div class="item flex-vertical-center-l">
        <span>*</span>
        <div class="name">中医病名：</div>
        <div class="input">
          <el-select
            size="mini"
            v-model="form.cmName"
            @change="cNameChange"
            placeholder="请选择"
            :disabled="type=='find'"
            filterable
            remote
            :filter-method="filterMethod"
          >
            <el-option
              :label="item.disname"
              :value="item.disname"
              v-for="(item,index) in cmNameList"
              :key="index"
            ></el-option>
          </el-select>
        </div>
      </div>
      <div class="item flex-vertical-center-l">
        <span>*</span>
        <div class="name">证型：</div>
        <div class="input">
          <el-autocomplete
            size="mini"
            v-model="form.cardType"
            :fetch-suggestions="searchZhengxing"
            :trigger-on-focus="true"
            @select="selectZX($event)"
            ref="zhengxing"
            :id="'zhengxing'"
            placeholder="请输入"
            :disabled="type=='find'"
          ></el-autocomplete>
        </div>
      </div>-->
      <div class="item flex-vertical-center-l">
        <span></span>
        <div class="name">方解：</div>
        <div class="input">
          <el-input
            size="mini"
            v-model="form.solution"
            type="textarea"
            placeholder="请输入"
            :disabled="type=='find'"
          ></el-input>
        </div>
      </div>

      <div class="item flex-vertical-center-l">
        <span></span>
        <div class="name">专家：</div>
        <div class="input">
          <el-input size="mini" v-model="form.experts" placeholder="请输入" :disabled="type=='find'"></el-input>
        </div>
      </div>
      <div class="item flex-vertical-center-l">
        <span></span>
        <div class="name">专家名衔：</div>
        <div class="input">
          <el-select size="mini" v-model="form.titles" placeholder="请选择" :disabled="type=='find'">
            <el-option
              :label="item.value"
              :value="item.value"
              v-for="(item,index) in titlesList"
              :key="index"
            ></el-option>
          </el-select>
        </div>
      </div>
      <div class="item flex-vertical-center-l">
        <span></span>
        <div class="name">修改限制：</div>
        <div class="input">
          <el-switch
            size="mini"
            :disabled="type=='find'"
            v-model="form.switch"
            active-color="#5EC7B1"
            inactive-color="#ff4949"
          ></el-switch>
        </div>
      </div>
    </div>
    <div>
      <TCMDiagnosis title="中医" ref="TCM"></TCMDiagnosis>
    </div>

    <div class="pre-detail">处方明细:</div>
    <div>
      <MedicineAccord></MedicineAccord>
    </div>

    <!-- <div class="save flex-center" v-if="(type=='edit' &&showBtn) || (type=='add' && showBtn)" @click="save()">保存
    </div>-->
    <div style="margin-top:10px;">
      <el-button
        size="mini"
        type="warning"
        v-if="(type=='edit' &&showBtn) || (type=='add' && showBtn)"
        @click="save()"
      >保存</el-button>
    </div>
    <!-- 药品详情 -->
    <Popup
      width="80%"
      :showDialog="showDrug"
      @cancle="showDrug=false"
      title="药品详情"
      :showBtns="false"
    >
      <div class="drug-body" slot="body">
        <div class="drug-item flex-plane-center-l">
          <span>名称：</span>
          <div>{{drugInfo.matname}}</div>
        </div>
        <div class="drug-item flex-plane-center-l">
          <span>别名：</span>
          <div>{{drugInfo.matsynonyms}}</div>
        </div>
        <div class="drug-item flex-plane-center-l">
          <span>剂量区间：</span>
          <div>{{drugInfo.matmindosage}}-{{drugInfo.matmindosage}}{{drugInfo.unit}}</div>
        </div>
        <div class="drug-item flex-plane-center-l">
          <span>单位：</span>
          <div>{{drugInfo.unit}}</div>
        </div>
        <div class="drug-item flex-plane-center-l">
          <span>用法：</span>
          <div>{{drugInfo.matusage}}</div>
        </div>
        <div class="drug-item flex-plane-center-l">
          <span>用法禁忌：</span>
          <div>{{drugInfo.matsjj}}</div>
        </div>
        <div class="drug-item flex-plane-center-l">
          <span>性味：</span>
          <div>{{drugInfo.matflavour}}</div>
        </div>
        <div class="drug-item flex-plane-center-l">
          <span>归经：</span>
          <div>{{drugInfo.matmeridian}}</div>
        </div>
        <div class="drug-item flex-plane-center-l">
          <span>功效：</span>
          <div>{{drugInfo.matefficacy}}</div>
        </div>
        <div class="drug-item flex-plane-center-l">
          <span>应用：</span>
          <div>{{drugInfo.matapplication}}</div>
        </div>
        <div class="drug-item flex-plane-center-l">
          <span>使用注意：</span>
          <div>
            <div>{{drugInfo.mattaboo}}</div>
            <!-- <div>2.通常补血用当归身，活血用当归尾，补血活血用全当归</div> -->
          </div>
        </div>
        <div class="drug-item flex-plane-center-l">
          <span>图示：</span>
          <div class="flex-plane-center-l" v-for="(item,index) in drugInfo.matphoto" :key="index">
            <img :src="item" alt />
          </div>
        </div>
        <div class="flex-vertical-center-l flex-wrap">
          <div class="drug-item1 flex-plane-center-l">
            <span>相似中药鉴别使用：</span>
            <div>
              <div v-for="(item,index) in drugInfo.xiangsi" :key="index">
                <span
                  class="mad-cy"
                  v-for="(item1,index1) in item.relmats"
                  :key="index1"
                >{{item1.matname}}{{index1==item.relmats.length-1?'':'、'}}</span>
                <div style="margin-bottom:10px;">{{item.differencedesc}}</div>
              </div>
            </div>
          </div>
        </div>
        <div class="flex-vertical-center-l flex-wrap">
          <div class="drug-item1 flex-plane-center-l">
            <span>常用药对：</span>
            <div>
              <div v-for="(item,index) in drugInfo.changyong" :key="index">
                <span
                  class="mad-cy"
                  v-for="(item1,index1) in item.relmats"
                  :key="index1"
                >{{item1.matname}}{{index1==item.relmats.length-1?'':'、'}}</span>
                <div style="margin-bottom:10px;">{{item.differencedesc}}</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </Popup>
  </div>
</template>
<script>
import Popup from "@/components/Propup.vue";
import MedicineAccord from "../../components/MedicineAccord.vue";
import TCMDiagnosis from "../../components/TCMDiagnosis.vue";
import { debounce } from "@/utils/format.js";
import {
  getTableDrug,
  getAddressForHospital,
  getPharmacyID,
  changePharmacy,
  getDrugDetail,
  customerQuery
} from "@/api/diagnosis.js";
import { getSelectType } from "@/api/city.js";
import {
  getCDiseaseName,
  getXDiseaseName,
  getCCardType
} from "@/api/knowledge.js";

import {
  addExperince,
  getExperinceDetail,
  editExperince
} from "@/api/business";
import {CC_Dosage2Basis} from '@/utils/medicine';

export default {
  components: {
    Popup,
    MedicineAccord,
    TCMDiagnosis
  },
  props: {
    showBtn: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      showDrug: false,
      drugInfo: {},
      form: {
        name: "", // 方名
        efficacy: "", // 功效
        doseType: "", //剂型

        cmName: "", // 中医病名
        cmNameID: "", // 中医病名id
        cardType: "", // 证型
        cardTypeID: "", // 证型id
        solution: "", // 方解
        cMedType: "", // 中药类型
        experts: "", // 专家
        titles: "", // 专家头衔
        switch: false // 修改限制
      },
      cmNameList: [], // 中医病名列表
      doseTypeList: [], // 剂型选择器
      cardTypeList: [], // 中医证型
      titlesList: [
        {
          key: "1",
          value: "国医大师"
        },
        {
          key: "2",
          value: "国家级名老中医"
        },
        {
          key: "3",
          value: "省级名老中医"
        },
        {
          key: "4",
          value: "名医"
        }
      ],
      pharmacyID: "", // 药房id
      pharmacyList: [],
      cMedType: [
        {
          pharmacyName: "散装饮片",
          pid: "0"
        },
        {
          pharmacyName: "散装颗粒",
          pid: "1"
        },
        {
          pharmacyName: "小包装饮片",
          pid: "2"
        },
        {
          pharmacyName: "小包装颗粒",
          pid: "3"
        }
      ], // 中药类型 pharmacyName /pharmacyId

      /*---------顶部字段信息 结束-------------*/

      index: 1,
      pid: "", // 协定方id
      type: "add" // 是否是 查看
    };
  },
  created() {
    this.getSelectType("剂型", 0);
    this.customerQuery();
    if (this.$route.query.type) {
      this.type = this.$route.query.type;
      this.getExperinceDetail();
    } else {
      this.getSelectType("中药药品用法", 0);
    }
  },
  methods: {
    // 保存按钮点击
    save() {
      if (!this.form.name) {
        this.$message({
          type: "error",
          message: "请输入方名",
          showClose: true
        });
        return;
      }
      if (!this.form.doseType) {
        this.$message({
          type: "error",
          message: "请选择剂型",
          showClose: true
        });
        return;
      }
      let tcmdParams = this.$refs.TCM.getParams();
      if (tcmdParams.namemedicine == "") {
        this.$message({
          type: "error",
          message: "请输入病名",
          showClose: true
        });
        return;
      }

      if (tcmdParams.syndrometypes == "") {
        this.$message({
          type: "error",
          message: "请输入证型",
          showClose: true
        });
        return;
      }

      if (tcmdParams.treatment == "") {
        this.$message({
          type: "error",
          message: "请输入治法",
          showClose: true
        });
        return;
      }

      // if (!this.form.cMedType) {
      //     this.$message({
      //         type: 'error',
      //         message: '请选择中药类型',
      //         showClose: true
      //     })
      //     return
      // }
      // let hasDrug = false
      // this.totalTableD.forEach(item => {
      //     if (item.name) {
      //         hasDrug = true
      //     }
      // })
      // if (!hasDrug) {

      //     this.$message({
      //         type: 'error',
      //         message: '请完善处方明细信息',
      //         showClose: true
      //     })
      //     return

      // }

      if (this.type == "add") {
        this.addExperince();
      } else {
        this.editExperince();
      }
    },
    cNameChange() {
      // let id = ''
      this.cmNameList.forEach(item => {
        if (item.disname == this.form.cmName) {
          // id = item.disid
          this.form.cmNameID = item.disid;
        }
      });
      this.form.cardType = "";
      this.form.cardTypeID = "";

      this.getCCardType(this.form.cmNameID);
      setTimeout(() => {
        this.$refs.zhengxing.focus();
      }, 200);
    },
    filterMethod(e) {
      let pinyin = /^[A-Za-z]+$/g;
      if (pinyin.test(e)) {
        this.getCDiseaseName(e, "1");
      } else {
        this.getCDiseaseName(e, "");
      }
    },

    selectZX(e) {
      this.form.cardType = e.value;
      this.form.cardTypeID = e.id;
    },
    async customerQuery() {
      let res = await customerQuery({
        type: 0
      });
      if (res.ResultCode == 0) {
        // this.pharmacyID = res.Data[0].pid
        this.pharmacyList = res.Data;
      }
    },
    // 获取药品详细信息并展示
    async getDrugDetail(id) {
      let res = await getDrugDetail({
        stiDrugId: id
      });
      if (res.ResultCode == 0) {
        res.Data.matphoto = res.Data.matphoto.split(",");
        // res.data.matphoto = res.data.matphoto.split(',')
        res.Data.xiangsi = res.Data.relativedata.filter(item => {
          return item.relativetype == 1;
        });
        res.Data.changyong = res.Data.relativedata.filter(item => {
          return item.relativetype == 2;
        });
        this.drugInfo = res.Data;
        this.showDrug = true;
      }
    },
    // 获取详情
    async getExperinceDetail() {
      let res = await getExperinceDetail({
        pid: this.$route.query.pid
      });
      if (res.ResultCode == 0) {
        this.form = {
          name: res.Data.name, // 方名
          efficacy: res.Data.effect, // 功效
          doseType: res.Data.curetype, //剂型

          cmName: res.Data.diseasename, // 中医病名
          cmNameID: res.Data.diseaseid, // 中医病名id
          cardType: res.Data.symptomname, // 证型
          cardTypeID: res.Data.symptomid, // 证型id
          solution: res.Data.solution, // 方解
          cMedType: res.Data.prescriptiontype, // 中药类型
          experts: res.Data.expert, // 专家
          titles: res.Data.experttitle, // 专家头衔
          switch: res.Data.isupdate == 0 ? true : false // 修改限制
        };

        let tcmd = this.$refs.TCM;
        let data = {
          namemedicine: res.Data.diseasename,
          disid: res.Data.diseaseid,
          //   证型及id
          symptomid: res.Data.symptomid,
          syndrometypes: res.Data.symptomname,
          //   治法
          treatment: res.Data.treatment || ""
        };
        tcmd.setParams(data);
        this.getCCardType(this.form.cmNameID);

        this.assignTableData(res.Data.prescriptionDetailVos);
      }
    },
    // 处理开方数据
    dealTableData() {
      let hasDoseNum = true; // 是否有剂数
      let hasData = true; // 是否有处方药品数据

      let children = this.$children.filter(item => {
        return item.name == "中药处方";
      });
      let data1 = children[0];
      this.totalTableD = data1.recipe_tabs[data1.recipe_tabs_c].totalTableD;
      this.tableData = data1.recipe_tabs[data1.recipe_tabs_c].tableData;
      this.tableData1 = data1.recipe_tabs[data1.recipe_tabs_c].tableData1;

      this.totalTableD.forEach(item1 => {
        if (!item1.dose && item1.name) {
          hasDoseNum = false;
        }
      });

      if (!hasDoseNum) {
        this.$message.error("请完善处方剂量信息");
        return false;
      }

      let zhongPrescriptionVo = [];

      this.totalTableD.forEach(item1 => {
        if (item1.name) {
          let obj1 = {
            allprice: item1.total,
            dose: Number(item1.dose),
            drugname: item1.name,
            drugid: item1.medid,
            origin: item1.originname,
            seqn: item1.id,
            specification: item1.spec,
            unit: item1.unit,
            unitprice: item1.price,
            usagestr: item1.usage
          };

          zhongPrescriptionVo.push(obj1);
        }
      });

      return zhongPrescriptionVo;
    },
    // 赋值给处方数据
    assignTableData(data) {
      this.totalTableD = [];
      data.forEach((item1, index1) => {
        let obj1 = {
          drugList: [],
          page: 1,
          loadMore: true,
          usageList: this.useList,
          id: item1.seqn || item1.id,
          name: item1.drugname || item1.name,
          spec: item1.specification || item1.spec, // 规格
          dose: item1.dose, // 剂量
          unit: item1.unit, // 单位
          usage: item1.usagestr || item1.usage, // 用法
          // usage: item1.usagestr,
          // price: item.unitprice,
          total: item1.price ? item1.dose * item1.price : 0,
          inventory: item1.instock || item1.inventory, // 库存
          key: "",
          search_i: index1,
          medid: item1.drugid || item1.medid, // 药品id
          originname: item1.origin || item1.originname // 产地名称
        };

        this.totalTableD.push(obj1);
      });
      this.totalTableD.push({
        drugList: [],
        page: 1,
        loadMore: true,
        usageList: [],
        id: Number(data[data.length - 1].seqn) + 1
      });

      this.totalTableD.filter((item3, index3) => {
        return (item3.id = index3 + 1);
      });

      this.tableData = this.totalTableD.filter(item2 => {
        return Number(item2.id) % 2 != 0;
      });
      this.tableData1 = this.totalTableD.filter(item2 => {
        return Number(item2.id) % 2 == 0;
      });

      setTimeout(() => {
        let children = this.$children.filter(item => {
          return item.name == "中药处方";
        });

        let data1 = children[0];
        console.log(data1, "data1");
        data1.recipe_tabs[data1.recipe_tabs_c].totalTableD = this.totalTableD;
        data1.recipe_tabs[data1.recipe_tabs_c].tableData = this.tableData;
        data1.recipe_tabs[data1.recipe_tabs_c].tableData1 = this.tableData1;

        setTimeout(() => {
          data1.changePharmacy(data1.recipe_tabs[data1.recipe_tabs_c].lastType);
        }, 500);
      }, 1000);
    },
    // 获取下拉列表信息
    async getSelectType(data) {
      let res = await getSelectType(data);
      if (res.ResultCode == 0) {
        if (data == "剂型") {
          this.doseTypeList = res.Data;
        } else if (data == "处方用法") {
          this.recipeUseList = res.Data;
        } else if (data == "中药频次") {
          this.timesList = res.Data;
        } else if (data == "中药药品用法") {
          this.useList = res.Data;
        } else if (data == "中药服药时间") {
          this.useTimeList = res.Data;
        }
      }
    },
    // 修改专家经验
    async editExperince() {
      let children = this.$children.filter(item => {
        return item.name == "中药处方";
      });

      let data1 = children[0];
      let prescriptionDetailVos = this.dealTableData();
      let colorRed = false;
      this.totalTableD.forEach(item => {
        if (item.color == "red") {
          colorRed = true;
        }
      });

      if (colorRed) {
        this.$message({
          type: "error",
          message: "部分药品不存在,请重新选择",
          showClose: true
        });

        return;
      }

      if (prescriptionDetailVos === false) return;
      let TCMParams = this.$refs.TCM.getParams();
      let params = {
        curetype: this.form.doseType,
        diseaseid: TCMParams.disid,
        diseasename: TCMParams.namemedicine,
        effect: this.form.efficacy,
        expert: this.form.experts,
        experttitle: this.form.titles,
        isupdate: this.form.switch ? 0 : 1,
        name: this.form.name,
        // pharmacyid: this.pharmacyID,
        pharmacyid: data1.recipe_tabs[data1.recipe_tabs_c].pharmacyID, // 药房id 暂时写死
        prescriptiontype: this.form.cMedType,
        solution: this.form.solution,
        symptomid: TCMParams.symptomid,
        symptomname: TCMParams.syndrometypes,
        prescriptionDetailVos,
        treatment: TCMParams.treatment,
        pid: this.$route.query.pid
      };

      let res = await editExperince(params);
      if (res.ResultCode == 0) {
        this.$message({
          type: "success",
          message: "修改成功",
          showClose: true
        });
        setTimeout(() => {
          this.$router.back();
        }, 2000);
      } else {
        this.$message({
          type: "error",
          message: res.ResultInfo,
          showClose: true
        });
      }
    },
    // 添加专家经验
    async addExperince() {
      let children = this.$children.filter(item => {
        return item.name == "中药处方";
      });

      let data1 = children[0];
      let prescriptionDetailVos = this.dealTableData();
      let colorRed = false;
      this.totalTableD.forEach(item => {
        if (item.color == "red") {
          colorRed = true;
        }
      });

      if (colorRed) {
        this.$message({
          type: "error",
          message: "部分药品不存在,请重新选择",
          showClose: true
        });

        return;
      }

      if (prescriptionDetailVos === false) return;
      let TCMParams = this.$refs.TCM.getParams();
      let params = {
        curetype: this.form.doseType,
        diseaseid: TCMParams.disid,
        diseasename: TCMParams.namemedicine,
        effect: this.form.efficacy,
        expert: this.form.experts,
        experttitle: this.form.titles,
        isupdate: this.form.switch ? 0 : 1,
        name: this.form.name,
        // pharmacyid: this.pharmacyID,
        pharmacyid: data1.recipe_tabs[data1.recipe_tabs_c].pharmacyID, // 药房id 暂时写死
        prescriptiontype: this.form.cMedType,
        solution: this.form.solution,
        symptomid: TCMParams.symptomid,
        symptomname: TCMParams.syndrometypes,
        prescriptionDetailVos,
        treatment: TCMParams.treatment
      };
      let res = await addExperince(params);
      if (res.ResultCode == 0) {
        this.$message({
          type: "success",
          message: "保存成功",
          showClose: true
        });
        setTimeout(() => {
          this.$router.back();
        }, 2000);
      } else {
        this.$message({
          type: "error",
          message: res.ResultInfo,
          showClose: true
        });
      }
    },
    // 通过中药类型获取药房id
    async getPharmacyID() {
      return;
      let res = await getPharmacyID({
        type: this.form.cMedType
      });
      if (res.ResultCode == 0) {
        if (res.ResultInfo == "") {
          this.$message({
            showClose: true,
            message: "当前类型无法开药,请切换类型",
            type: "error"
          });
          return;
        }

        this.pharmacyID = res.ResultInfo;
      }
    },
    // 获取中医病名数据
    async getCDiseaseName(key, serchtype = "") {
      let params = {
        pageid: 1,
        pagesize: 9999,
        serchtype,
        keyword: key
      };
      let res = await getCDiseaseName(params);
      if (res.code == 0) {
        this.cmNameList = res.data.diseases;
      }
    },
    // 主诊断证型搜索
    async searchZhengxing(key, cb) {
      let pinyin = /^[A-Za-z]+$/g;
      if (pinyin.test(key)) {
        await this.getCCardType(this.form.cmNameID, "", key, "1");
      } else {
        await this.getCCardType(this.form.cmNameID, "", key, "");
      }

      if (this.cardTypeList.length > 0) {
        let resault = [];
        this.cardTypeList.forEach(item => {
          let obj = {
            value: item.symname,
            id: item.symid,
            therapys: item.therapys
          };
          resault.push(obj);
        });
        cb(resault);
      } else {
        cb([
          {
            value: "搜索不到数据"
          }
        ]);
      }
    },
    // 获取中医证型
    async getCCardType(id, index = "", key = "", serchtype = "") {
      let params = {
        pageid: 1,
        pagesize: 9999,
        disid: serchtype == 1 ? "" : id,
        serchtype,
        keyword: key
      };
      let res = await getCCardType(params);

      if (res.code == 0) {
        if (index === "") {
          this.cardTypeList = res.data.sysptoms;
        }
      }
    },
    // 切换中药类型时 切换 药房 获取 药品里面有没有这条数据
    async changePharmacy(type) {
      let drugIds = [];

      this.totalTableD.forEach(item => {
        if (item.name) {
          item.oldDose = CC_Dosage2Basis(item);
          let idDose = item.medid + "&" + item.oldDose;
          // drugIds.push(item.medid)
          drugIds.push(idDose);
        }
      });
      let pharmacyName = "";
      let type1 = 0;
      this.pharmacyList.forEach(item => {
        if (item.pid == this.pharmacyID) {
          pharmacyName = item.pharmacyName;
        }
      });
      if (this.form.cMedType == 0) {
        if (pharmacyName.indexOf("饮片") != -1) {
          type1 = 0;
        } else if (pharmacyName.indexOf("颗粒") != -1) {
          type1 = 1;
        }
      } else {
        if (pharmacyName.indexOf("饮片") != -1) {
          type1 = 2;
        } else if (pharmacyName.indexOf("颗粒") != -1) {
          type1 = 3;
        }
      }
      let params = {
        type: type1,
        pharmacyid: this.pharmacyID,
        drugIds,
        preType: "",
        oldType: type
      };
      let res = await changePharmacy(params);
      if (res.ResultCode == 0) {
        this.totalTableD.forEach((item1, index1) => {
          if (item1.name) {
            res.Data.forEach((item, index) => {
              if (item == item1.medid) {
                item1.color = "red";
              }

              // console.log(item instanceof Object);
              if (item instanceof Object && item.oldYpid == item1.medid) {
                item1.id = 2;
                item1.name = item.ypmc;
                item1.spec = item.gg; // 规格
                item1.dose = item.dose; // 剂量
                item1.unit = item.dw; // 单位
                // usage: item.usagestr, // 用法
                item1.usage = "";
                item1.price = item.lsjg;
                item1.total = 0;
                item1.inventory = item.kc; // 库存
                item1.key = "";
                item1.search_i = index;
                item1.medid = item.pid; // 药品id
                item1.originname = item.cdmc; // 产地名称
                item1.showSearch = false;

                item1.color = "#000";
                item1.ggnum = +item.ggnum || 1;
                item1.xbzxs = +item.xbzxs || '34'.includes(item.zylx) ? item1.ggnum : 1;
              }

              this.$set(this.totalTableD, index1, item1);
            });
          }
        });
        this.totalTableD.filter((item, index) => {
          this.getSelectType("中药药品用法", index);
          return (item.id = index + 1);
        });
        this.totalTableD.filter((item, index) => {
          return item.id % 2 != 0;
        });
        this.totalTableD.filter((item, index) => {
          return item.id % 2 == 0;
        });

        // this.form.lastType = this.form.cMedType // 存储这一次的 药房类型
        this.form.lastType = type1;
        // console.log(this.recipe_tabs[this.recipe_tabs_c].totalTableD);
      }
    }
  }
};
</script>
<style lang="scss" scoped>
@import "../../style/common.scss";

.accordEdit {
  padding: 10px 10px;
  background: #ffffff;
  border-radius: 5px;
  height: 99%;
  overflow: auto;
  box-sizing: border-box;

  .back {
    width: 74px;
    height: 36px;
    background: #5386f6;
    border-radius: 4px;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #ffffff;
    margin-bottom: 49px;
    cursor: pointer;
  }

  .item {
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #333;
    margin-right: 62px;
    margin-bottom: 10px;

    span {
      color: #ff3a3a;
    }

    .input {
      width: 260px;
    }
  }

  .bottom {
    .title {
      margin-bottom: 10px;
    }
  }

  .save {
    width: 74px;
    height: 36px;
    background: #ffae45;
    border-radius: 4px;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #ffffff;
    cursor: pointer;
  }
}
</style>