<template>
  <div>
    <el-card>
      <el-select v-model="projectNameValue" clearable filterable placeholder="请选择项目名称" size="small" style="margin-left: 10px;width: 200px" @change="searchPackingList();searchPackingListDetails();searchInvoice()" @clear="clearProject()">
        <el-option
          v-for="item in projectName"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      <!--<el-button type="success" icon="el-icon-search" size="small" style="margin-left: 10px" @click="searchPackingList();searchPackingListDetails();searchInvoice()">查询</el-button>-->
      <el-button type="primary" icon="el-icon-circle-plus-outline" size="small" style="margin-left: 10px" @click="showAddInvoice();flag1 = 1">增加</el-button>
      <div style="margin-left: 15px;display: inline-block;color:gray"><span>总装箱单号：</span></div>{{ packingListNumber }}
      <div style="margin-left: 15px;display: inline-block;color:gray"><span>发货节点：</span></div>{{ consignmentNode }}
      <div style="margin-left: 15px;display: inline-block;color:gray"><span>设备名称：</span></div>{{ deviceName }}
      <div style="margin-left: 15px;display: inline-block;color:gray"><span>收货单位：</span></div>{{ receivingUnit }}
      <div style="margin-left: 15px;display: inline-block;color:gray"><span>联系人：</span></div>{{ contacts }}
      <div style="margin-left: 15px;display: inline-block;color:gray"><span>联系电话：</span></div>{{ contactNumber }}
    </el-card>
    <el-card>
      <el-row>
        <el-col :span="17"><div class="grid-content bg-purple">
          <el-table
            v-loading="tableData2Loading"
            id="tb"
            :row-style="tableRowClassName1"
            :data="tableData5"
            highlight-current-row
            style="width: 100%"
            height="315"
            size="mini"
            @row-click="searchCargoBox"
          >
            <el-table-column align="center" label="发货单号" width="150">
              <template slot-scope="scope">
                {{ scope.row.发货单号 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="收货地址" width="230">
              <template slot-scope="scope">
                {{ scope.row.省份 + scope.row.市名 + scope.row.详细地址 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="收货人" width="80">
              <template slot-scope="scope">
                {{ scope.row.联系人 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="联系电话" width="150">
              <template slot-scope="scope">
                {{ scope.row.联系方式 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="车辆牌号" width="150">
              <template slot-scope="scope">
                {{ scope.row.车辆牌号 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="发货日期" width="150">
              <template slot-scope="scope">
                {{ scope.row.发货日期 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="运输状态" width="80">
              <template slot-scope="scope">
                {{ scope.row.运输状态 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="运费" width="80">
              <template slot-scope="scope">
                {{ scope.row.运费 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="签收人" width="80">
              <template slot-scope="scope">
                {{ scope.row.签收人 === '' || scope.row.签收人 === null ? '未签收' : scope.row.签收人 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="追溯码" width="150">
              <template slot-scope="scope">
                <canvas :id="canvas[scope.$index]"/>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="300">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="warning"
                  icon="el-icon-edit"
                  @click.stop="exportTable(scope.row)">导出</el-button>
                <el-button
                  size="mini"
                  type="primary"
                  icon="el-icon-edit"
                  @click.stop="showEditInvoice(scope.row);flag1 = 2">编辑</el-button>
                <el-button
                  size="mini"
                  type="danger"
                  icon="el-icon-delete"
                  @click.stop="delInvoice(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div></el-col>
        <el-col :span="7"><div class="grid-content bg-purple-light">
          <div style="width: 473px;height:315px; border: 2px solid rgb(228, 231, 237);margin-left: 5px">
            <el-upload
              :on-preview="handlePictureCardPreview"
              :on-remove="handleRemove"
              :file-list="fileList"
              :before-upload="beforeUpload"
              :on-success="onSuccess"
              :limit="5"
              :action="upload2 + '?InvoiceNum=' + invoiceNum"
              list-type="picture-card">
              <i class="el-icon-plus"/>
            </el-upload>
            <el-dialog :visible.sync="dialogVisible">
              <img :src="dialogImageUrl" width="100%" alt="">
            </el-dialog>
          </div>
        </div></el-col>
      </el-row>
    </el-card>
    <el-card>
      <el-row>
        <el-col :span="11"><div class="grid-content bg-purple">
          <el-tabs v-model="activeName">
            <el-tab-pane label="主机" name="first">
              <el-table
                v-loading="tableData1Loading"
                :row-key="getRowKeys"
                :expand-row-keys="expands"
                :data="tableData1"
                highlight-current-row
                border
                style="width: 100%"
                height="300"
                size="mini"
                @expand-change="selectMachine"
              >
                <el-table-column type="expand">
                  <template slot-scope="scope">
                    <el-table
                      :data="tableData4"
                      border
                      style="width: 600px; text-align: center"
                      height="300"
                      highlight-current-row
                      size="mini"
                      @row-click="choiceParts"
                    >
                      <el-table-column
                        align="center"
                        label="序号"
                        type="index"
                        width="50"/>
                      <el-table-column label="代号" align="center">
                        <template slot-scope="scope">
                          {{ scope.row.代号 }}
                        </template>
                      </el-table-column>
                      <el-table-column label="名称" align="center">
                        <template slot-scope="scope">
                          {{ scope.row.名称 }}
                        </template>
                      </el-table-column>
                      <el-table-column label="规格" align="center">
                        <template slot-scope="scope">
                          {{ scope.row.规格 }}
                        </template>
                      </el-table-column>
                      <el-table-column label="总数量" align="center">
                        <template slot-scope="scope">
                          {{ scope.row.数量 }}
                        </template>
                      </el-table-column>
                      <el-table-column label="未发数量" align="center">
                        <template slot-scope="scope">
                          <el-tag>{{ scope.row.未发数量 }}</el-tag>
                        </template>
                      </el-table-column>
                      <el-table-column label="备注" align="center">
                        <template slot-scope="scope">
                          {{ scope.row.备注 }}
                        </template>
                      </el-table-column>
                    </el-table>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="序号" type="index" width="50"/>
                <el-table-column align="center" label="代号">
                  <template slot-scope="scope">
                    {{ scope.row.代号 }}
                  </template>
                </el-table-column>
                <el-table-column align="center" label="名称">
                  <template slot-scope="scope">
                    {{ scope.row.名称 }}
                  </template>
                </el-table-column>
                <el-table-column align="center" label="数量">
                  <template slot-scope="scope">
                    {{ scope.row.数量 }}
                  </template>
                </el-table-column>
                <el-table-column align="center" label="备注">
                  <template slot-scope="scope">
                    {{ scope.row.备注 }}
                  </template>
                </el-table-column>
              </el-table>
            </el-tab-pane>
            <el-tab-pane label="随机供应备件" name="second">
              <el-table
                v-loading="tableData2Loading"
                :data="tableData2"
                highlight-current-row
                border
                style="width: 100%"
                height="300"
                size="mini"
                @row-click="choiceSpare"
              >
                <el-table-column align="center" label="序号" type="index" width="50"/>
                <el-table-column align="center" label="名称">
                  <template slot-scope="scope">
                    {{ scope.row.名称 }}
                  </template>
                </el-table-column>
                <el-table-column align="center" label="规格">
                  <template slot-scope="scope">
                    {{ scope.row.规格 }}
                  </template>
                </el-table-column>
                <el-table-column label="总数量" align="center">
                  <template slot-scope="scope">
                    {{ scope.row.数量 }}
                  </template>
                </el-table-column>
                <el-table-column align="center" label="未发数量">
                  <template slot-scope="scope">
                    <el-tag>{{ scope.row.未发数量 }}</el-tag>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="单位">
                  <template slot-scope="scope">
                    {{ scope.row.单位 }}
                  </template>
                </el-table-column>
                <el-table-column align="center" label="备注">
                  <template slot-scope="scope">
                    {{ scope.row.备注 }}
                  </template>
                </el-table-column>
              </el-table>
            </el-tab-pane>
            <el-tab-pane label="随机技术文件" name="third">
              <el-table
                v-loading="tableData3Loading"
                :data="tableData3"
                highlight-current-row
                border
                style="width: 100%"
                height="300"
                size="mini"
                @row-click="choiceFile"
              >
                <el-table-column align="center" label="序号" type="index" width="50"/>
                <el-table-column align="center" label="名称">
                  <template slot-scope="scope">
                    {{ scope.row.名称 }}
                  </template>
                </el-table-column>
                <el-table-column label="总数量" align="center">
                  <template slot-scope="scope">
                    {{ scope.row.数量 }}
                  </template>
                </el-table-column>
                <el-table-column align="center" label="未发数量">
                  <template slot-scope="scope">
                    <el-tag>{{ scope.row.未发数量 }}</el-tag>
                  </template>
                </el-table-column>
                <el-table-column align="center" label="备注">
                  <template slot-scope="scope">
                    {{ scope.row.备注 }}
                  </template>
                </el-table-column>
              </el-table>
            </el-tab-pane>
          </el-tabs>
        </div></el-col>
        <el-col :span="2">
          <div class="grid-content bg-purple">
            <div style="height:300px">
              <div>
                <el-button :disabled="disabledmoveInto" round type="primary" size="small" style="margin-top: 200px;margin-left: 45px" @click="moveInto()">➡</el-button>
              </div>
              <div>
                <el-button :disabled="disabledremoveInto" round type="danger" size="small" style="margin-top: 50px;margin-left: 45px" @click="remove()">⬅</el-button>
              </div>
            </div>
          </div>
        </el-col>
        <el-col :span="11"><div class="grid-content bg-purple-light">
          <span style="margin-left: 20px">
            货箱号：
          </span>
          <el-select v-model="cargoBoxValue" clearable filterable placeholder="请选择货箱号" size="small" style="margin-left: 2px;width: 200px" @change="searchCargoBoxDetailed" @clear="clear">
            <el-option
              v-for="item in cargoBox"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
          <el-button :disabled="btnAdd" type="primary" icon="el-icon-circle-plus-outline" size="small" style="margin-left: 10px" @click="addCargoBox()">增加</el-button>
          <el-button :disabled="btnDel" type="danger" icon="el-icon-circle-plus-outline" size="small" style="margin-left: 10px;margin-right: 50px" @click="delCargoBox()">删除</el-button>
          <el-popover
            placement="right"
            width="200"
            trigger="hover"
          >
            <div ref="imageWrapper">
              <img :src="dataURL">
              <slot>
                <div v-show="show" style="text-align: center">
                  <canvas id="canvas"/>
                  <span>{{ containerNumber }}</span>
                </div>
              </slot>
            </div>
            <el-button slot="reference" @click="toImage">追溯码</el-button>
          </el-popover>
          <hr style="border:none;border-top:2px solid rgb(228, 231, 237)" >
          <el-table
            v-loading="tableData6Loading"
            :data="tableData6"
            border
            style="width: 100%;margin-top: 3px"
            height="300"
            highlight-current-row
            @row-click="choiceGoods"
          >
            <el-table-column align="center" label="序号" type="index" width="100"/>
            <el-table-column align="center" label="代号">
              <template slot-scope="scope">
                {{ scope.row.代号 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="名称">
              <template slot-scope="scope">
                {{ scope.row.名称 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="规格">
              <template slot-scope="scope">
                {{ scope.row.规格 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="数量">
              <template slot-scope="scope">
                {{ scope.row.数量 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="备注">
              <template slot-scope="scope">
                {{ scope.row.备注 }}
              </template>
            </el-table-column>
          </el-table>
        </div></el-col>
      </el-row>
    </el-card>

    <!--发货单新增或编辑-->
    <el-dialog :title="title1" :visible.sync="dialogFormVisible1" width="40%" center>
      <el-form ref="form1" :model="form1" :rules="rules1" label-position="left">
        <el-row>
          <el-col :span="12">
            <el-form-item label="收货地址" prop="收货地址" label-width="110px">
              <el-input v-model="form1.收货地址" clearable size="small" placeholder="请选择收货地址" style="width: 200px" readonly autosize @dblclick.native="dialogFormVisible2 = true"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="车辆牌号" prop="车辆牌号" label-width="110px">
              <el-input v-model="form1.车辆牌号" size="small" placeholder="请输入车辆牌号" style="width: 200px"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系人" prop="联系人" label-width="110px">
              <el-input v-model="form1.联系人" size="small" placeholder="请输入联系人" style="width: 200px" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="联系方式" label-width="110px">
              <el-input v-model="form1.联系方式" size="small" placeholder="请输入联系电话" style="width: 200px" disabled/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="发货日期" prop="发货日期" label-width="110px">
              <el-date-picker
                v-model="form1.发货日期"
                style="width: 200px"
                value-format="yyyy-MM-dd"
                size="small"
                type="date"
                placeholder="请选择发货日期"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="运输状态" prop="entryNameValue" label-width="110px">
              <el-select v-model="form1.运输状态" clearable filterable placeholder="请选择运输状态" style="width: 200px" size="small" disabled>
                <el-option
                  v-for="item in Transport"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="运费" prop="运费" label-width="110px">
              <el-input-number v-model="form1.运费" :precision="2" :step="0.1" style="width: 200px" size="small"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="callOffInvoice('form1')">取消</el-button>
        <el-button type="primary" @click="submitInvoice('form1')">确 定</el-button>
      </div>
    </el-dialog>

    <!--地址选择-->
    <el-dialog :visible.sync="dialogFormVisible2" title="地址选择" center width="50%">
      <el-card>
        <el-select v-model="provinceValue" placeholder="请选择省份" size="mini" clearable style="width: 120px" @change="provinceChange">
          <el-option
            v-for="item in province"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <el-select v-model="cityValue" placeholder="请选择市名" size="mini" clearable style="width: 120px">
          <el-option
            v-for="item in city"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <el-input v-model="detailedAddress" clearable size="mini" style="width:200px" placeholder="请输入详细地址"/>
        <el-input v-model="people" clearable size="mini" style="width:100px" placeholder="联系人"/>
        <el-input v-model="phoneNumber" clearable size="mini" style="width:150px" placeholder="请输入联系方式"/>
        <el-button type="primary" size="mini" style="margin-left: 15px" @click="submitAdress">新增</el-button>
        <el-button type="warning" size="mini" @click="editAdress">编辑</el-button>
      </el-card>
      <el-table :data="addressData" highlight-current-row height="300" show-overflow-tooltip style="height: 330px; margin-top: 20px" @row-click="handleAdressChange">
        <el-table-column label="省份" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.省份 }}
          </template>
        </el-table-column>
        <el-table-column label="市" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.市名 }}
          </template>
        </el-table-column>
        <el-table-column label="详细地址" align="center">
          <template slot-scope="scope">
            {{ scope.row.详细地址 }}
          </template>
        </el-table-column>
        <el-table-column label="联系人" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.联系人 }}
          </template>
        </el-table-column>
        <el-table-column label="联系方式" align="center">
          <template slot-scope="scope">
            {{ scope.row.联系方式 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="200px" fixed="right">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              @click="deleteAdress(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="pageCurrent1"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize1"
        :total="total1"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange1"
        @current-change="handleCurrentChange1"/>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogFormVisible2 = false">取消</el-button>
        <el-button size="small" type="primary" @click="dialogFormVisible2 = false">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogFormVisible3" title="移入" width="20%" center>
      <el-form ref="form2" :model="form2" :rules="rules2" label-position="left">
        <el-form-item label="名称" prop="名称" label-width="110px">
          <el-input v-model="form2.名称" size="small" style="width: 200px" disabled/>
        </el-form-item>
        <el-form-item label="数量" prop="数量" label-width="110px">
          <el-input-number v-model="form2.数量" :min="0" :max="maxNum" controls-position="right" size="small" style="width: 200px" placeholder="请输入本次付款金额"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="btnLoading" @click="dialogFormVisible3 = false">取消</el-button>
        <el-button :loading="btnLoading" type="primary" @click="submitMoveInto('form2')">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogFormVisible4" title="移出" width="20%" center>
      <el-form ref="form3" :model="form3" :rules="rules2" label-position="left">
        <el-form-item label="名称" prop="名称" label-width="110px">
          <el-input v-model="form3.名称" size="small" style="width: 200px" disabled/>
        </el-form-item>
        <el-form-item label="数量" prop="数量" label-width="110px">
          <el-input-number v-model="form3.数量" :min="0" :max="maxNum" :precision="2" :step="1" controls-position="right" size="small" style="width: 200px" placeholder="请输入本次付款金额" disabled/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="btnLoading" @click="dialogFormVisible4 = false">取消</el-button>
        <el-button :loading="btnLoading" type="primary" @click="submitRremove('form3')" >确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="DeliveryVisiable" width="70%" center>
      <el-card>
        <div id="pdfDom" style="width: 100%">
          <table id="table" class="tg" style="table-layout: fixed; width: 1228px;margin: auto;left: 50%;right: 50%">
            <colgroup>
              <col style="width: 100px">
              <col style="width: 100px">
              <col style="width: 100px">
              <col style="width: 100px">
              <col style="width: 100px">
              <col style="width: 100px">
              <col style="width: 100px">
              <col style="width: 100px">
              <col style="width: 100px">
            </colgroup>
            <tr>
              <th class="tg-v15n" colspan="11" style="font-size: 30px">江苏高精机电装备有限公司</th>
              <th class="tg-c3ow" rowspan="2" style="text-align: center; line-height: 17px"><img id="img" alt="" src="http://123.206.50.60:8412/#/searchBoxDetails/index?id="></th>
            </tr>
            <tr>
              <td class="tg-uys7" colspan="11" style="text-align: center;font-size: 20px">{{ 装箱单名称 }}发货单</td>
            </tr>
            <tr>
              <td class="tg-c3ow">发货单号</td>
              <td class="tg-c3ow" colspan="3">{{ 发货单号 }}</td>
              <td class="tg-c3ow">收货人</td>
              <td class="tg-c3ow" colspan="3">{{ 收货人 }}</td>
              <td class="tg-c3ow">联系电话</td>
              <td class="tg-c3ow" colspan="3">{{ 联系电话 }}</td>
            </tr>
            <tr>
              <td class="tg-c3ow">收货地址</td>
              <td class="tg-c3ow" colspan="3">{{ 收货地址 }}</td>
              <td class="tg-c3ow">委托车辆</td>
              <td class="tg-c3ow" colspan="3">{{ 委托车辆 }}</td>
              <td class="tg-c3ow">发货日期</td>
              <td class="tg-c3ow" colspan="3">{{ 发货日期 }}</td>
            </tr>
            <tr>
              <td class="tg-c3ow">序号</td>
              <td class="tg-c3ow" colspan="2">货箱号</td>
              <td class="tg-c3ow" colspan="2">名称</td>
              <td class="tg-c3ow">代号</td>
              <td class="tg-c3ow">规格</td>
              <td class="tg-c3ow">数量</td>
              <td class="tg-c3ow" colspan="3">备注</td>
              <td class="tg-c3ow">确认</td>
            </tr>
            <tr v-for="(list, index) in table" :key="index">
              <td class="tg-c3ow">{{ index + 1 }}</td>
              <td class="tg-c3ow" colspan="2">{{ list.货箱号 }}</td>
              <td class="tg-c3ow" colspan="2">{{ list.名称 }}</td>
              <td class="tg-c3ow">{{ list.代号 }}</td>
              <td class="tg-c3ow">{{ list.规格 }}</td>
              <td class="tg-c3ow">{{ list.数量 }}</td>
              <td class="tg-c3ow" colspan="3">{{ list.备注 }}</td>
              <td class="tg-c3ow"/>
            </tr>
            <tr>
              <td class="tg-c3ow" colspan="9">本清单一式两份：一份请收货人清点货物；一份请签收人签收后交还司机带回本公司。请签收人在货物卸车后立即清点！</td>
              <td class="tg-c3ow" colspan="2">签收人签字：</td>
              <td class="tg-c3ow"/>
            </tr>
          </table>
        </div>
      </el-card>
      <div slot="footer" class="dialog-footer">
        <el-button @click="callOffDownLoadDelivery()">取消</el-button>
        <el-button type="primary" @click="downLoadDelivery()">打印</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import request from '@/utils/request'
import elInput from 'element-ui/packages/input'
import $ from 'jquery'
import { selectDelivery, submitRremove, searchCargoBoxDetailed, submitMoveInto, delCargoBox, addCargoBox, searchCargoBox, editInvoice, delInvoice, addInvoice, editAdress, addAdress, deleteAdress, citySearch, provinceSearch, addressSearch, searchParts, searchHost, searchSparePart, searchProjectName, searchPackingList, searchFile, searchInvoice } from '@/api//MarketingCenter/DeliveryManagement'
import QRCode from 'qrcode'
import { upload2, readImg } from '@/utils/request'
import html2Canvas from 'html2canvas'
export default {
  components: {
    elInput
  },
  data() {
    return {
      upload2: upload2,
      btnAdd: false,
      btnDel: false,
      btnLoading: false,
      table: [],
      canvas: [],
      show: false,
      show1: false,
      num: '',
      DeliveryVisiable: false,
      fileList: [],
      发货单号: '',
      收货人: '',
      收货地址: '',
      联系电话: '',
      委托车辆: '',
      发货日期: '',
      装箱单名称: '',
      运输状态: '',
      containerNumber: '',
      dataURL: '',
      a: 1, // 嵌套表格交换变量
      b: 1, // 嵌套表格交换变量
      flag1: '', // 发货单旗帜变量
      flag2: '', // 表格选择旗帜变量
      title1: '', // 发货单对话框标题
      projectNameValue: '', // 项目名称
      activeName: 'first', // 标签页索引
      packingListNumber: '', // 装箱单号
      deviceName: '', // 设备名称
      consignmentNode: '', // 发货节点
      receivingUnit: '', // 收货单位
      contacts: '', // 联系人
      contactNumber: '', // 联系方式
      provinceValue: '', // 省份
      adressNum: '', // 收货地址流水号
      invoiceNum: '', // 发货单编号
      detailedAddress: '',
      disabledmoveInto: false,
      disabledremoveInto: false,
      people: '',
      phoneNumber: '',
      cityValue: '', // 市名
      pageCurrent1: 1,
      code: '',
      pageSize1: 10,
      total1: null,
      cargoBoxValue: '',
      DetailOfGoodsCode: '',
      maxNum: 10, // 移入的最大数量
      goodsCodeName: '', // 货物代号
      goodsName: '', // 货物名称
      goodsSpecifications: '', // 货物规格
      goodsNumber: '', // 货物数量
      goodsRemark: '', // 货物备注
      partsCode: '', // 部件编号
      sparePartCode: '', // 备件编号
      fileCode: '', // 文件编号
      File: [],
      Parts: [],
      Spare: [],
      cargoBox: [],
      addressData: [],
      tableData1: [], // 主机表格
      tableData2: [], // 备件表格
      tableData3: [], // 随机文件表格
      tableData4: [], // 机床部件表格
      tableData5: [], // 发货单表格
      tableData6: [], // 货箱明细表格
      projectName: [], // 项目名称下拉框数组
      city: [], // 市名下拉框数组
      province: [], // 省份下拉框数组
      expands: [], // 嵌套表格
      tableData2Loading: false, // 备件加载动画
      tableData3Loading: false, // 随机文件加载动画
      tableData1Loading: false, // 主机加载动画
      tableData4Loading: false, // 机床所属部件加载动画
      tableData5Loading: false, // 发货单加载动画
      tableData6Loading: false, // 货箱明细加载动画
      dialogFormVisible1: false, // 发货单对话框标题显示隐藏
      dialogFormVisible2: false, // 地址选择对话框显示隐藏
      dialogFormVisible3: false, // 填充货箱内货物对话框显示隐藏
      dialogFormVisible4: false, // 移除货箱内货物对话框显示隐藏
      QueryDetail: '',
      QueryDetail1: '',
      dialogImageUrl: '',
      dialogVisible: false,
      Transport: [
        {
          value: 0,
          label: '运输中'
        },
        {
          value: 1,
          label: '已签收'
        }
      ],
      form1: {
        收货地址: '',
        车辆牌号: '',
        发货日期: '',
        运输状态: 0,
        联系人: '',
        联系方式: '',
        运费: ''
      },
      form2: {
        名称: '',
        数量: ''
      },
      form3: {
        名称: '',
        数量: ''
      },
      rules1: {
        收货地址: [{ required: true, message: '请选择收货地址', trigger: 'change' }],
        车辆牌号: [{ required: true, message: '请输入车辆牌号', trigger: 'blur' }],
        联系人: [{ required: true, message: '请选择联系人', trigger: 'blur' }],
        联系方式: [{ required: true, message: '请选择联系方式', trigger: 'blur' }],
        发货日期: [{ required: true, message: '请选择发货日期', trigger: 'change' }],
        运输状态: [{ required: true, message: '请选择运输状态' }],
        运费: [{ required: true, message: '请输入运费' }]
      },
      rules2: {}
    }
  },
  created() {
    this.init()
  },
  methods: {
    // 初始化函数
    init() {
      this.getSelect(searchProjectName, ['项目名称', '装箱单编号'], 'projectName')
      this.getSelect(provinceSearch, ['省份', '省份流水号'], 'province')
      this.getTable(addressSearch, [this.pageCurrent1, this.pageSize1], ['addressData', 'total1'])
    },
    // 查询总单据信息
    searchPackingList() {
      searchPackingList(this.projectNameValue).then(response => {
        this.packingListNumber = response.data[0].装箱单号
        this.deviceName = response.data[0].名称
        this.consignmentNode = response.data[0].发货节点
        this.receivingUnit = response.data[0].收货单位
        this.contacts = response.data[0].联系人
        this.contactNumber = response.data[0].联系方式
      })
    },
    // 查询总单据明细
    searchPackingListDetails() {
      // 备件查询
      this.tableData2Loading = true
      searchSparePart(this.projectNameValue).then(response => {
        this.tableData2Loading = false
        this.tableData2 = response.data
      })
      // 随机文件查询
      this.tableData3Loading = true
      searchFile(this.projectNameValue).then(response => {
        this.tableData3Loading = false
        this.tableData3 = response.data
      })
      this.tableData1Loading = true
      searchHost(this.projectNameValue).then(response => {
        this.tableData1Loading = false
        this.tableData1 = response.data
      })
    },
    getRowKeys(row) {
      return row.代号
    },
    // 查询机床所属部件
    selectMachine(row) {
      this.code = row.代号
      this.tableData4Loading = true
      this.tableData4 = []
      searchParts(this.code).then(response => {
        this.tableData4Loading = false
        this.tableData4 = response.data
      })
      this.id = row.代号
      if (this.a === 1) {
        this.expands.push(row.代号)
        this.b = row.代号
        this.a = 0
      } else {
        if (this.b === row.代号) {
          this.expands = []
          this.a = 1
        } else {
          this.expands = []
          this.expands.push(row.代号)
          this.a = 0
          this.b = row.代号
        }
      }
    },
    // 发货单查询
    searchInvoice() {
      this.cargoBoxValue = ''
      this.tableData6 = []
      this.tableData5Loading = true
      searchInvoice(this.projectNameValue).then(response => {
        const data = response.data
        this.tableData5 = data
        this.canvas = []
        for (let i = 0; i < data.length; i++) {
          this.canvas.push(data[i].发货单编号.toString())
          data[i].发货日期 = data[i].发货日期.substring(0, data[i].发货日期.length - 9)
          data[i].运输状态 === 0 ? data[i].运输状态 = '运输中' : data[i].运输状态 = '已签收'
          // QRCode.toCanvas(document.getElementById(this.canvas[i]), data[i].发货单编号.toString(), function(error) {
          //   if (error) console.error(error)
          //   console.log('success!')
          // })
        }
        this.tableData5Loading = false
        this.tableData5 = data
        return data
      }).then(res => {
        for (let i = 0; i < res.length; i++) {
          QRCode.toCanvas(document.getElementById(this.canvas[i]), 'http://123.206.50.60:8412/#/DeliveryManagement/index?id=' + res[i].发货单编号.toString(), function(error) {
            if (error) console.error(error)
            console.log('success!')
          })
        }
        this.tableData5 = res
      })
    },
    // 显示新增发货单对话框
    showAddInvoice() {
      if (this.projectNameValue === '') {
        this.$message.warning('请选择装箱单')
      } else {
        this.addForm('form1')
        this.dialogFormVisible1 = true
        this.title1 = '新增'
      }
    },
    // 提交发货单
    submitInvoice(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.flag1 === 1) {
            addInvoice(this.projectNameValue, this.form1.车辆牌号, this.form1.运输状态, this.adressNum, this.form1.发货日期, this.form1.运费).then(response => {
              this.dialogFormVisible1 = false
              if (response.data[0].result === '1') {
                this.$message.success('添加成功')
                this.searchInvoice()
                this.flag1 = ''
              } else {
                this.$message.error('添加失败')
              }
            })
          } else {
            editInvoice(this.form1.车辆牌号, this.form1.运输状态, this.adressNum, this.form1.发货日期, this.invoiceNum, this.form1.运费).then(response => {
              this.dialogFormVisible1 = false
              if (response.data[0].result === '1') {
                this.$message.success('信息更新成功')
                this.searchInvoice()
                this.flag1 = ''
              } else {
                this.$message.error('信息更新失败')
              }
            })
          }
        }
      })
    },
    // 显示编辑发货单对话框
    showEditInvoice(row) {
      this.dialogFormVisible1 = true
      this.form1.收货地址 = row.省份 + row.市名 + row.详细地址
      this.form1.车辆牌号 = row.车辆牌号
      this.form1.发货日期 = row.发货日期
      row.运输状态 === '运输中' ? this.form1.运输状态 = 0 : this.form1.运输状态 = 1
      this.form1.联系人 = row.联系人
      this.form1.联系方式 = row.联系方式
      this.adressNum = row.收货地址流水号
      this.invoiceNum = row.发货单编号
      this.title1 = '编辑'
      this.form1.运费 = row.运费
    },
    // 删除发货单
    delInvoice(row) {
      this.deleteRow(delInvoice, row.发货单编号, function() { this.searchInvoice() })
    },
    // 收货地址表格分页
    handleSizeChange1(val) {
      this.pageCurrent1 = 1
      this.pageSize1 = val
      this.getTable(addressSearch, [this.pageCurrent1, this.pageSize1], ['addressData', 'total1'])
    },
    // 收货地址表格分页
    handleCurrentChange1(val) {
      this.pageCurrent1 = val
      this.getTable(addressSearch, [this.pageCurrent1, this.pageSize1], ['addressData', 'total1'])
    },
    // 根据省分查市名
    provinceChange() {
      this.city = []
      this.cityValue = ''
      this.getSelect(citySearch, ['市名', '市流水号'], 'city', this.provinceValue)
    },
    // 删除地址
    deleteAdress(row) {
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteAdress(row.收货地址流水号).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('删除成功')
            this.getTable(addressSearch, [this.pageCurrent1, this.pageSize1], ['addressData', 'total1'])
          } else { this.$message.error('删除失败') }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 选中地址
    handleAdressChange(row) {
      this.people = row.联系人
      this.phoneNumber = row.联系方式
      this.detailedAddress = row.详细地址
      this.provinceValue = parseInt(row.省份流水号)
      this.getSelect(citySearch, ['市名', '市流水号'], 'city', this.provinceValue)
      this.cityValue = parseInt(row.市流水号)
      this.adressNum = row.收货地址流水号
      this.form1.收货地址 = row.省份 + row.市名 + row.详细地址
      this.form1.联系人 = row.联系人
      this.form1.联系方式 = row.联系方式
    },
    submitAdress() {
      if (this.people === '' || this.phoneNumber === '' || this.detailedAddress === '' || this.provinceValue === '' || this.cityValue === '') {
        this.$message.warning('请填写全部信息')
      } else {
        this.$confirm('此操作将增加新地址，是否继续', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          addAdress(this.provinceValue, this.cityValue, this.detailedAddress, this.people, this.phoneNumber).then(response => {
            if (response.data[0].result === '1') {
              this.provinceValue = ''
              this.cityValue = ''
              this.detailedAddress = ''
              this.people = ''
              this.phoneNumber = ''
              this.getTable(addressSearch, [this.pageCurrent1, this.pageSize1], ['addressData', 'total1'])
              this.$message.success('增加成功')
            } else { this.$message.error('增加失败') }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消增加'
          })
        })
      }
    },
    editAdress() {
      if (this.people === '' || this.phoneNumber === '' || this.detailedAddress === '' || this.provinceValue === '' || this.cityValue === '' || this.adressNum === '') {
        this.$message.warning('请选择要修改的地址并填全信息')
      } else {
        this.$confirm('此操作将修改该地址，是否继续', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          editAdress(this.provinceValue, this.cityValue, this.detailedAddress, this.people, this.phoneNumber, this.adressNum).then(response => {
            if (response.data[0].result === '1') {
              this.provinceValue = ''
              this.cityValue = ''
              this.detailedAddress = ''
              this.people = ''
              this.phoneNumber = ''
              this.getTable(addressSearch, [this.pageCurrent1, this.pageSize1], ['addressData', 'total1'])
              this.$message.success('修改成功')
            } else { this.$message.error('修改失败') }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消增加'
          })
        })
      }
    },
    searchCargoBox(row) {
      this.invoiceNum = row.发货单编号
      this.运输状态 = row.运输状态
      this.运输状态 === '已签收' ? this.disabledremoveInto = true : this.disabledremoveInto = false
      this.运输状态 === '已签收' ? this.disabledmoveInto = true : this.disabledmoveInto = false
      this.运输状态 === '已签收' ? this.btnAdd = true : this.btnAdd = false
      this.运输状态 === '已签收' ? this.btnDel = true : this.btnDel = false
      this.getFileList()
      this.getSelect(searchCargoBox, ['货箱号', '货箱号编号'], 'cargoBox', this.invoiceNum)
    },
    addCargoBox() {
      this.$confirm('此操作将新增货箱, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        addCargoBox(this.invoiceNum).then(response => {
          console.log(response)
          if (response.data[0].result === '1') {
            this.$message.success('增加成功')
            this.cargoBox = []
            this.cargoBoxValue = ''
          } else {
            this.$message.error('增加失败')
          }
        }).then(() => {
          this.getSelect(searchCargoBox, ['货箱号', '货箱号编号'], 'cargoBox', this.invoiceNum)
          this.运输状态 === '已签收' ? this.disabledremoveInto = true : this.disabledremoveInto = false
          this.运输状态 === '已签收' ? this.disabledmoveInto = true : this.disabledmoveInto = false
          this.运输状态 === '已签收' ? this.btnAdd = true : this.btnAdd = false
          this.运输状态 === '已签收' ? this.btnDel = true : this.btnDel = false
        })
      })
    },
    delCargoBox() {
      this.$confirm('此操作会永久删除改行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delCargoBox(this.cargoBoxValue).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('删除成功')
            this.cargoBox = []
            this.cargoBoxValue = ''
          } else {
            this.$message.error('数据占用')
          }
        }).then(() => {
          this.getSelect(searchCargoBox, ['货箱号', '货箱号编号'], 'cargoBox', this.invoiceNum)
          this.运输状态 === '已签收' ? this.disabledremoveInto = true : this.disabledremoveInto = false
          this.运输状态 === '已签收' ? this.disabledmoveInto = true : this.disabledmoveInto = false
          this.运输状态 === '已签收' ? this.btnAdd = true : this.btnAdd = false
          this.运输状态 === '已签收' ? this.btnDel = true : this.btnDel = false
        })
      })
    },
    // 选择备件
    choiceSpare(row) {
      if (parseInt(row.未发数量) === 0) {
        this.disabledmoveInto = true
      } else {
        this.disabledmoveInto = false
      }
      this.maxNum = row.未发数量
      this.form2.名称 = row.名称
      this.form2.数量 = row.数量
      this.goodsCodeName = ''
      this.partsCode = ''
      this.sparePartCode = row.备件编号
      this.fileCode = ''
      if (row.名称 === null) { this.goodsName = '' } else { this.goodsName = row.名称 }
      if (row.规格 === null) { this.goodsSpecifications = '' } else { this.goodsSpecifications = row.规格 }
      if (row.数量 === null) { this.goodsNumber = '' } else { this.goodsNumber = row.数量 }
      if (row.备注 === null) { this.goodsRemark = '' } else { this.goodsRemark = row.备注 }
    },
    // 选择文件
    choiceFile(row) {
      if (parseInt(row.未发数量) === 0) {
        this.disabledmoveInto = true
      } else {
        this.disabledmoveInto = false
      }
      this.maxNum = row.未发数量
      this.form2.名称 = row.名称
      this.form2.数量 = row.数量
      this.goodsCodeName = ''
      this.partsCode = ''
      this.sparePartCode = ''
      this.fileCode = row.文件编号
      if (row.名称 === null) { this.goodsName = '' } else { this.goodsName = row.名称 }
      this.goodsSpecifications = ''
      if (row.数量 === null) { this.goodsNumber = '' } else { this.goodsNumber = row.数量 }
      if (row.备注 === null) { this.goodsRemark = '' } else { this.goodsRemark = row.备注 }
    },
    // 选择部件
    choiceParts(row) {
      if (parseInt(row.未发数量) === 0) {
        this.disabledmoveInto = true
      } else {
        this.disabledmoveInto = false
      }
      this.maxNum = row.未发数量
      this.form2.名称 = row.名称
      this.form2.数量 = row.数量
      this.partsCode = row.部件编号
      this.sparePartCode = ''
      this.fileCode = ''
      if (row.代号 === null) { this.goodsCodeName = '' } else { this.goodsCodeName = row.代号 }
      if (row.名称 === null) { this.goodsName = '' } else { this.goodsName = row.名称 }
      if (row.规格 === null) { this.goodsSpecifications = '' } else { this.goodsSpecifications = row.规格 }
      if (row.数量 === null) { this.goodsNumber = '' } else { this.goodsNumber = row.数量 }
      if (row.备注 === null) { this.goodsRemark = '' } else { this.goodsRemark = row.备注 }
    },
    choiceGoods(row) {
      this.maxNum = row.数量
      this.form3.名称 = row.名称
      this.form3.数量 = row.数量
      this.DetailOfGoodsCode = row.货箱明细编号
      this.sparePartCode = row.备件编号
      this.fileCode = row.文件编号
      this.partsCode = row.部件编号
    },
    moveInto() {
      if (this.form2.名称 !== '' && this.form2.数量 !== '' && this.cargoBoxValue !== '') {
        this.dialogFormVisible3 = true
      } else {
        this.$message.warning(`请选择货箱及货物`)
      }
    },
    submitMoveInto() {
      this.btnLoading = true
      submitMoveInto(this.cargoBoxValue, this.goodsCodeName, this.goodsName, this.goodsSpecifications, this.form2.数量, this.goodsRemark, this.partsCode, this.sparePartCode, this.fileCode).then(response => {
        this.btnLoading = false
        if (response.data[0].result === '1') {
          this.$message.success('添加成功')
          this.form2.名称 = ''
          this.form2.数量 = ''
          this.dialogFormVisible3 = false
          this.searchCargoBoxDetailed()
          this.searchPackingListDetails()
          searchParts(this.code).then(response => {
            this.tableData4 = response.data
          })
        } else { this.$message.error('添加失败') }
      })
    },
    searchCargoBoxDetailed() {
      this.货箱号 = ''
      this.dataURL = ''
      for (let i = 0; i < this.cargoBox.length; i++) {
        if (this.cargoBoxValue === this.cargoBox[i].value) {
          this.containerNumber = this.cargoBox[i].label
        }
      }
      this.tableData6Loading = true
      searchCargoBoxDetailed(this.cargoBoxValue).then(response => {
        this.tableData6Loading = false
        this.tableData6 = response.data
      })
      this.useqrcode()
    },
    remove() {
      if (this.cargoBoxValue === '' || this.form3.名称 === '' || this.form3.数量 === '') {
        this.$message.warning('请选择货箱并选择货物')
      } else {
        this.dialogFormVisible4 = true
      }
    },
    submitRremove() {
      this.btnLoading = true
      submitRremove(this.DetailOfGoodsCode, this.form3.数量, this.partsCode, this.sparePartCode, this.fileCode, this.cargoBoxValue).then(response => {
        this.btnLoading = false
        this.dialogFormVisible4 = false
        this.form3.名称 = ''
        this.form3.数量 = ''
        if (response.data[0].result === '1') {
          this.searchCargoBoxDetailed()
          this.searchPackingListDetails()
          searchParts(this.code).then(response => {
            this.tableData4 = response.data
          })
          this.$message.sucess('移除成功')
        } else {
          this.$message.error('移除失败')
        }
      })
    },
    tableRowClassName1({ row }) {
      if (row.运输状态 === '已签收') {
        return 'background: #33cc00'
      } else {
        return ''
      }
    },
    useqrcode() {
      this.show = true
      // 生成的二维码内容，可以添加变量
      this.QueryDetail = this.cargoBoxValue.toString()
      var canvas = document.getElementById('canvas')
      QRCode.toCanvas(canvas, 'http://123.206.50.60:8412/#/searchBoxDetails/index?id=' + this.QueryDetail, function(error) {
        if (error) console.error(error)
        console.log('success!')
      })
    },
    callOffInvoice() {
      this.dialogFormVisible1 = false
    },
    clear() {
      this.show = false
      this.货箱号 = ''
      this.dataURL = ''
    },
    async getFileList() {
      const { data } = await request({
        url: '',
        method: 'post',
        data: {
          type: '3',
          name: `select * from 发货管理_附件 where 是否启用 = 1 and 发货单编号 = ${this.invoiceNum}`
        }
      })
      this.fileList = data.map(item => {
        return {
          _id: item.附件号,
          name: item.文件标识,
          url: readImg + item.文件标识
        }
      })
    },
    async handleRemove(file, fileList) {
      const { data } = await request({
        url: '',
        method: 'post',
        data: {
          type: '4',
          name: `update 发货管理_附件 set 是否启用 = 0 where 附件号 = ${file._id}`
        }
      })
      if (data[0].result === '0') {
        this.$message.error('删除失败')
      }
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url
      this.dialogVisible = true
    },
    beforeUpload(file) {
      const isJPG = /^image\/.*/.test(file.type)
      const isLt4M = file.size / 1024 / 1024 < 4
      const isInvoiceNum = !!this.invoiceNum

      if (!isInvoiceNum) {
        this.$message.error('请先选择装箱单。。')
      }

      if (!isJPG) {
        this.$message.error('只能上传图片。。')
      }
      if (!isLt4M) {
        this.$message.error('上传图片大小不能超过 4MB!')
      }

      return isJPG && isLt4M && isInvoiceNum
    },
    onSuccess(res, file, fileList) {
      fileList = []
      if (res[0].result === '1') {
        this.getFileList()
      } else {
        this.$message.error('上传失败')
      }
    },
    exportTable(row) {
      this.QueryDetail1 = row.发货单编号.toString()
      this.invoiceNum = row.发货单编号
      this.DeliveryVisiable = true
      selectDelivery(this.invoiceNum).then(response => {
        this.table = response.data
        this.装箱单名称 = response.data[0].装箱单名称
        this.发货单号 = response.data[0].发货单号
        this.收货人 = response.data[0].联系人
        this.收货地址 = response.data[0].省份 + response.data[0].市名 + response.data[0].详细地址
        this.委托车辆 = response.data[0].车辆牌号
        this.联系电话 = response.data[0].联系方式
        if (response.data[0].发货日期 !== '' || response.data[0].发货日期 !== null) {
          this.发货日期 = response.data[0].发货日期.substring(0, response.data[0].发货日期.length - 8)
        }
        return this.QueryDetail1
      }).then(data => {
        const opts = {
          errorCorrectionLevel: 'H',
          type: 'image/jpeg',
          rendererOpts: {
            quality: 0.3
          }
        }
        QRCode.toDataURL('http://123.206.50.60:8412/#/DeliveryManagement/index?id=' + data, opts, function(err, url) {
          if (err) throw err
          const img = document.getElementById('img')
          img.src = url
        })
      })
    },
    clearProject() {
      this.cargoBox = []
      this.cargoBoxValue = ''
      this.tableData6 = []
      this.fileList = []
    },
    downLoadDelivery() {
      const htmlNode = $('#pdfDom').html()
      const body = $('body')
      body.children().hide()
      const printNode = $(htmlNode)
      body.append(printNode)
      window.print()
      body.children().not('script').show()
      printNode.remove()
    },
    callOffDownLoadDelivery() {
      this.DeliveryVisiable = false
    },
    toImage() {
      this.show = false
      html2Canvas(this.$refs.imageWrapper, {
        backgroundColor: '#FFFFFF'
      }).then((canvas) => {
        const dataURL = canvas.toDataURL('image/jpeg')
        this.dataURL = dataURL
      }).then(() => {
        // var oCanvas = document.getElementById('canvas')
        var save_url = this.dataURL
        var a = document.createElement('a')
        document.body.appendChild(a)
        a.href = save_url
        a.download = this.containerNumber
        a.click()
      })
    }
  }
}
</script>

<style scoped>
  canvas{
    width: 45px !important;
    height: auto!important;
  }
  #canvas{
    width: 170px !important;
    height: auto!important;
  }
  #img{
    width: 120px !important;
    height: 120px !important;
    margin-top: 5px;
  }
  .tg  {border-collapse:collapse;border-spacing:0;}
  .tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}
  .tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:0px 0px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}
  .tg .tg-v15n{font-weight:bold;font-size:24px;border-color:inherit;text-align:center}
  .tg .tg-c3ow{border-color:inherit;text-align:center;vertical-align:top}
  .tg .tg-kluc{font-size:24px;border-color:inherit;text-align:center}
</style>
