<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <div class="query-box">
        <div class="query-box__left">
          <el-form-item label="" prop="yljgId">
            <el-select
              style="width:160px"
              v-model="queryParams.yljgId"
              placeholder="请选择医疗机构"
            >
              <el-option
                v-for="item in listMedicalMechanismArr"
                :key="item.id"
                :value="item.id"
                :label="item.name"
                :disabled="item.state == 1 ? false : true"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="" prop="preNo">
            <el-input
              style="width:160px"
              v-model="queryParams.preNo"
              placeholder="请输入处方号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item label="" prop="name">
            <el-input
              style="width:160px"
              v-model="queryParams.name"
              placeholder="请输入患者姓名"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item label="" prop="prescriptionTime">
            <el-date-picker
              style="width:260px"
              clearable
              size="small"
              v-model="queryParams.prescriptionTime"
              type="daterange"
              value-format="yyyy-MM-dd"
              start-placeholder="开方开始时间"
              end-placeholder="开方结束时间"
            >
            </el-date-picker>
          </el-form-item>

          <el-form-item label="" prop="thread">
            <el-select v-model="queryParams.thread" placeholder="请选择处方状态"
              style="width:160px">
              <el-option
                v-for="item in deployStateArr"
                :key="item.id"
                :value="item.id"
                :label="item.name"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </div>
      </div>
    </el-form>


    <el-table
      v-loading="loading"
      :data="prescriptionCoreList"
      @selection-change="handleSelectionChange"
      border
      size="mini"
    >
      <el-table-column type="index" width="55" align="center" label="序号"/>
      <el-table-column label="处方号" align="center" prop="preNo" />
      <el-table-column label="医疗机构" align="center" prop="yijgName" />
      <el-table-column label="门诊/住院" align="center" prop="premzzy">
        <template slot-scope="scope">{{scope.row.preMzZy==1?'门诊':'住院'}}</template>
      </el-table-column>
      <el-table-column label="患者姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="临床诊断" align="center" prop="disName">
        <template slot-scope="scope">
          {{ scope.row.disName + "-" + scope.row.symName}}
        </template>
      </el-table-column>
      <el-table-column label="开方医生" align="center" prop="doctor" />
      <el-table-column label="处方名称" align="center" prop="preName" />
      <el-table-column label="处方类型" align="center" prop="type">
        <template slot-scope="scope">
          {{ scope.row.type === 1 ? "中药制剂" : "中药处方" }}
        </template>
      </el-table-column>
      <el-table-column
        label="开方时间"
        align="center"
        prop="prescriptionTime"
        width="180"
      >
        <template slot-scope="scope">
<!--          // parseTime(scope.row.prescriptionTime, "{y}-{m}-{d}")-->
          <span>{{
            scope.row.prescriptionTime
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="溯源状态" align="center" prop="thread">
        <template slot-scope="scope">
          <dict-tag :options="deployStateArr" :value="scope.row.thread" />
        </template>
      </el-table-column>

<!--      <el-table-column label="备注" align="center" prop="remarks" />-->
      <el-table-column label="审核人" align="center" prop="checkBy" />
      <el-table-column label="审核时间" align="center" prop="checkTime" />

      <el-table-column
        label="操作"
        fixed="right"
        align="center"
        width="180"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            style="width: 40px"
            @click="handleUpdate(scope.row)"
            >详情</el-button
          >
          <el-button
            size="mini"
            class="printbtn"
            style="width: 40px"
            @click="consoleBtn(scope.row)"
            v-if="scope.row.checkState == 1"
          >打印</el-button
          >

<!--          v-hasPermi="['prescription:prescriptionCore:edit']"-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改处方审核对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1280px"
      append-to-body
    >
      <div>
        <div style="display: flex; align-items: center;margin-bottom:20px;">
          <h3>处方信息</h3>
          <div style="margin: 0 0 0 30px">处方号：{{detailData.preNo}}</div>
        </div>

        <el-divider></el-divider>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-descriptions title="" :column="5">
              <el-descriptions-item label="患者姓名">{{
                detailData.name
              }}</el-descriptions-item>
              <el-descriptions-item label="性别">{{
                detailData.sex
              }}</el-descriptions-item>
              <el-descriptions-item label="年龄">{{
                detailData.age
              }}</el-descriptions-item>
              <el-descriptions-item label="科室">{{
                detailData.department
              }}</el-descriptions-item>
              <el-descriptions-item label="临床诊断">
                {{detailData.disName}}-{{detailData.symName}}
              </el-descriptions-item>
              <el-descriptions-item label="开方医生">{{
                detailData.doctor
              }}</el-descriptions-item>
              <el-descriptions-item label="处方类型">{{
                detailData.type == 1 ? "中药处方" : "中药制剂"
              }}</el-descriptions-item>
              <el-descriptions-item label="发药状态">{{ detailData.fyState == 0 ? "未发药": detailData.fyState==1?'已发药' : "取消发药" }}</el-descriptions-item>
              <el-descriptions-item label="煎药方式">{{
                detailData.oralPre && detailData.oralPre.decoctingMethod
              }} <span v-if="detailData.oralPre && detailData.oralPre.decoctingMethod=='浓煎'">{{detailData.oralPre && detailData.oralPre.concentration}}</span></el-descriptions-item>

              <el-descriptions-item label="处方金额">{{
                detailData.type == 1
                  ? detailData.oralPre &&
                    detailData.oralPre.prescriptionTotleSum
                  : detailData.solidPre &&
                    detailData.solidPre.prescriptionTotleSum
              }}</el-descriptions-item>
              <el-descriptions-item label="剂型">{{
                detailData.oralPre && detailData.oralPre.dosageForm
              }}</el-descriptions-item>
              <el-descriptions-item label="剂数">{{
                detailData.oralPre && detailData.oralPre.number
              }}</el-descriptions-item>
              <el-descriptions-item label="代煎剂数">{{
                detailData.oralPre && detailData.oralPre.daijianNumber
              }}</el-descriptions-item>
              <el-descriptions-item label="代煎费用">{{
                detailData.oralPre && detailData.oralPre.daijianCost
              }}</el-descriptions-item>
              <el-descriptions-item label="处方用法">{{
                detailData.oralPre && detailData.oralPre.prescriptionusage
              }}</el-descriptions-item>
              <el-descriptions-item label="服药时间">{{
                detailData.oralPre && detailData.oralPre.medicationTime
              }}</el-descriptions-item>
              <el-descriptions-item label="频次">{{
                detailData.oralPre && detailData.oralPre.frequency
              }}</el-descriptions-item>
              <el-descriptions-item label="快递单号">{{
                detailData.expressCode
              }}</el-descriptions-item>
              <el-descriptions-item label="收件人">{{
                detailData.consignee
              }}</el-descriptions-item>
              <el-descriptions-item label="收货电话">{{
                detailData.contactNumber
              }}</el-descriptions-item>
              <el-descriptions-item label="配送费用">{{
                detailData.oralPre && detailData.oralPre.distributionCost
              }}</el-descriptions-item>
              <el-descriptions-item label="总金额">{{
                detailData.oralPre && detailData.oralPre.prescriptionTotleSum
              }}</el-descriptions-item>
            </el-descriptions>
            <el-descriptions>
              <el-descriptions-item label="嘱托">{{
                detailData.oralPre && detailData.oralPre.entrust
              }}</el-descriptions-item>
            </el-descriptions>
            <el-descriptions>
              <el-descriptions-item label="收货地址">{{
                detailData.address
              }}</el-descriptions-item>
            </el-descriptions>
          </el-col>
          <el-col :span="24">
            <el-table
              v-loading="loading"
              :data="detailData && detailData.oralPreItemList"
              @selection-change="handleSelectionChange"
            >
              <el-table-column type="index" width="55" align="center" />
              <el-table-column label="药品名称" align="center" prop="matName" />
              <el-table-column
                label="药品规格"
                align="center"
                prop="ypggCenter"
              />
              <el-table-column label="单位" align="center" prop="matUnitName" />
              <el-table-column label="用法" align="center" prop="matUsageName" />
              <el-table-column label="剂量" align="center" prop="matDose" />
              <el-table-column label="零售价" align="center" prop="matXsj" />
              <el-table-column label="产地" align="center" prop="matOrigin" />
              <el-table-column
                label="小计"
                align="center"
                prop="subtotalMoney"
              />
              <!-- <el-table-column label="库存数量" align="center" prop="stock" /> -->
            </el-table>
          </el-col>
        </el-row>

        <h3 style="margin: 60px 0 0 0">溯源记录</h3>
        <div style="display:flex;flex-wrap:wrap;align-items:center;margin-top:20px">
          <div style="display:flex;margin: 0 10px 5px 0" v-for="item in deployStateArr">
            <el-tag
              v-if="detailData && detailData[item.key] && detailData[item.key].length>0"
              :key="item.id"
              class="mx-1"
              :effect="item.key==currentDepoly?'dark':'plain'"
              @click.native="handleDeploy(item)"
            >
              {{ item.name }}
            </el-tag>
            <i v-if="detailData && detailData[item.key] && detailData[item.key].length" class="el-icon-arrow-right el-icon--right" style="display:flex;align-items:center;"></i>
          </div>
        </div>
        <el-divider></el-divider>
        <div class="deploy-record" v-if="depolyStatusObj.createTime">
          <div class="deploy">
            <div class="content" v-if="depolyStatusObj.createTime">
              <div class="title body">操作时间：</div>
              <div class="body">{{ depolyStatusObj.createTime }}</div>
<!--              <div class="body" v-else> </div>-->
            </div>
            <div class="content" v-if="depolyStatusObj.operateType && currentDepoly">
              <div class="title body">操作模式：</div>
              <div class="body" v-if="depolyStatusObj.operateType">{{ (currentDepoly == 'audited' || currentDepoly == 'reviewed' || currentDepoly == 'cooked')?'人工':depolyStatusObj.operateType=='0'?'自动化':'人工' }}</div>
              <div class="body" v-else> </div>
            </div>
            <div class="content" v-if="(currentDepoly == 'audited' || currentDepoly == 'reviewed' || currentDepoly == 'cooked') || depolyStatusObj.operateType!=='0' && depolyStatusObj.createBy">
              <div class="title body">操作人：</div>
              <div class="body" v-if="depolyStatusObj.createBy">{{ depolyStatusObj.createBy }}</div>
              <div class="body" v-else> </div>
            </div>
            <div class="content" style="justify-content: flex-start;"  v-if="currentDepoly == 'reviewed' && depolyStatusObj.dosage">
              <div class="title body">复核重量：</div>
              <div class="body" v-if="depolyStatusObj.dosage">{{ depolyStatusObj.dosage }}</div>
              <div class="body" v-else> </div>
            </div>
            <div class="content" style="justify-content: flex-start;"  v-if="(currentDepoly !== 'audited' && currentDepoly !== 'reviewed' && currentDepoly !== 'cooked') && depolyStatusObj.operateType=='0' && depolyStatusObj.deviceNo">
              <div class="title body">设备编号：</div>
              <div class="body" v-if="depolyStatusObj.deviceNo">{{ depolyStatusObj.deviceNo }}</div>
              <div class="body" v-else> </div>
            </div>
            <div class="content"  v-if="(currentDepoly == 'audited' || currentDepoly == 'allocated' || currentDepoly == 'reviewed' || currentDepoly == 'soaked' || currentDepoly == 'cooked') || depolyStatusObj.operateType!=='0' && depolyStatusObj.remarks">
              <div class="title body">备注信息：</div>
              <div class="body" v-if="depolyStatusObj.remarks">{{ depolyStatusObj.remarks }}</div>
              <div class="body" v-else> </div>
            </div>
            <div class="content"  v-if="depolyStatusObj.dosage && depolyStatusObj.operateType=='0' && currentDepoly == 'startedConcentration' && depolyStatusObj.dosage">
              <div class="title body">开始浓缩药液量：</div>
              <div class="body" v-if="depolyStatusObj.dosage">{{ depolyStatusObj.dosage }}</div>
              <div class="body" v-else> </div>
            </div>
            <div class="content"  v-if="depolyStatusObj.dosage && depolyStatusObj.operateType=='0' && currentDepoly == 'finishedConcentration' && depolyStatusObj.dosage">
              <div class="title body">结束浓缩药液量：</div>
              <div class="body" v-if="depolyStatusObj.dosage">{{ depolyStatusObj.dosage }}</div>
              <div class="body" v-else> </div>
            </div>
          </div>

         <div class="deploy" v-if="depolyStatusObj&& depolyStatusObj.imgs &&depolyStatusObj.imgs.length>0" style="justify-content:flex-start;"> <!-- v-if="depolyStatusObj&&depolyStatusObj.prescriptionFiles&&depolyStatusObj.prescriptionFiles.length>0"-->
            <div class="content">
              <div class="title body">照片：</div>
              <div class="body" style="height: 100px!important;" v-if="depolyStatusObj">
                <el-image v-for="img in depolyStatusObj.imgs"
                          style="width: 100px; height: 100px; padding-right: 10px;"
                          :src="img"
                          fit="fill"></el-image>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :title="title"
      :visible.sync="openPrint"
      width="1280px"
      append-to-body
    >
      <div style="display: flex;padding: 10px;">
        <div style="display: flex;width: 170px;flex-direction: column;align-items: center;border-right: 1px solid #1ab394;">
          <div style="display: flex;justify-content: center;align-items: center;height: 50px;width: 150px;font-size: 25px;padding: 10px;color: #1ab394;"
               v-for="item in printType" :key="item.id"
               @click="handlePrintType(item)"
               :class="activePrint===item.name?'active':''" >{{item.name}}</div>
        </div>

        <div style="display: flex;flex-direction: column;justify-content:center;align-items:center;width: 1120px;">
          <div class="print" id="deloy">



            <!-- 20231219更改 -->
            <div style="display: flex;flex-direction: column;width:460px;height: 250px;"  v-if="activePrint==='标签'">
              <div style="font-size: 25px;font-weight: 500;display: flex;justify-content:center;margin-top:20px;">{{detailData.yljgName || '默默事中医院取药标签打印(门诊)'}}(取药凭条)</div>
              <div style="display: flex;margin-top: 15px;">
                <div style="display: flex;flex-direction: column;justify-content:center;">
                  <JsBarcode v-if="openPrint"
                    :presno="curPreNo" style="margin-top:15px;"
                  ></JsBarcode>
                </div>
                <div style="display: flex;flex-direction: column;margin-top:12px;">
                  <div style="display: flex;font-size: 23px;">患者:<div style="font-weight: 500;">{{curName}}，{{curSex}}</div></div>
                  <div style="display: flex;font-size: 20px;margin-top:5px;">出生日期:<div style="font-weight: 500;">{{curPatientBirthday}}</div></div>
                  <div style="display: flex;font-size: 20px;margin-top:5px;">类型:<div style="font-weight: 500;">{{curPreName}}</div></div>
                  <div style="display: flex;font-size: 20px;margin-top:5px;">剂数:<div style="font-weight: 500;font-size:24px;margin-top:-1px;">{{curNumber}}</div></div>
                </div>
              </div>
              <div style="display: flex;justify-content:center;font-size: 20px;margin-top:30px;">打印时间:{{curPrintTime}}</div>
            </div>

            <div v-else style="display: flex;margin: 5px;background-color: #fff;flex-direction:column;align-items: center;height: 1030px;width: 680px;box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);">
              <div style="display: flex;flex-direction:column;width: 660px;">
                <div style="display: flex;flex-direction:row;justify-content: space-between;margin-top: 15px;">
                  <div style="display: flex;align-items: flex-start;border-right:0!important;">
                    <div style="display: flex;flex-direction:column;">
                      <JsBarcode
                        :presno="curPreNo"
                      ></JsBarcode>
                    </div>
                  </div>
                  <div style="display: flex;justify-content:center;align-items:center;margin-right: 150px;font-size: 23.75px;font-weight: 800;">
                    中药处方笺
                  </div>
                  <div style="display: flex;justify-content:center;font-size: 16px;width: 40px;font-weight: 300;">{{detailData.type=='1'?"中药处方":detailData.type=='2'?"中药制剂":""}}</div>
                </div>
                <div style="display: flex;flex-direction:column;margin: 20px 10px 10px;padding-bottom: 15px;border-bottom: 1px solid #979797;">
                  <div style="display: flex;flex-direction:row;margin-bottom:5px;">
                    <div style="font-size: 12px;font-weight: 400;margin-right: 30px;"><span style="color:#999999;">姓名：</span>{{detailData.name}}</div>
                    <div style="font-size: 12px;font-weight: 400;margin-right: 30px;"><span style="color:#999999;">性别：</span>{{detailData.sex}}</div>
                    <div style="font-size: 12px;font-weight: 400;margin-right: 30px;"><span style="color:#999999;">年龄：</span>{{detailData.age}}岁</div>
                    <div style="font-size: 12px;font-weight: 400;margin-right: 30px;"><span style="color:#999999;">电话：</span>{{detailData.contactNumber}}</div>
                    <div style="font-size: 12px;font-weight: 400;margin-right: 30px;"><span style="color:#999999;">当前处方状态：</span>{{detailData.state=="1"?"配药":detailData.state=="2"?"煎药":detailData.state=="3"?"发药":detailData.state=="4"?"配送":""}}</div>
                  </div>
                  <div style="display: flex;flex-direction:row;margin-bottom:5px;">
                    <div style="font-size: 12px;font-weight: 400;margin-right: 30px;"><span style="color:#999999;">就诊科室：</span>{{detailData.department}}</div>
                    <div style="font-size: 12px;font-weight: 400;margin-right: 30px;"><span style="color:#999999;">临床诊断：</span>{{detailData.disName}}—{{detailData.symName}}</div>
                    <div style="font-size: 12px;font-weight: 400;margin-right: 30px;"><span style="color:#999999;">开方时间：</span>{{detailData.prescriptionTime}}</div>
                  </div>
                  <div style="display: flex;flex-direction:row;font-size: 12px;"><span style="color:#999999;">联系地址：</span>{{detailData.address}}</div>
                </div>
              </div>
              <div style="display: flex;flex-direction:column;width: 640px;align-items:flex-start;border-bottom: 1px solid #5a5e66;margin:0px 10px 10px;">
                <div style="display: flex;font-size: 22px;">
                  Rp:
                </div>
                <div style="display: flex;flex-wrap: wrap;flex-direction: row;justify-content:flex-start;align-content:flex-start;margin-left:20px;height: 515px;">
                  <div style="display: flex;justify-content:center;width: 150px;align-items: center;margin: 0 0 10px 0;" v-for="(x, i) in detailData.detailList" :key="i">
                    <div style="display: flex;font-size: 15px;width: 100px;word-wrap: break-word;z-index: 100;justify-content:center;align-items: center;padding: 2px 5px;">
                      <!--                      <el-tag effect="plain" >{{x.matName}} {{x.matDose}} {{x.matUnitName}}</el-tag>-->
                      {{x.matName}}{{x.matDose}}{{x.matUnitName}}
                    </div>
                    <div style="display: flex;flex-direction:column;margin-left: 5.31px;z-index: 200;">
                      <div style="font-size: 10px;height: 12.5px;"> {{x.matUsageName}}</div>
                      <div style="font-size: 10px;height: 12.5px;"> {{x.sign}}</div>
                    </div>
                  </div>
                </div>
                <div style="margin: 0 10px 10px;display: flex;font-size: 15px;">
                  <div style="display: flex;margin-right: 54.4px;">
                    剂数：{{detailData.number}}
                    <div v-if="detailData.daijianCost!==''" class="pies_tips">
                      (代煎)
                    </div>
                  </div>
                  <div style="display: flex;margin-right: 54.4px;">{{detailData.dosageForm}}</div>
                  <div style="display: flex;margin-right: 54.4px;">{{detailData.prescriptionUsage}}</div>
                  <div style="display: flex;margin-right: 54.4px;">每次{{detailData.concentration}}</div>
                  <div style="display: flex;margin-right: 54.4px;">{{detailData.frequency}}</div>
                  <div >{{detailData.medicationTime}}</div>
                </div>
                <div style="display: flex;justify-content:flex-end;font-size: 15px;margin-right: 10px;">{{detailData.entrust}}</div>
              </div>
              <div style="display: flex;margin: 0 10px 0;padding-bottom: 5px;border-bottom: 1px solid #979797;">
                <div style="display: flex;flex-direction:column;">
                  <div style="border: 1px solid #979797;font-size: 15px;width: 287.5px;display: flex;justify-content:center;align-items: center;height: 30px;">
                    <div class="pijw">药品金额：{{detailData.prescriptionSum}}</div>
                  </div>
                  <div style="display: flex;justify-content:center;align-items: center;font-size: 15px;height: 30px;width: 287.5px;border-left: 1px solid #979797;border-right: 1px solid #979797;">
                    <div style="width: 143.93px;display: flex;justify-content:center;align-items: center;height: 30px;">煎药费：{{detailData.daijianCost}}</div>
                    <div style="border-left: 1px solid #979797;width: 143.93px;display: flex;justify-content:center;align-items: center;height: 30px;">配送费：{{detailData.distributionCost}}</div>
                  </div>
                  <div style="display: flex;justify-content:center;align-items: center;height: 30px;font-size: 15px;border: 1px solid #979797;">
                    总金额：{{detailData.prescriptionTotalSum}}
                    <!-- <div class="zjw"></div> -->
                  </div>
                </div>
                <div style="display: flex;flex-wrap: wrap;margin-left: 20px;">
                  <div style="font-size: 15px;margin-right: 60px;width:90px;"><span style="font-size: 15px;color:#999999;">开方：</span>{{operateList[0].operater}}</div>
                  <div style="font-size: 15px;margin-right: 60px;width:90px;"><span style="font-size: 15px;color:#999999;">审核：</span>{{operateList[1].operater}}</div>
                  <div style="font-size: 15px;margin-right: 60px;width:90px;"><span style="font-size: 15px;color:#999999;">调配：</span>{{operateList[2].operater}}</div>
                  <div style="font-size: 15px;margin-right: 60px;width:90px;"><span style="font-size: 15px;color:#999999;">复核：</span>{{operateList[3].operater}}</div>
                  <div style="font-size: 15px;margin-right: 60px;width:90px;"><span style="font-size: 15px;color:#999999;">浸泡：</span>{{operateList[4].operater}}</div>
                  <div style="font-size: 15px;margin-right: 60px;width:90px;"><span style="font-size: 15px;color:#999999;">煎煮：</span>{{operateList[5].operater}}</div>
                  <div style="font-size: 15px;margin-right: 60px;width:90px;"><span style="font-size: 15px;color:#999999;">打包：</span>{{operateList[6].operater}}</div>
                  <div style="font-size: 15px;margin-right: 60px;width:90px;"><span style="font-size: 15px;color:#999999;">发药：</span>{{operateList[7].operater}}</div>
                </div>
              </div>
              <div style="margin: 10px 16px 10px;font-size: 15px;display: flex;">
                <div class="z">注：</div>
                <div>{{entrust1111}}</div>
              </div>
            </div>
          </div>
          <el-button style="margin-top: 50px;display: flex;justify-content:center;align-items:center;background-color: #1ab394;color: #FFFFFF;font-size: 20px;margin-top: 40px;width: 300px;height: 50px;" v-print="'#deloy'">打 印</el-button>
        </div>

      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listPrescriptionCore,
  getPrescriptionCore,
  delPrescriptionCore,
  addPrescriptionCore,
  updatePrescriptionCore,
  exportPrescriptionCore,
} from "@/api/prescription/prescriptionCore";

import { listMedicalMechanism } from "@/api/medical/mechanism";
import {selectOrderDetail} from "@/api/prescription/prescriptionAudit";

import JsBarcode from "@/components/JsBarcode/index.vue";
import Pres from "@/components/Pres/index.vue";
import dayjs     from 'dayjs'

export default {
  name: "PrescriptionCore",
  components:{ JsBarcode,},
  data() {
    const now = dayjs().format('YYYY-MM-DD');
    return {
      curPreNo:'',
      curName:'',
      curSex:'',
      curAge:'',
      curPatientBirthday:'',
      //20231219新增三个字段
      curPreName:'',
      curNumber:'',
      curPrintTime:'',

      $baseUrl: this.$baseUrl,
      detailData: {
        oralPre: {
          oralPreItemList: []
        }
      },
      activeName: "first",

      // print相关
      openPrint: false,
      activePrint: '标签',
      printType:[
        {name:'标签', id:0},
        {name:'中药处方笺', id:1}
      ],

      operateList:[
        {py:'kf',title:'开方',operater:''},
        {py:'sh',title:'审核',operater:''},
        {py:'tp',title:'调配',operater:''},
        {py:'fh',title:'复核',operater:''},
        {py:'jp',title:'浸泡',operater:''},
        {py:'jz',title:'煎煮',operater:''},
        {py:'db',title:'打包',operater:''},
        {py:'fy',title:'发药',operater:''},
      ],

      entrust1111:'1、本处方当日有效\n  2、取药时请您当面核对。。。。 \n  3、延长处方用量时间原油：慢性病 其他老年病 外地 其他',

      state: {
        1: "配药",
        2: "煎药",
        3: "发药",
        4: "配送",
      },
      stateArr: [
        { name: "配药", id: 1 },
        { name: "煎药", id: 2 },
        { name: "发药", id: 3 },
        { name: "配送", id: 4 },
      ],
      deployStateArr: [
        { name: "已审核", id: 110, key: "audited" },
        // { name: "已审核不通过", id: 120, key: "---" },
        { name: "已调配", id: 130, key: "allocated" },
        { name: "已复核", id: 140, key: "reviewed" },
        { name: "已浸泡", id: 150, key: "soaked" },
        { name: "已煎煮", id: 160, key: "cooked" },
        { name: "已先煎", id: 161, key: "preCooked" },
        { name: "已开始煎煮", id: 162, key: "startedCooking" },
        { name: "已后下", id: 163, key: "lowered" },
        { name: "已结束煎煮", id: 164, key: "finishedCooking" },
        { name: "已开始浓缩", id: 165, key: "startedConcentration" },
        { name: "已结束浓缩", id: 166, key: "finishedConcentration" },
        { name: "已打包", id: 170, key: "packaged" },
        { name: "已上架", id: 171, key: "grounding" },
        { name: "已发药", id: 175, key: "send" },
        // { name: "煎药已作废", id: 999, key: "---" },
      ],
      depolyStatusObj:{
        type:'',
        createTime:'',
        operate:'',
        createBy:'',
        urls:'',
        remarks:'',
        deviceNo:'',
        dosage:''
      },
      effectStatus:'plain',
      currentDepoly:'audited',
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 处方审核表格数据
      prescriptionCoreList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        notCheckState: 0,
        pageNum: 1,
        pageSize: 10,
        state: null,
        thread: null,
        appId: null,
        yljgId: null,
        timeStamp: null,
        token: null,
        preNo: null,
        preName: null,
        name: null,
        sex: null,
        age: null,
        department: null,
        doctor: null,
        prescriptionTime: [now, now],
        disCode: null,
        disName: null,
        symCode: null,
        symName: null,
        westernDisease: null,
        westernCode: null,
        patientContent: null,
        nowDesc: null,
        pastDesc: null,
        fourDiagnosis: null,
        physical: null,
        auxiliaryExam: null,
        premzzy: null,
        visitNo: null,
        checkState: null,
        remarks: null,
        extendedTxt: null,
        address: null,
        contactNumber: null,
        consignee: null,
        takingMethod: null,
        yfId: window.localStorage.getItem("pharmacyId"),
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      listMedicalMechanismArr: [],
    };
  },
  created() {
    this.getList();
    this.getListMedicalMechanism();
    this.currentDepoly = 'audited';
  },
  methods: {
    handleClick(tab, event) {
      //console.log(tab, event);
    },
    /** 查询处方审核列表 */
    getList() {
      this.loading = true;
      console.log('this.queryParams',this.queryParams)
      var form = Object.assign({}, this.queryParams)
      if (this.queryParams.prescriptionTime && this.queryParams.prescriptionTime.length) {
        form.startTime = this.queryParams.prescriptionTime[0]
        form.endTime = this.queryParams.prescriptionTime[1]
      } else {
        form.startTime = ''
        form.endTime = ''
      }
      delete form.prescriptionTime
      listPrescriptionCore(form).then((response) => {
        this.prescriptionCoreList = response.rows;
        this.total = response.total;
        this.loading = false;

      });
    },
    getListMedicalMechanism() {
      listMedicalMechanism().then((res) => {
        this.listMedicalMechanismArr = res.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.curPreNo = ''
      this.curName = ''
      this.curSex = ''
      this.curAge = ''
      this.curPatientBirthday = ''
      //20231219新增三个字段
      this.curPreName=''
      this.curNumber=''
      this.curPrintTime=''
      this.detailData = {
        oralPre: {
          oralPreItemList: []
        }
      },
      this.form = {
        id: null,
        appId: null,
        yljgId: null,
        yfId: null,
        timeStamp: null,
        token: null,
        preNo: null,
        preName: null,
        name: null,
        sex: null,
        age: null,
        department: null,
        doctor: null,
        prescriptionTime: null,
        disCode: null,
        disName: null,
        symCode: null,
        symName: null,
        westernDisease: null,
        westernCode: null,
        patientContent: null,
        nowDesc: null,
        pastDesc: null,
        fourDiagnosis: null,
        physical: null,
        auxiliaryExam: null,
        premzzy: null,
        visitNo: null,
        checkState: null,
        remarks: null,
        extendedTxt: null,
        address: null,
        contactNumber: null,
        consignee: null,
        takingMethod: null,
      };
      this.remarks = null;
      this.resetForm("form");
    },
    //打印
    consoleBtn(row) {

      this.reset();
      this.activePrint = '标签'
      const id = row.id;
      console.log('id>>>>',id)
      this.detailData = {}
      selectOrderDetail({id:id}).then((response) => {
        console.log('response.data>>>>', response.data)
        // debugger
        this.form = response.data;
        this.detailData = response.data;
        this.curPreNo = response.data.preNo;
        this.curName = response.data.name;
        this.curSex = response.data.sex;
        this.curAge = response.data.age;
        this.curPatientBirthday = response.data.patientBirthday;
        //20231219新增三个字段
        this.curPreName = response.data.preName;
        this.curNumber = response.data.number;
        this.curPrintTime = response.data.printTime;

        this.detailData.patientBirthday = this.detailData.patientBirthday?this.detailData.patientBirthday:'';
        this.detailData.presType = '普通处方'; //TODO neo
        console.log('handlePrint detailData', this.detailData)
        this.openPrint = true;
        this.operateList[0].operater = this.detailData.doctor|| '';
        this.operateList[1].operater = this.detailData.checkBy|| '';
        this.operateList[2].operater = this.detailData.tiaopeiName || '';
        const length = response.data.operateList
        if(length > 0){
          response.data.operateList.forEach((item)=>{
            switch(item.type){
              case '2':
                this.operateList[3].operater = item.createBy
                break
              case '3':
                this.operateList[4].operater = item.createBy
                break
              case '4':
                this.operateList[5].operater = item.createBy
                break
              case '5':
                this.operateList[6].operater = item.createBy
                break
              case '6':
                this.operateList[7].operater = item.createBy
                break
                defalut:console.log('处方签res.data.operateList数据异常',item.type)
            }
          })
        }
        // this.title = "查看处/**/方审核";
        //console.log(response);
      });
    },
    handlePrintType(e) {
      console.log('this.activePrint',this.activePrint)
      console.log('click>>>',e.name)
      if(e.name && e.name!==this.activePrint){
        this.activePrint = e.name
        console.log(' change this.activePrint',this.activePrint)
      } else {
        console.log('nochange this.activePrint',this.activePrint)
      }

    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      const now = dayjs().format('YYYY-MM-DD');
      this.queryParams.prescriptionTime = [now, now];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.activeName = 'first'
      this.title = "添加处方审核";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getPrescriptionCore(id).then((response) => {
        // this.form = response.data;
        this.detailData = response.data;
        this.open = true;
        this.activeName = 'first'
        this.title = "溯源详情";
        this.handleDeploy({ name: "已审核", id: 1, key: "audited" })
        console.log('$baseUrl', this.$baseUrl);
      });
    },

    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除处方审核编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delPrescriptionCore(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有处方审核数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportPrescriptionCore(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
    // 改变溯源记录的状态
    handleDeploy(item) {

      this.currentDepoly = item.key
      this.depolyStatusObj = this.detailData[this.currentDepoly][0] ||{}
      if(this.detailData[this.currentDepoly][0]&&this.detailData[this.currentDepoly][0].urls) {
        const urlss = this.detailData[this.currentDepoly][0].urls
        if( urlss){
          this.depolyStatusObj.imgs=urlss.split(',')
        }
      }

    }
  },
};
</script>
<style scoped>
h3 {
  margin: 0;
}
.el-divider--horizontal{
  margin: 8px 0;
  /*background: 0 0;*/
  /*border-top: 1px dashed #e8eaec;*/
}
.deploy-record{
  display: flex;

}
.deploy {
  display: flex;
  flex-direction:column;
  align-items:flex-end;
  justify-content:center;
}
.content{
  display: flex;
  width: 320px;
  justify-content:flex-start;
}
.body{
  display: flex;
  height: 30px;
  width: 200px;
  justify-content:flex-start;
  align-items: center;
}
.title{
  margin-bottom: 0;
  font-weight: bolder;
  justify-content: flex-end!important;
  width: 120px!important;
  /*justify-content:center;*/
}

.active{ background-color: #1ab394; color: #FFFFFF!important;}
#qrcode {
  width: 160px;
  margin: 0 auto;
}
.printbtn { background: #409eff; color: #fff; }
</style>
