<template>
  <div>
    <el-card>
      <div style="display: flex; width: 100%;">
        <!-- 查询条件 与列表  -->
        <div class="queryDivClass">
          <!-- 查询条件 -->
          <div style="height: 80px;">
            <div style="display:flex;">
              <div>
                <span>登记日期：</span>
                <el-date-picker v-model="query.dateRange" type="daterange" align="right" unlink-panels range-separator="至"
                  start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions" size="small"
                  style="width: 240px">
                </el-date-picker>
              </div>
              <div style="margin-left:10px;">
                <el-button type="primary" class="btnClass" @click="Query">查询</el-button>
              </div>
            </div>
            <div style="display:flex;margin-top:10px;">
              <el-radio v-model="query.chargeFlag" label="N">未收费</el-radio>
              <el-radio v-model="query.chargeFlag" label="Y">已收费</el-radio>
              <el-radio v-model="query.chargeFlag" label="B">已退费</el-radio>
            </div>
          </div>
          <!-- 列表 -->
          <div class="prListDivClass">
            <el-table :data="patientRegister.prList" border highlight-current-row
              :height="(window.pageHeight > 600 ? (window.pageHeight - 230) : 350)" @row-click="rowClick" size="small"
              @selection-change="handleSelectionChange">
              <el-table-column prop="customerOrgParentName" label="单位" width="180">
                <template slot-scope="scope">
                  <div>{{ scope.row.customerOrgParentName ? scope.row.customerOrgParentName : scope.row.customerOrgName }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="patientName" label="姓名" />
              <el-table-column prop="sexId" label="性别">
                <template slot-scope="scope">
                  <div>{{ dddw(dict.sex, "id", scope.row.sexId, "displayName") }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="age" label="年龄" />
              <el-table-column prop="patientRegisterNo" label="条码号" width="150" />
              <el-table-column prop="patientNo" label="档案号" />
              <el-table-column prop="medicalTimes" label="体检次数"></el-table-column>
              <el-table-column label="分组/套餐" width="150">
                <template slot-scope="scope">
                  <div
                    v-if="scope.row.medicalPackageId !== dict.personOrgId && scope.row.customerOrgId === dict.personOrgId">
                    {{ dddw(dict.medicalPackage, "id", scope.row.medicalPackageId, "displayName") }}
                  </div>
                  <div
                    v-if="scope.row.medicalPackageId !== dict.personOrgId && scope.row.customerOrgId !== dict.personOrgId">
                    {{ dddw(dict.customerOrgGroupAll, "id", scope.row.customerOrgGroupId, "displayName") }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="completeFlag" label="体检进度">
                <template slot-scope="scope">
                  <div>{{ dddw(dict.completeFlag, "id", scope.row.completeFlag, "displayName") }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="guidePrintTimes" label="打印" width="50">
                <template slot-scope="scope">
                  <i class="el-icon-printer" v-if="scope.row.guidePrintTimes > 0"
                    style="font-size: 24px;color: green;"></i>
                </template>
              </el-table-column>
              <el-table-column prop="isLock" label="锁住">
                <template slot-scope="scope">
                  <div>{{ scope.row.isLock == "Y" ? "是" : "否" }}</div>
                </template>
              </el-table-column>

              <el-table-column prop="customerOrgName" label="部门" width="180">
                <template slot-scope="scope">
                  <div>{{ scope.row.customerOrgParentName ? scope.row.customerOrgName : "" }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="nationId" label="民族">
                <template slot-scope="scope">
                  <div>
                    {{ dddw(dict.nation, "nationId", scope.row.nationId, "displayName") }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="idNo" label="身份证" width="150" />
              <el-table-column prop="birthDate" label="出生日期" width="100">
                <template slot-scope="scope">
                  <div v-if="scope.row.birthDate">
                    {{ lmoment(scope.row.birthDate, "yyyy-MM-DD") }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="email" label="邮箱" width="180" />
              <el-table-column prop="mobileTelephone" label="手机" width="100" />
              <el-table-column prop="telephone" label="电话" width="100" />
              <el-table-column prop="address" label="地址" width="300" />
              <el-table-column prop="medicalCardNo" label="体检卡号" />
              <el-table-column prop="jobCardNo" label="工卡号" />
              <el-table-column prop="maritalStatusId" label="婚姻状况">
                <template slot-scope="scope">
                  <div>
                    {{ dddw(dict.maritalStatus, "id", scope.row.maritalStatusId, "displayName") }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="medicalTypeId" label="体检类别">
                <template slot-scope="scope">
                  <div v-if="scope.row.medicalTypeId !== dict.personOrgId">
                    {{ dddw(dict.medicalType, "id", scope.row.medicalTypeId, "displayName") }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="personnelTypeId" label="人员类别">
                <template slot-scope="scope">
                  <div v-if="scope.row.personnelTypeId !== dict.personOrgId">
                    {{ dddw(dict.personnelType, "id", scope.row.personnelTypeId, "displayName") }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="jobPost" label="职务" />
              <el-table-column prop="jobTitle" label="职称" />
              <el-table-column prop="salesman" label="介绍人" />
              <el-table-column prop="isVip" label="是否VIP">
                <template slot-scope="scope">
                  <div>{{ scope.row.isVip == "Y" ? "是" : "否" }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="creatorName" label="登记人" />
              <el-table-column prop="creationTime" label="登记日期" width="100">
                <template slot-scope="scope">
                  <div>{{ lmoment(scope.row.creationTime, "yyyy-MM-DD") }}</div>
                </template>
              </el-table-column>
              <el-table-column prop="isUpload" label="是否上传">
                <template slot-scope="scope">
                  <div>{{ scope.row.isUpload == "Y" ? "是" : "否" }}</div>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <!-- 收费操作  -->
        <div class="queryDivClass" style="margin-left:5px;">
          <!-- 查询信息  -->
          <div style="height: 40px;">
            <div style="display: flex; flex-wrap: wrap;margin-top:40px; height:40px; width: 100%;">
              <div class="query">
                <span>条码号</span>
                <el-input placeholder="条码号" v-model="query.patientRegisterNo" size="small" style="width: 140px" clearable
                  @change="Query" />
              </div>
              <div class="query">
                <span>档案号</span>
                <el-input placeholder="档案号" v-model="query.patientNo" size="small" style="width: 100px" clearable
                  @change="Query" />
              </div>
              <div class="query">
                <span>姓名</span>
                <el-input placeholder="姓名" v-model="query.patientName" size="small" style="width: 100px" disabled />
              </div>
            </div>
          </div>
          <!-- 收费信息  -->
          <div class="prListDivClass">
            <!-- charge  -->
            <div>
              <el-form ref="form" :model="form" label-width="80px" :rules="rules" size="small">
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="发票号" prop="invoiceNo">
                      <el-input v-model="form.invoiceNo" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="开票抬头" prop="invoiceOrgName">
                      <el-input v-model="form.invoiceOrgName" />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="折扣" prop="discount">
                      <el-input v-model="form.discount" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="应收金额" prop="total">
                      <el-input v-model="form.total" />
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="预收金额" prop="preTotal">
                      <el-input v-model="form.preTotal" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="找零" prop="balance">
                      <el-input v-model="form.balance" />
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </div>
            <!-- charge_pay  -->
            <div>
              <div style="margin-top:5px;font-size:10px;">收费方式：</div>
              <el-table :data="chargePays" border highlight-current-row size="small"
                :height="window.pageHeight > 600 ? (window.pageHeight - 230 - 146) / 2 : 112">
                <el-table-column prop="payModeId" label="收费方式" width="180">
                  <template slot-scope="scope">
                    <div>{{ dddw(dict.payMode, "id", scope.row.payModeId, "displayName") }}</div>
                  </template>
                </el-table-column>
                <el-table-column prop="chargeMoney" label="金额">
                  <template slot-scope="scope">
                    <el-input type="number" v-model="scope.row.chargeMoney" size="small" @input="inputMoney" />
                  </template>
                </el-table-column>
                <el-table-column prop="cardBillId" label="会员卡">
                  <template slot-scope="scope">
                    <el-select v-model="scope.row.cardBillId" placeholder="请选择" size="small" filterable clearable
                      :disabled="scope.row.payModeId == '05' ? false : true">
                      <el-option v-for="item in cardRegister" :key="item.id" :label="item.idNo" :value="item.id" />
                    </el-select>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <!-- asbitem  -->
            <div>
              <div style="margin-top:5px; font-size:10px;">待收费项目：</div>
              <el-table :data="asbItemsForFee" border highlight-current-row
                :height="window.pageHeight > 600 ? (window.pageHeight - 230 - 146) / 2 : 112" size="small"
                @selection-change="handleSelectionChange" ref="asbItemsForFeeTable">
                <el-table-column type="selection" align="center" />
                <el-table-column label="已选组合项目" width="120" prop="asbitemName" />
                <el-table-column label="标准价格" prop="standardPrice" width="80" align="center" />
                <el-table-column label="折扣" prop="discount" width="60">
                  <template slot-scope="scope">
                    <el-input type="number" v-model="scope.row.discount"
                      :disabled="scope.row.isCharge == 'Y' ? true : false" size="small"
                      @input="changeDiscount(scope.row)" />
                  </template>
                </el-table-column>
                <el-table-column label="数量" prop="amount" width="50">
                  <template slot-scope="scope">
                    <el-input type="number" v-model="scope.row.amount" size="small" />
                  </template>
                </el-table-column>
                <el-table-column label="实收价格" prop="chargePrice" width="80">
                  <template slot-scope="scope">
                    <el-input type="number" v-model="scope.row.chargePrice"
                      :disabled="scope.row.isCharge == 'Y' ? true : false" size="small" @input="changePrice(scope.row)" />
                  </template>
                </el-table-column>
                <el-table-column prop="total" label="金额" width="70" v-if="false" />
                <el-table-column prop="standardPrice" label="标准金额" width="80" v-if="false" />
                <el-table-column label="支付方式" prop="payTypeFlag" width="100">
                  <template slot-scope="scope">
                    <el-select v-model="scope.row.payTypeFlag" size="small">
                      <el-option v-for="item in dict.payType" :key="item.id" :label="item.displayName" :value="item.id" />
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column prop="checkCompleteFlag" label="状态" align="center">
                  <template slot-scope="scope">
                    <div>{{ dddw(dict.checkCompleteFlag, "id", scope.row.checkCompleteFlag, "displayName") }}</div>
                  </template>
                </el-table-column>
                <el-table-column prop="creatorName" label="登记人" align="center" />
                <el-table-column prop="creationTime" label="登记日期" width="90" align="center">
                  <template slot-scope="scope">
                    <div>{{ moment(scope.row.creationTime, 'yyyy-MM-DD') }}</div>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </div>
        <div class="btnDivClass">
          <div class="btnListClass">
            <el-button type="primary" class="btnClass" @click="charge" :disabled="query.chargeFlag == 'N' ? false:true">收费</el-button>
          </div>
          <div class="btnListClass">
            <el-button type="danger" class="btnClass" @click="chargeBack" :disabled="query.chargeFlag == 'Y' ? false:true">退费</el-button>
          </div>
          <div class="btnListClass">
            <el-button type="success" class="btnClass" @click="chargePrint('0007', false, form.id)" :disabled="query.chargeFlag == 'B' ? true:false">打印</el-button>
          </div>
        </div>
      </div>
    </el-card>
  </div>
</template>
<script>
import moment from 'moment';
import { mapState, mapActions } from "vuex";
import { getapi, postapi, putapi, deletapi } from "@/api/api";
import { tcdate, dddw, arrayExistObj } from "../../utlis/proFunc";

import PatientRegisterQuery from "../../components/patientRegister/patientRegisterQuery.vue";
import PatientRegisterRefuseList from "../../components/patientRegister/PatientRegisterRefuseList.vue";

export default {
  components: {
    PatientRegisterQuery,
    PatientRegisterRefuseList,
  },
  data() {
    return {
      query: { chargeFlag: 'N' },//查询条件
      form: {
        id: null,
        patientRegisterId: null,
        invoiceNo: '',
        invoiceOrgName: '',
        chargeFlag: '1',
        discount: 0,
        total: 0,  //应收金额
        preTotal: 0,  //预收金额
        balance: 0,  //找零
      },  //收费主表
      rules: {
        invoiceNo: [
          { required: true, message: "请填写发票/收据号", trigger: "blur" },
        ],
        total: [
          { required: true, message: "请填写应收金额", trigger: "blur" },
        ],
      },

      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      chargePays: [],  //收支方式
      asbItemsForFee: [],  //待收费项目
      selectedData: [],    //选中项目
      cardRegister: [{ id: '00000000-0000-0000-0000-000000000000', idNo: '0001' }],      //当前客户的会员卡
      cardRegisterAll: [],   //所有客户的会员卡
    };
  },

  created() { },

  //挂载完成
  mounted() {
    this.dictInit();
  },

  computed: {
    ...mapState(["window", "dict", "patientRegister", "customerOrg"]),
  },

  methods: {
    ...mapActions(["getCustomerOrgGroup"]),

    dddw, moment,

    //查询人员列表数据
    Query() {
      console.log('query', this.query);
    },

    //人员列表点击
    rowClick(row) {
      this.getAsbItemsForFee(row.patientRegisterId, row.chargeId);
    },

    //获取项目列表
    async getAsbItemsForFee(patientRegisterId, chargeId) {
      //待收费项目列表      
      this.asbItemsForFee = [];
      if (this.query.chargeFlag = 'N') {
        getapi(`/api/app/registerasbitem/getlistinpatientregisterid?PatientRegisterId=${patientRegisterId}`)
          .then(res => {
            if (res.code == 1) {
              this.asbItemsForFee = res.data;
              this.asbItemsForFee.forEach(e => {
                e.chargePriceOri = e.chargePrice;
                e.standTotal = e.amount * e.standardPrice;
                e.total = e.amount * e.chargePrice;
                return e
              });
              this.toCharge(patientRegisterId, chargeId);
            }
          });
      } else {
        //已收费项目列表
        getapi(`/api/app/registerasbitem/getlistinpatientregisterid?PatientRegisterId=${chargeId}`)
          .then(res => {
            if (res.code == 1) {
              this.asbItemsForFee = res.data;
            }
          });
      }
    },

    //待收费数据分析
    toCharge() {
      //默认全部选中
      this.selectedData = this.asbItemsForFee;
      this.$nextTick(function () {
        // let rows = []
        // for (let m = 0; m < this.selectedData.length; m++) {
        //   for (let n = 0; n < this.tableData.length; n++) {
        //     if (this.selectedData[m].id === this.tableData[n].id) {
        //       rows.push(this.tableData[n])
        //     }
        //   }
        // }
        this.selectedData.forEach(row => {
          this.$refs['asbItemsForFeeTable'].toggleRowSelection(row)
        })
      });
      this.form.patientRegisterId = patientRegisterId;
    },

    //根据明细算总价与折扣
    sumTotal() {
      let total = Number(0), totalOri = Number(0);
      this.selectedData.forEach(e => {
        totalOri += Number(e.amount * e.chargePriceOri);  //原始实收价格
        total += Number(e.amount * e.chargePrice);      //当前实收价格
      });
      this.form.total = total;
      if (totalOri == 0) {
        this.form.discount = 100;
      } else {
        this.form.discount = Math.round(total / totalOri, 2);
      }
    },

    //通过折扣计算总价与明细价格
    discountToDetails() {
      let discount = this.form.discount;
      let totalOri = Number(0), totalCompute = Number(0), totalPlan = Number(0);
      let lfind = -1;
      this.selectedData.forEach(e => {
        totalOri += Number(e.amount * e.chargePriceOri);  //原始实收价格
        lfind = arrayExistObj(this.asbItemsForFee, 'id', e.id)
        if (lfind > -1 && e.chargePriceOri != 0) {
          this.asbItemsForFee[lfind].discount = discount;
          this.asbItemsForFee[lfind].chargePrice = Math.round(e.chargePriceOri * discount, 2);
          totalCompute += Number(this.asbItemsForFee[lfind].chargePrice * e.amount);
        }
      });
      totalPlan = Math.round(totalOri * discount, 2);
      this.form.total = totalPlan;
      //明细和与总金额不符处理 (其实不处理亦无关系)
      this.handleBalance(totalPlan, totalCompute);

    },

    //通过折扣计算总价与明细价格
    totalToDetails() {
      let discount = 0;
      let totalOri = Number(0), totalCompute = Number(0), totalPlan = Number(this.form.total);
      let lfind = -1;
      this.selectedData.forEach(e => {
        totalOri += Number(e.amount * e.chargePriceOri);  //原始实收价格        
      });

      discount = Math.round(totalPlan / totalOri, 2);

      //
      this.selectedData.forEach(e => {
        lfind = arrayExistObj(this.asbItemsForFee, 'id', e.id);
        if (lfind > -1) {
          this.asbItemsForFee[lfind].chargePrice = Math.round(this.asbItemsForFee[lfind].chargePrice * discount, 2);
          totalCompute += this.asbItemsForFee[lfind].chargePrice * e.amount;
        }
      });

      //明细和与总金额不符处理 (其实不处理亦无关系)
      this.handleBalance(totalPlan, totalCompute);
    },

    //明细合计金额与总金额不一致时，处理
    handleBalance(totalPlan, totalCompute) {
      if (totalPlan != totalCompute) {
        for (let i = this.selectedData.length - 1; i = 0; i--) {
          lfind = lfind = arrayExistObj(this.asbItemsForFee, 'id', this.selectedData[i].id);
          if (lfind > -1 && this.selectedData[i].amount == 1) {
            this.asbItemsForFee[lfind].chargePrice = this.asbItemsForFee[lfind].chargePrice + totalPlan - totalCompute;
            this.selectedData[i].chargePrice = this.asbItemsForFee[lfind].chargePrice;
            break;
          }
        }
      }
    },

    //输入收费方式金额
    inputMoney() {
      let total = Number(0);
      this.chargePays.forEach(e => {
        total += Number(e.chargeMoney);
      });
      if (total > this.form.total) this.$message.warning("输入金额超过总金额");
    },

    //勾选要收费的项目
    handleSelectionChange(v) {
      this.selectedData = v;
      this.sumTotal();
    },

    //调整明细折扣
    changeDiscount(row) {
      let total = this.form.total;
      let totalDetailsOri = row.amount * row.chargePrice;
      let totalDetailsCur = Number(0);

      row.chargePrice = Math.round(row.discount * row.chargePriceOri, 2);
      let lfind = arrayExistObj(this.selectedData, 'id', row.id);
      if (lfind > -1) {
        totalDetailsCur = row.amount * row.chargePrice;
        this.form.total = total + totalDetailsCur - totalDetailsOri;
      }
    },

    //调整明细实收价格
    changePrice(row) {
      if (row.chargePriceOri != 0) {
        row.discount = Math.round(row.chargePrice / row.chargePriceOri, 2);
      }

      row.chargePrice = Math.round(row.discount * row.chargePriceOri, 2);
      let lfind = arrayExistObj(this.selectedData, 'id', row.id);
      if (lfind > -1) {
        this.selectedData[lfind].discount = row.discount;
        this.selectedData[lfind].chargePrice = row.chargePrice;
      }

      this.sumTotal();

    },

    //收费
    charge() {

      let total = Number(0);
      let msg = '';
      let form = {};
      let chargePays = [];
      let chargeAsbitem = [];

      this.chargePays.forEach(e => {
        total += Number(e.chargeMoney);
        if (e.payModeId == '05') {
          if (!e.cardBillId) msg = '请先择会员卡号';
        } else {
          e.cardBillId = null;
        }
        return e;
      });

      if (msg) {
        this.$message.warning(msg);
        return;
      }
      if (total != this.form.total) {
        this.$message.warning("收费方式合计金额与收费总金额不符");
        return;
      }

      this.$refs[form].validate((valid) => {
        if (!valid) {
          this.$message.warning("数据未通过校验！");
          return;
        }
      });

      this.chargePays.forEach(e => {
        if (e.chargeMoney) {
          chargePays.push(e);
        }
      });

      form = {
        patientRegisterId: this.form.patientRegisterId,
        invoiceNo: this.form.invoiceNo,
        invoiceOrgName: this.form.invoiceOrgName,
        chargeFlag: this.form.chargeFlag,
      };

      this.selectedData.forEach(e => {
        chargeAsbitem.push({
          asbitemId: e.asbitemId,
          chargePrice: e.chargePrice,
          amount: e.amount,
          registerAsbitemId: e.id,
        });
      });

    },

    //退费
    chargeBack() {
      let chargeId = this.form.id;
      let msg = '';
      let chargeBackPays = [];


      this.chargePays.forEach(e => {
        total += Number(e.chargeMoney);
        if (e.payModeId == '05') {
          if (!e.cardBillId) msg = '请先择会员卡号';
        } else {
          e.cardBillId = null;
        }
        return e;
      });

      if (msg) {
        this.$message.warning(msg);
        return;
      }
      if (total != this.form.total) {
        this.$message.warning("退费方式合计金额与退费总金额不符");
        return;
      }

      this.chargePays.forEach(e => {
        if (e.chargeMoney) {
          chargeBackPays.push(e);
        }
      });

    },

    //收费打印
    chargePrint(ReportCode, isPreview, chargeId) {
      if (chargeId.length < 1) {
        this.$message.info("人员信息尚未保存，不可执行此操作！");
        return;
      }

      let token = localStorage.getItem('token');
      let user = localStorage.getItem('user');
      let toOutShell = {
        ReportCode, token,
        preViewCanPrint: 'Y',
        Parameters: [
          { Name: 'printer', Value: user },
          { Name: 'hisLog', Value: 'pic/hisLog.jpg' },
        ],
      };


      if (isPreview) {
        getapi(`/api/app/printreport/getpatientregisterguidereport?PatientRegisterId=${chargeId}`)
          .then((res) => {
            if (res.code != -1) {
              toOutShell.ReportTable = res.data;
              console.log('JSON.stringify(toOutShell)', JSON.stringify(toOutShell));
              return this.$peisAPI.printPre(JSON.stringify(toOutShell));
            }
          })
          .catch(err => {
            this.$message.warning(err);
          });
      } else {
        getapi(`/api/app/printreport/getpatientregisterguidereport?PatientRegisterId=${chargeId}`)
          .then((res) => {
            if (res.code != -1) {
              toOutShell.ReportTable = res.data;
              console.log('JSON.stringify(toOutShell)', JSON.stringify(toOutShell));
              return this.$peisAPI.print(JSON.stringify(toOutShell));
            }
          })
          .catch(err => {
            this.$message.warning(err);
          });

      }
    },


    //数据初始化
    dictInit() {

      //性别（仅档案用）
      getapi("/api/app/sex").then((res) => {
        if (res.code == 1) {
          this.dict.sex = res.data;
        }
      });

      //性别（查询）
      getapi("/api/app/for-sex").then((res) => {
        if (res.code == 1) {
          this.dict.forSex = res.data;
        }
      });

      //体检单位
      getapi("/api/app/customer-org/by-code-all").then((res) => {
        this.patientRegister.customerOrgTreeAll = res.data;
        tcdate(this.patientRegister.customerOrgTreeAll)
      });

      //体检中心
      getapi("/api/app/organization-units/organization-unit-by-is-peis").then(
        (res) => {
          if (res.code == 1) {
            this.dict.organization = res.data;
          }
        }
      );

      //体检单位
      getapi("/api/app/customer-org/in-filter").then((res) => {
        if (res.code == 1) {
          this.dict.customerOrg = res.data.items;
        }
      });

      //体检类别
      getapi("/api/app/medical-type/in-filter").then((res) => {
        if (res.code == 1) {
          this.dict.medicalType = res.data.items;
        }
      });

      //人员类别
      getapi("/api/app/personnel-type/in-filter").then((res) => {
        if (res.code == 1) {
          this.dict.personnelType = res.data.items;
        }
      });

      //婚姻状况
      getapi("/api/app/marital-statuses").then((res) => {
        if (res.code == 1) {
          this.dict.maritalStatus = res.data.items;
        }
      });

      //性激素期
      getapi("/api/app/sex-hormone-term/in-filter").then((res) => {
        if (res.code == 1) {
          this.dict.sexHormoneTerm = res.data.items;
        }
      });

      //民族
      getapi("/api/app/nation/in-filter").then((res) => {
        if (res.code == 1) {
          this.dict.nation = res.data.items;
        }
      });

      //籍惯 ，出生地
      getapi("/api/app/birth-place/in-filter").then((res) => {
        if (res.code == 1) {
          this.dict.birthPlace = res.data.items;
        }
      });

      //套餐
      getapi("/api/app/medical-package/in-filter").then((res) => {
        if (res.code == 1) {
          this.dict.medicalPackage = res.data.items;
        }
      });

      //分组，所有分组，不限单位，不限次数
      getapi("/api/app/customer-org-group").then((res) => {
        if (res.code == 1) {
          this.dict.customerOrgGroupAll = res.data.items;
        }
      });

      //支付方式
      getapi("/api/app/pay-mode").then((res) => {
        if (res.code == 1) {
          this.dict.payMode = res.data;
          //未收费时
          this.chargePays = [];
          this.dict.payMode.forEach(e => {
            this.chargePays.push({ chargeId: null, payModeId: e.id, chargeMoney: 0, cardBillId: null })
          })
        }
      });

      //体检类别 树结构
      getapi("/api/app/item-type/by-code-all").then((res) => {
        if (res.code == 1) {
          this.dict.itemTypeTree = res.data;
          tcdate(this.dict.itemTypeTree);
        }
      });

      getapi("/api/app/asbitem/in-filter?Filter").then((res) => {
        if (res.code == 1) {
          this.dict.asbItemAll = res.data.items;
        }
      });

      console.log("dict", this.dict);
    },
  },

  //监听事件()
  watch: {

  },
};
</script>
<style scoped>
::v-deep .el-form-item {
  margin-bottom: 1px;
}

::v-deep .el-table--small .el-table__cell {
  padding: 0px 0;
}

::v-deep .el-input__inner {
  text-align: left;
  padding-left: 5px;
  padding-right: 15px;
}

::v-deep input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none !important;
  margin: 0 !important;
}

::v-deep .el-table th.el-table__cell {
  text-align: center;
  padding-left: 1px;
  padding-right: 1px;
}

::v-deep .el-table td.el-table__cell {
  padding-left: 1px;
  padding-right: 1px;
}

::v-deep .el-table .cell {
  padding-left: 1px;
  padding-right: 1px;
}

.queryDivClass {
  display: block;
  width: v-bind("(window.pageWidth > 600 ? (window.pageWidth - 120 - 80) / 2 : 200) + 'px'");
  height: v-bind("(window.pageHeight > 600 ? (window.pageHeight - 150) : 450) + 'px'");
}

.query {
  margin-left: 10px;
}

.prListDivClass {
  height: v-bind("(window.pageHeight > 600 ? (window.pageHeight - 250) : 350) + 'px'");
}

.btnDivClass {
  display: block;
  width: 110px;
  margin-left: 5px;
  margin-top: 180px;
}

.btnListClass {
  margin-top: 10px;
}

.btnClass {
  width: 110px;
}
</style>
