<template>
  <div class="app-container">

    <div class = "search-bx"  >
        <div class="search">
          <el-row :gutter="0">
            <el-col :span="20">
              <el-input v-model="tableObj.getdataListParm.parammaps.deliveryCode" placeholder="发货单号" class="filter-item" style="width: 120px" />
              <el-input v-model="tableObj.getdataListParm.parammaps.stockupCodes" placeholder="备货单号" class="filter-item" style="width: 120px" />

              <!-- <el-select v-model="tableObj.getdataListParm.parammaps.customerId" placeholder="客户名称" class="filter-item" style="width: 120px;" clearable filterable>
                <el-option v-for="item in customerNameList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select> -->
              <!-- <el-autocomplete v-model="tableObj.getdataListParm.parammaps.customerName" :fetch-suggestions="customer_search" placeholder="客户名称" style="width: 200px;margin-right:10px" @select="change_customer_select" @clear="clear_customer_select" @blur="customer_search_blur" clearable>
                <template slot-scope="{ item }">
                  <span class="name">{{ item.name }}</span>
                </template>
              </el-autocomplete> -->

              <el-input v-model="tableObj.getdataListParm.parammaps.customerName" placeholder="客户名称" style="width: 180px;" class="filter-item" clearable />

              <el-select v-model="tableObj.getdataListParm.parammaps.groupId" placeholder="所属集团" class="filter-item" style="width: 120px;" clearable>
                <el-option v-for="item in groupNameList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>

              <el-select v-model="tableObj.getdataListParm.parammaps.postName" placeholder="快递名称" class="filter-item" style="width: 120px;" clearable>
                <el-option v-for="item in postNameList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>

              <el-input v-model="tableObj.getdataListParm.parammaps.postCode" placeholder="快递单号" class="filter-item" style="width: 120px" />

              <el-date-picker v-model="tableObj.getdataListParm.parammaps.inputDatetime" class="inputDatetime filter-item" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;" />

              <el-select v-model="tableObj.getdataListParm.parammaps.statusName" placeholder="单据状态" class="filter-item" style="width: 120px;" clearable>
                  <el-option v-for="item in billStatusNameList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>

            </el-col>
            <el-col :span="4">
              <el-row :gutter="0" style = "padding-bottom:10px;padding-right:20px;text-align:right;">
                <el-button class="successBorder" @click="form_search">查询</el-button>
                <el-button class="successBorder" @click="form_clear">重置</el-button>
              </el-row>
              <el-row :gutter="0" style = "padding-right:20px;text-align:right;">
                <el-button v-if="isDeliveryAdd" class="success" icon="el-icon-plus" @click="form_add">新增</el-button>
                <!-- <el-button  class="success" icon="el-icon-upload2" @click="form_export">导出</el-button> -->
              </el-row>
            </el-col>
          </el-row>
        </div>
        <!-- <div class="operation">


          <el-row :gutter="0">
            <el-col :span="21">
              <el-button v-if="isRoleEdit" class="success" icon="el-icon-plus" @click="form_add">新增</el-button>
            </el-col>
            <el-col :span="3">
                <el-dropdown>
                  <el-button class="export">导出</el-button>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item @click.native="form_export(1)">导出模板</el-dropdown-item>
                    <el-dropdown-item @click.native="form_export(2)">导出数据</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
            </el-col>
          </el-row>


        </div> -->
    </div>


    <div class="table" style="margin-top:120px">
      <el-table :key="tableObj.tableKey" v-loading="tableObj.listLoading" element-loading-text="给我一点时间" :data="tableObj.list" border fit highlight-current-row style="width: 100%;" :row-style="rowStyle" :cell-style="cellStyle" class="elTable table-fixed">
        <!-- <el-table-column type="selection" align="center" width="50" /> -->
        <el-table-column label="序号" align="center" type="index" width="50px" fixed="left">
          <template slot-scope="scope">
            <span>{{ scope.$index + (tableObj.pageNum-1) * tableObj.pageSize + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="发货单号" min-width="120px" align="center" show-overflow-tooltip fixed="left">
          <template slot-scope="scope">
            <span style = "color:#409EFF; cursor: pointer;" @click="form_see(scope.row)">{{ scope.row.deliveryCode }}</span>
          </template>
        </el-table-column>
        <el-table-column label="单据状态" min-width="90px" align="center" fixed="left">
          <template slot-scope="scope">
            <span>{{ scope.row.statusName  }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户名称" min-width="120px" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.customerName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="所属集团" min-width="110px" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.groupName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="发货日期" min-width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.sendDate }}</span>
          </template>
        </el-table-column>
        <el-table-column label="收件人名称" min-width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.receiverName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="收件人电话" min-width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.receiverTel }}</span>
          </template>
        </el-table-column>
        <el-table-column label="快递名称" min-width="110px" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.postName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="快递单号" min-width="130px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.postCode }}</span>
          </template>
        </el-table-column>

        <el-table-column label="备货单号" min-width="130px" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.stockupCodes }}</span>
          </template>
        </el-table-column>
        <el-table-column label="备注" min-width="120px" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.remark }}</span>
          </template>
        </el-table-column>
        <el-table-column label="录入日期" min-width="110px" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.createrDate }}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建人" min-width="110px" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.createrName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center"   :width="autoWidth"  v-if="autoWidth !== 0"   class-name="small-padding fixed-width" fixed="right">
          <template slot-scope="{row}">


            <el-button v-if="isDeliveryAdd && row.isModify == 1" class="miniSuccess" @click="form_edit(row)">编辑</el-button>
            <el-button v-if="isDeliveryAdd && row.isDel == 1" class="miniDanger" @click="form_delete(row)">删除</el-button>

            <el-button   v-if="row.isRevoke == 1  &&  isDeliveryAdd"    class="miniSuccess" @click="form_revoke(row)">撤销</el-button>

          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="tableObj.total>=0" :total="tableObj.total" :page.sync="tableObj.getdataListParm.offset" :limit.sync="tableObj.getdataListParm.pagecount" @pagination="get_table_data" />
    </div>

    <!-- 新增/编辑 -->
    <el-dialog :title="textMap[create.dialogStatus]" :visible.sync="create.dialogFormVisible" :close-on-click-modal="false" width="95%"  :before-close="dialog_close">
      <div class="app-add">
        <el-form ref="temp" :rules="create.rules" :model="create.temp" label-position="right" label-width="150px" style="width: 95%;margin:0 auto 50px">
          <el-row :gutter="25">
              <el-col :span="8">


                 <!-- <el-row>
                    <el-form-item label="所属集团：" prop="groupId">
                      <el-select v-model="create.temp.groupId" placeholder="所属集团" class="filter-item" style="width: 100%;" filterable  @change="change_group" clearable :disabled="create.dialogStatus=='see' || create.dialogStatus=='update'  || isHome=='home' ">
                        <el-option v-for="item in groupNameList" :key="item.id" :label="item.name" :value="item.id" />
                      </el-select>
                    </el-form-item>
                  </el-row> -->

                  <el-row>
                    <el-form-item label="客户名称：" prop="customerId">
                      <el-select v-model="create.temp.customerId" filterable placeholder="客户名称" class="filter-item"  style="width: 100%;" clearable @change="change_customer" :disabled="create.dialogStatus=='see' || create.dialogStatus=='update' || isHome=='home' ">
                        <el-option v-for="item in create.customerNameList" :key="item.id" :label="item.name" :value="item.id" />
                      </el-select>
                    </el-form-item>
                  </el-row>
                  <el-form-item label="集团：" prop="groupName">
                    <el-input ref="groupName" v-model="create.temp.groupName" class="filter-item" style="width: 100%;" disabled/>
                  </el-form-item>
                  <el-row>

                  </el-row>

                 <el-row  v-if="create.dialogStatus==='create' && isHome !=='home' ">
                      <el-form-item label="选择备货单：" prop="contractCode">
                         <el-input ref="contractCode" v-model="create.temp.stockupNums" class="filter-item" style="width: 100%;" disabled/>
                        <el-button class="miniPrimary" @click="choose_stock('create')">选择备货单</el-button>
                      </el-form-item>
                  </el-row>

                  <el-row  v-if="create.dialogStatus==='update'">
                      <el-form-item label="备货单数：" prop="contractCode">
                         <el-input ref="contractCode" v-model="create.temp.stockupNums" class="filter-item" style="width: 100%;" disabled/>
                        <el-button class="miniPrimary" @click="choose_stock('create')">选择备货单</el-button>
                      </el-form-item>
                  </el-row>

                  <el-row  v-if="create.dialogStatus==='see' ">
                      <el-form-item label="备货单数：" prop="contractCode">
                        <!-- <el-input ref="contractCode" v-model="create.temp.contractCode" class="filter-item" style="width: 100%;" disabled/> -->
                        <span style = "color:#409EFF; cursor: pointer;" @click="choose_stock('see')">{{create.temp.stockupNums }}</span>

                      </el-form-item>
                  </el-row>


                  <el-row>
                    <el-form-item label="发货日期：" prop="sendDate">
                      <el-date-picker v-model="create.temp.sendDate" type="date" placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd" style="width: 100%;" :clearable="false" :disabled="create.dialogStatus=='see'" />
                    </el-form-item>
                  </el-row>


                  <el-row>
                    <el-form-item label="收件人姓名：" prop="receiverName">
                      <el-input ref="receiverName" v-model="create.temp.receiverName" class="filter-item" style="width: 100%;"  placeholder="请输入收件人姓名" :disabled="create.dialogStatus=='see'" />
                    </el-form-item>
                  </el-row>

                  <el-row>
                    <el-form-item label="收件人电话：" prop="receiverTel">
                      <el-input ref="receiverTel" v-model="create.temp.receiverTel" class="filter-item" style="width: 100%;" maxlength="11" placeholder="请输入收件人电话" :disabled="create.dialogStatus=='see'" />
                    </el-form-item>
                  </el-row>

                  <el-row>
                      <el-form-item label="快递名称：" prop="postName">
                        <el-select ref="postName" v-model="create.temp.postName"   placeholder="请选择快递" class="filter-item" style="width: 100%;" allow-create :disabled="create.dialogStatus=='see'">
                          <el-option v-for="item in postNameList" :key="item.id" :label="item.name" :value="item.id" />
                        </el-select>
                      </el-form-item>
                  </el-row>


                  <el-row>
                      <el-form-item label="快递单号：" prop="postCode">
                        <el-input ref="postCode" v-model="create.temp.postCode" placeholder="请输入快递单号" maxlength="255" class="filter-item" style="width: 100%;" :disabled="create.dialogStatus=='see'" />
                      </el-form-item>
                  </el-row>

                  <el-row>

                    <el-form-item label="备注：" prop="remark">
                      <el-input ref="remark" v-model="create.temp.remark" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" placeholder="请输入备注，最多255个字" maxlength="255" class="filter-item" style="width: 100%;" :disabled="create.dialogStatus=='see'" />
                    </el-form-item>

                  </el-row>

              </el-col>

              <el-col :span="16">

                <h3>发货清单</h3>
                <el-row v-if="create.dialogStatus=='create' || create.dialogStatus=='update'">
                    <el-form-item label="发货详情：" prop="stockupId">
                      <el-select ref="stockupId" v-model="create.temp.stockupId" filterable placeholder="请选择发货详情" class="filter-item" style="width: 100%;" :disabled="create.dialogStatus=='see'" @change="change_receProduct">


                          <el-option v-for="item in receProductNameList" :key="item.productsId" :label='"货品名称："+ item.productsName + " 型号：" + item.model + " 规格：" + item.Specifications' :value="item.productsId">
                          </el-option>

                      </el-select>
                    </el-form-item>

                </el-row>
                <el-row>
                  <div class="table">
                    <el-table  key="0"  :data="tableDeliveryList" border fit highlight-current-row style="width: 100%;" :row-style="rowStyle" :cell-style="cellStyle" class="elTable table-fixed">

                          <el-table-column label="序号" align="center" type="index" width="50px">
                            <template slot-scope="scope">
                              <span>{{ scope.$index +1  }} </span>
                            </template>
                          </el-table-column>
                          <el-table-column label="类别" min-width="110px" align="center">
                            <template slot-scope="scope">
                              <span>{{ scope.row.categoryName  }}</span>
                            </template>
                          </el-table-column>
                            <el-table-column label="型号" min-width="110px" align="center">
                            <template slot-scope="scope">
                              <span>{{ scope.row.model }}</span>
                            </template>
                          </el-table-column>
                           <el-table-column label="规格" min-width="110px" align="center">
                            <template slot-scope="scope">
                              <span>{{ scope.row.Specifications }}</span>
                            </template>
                          </el-table-column>
                          <el-table-column label="货品名称" min-width="110px" align="center">
                            <template slot-scope="scope">
                              <span>{{ scope.row.productsName }}</span>
                            </template>
                          </el-table-column>
                          <el-table-column label="数量" min-width="110px" align="center">
                            <template slot-scope="scope">
                              <span v-if="create.dialogStatus == 'see'">{{ scope.row.nums }}</span>
                              <el-input v-if="create.dialogStatus == 'update' ||  create.dialogStatus == 'create' " v-model="scope.row.nums"   style="width:95%;padding:10px 0;" />
                            </template>
                          </el-table-column>

                          <el-table-column label="单价(元)" min-width="110px" align="center">
                            <template slot-scope="scope">
                              <span>{{ scope.row.price }}</span>
                            </template>
                          </el-table-column>

                          <el-table-column label="总价(元)" min-width="110px" align="center">
                            <template slot-scope="scope">
                              <span>{{ scope.row.sumPrice  }}</span>
                            </template>
                          </el-table-column>

                          <el-table-column label="备注" min-width="280px" align="center">
                            <template slot-scope="scope">
                              <span v-if="create.dialogStatus == 'see'">{{ scope.row.remark }}</span>
                              <el-input v-if="create.dialogStatus == 'update' ||  create.dialogStatus == 'create' " v-model="scope.row.remark" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" style="width:95%;padding:10px 0;" />
                            </template>
                          </el-table-column>
                          <el-table-column v-if="create.dialogStatus == 'update' ||  create.dialogStatus == 'create' " label="操作" align="center" width="110" class-name="small-padding fixed-width" fixed="right">
                            <template slot-scope="{row}">
                              <el-button v-if="create.dialogStatus == 'update' ||  create.dialogStatus == 'create' " class="miniDanger" @click="delivery_delete(row)">删除</el-button>
                            </template>
                          </el-table-column>

                    </el-table>

                  </div>
                </el-row>

                <el-row type="flex" justify="end">
                  <el-col style="color:#FF4949" :span="6" :offset="18">列表货物总价：{{devliSumPrice}}</el-col>
                </el-row>
                <el-divider></el-divider>


                <h3>备货清单</h3>
                <el-row  v-if = "false" >
                    <el-form-item label="备货单号：" prop="stockupId">
                      <el-select ref="stockupId" v-model="create.stockupCodeId" filterable  class="filter-item" style="width: 100%;"  @change="change_stockupCode">
                        <el-option v-for="item in create.stockupCodeList" :key="item.name" :label='item.name' :value="item.id">
                        </el-option>
                      </el-select>
                    </el-form-item>

                </el-row>

                <el-row>
                  <div class="table">
                    <el-table  key="0"  :data="tableStockList" border fit highlight-current-row style="width: 100%;" :row-style="rowStyle" :cell-style="cellStyle" class="elTable table-fixed">

                          <el-table-column label="序号" align="center" type="index" width="50px">
                            <template slot-scope="scope">
                              <span>{{ scope.row.sort  }}</span>
                            </template>
                          </el-table-column>
                          <el-table-column label="备货单号" min-width="130px" align="center">
                            <template slot-scope="scope">
                              <span>{{ scope.row.stockupCode }}</span>
                            </template>
                          </el-table-column>
                          <el-table-column label="类别" min-width="110px" align="center">
                            <template slot-scope="scope">
                              <span>{{ scope.row.categoryName  }}</span>
                            </template>
                          </el-table-column>
                          <el-table-column label="型号" min-width="110px" align="center">
                            <template slot-scope="scope">
                              <span>{{ scope.row.model }}</span>
                            </template>
                          </el-table-column>
                          <el-table-column label="规格" min-width="110px" align="center">
                            <template slot-scope="scope">
                              <span>{{ scope.row.Specifications }}</span>
                            </template>
                          </el-table-column>
                          <el-table-column label="货品名称" min-width="110px" align="center">
                            <template slot-scope="scope">
                              <span>{{ scope.row.productsName }}</span>
                            </template>
                          </el-table-column>


                          <el-table-column label="数量" min-width="110px" align="center">
                            <template slot-scope="scope">
                              <span v-if="create.dialogStatus == 'see'">{{ scope.row.nums }}</span>
                              <el-input v-if="create.dialogStatus == 'update' ||  create.dialogStatus == 'create' " v-model="scope.row.nums"   type="number"  />
                            </template>
                          </el-table-column>
                          <el-table-column label="单价(元)" min-width="110px" align="center">
                            <template slot-scope="scope">
                              <span>{{ scope.row.price }}</span>
                            </template>
                          </el-table-column>

                          <el-table-column label="总价(元)" min-width="110px" align="center">
                            <template slot-scope="scope">
                              <span>{{ scope.row.sumPrice  }}</span>
                            </template>
                          </el-table-column>

                          <el-table-column label="备注" min-width="280px" align="center">
                            <template slot-scope="scope">
                              <span v-if="create.dialogStatus == 'see'">{{ scope.row.remark }}</span>
                              <el-input v-if="create.dialogStatus == 'update' ||  create.dialogStatus == 'create' " v-model="scope.row.remark" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" style="width:95%;padding:10px 0;" />
                            </template>
                          </el-table-column>
                          <!-- <el-table-column v-if="create.dialogStatus == 'update' ||  create.dialogStatus == 'create' " label="操作" align="center" width="110" class-name="small-padding fixed-width" fixed="right">
                            <template slot-scope="{row}">
                              <el-button v-if="create.dialogStatus == 'update' ||  create.dialogStatus == 'create' " class="miniDanger" @click="stock_delete(row)">删除</el-button>
                            </template>
                          </el-table-column> -->

                    </el-table>

                  </div>
                </el-row>


                <el-row type="flex"  >
                  <el-col style="color:#FF4949;" :span="6" :offset="18">列表货物总价：{{stockSumPrice}}</el-col>
                </el-row>
                <el-divider></el-divider>

              </el-col>
          </el-row>


        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button class="cancelClose" @click="dialog_close()">关闭</el-button>

          <el-button v-if="create.dialogStatus==='create' || create.dialogStatus==='update'" class="success" :disabled="isokDisable" @click="create.dialogStatus==='create'?add_dialog_save():form_edit_save()">确认</el-button>
        </div>
      </div>
    </el-dialog>

   <!-- 备货单详情 -->
    <el-dialog  title="备货单详情" :visible.sync="seeStock.dialogFormVisible" top="10px"  :close-on-click-modal="false" width="95%">
      <div class="app-add">
        <StockDetail :stock-data="stockData"  ref="childstock"/>

        <div slot="footer" class="dialog-footer">
          <el-button  class="success"   @click="add_stock_save()">确认</el-button>
          <el-button class="cancelClose" @click="add_stock_cancel()">关闭</el-button>

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

    <!-- 撤销 -->
    <el-dialog title="确认是否撤销" :visible.sync="revoke.dialogFormVisible" :close-on-click-modal="false" width="60%">
      <div class="app-add">
        <el-form ref="revoketemp" :rules="revoke.rules" :model="revoke.temp" label-position="right" label-width="150px" style="width: 80%;margin:0 auto 50px">

          <el-form-item label="撤销原因：" prop="revokeReason">
            <el-input ref="remark" v-model="revoke.temp.revokeReason" type="textarea" :autosize="{ minRows: 4, maxRows: 8} "  :rows="8" placeholder="请输入备注，最多200个字" maxlength="200" class="filter-item" style="width: 100%;"   />
          </el-form-item>


        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button class="cancelClose" @click="revoke.dialogFormVisible = false;get_table_data()">关闭</el-button>
          <el-button class="success" @click="form_revoke_save()">确认</el-button>
        </div>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { GetDataByName, PostDataByName, failproccess, ExecDataByConfig, GetDataByNames, checkButtons, calculativeWidth, wxpush } from '@/api/common'
import Cookies from 'js-cookie'
import {  parseTime, json2excel } from '@/utils/index.js'
// import littleTable from './components/littleTable'
import Pagination from '@/components/Pagination'
import { MessageBox } from 'element-ui'

import StockDetail from '@/componentView/StockDetail.vue'

export default {
  name: 'DeliveryRecord',
  components: { Pagination, StockDetail},
  data() {
    return {

      employeid: Cookies.get('employeid'),
      isRoleEdit: [],isDeliveryAdd: [],

      rowData:{},
      isHome:"",
      send_select_list: [
        { name: 'getCustomerSelect', offset: 0, pagecount: 0, parammaps: {} },
        { name: 'getDictListSelect1', offset: 0, pagecount: 0, parammaps: { "pid": "54" } },
        { name: 'getDictListSelect4', offset: 0, pagecount: 0, parammaps: { "pid": "60" } },

        { name: 'getProductsEnable', offset: 0, pagecount: 0, parammaps: { "enable": "1" } },


      ],

      customerNameList: [], // 客户名称
      groupNameList: [], // 集团
      // 下拉框 - 快递名称
      postNameList: [
         {id: "中通快递", name: "中通快递"},
         {id: "申通快递", name: "申通快递"},
         {id: "圆通快递", name: "圆通快递"},
         {id: "顺丰快递", name: "顺丰快递"},
         {id: "韵达快递", name: "韵达快递"},
         {id: "德邦快递", name: "德邦快递"},
         {id: "京东快递", name: "京东快递"},
         {id: "其他快递", name: "其他快递"},
      ], //
      receProductNameList: [],


      // 下拉框 - 单据状态
      billStatusNameList: [
        { "name": "正常", "id": "正常" },
        { "name": "已撤销", "id": "已撤销" }
      ],

      //表格请求参数~~
      tableObj: {
        getdataListParm: {
          name: 'getDelivery',
          page: 1,
          offset: 1,
          pagecount: parseInt(Cookies.get('pagecount')),
          returntype: 'Map',
          parammaps: {
            roleId: Cookies.get('g_roleId'),
            userId: Cookies.get('g_userId'),
            customerName: "",
            deliveryCode: "",
            stockupCodes: "",
            customerId: "",
            groupId: "",
            postName: "",
            postCode: "",
            inputDatetime: "",
            beginDate: "",
            endDate: "",
            statusName: "",
          }
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        temp: {}
      },

      download: {
        getdataListParm: {
          name: 'getDelivery',
          page: 1,
          offset: 1,
          pagecount: parseInt(Cookies.get('pagecount')),
          returntype: 'Map',
          parammaps: {
            roleId: Cookies.get('g_roleId'),
            userId: Cookies.get('g_userId'),
            customerName: "",
            deliveryCode: "",
            stockupCodes: "",
            customerId: "",
            groupId: "",
            postName: "",
            postCode: "",
            inputDatetime: "",
            beginDate: "",
            endDate: "",
            statusName: "",
          }
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        temp: {}
      },

      // 新增/编辑
      create: {
        dialogFormVisible: false,
        dialogStatus: '',
        temp: { customerId: '', groupId: '', groupName: '', sendDate: parseTime(new Date(), '{y}-{m}-{d}'), receiverName: '', receiverTel: '', receiverName: '', postName: '', postCode: '', stockupIds: '', remark: '', id: '', modifyName: 'add', receiverChoose: 'true' },

        rules: {
          customerId: [{ required: true, message: '必填', trigger: 'blur' }],
          //  groupId: [{ required: true, message: '必填', trigger: 'blur' }],
          sendDate: [{ required: true, message: '必填', trigger: 'blur' }],
          receiverName: [{ required: true, message: '必填', trigger: 'blur' }],
          receiverTel: [{ required: true, message: '电话不能为空'},
            { min: 11, max: 11, message: '必填11个字符', trigger: 'blur' }],
          postName: [{ required: true, message: '必填', trigger: 'blur' }],
          postCode: [{ required: true, message: '必填', trigger: 'blur' }],
          stockupIds: [{ required: true, message: '必填', trigger: 'blur' }]
        },
        // 客户名称、
        getdataListParmCust: {
          name: 'getCustomerByGroupId',
          returntype: 'Map',
          parammaps: { groupId: "" }
        },
        customerNameList:[],


        // 发货详情小表格 - 编辑和查看时才也有
        getdataListParmDelivery: {
          name: 'getDeliveryGoodsByDeliveryId',
          returntype: 'Map',
          parammaps: { deliveryId: "" }
        },


        // 弹窗里的表格，关联发货清单时调用
        getdataListParm3: {
          name: 'getStockGoodsBySid',
          returntype: 'Map',
          parammaps: { stockupId: "" }
        },

        // 弹窗里的表格，仅编辑查看时调用
        getdataListParm4: {
          name: 'getStockupGoodsByDeliveryId',
          returntype: 'Map',
          parammaps: { deliveryId: "" }
        },


        //备货内容 - 新增时用
        getdataListStockupCode: {
          name: 'getStockGoodsBySidOfDelivery',
          returntype: 'Map',
          parammaps: { stockupId: "" }
        },

        //备货内容 - 编辑时用
        getdataListStockupCode2: {
          name: 'getStockGoodsBySidOfDelivery',
          returntype: 'Map',
          parammaps: { id: "" , stockupId: "" }
        },
        //备货内容 - 查看时用
        getdataListStockupCode3: {
          name: 'getStockGoodsBySidOfDelivery2',
          returntype: 'Map',
          parammaps: { id: "" , stockupId: "" }
        },

        //下拉框 - 备货单号数组
        stockupCodeList:[]

      },
      textMap: {
        create: '新增',
        see: '查看',
        update: '编辑'
      },


      //备货单的ID集合
      stockupCodeIdArr: [],

      stockupIds:"",


      //发货表格集合
      tableDeliveryList: [],
      //备货表格集合
      tableStockList: [],


      //备货详情组件
      stockData:{ id:"" },
      seeStock: {
        dialogFormVisible: false,
      },


      // 撤销
      revoke: {
        dialogFormVisible: false,
        dialogStatus: '',
        temp: { revokeReason: '',  id: '' },
        rules: {
          revokeReason: [{ required: true, message: '必填', trigger: 'blur' }],
        }
      },

      devliSumPrice:0,
      stockSumPrice:0,

      autoWidth: 130,

      requestParam: {},
      isokDisable: false,
      selectList: [],
      rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
      cellStyle: { padding: 0 + 'px' }
    }
  },


  watch: {
    tableDeliveryList: {
      deep: true,
      handler: function (item) {
          //计算总价格
          var sum = 0
          this.tableDeliveryList.forEach(function(i){
              sum = parseInt(i.nums) * parseFloat(i.price) + sum
          })
          this.devliSumPrice = sum

      }
    },
    tableStockList: {
      deep: true,
      handler: function (item) {
          //计算总价格
          var sum = 0

          this.tableStockList.forEach(function(i){
              sum = parseInt(i.nums) * parseFloat(i.price) + sum
          })


          this.tableStockList.forEach(function(i){

            if(parseInt(i.nums) > parseFloat(i.maxNums)){
              i.nums = i.maxNums
            }

          })

          this.stockSumPrice = sum


      }
    },


  },

  created() {
    this.get_table_data()
    this.get_select_list()
    this.get_auto_buttons()

    var rowData = this.$route.params.rowData
    var isHome = this.$route.params.isHome

    console.log("rowData",rowData)
    console.log("isHome",isHome)

    if(isHome == 'home'){
      this.rowData = rowData
      this.isHome = isHome
      this.form_add()
    } else {
      this.rowData = {}
      this.isHome = ""
    }


  },

  mounted() {
    this.RoadlittleTable()


  },

  methods: {
    RoadlittleTable() {
      const vue = this
      var littleTable = () => import('./components/littleTable')
      return vue.littleTable = littleTable
    },
    //获取按钮权限
    get_auto_buttons() {
      const Edit = 'deliveryRecord'
      const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
      this.isRoleEdit = isRoleEdit

      const DeliveryAdd = 'business:delivery:add'
      const isDeliveryAdd = checkButtons(this.$store.state.user.buttons, DeliveryAdd)
      this.isDeliveryAdd = isDeliveryAdd


      //操作的宽度
    // var widthCount = calculativeWidth(isDeliveryAdd,isDeliveryAdd,isDeliveryAdd)
    // this.autoWidth = widthCount

    },
    //获取所有下拉框的内容
    get_select_list() {

      GetDataByNames(this.send_select_list).then(response => {
        this.create.customerNameList = response.data.getCustomerSelect.list
        console.log("客户名称下拉框", this.create.customerNameList)
        this.groupNameList = response.data.getDictListSelect1.list
        console.log("集团下拉框", this.groupNameList)
        // this.postNameList = response.data.getDictListSelect4.list
        // console.log("快递名下拉框", this.postNameList)

        response.data.getProductsEnable.list.map(function (i) {
          return (i.customerId = "")
        })
        response.data.getProductsEnable.list.map(function (i) {
          return (i.nums = "")
        })
        response.data.getProductsEnable.list.map(function (i) {
          return (i.remark = "")
        })
        this.receProductNameList = response.data.getProductsEnable.list
        console.log("货品下拉框", this.receProductNameList)


      })

    },
    //加载表格
    get_table_data() {
      var me = this

      this.tableObj.listLoading = true
      console.log("this.tableObj.getdataListParm======>", this.tableObj.getdataListParm)
      GetDataByName(this.tableObj.getdataListParm).then(response => {
        console.log('table数据======>', response.data.list)
        if (response.data.list !== null) {

          this.tableObj.list = response.data.list
          this.tableObj.pageNum = response.data.pageNum
          this.tableObj.pageSize = response.data.pageSize
          this.tableObj.total = response.data.total

           //计算操作栏宽度
           var btnNum = 0
              var arrList = response.data.list
              arrList.forEach(function(row){
                  var itemBtnNum = 0
                  if(me.isDeliveryAdd && row.isModify == 1 ){
                    itemBtnNum = itemBtnNum + 1
                  }
                  if(me.isDeliveryAdd && row.isDel == 1 ){
                    itemBtnNum = itemBtnNum + 1
                  }
                  if(row.isRevoke == 1  &&  me.isDeliveryAdd){
                    itemBtnNum = itemBtnNum + 1
                  }

                  console.log(itemBtnNum)
                  if(itemBtnNum > btnNum){
                    btnNum = itemBtnNum
                  }
              })
              console.log("btnNum=============",btnNum)
              me.autoWidth = btnNum * 90


        } else {
          this.tableObj.list = []
        }
        setTimeout(() => {
          this.tableObj.listLoading = false
        }, 100)
      })
    },
    form_search() {
      console.log('点击了查询')

      if (this.tableObj.getdataListParm.parammaps.inputDatetime !== '' && this.tableObj.getdataListParm.parammaps.inputDatetime !== null) {
        this.tableObj.getdataListParm.parammaps.beginDate = parseTime(this.tableObj.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
        this.tableObj.getdataListParm.parammaps.endDate = parseTime(this.tableObj.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
      } else {
        this.tableObj.getdataListParm.parammaps.inputDatetime = ''
        this.tableObj.getdataListParm.parammaps.beginDate = ''
        this.tableObj.getdataListParm.parammaps.endDate = ''
      }
      this.tableObj.getdataListParm.offset = 1
      this.get_table_data()
    },
    form_clear() {
      console.log('点击了重置')

      this.tableObj.getdataListParm.parammaps.customerName = ''

      this.tableObj.getdataListParm.parammaps.deliveryCode = ''
      this.tableObj.getdataListParm.parammaps.stockupCodes = ''
      this.tableObj.getdataListParm.parammaps.customerId = ''
      this.tableObj.getdataListParm.parammaps.groupId = ''
      this.tableObj.getdataListParm.parammaps.postName = ''
      this.tableObj.getdataListParm.parammaps.postCode = ''
      this.tableObj.getdataListParm.parammaps.beginDate = ''
      this.tableObj.getdataListParm.parammaps.endDate = ''
      this.tableObj.getdataListParm.parammaps.inputDatetime = ''
      this.tableObj.getdataListParm.offset = 1
      this.get_table_data()
    },

    // 新增
    form_reset() {
      this.create.temp = {customerName: "", customerId: '', groupId: '', groupName: '', sendDate: parseTime(new Date(), '{y}-{m}-{d}'), receiverName: '', receiverTel: '', receiverName: '', postName: '', postCode: '', stockupIds: '', remark: '', id: '', modifyName: 'add', receiverChoose: 'true' }
      this.stockupIdArr = []
      this.tableArrList = []
      this.tableDeliveryList = []
      this.tableStockList = []

    },


    //客户失去焦点
    customer_search_blur(item) {
      console.log("客户失去焦点")
      this.tableObj.getdataListParm.parammaps.customerId = ""
      this.tableObj.getdataListParm.parammaps.customerName = ""
      this.customerNameList = []
    },


    //模糊查询客户
    customer_search(queryString, cb) {
      console.log('模糊查询输入值', queryString)
      GetDataByName({ name: 'getCustomerNameFuzzy', page: 1, offset: 1, pagecount: 10, returntype: 'Map', parammaps: { inputvalue: queryString } }).then(response => {
        this.customerNameList = response.data.list
        console.log("客户名称下拉框", response)
        cb(response.data.list)
      })
    },

    //模糊查询客户选择
    change_customer_select(item) {
      console.log('客户名称模糊查询选中值', item)
      this.tableObj.getdataListParm.parammaps.customerId = item.id
      this.tableObj.getdataListParm.parammaps.customerName = item.name
    },

    //清空客户选择
    clear_customer_select(item) {
      document.activeElement.blur()

      this.tableObj.getdataListParm.parammaps.customerId = ""
      this.tableObj.getdataListParm.parammaps.customerName = ""


    },


    //监听 - 集团
    change_group(item) {
      console.log(item)
      console.log(this.create.temp.groupId)
      this.create.temp.groupId = item
      this.create.getdataListParmCust.parammaps.groupId = item

      this.create.temp.customerName = ""
      this.create.temp.customerId = ""
      this.create.customerNameList = []

      this.get_customer_list()


        //清空备货单信息
         this.create.temp.stockupCode = ""
        this.create.stockupCodeList = []
        this.stockupCodeIdArr = []
        this.create.temp.stockupNums = 0
        this.tableStockList = []


      this.$forceUpdate();

    },
    // 弹窗中的客户
    get_customer_list() {
      GetDataByName(this.create.getdataListParmCust).then(response => {
        if (response.data.list !== null) {
          this.create.customerNameList = response.data.list
          console.log('弹窗中的客户数据', response.data.list)
        } else {
          this.create.customerNameList = []
        }
      })
    },


    //监听 - 下拉中客户名称
    change_customer(item) {
      console.log(item)
      this.create.temp.customerId = item
      this.get_groupName(item)
        this.create.temp.stockupCode = ""
        this.create.stockupCodeList = []
        this.stockupCodeIdArr = []
        this.create.temp.stockupNums = 0
        this.tableStockList = []
        this.$forceUpdate();
    },


    // 获取集团名称
    get_groupName(customerId) {
      var me = this
      var send_data = {
        name: 'getgroupNameById',  returntype: 'Map',  parammaps: {  id: customerId }
      }
      GetDataByName(send_data).then(response => {

        console.log(response)
        if (response.data.list !== null) {
           me.create.temp.groupName = response.data.list[0].groupName
           me.create.temp.groupId = response.data.list[0].groupId
        } else {
           me.create.temp.groupName = ""
           me.create.temp.groupId = ""
        }
      })
    },


    //新增
    form_add() {
      console.log('点击了新增')

      this.create.dialogStatus = 'create'
      this.create.dialogFormVisible = true

      this.$nextTick(() => {
      //需要执行的内容
        this.form_reset()
        //首页跳过来的新增，要带出客户信息
        if(this.isHome == "home"){
            this.create.temp.groupId = this.rowData.groupId
            this.create.temp.customerId = this.rowData.customerId
            this.create.temp.groupName = this.rowData.groupName
            this.create.temp.customerName = this.rowData.customerName
            // this.create.getdataListParmCust.parammaps.groupId = this.rowData.groupId
            // this.get_customer_list()

            this.stockupCodeIdArr = [this.rowData.id]

            this.create.getdataListStockupCode.parammaps.stockupId = this.rowData.id
            this.getStockNameList()

            // this.create.getdataListParm1.parammaps.customerId = this.rowData.customerId
            // this.get_postalNameList()
            // this.create.getdataListParm4.parammaps.id = this.rowData.id
            // this.getReceProduct2()
            // this.create.getdataListParmCust.parammaps.groupId = this.rowData.groupId
            // this.get_customer_list()
        }
      })


    },
    //新增保存
    add_dialog_save() {
      console.log('点击了新增保存')
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.$refs['temp'].validate(valid => {
        if (valid) {
          this.isokDisable = true
          setTimeout(() => {
            this.isokDisable = false
          }, 1000)


            var stockupCodeIdArr = this.stockupCodeIdArr

            var customerId = this.create.temp.customerId

            this.tableDeliveryList.map(function (i) {
              return (i.customerId = customerId)
            })

            this.tableStockList.map(function (i) {
              return (i.customerId = customerId)
            })

            this.create.temp.stockupIds = stockupCodeIdArr.join()
            this.create.temp.createrId = Cookies.get('employeid')


          var send_data1 = {
              "common": {"returnmap": "0"},
              "data": [
                {
                  "name": "insertDelivery","type": "e",
                  "parammaps": this.create.temp
                },
                {
                  "name": "insertDeliveryGoods",
                  "resultmaps": {
                    "list": this.tableDeliveryList
                  },
                  "children": [{
                    "name": "insertDeliveryGoods",
                    "type": "e",
                    "parammaps": {
                    "deliveryId": "@insertDelivery.LastInsertId",
                    "customerId": "@insertDeliveryGoods.customerId",
                    "productsId": "@insertDeliveryGoods.productsId",
                    "nums": "@insertDeliveryGoods.nums",
                    "remark": "@insertDeliveryGoods.remark",
                    }
                  }]
                },

                {
                  "name": "insertDeliveryGoods2",
                  "resultmaps": {
                    "list": this.tableStockList
                  },
                  "children": [{
                      "name": "insertDeliveryGoods2",
                      "type": "e",
                      "parammaps": {
                        "deliveryId": "@insertDelivery.LastInsertId",
                      "customerId": "@insertDeliveryGoods2.customerId",
                        "productsId": "@insertDeliveryGoods2.productsId",
                        "nums": "@insertDeliveryGoods2.nums",
                        "remark": "@insertDeliveryGoods2.remark",
                        "useStockupId": "@insertDeliveryGoods2.useStockupId"
                      }
                    }]
                },


                {
                  "name": "updateStockupOnSendNums",
                  "type": "e",
                  "parammaps": {
                    "id":this.create.temp.stockupIds
                  }
                }
            ]
          }

          var send_data2 = {
              "common": {"returnmap": "0"},
              "data": [
                {
                  "name": "insertDelivery","type": "e",
                  "parammaps": this.create.temp
                },
                {
                  "name": "insertDeliveryGoods",
                  "resultmaps": {
                    "list": this.tableDeliveryList
                  },
                  "children": [{
                    "name": "insertDeliveryGoods",
                    "type": "e",
                    "parammaps": {
                    "deliveryId": "@insertDelivery.LastInsertId",
                    "customerId": "@insertDeliveryGoods.customerId",
                    "productsId": "@insertDeliveryGoods.productsId",
                    "nums": "@insertDeliveryGoods.nums",
                    "remark": "@insertDeliveryGoods.remark",
                    }
                  }]
                },

                {
                  "name": "updateStockupOnSendNums",
                  "type": "e",
                  "parammaps": {
                    "id":this.create.temp.stockupIds
                  }
                }
            ]
          }

          console.log("this.tableStockList",this.tableStockList.length )

            console.log('新增保存发送参数 - 有备货', send_data1)
            console.log('新增保存发送参数  - 无备货', send_data2)

            //无备货
            if(this.tableStockList.length == 0){
                ExecDataByConfig(send_data2).then(response => {

                  if (response.msg !== 'fail') {
                    this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
                    this.create.dialogFormVisible = false
                    this.get_table_data()


                    var rowId = response.data[0].resultmaps.LastInsertId
                    this.get_wxPush(21,'发货',rowId)


                    if(this.isHome == 'home'){
                      // 回到首页
                      this.$router.push({ name: 'Dashboard', params: { isTodo: 'delivery' }})
                    }
                  } else {
                    this.$notify({ title: '失败', message: '保存失败' + response.data, type: 'error', duration: 2000 })
                  }
                })
            //有备货
            } else {

              ExecDataByConfig(send_data1).then(response => {

                if (response.msg !== 'fail') {
                  this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
                  this.create.dialogFormVisible = false
                  this.get_table_data()


                  var rowId = response.data[0].resultmaps.LastInsertId
                    this.get_wxPush(21,'发货',rowId)


                  if(this.isHome == 'home'){
                      // 回到首页
                      this.$router.push({ name: 'Dashboard', params: { isTodo: 'delivery' }})
                    }
                } else {
                  this.$notify({ title: '失败', message: '保存失败' + response.data, type: 'error', duration: 2000 })
                }
              })

            }


            // ExecDataByConfig(send_data).then(response => {

            //   if (response.msg !== 'fail') {
            //     this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
            //     this.create.dialogFormVisible = false
            //     this.get_table_data()
            //   } else {
            //     this.$notify({ title: '失败', message: '保存失败' + response.data, type: 'error', duration: 2000 })
            //   }
            // })


        }
      })
    },
      //微信推送
      get_wxPush(remindId,remindTypeName,rowId){
                   var send_weixin_data1 = {
                        name: 'getRemindData',
                        parammaps: {
                          "userId":Cookies.get('g_userId'),
                          "remindId":remindId,
                          "remindTypeName":remindTypeName,
                          "rowId":rowId

                        }
                      }

                      GetDataByName(send_weixin_data1).then(response => {
                        console.log('微信推送(获取参数)======>', response )
                        if (response.data.message == 'ok') {
                          var receiverStr = response.data.list[0].receivers
                          var receiverArr = receiverStr.split(',')
                          var value1 = response.data.list[0].value1
                          var value2 = response.data.list[0].value2
                          var value3 = response.data.list[0].value3
                          var value4 = response.data.list[0].value4
                          var send_weixin_data2 = {
                            "target": receiverArr,
                            "serviceId": remindId,
                            "content": [
                              { "color": "#173177","value": value1 },
                              { "color": "#173177", "value": value2 },
                              { "color": "#173177", "value": value3 },
                              { "color": "#173177","value": value4 }
                            ]
                          }


                            wxpush(send_weixin_data2).then(response => {
                              console.log('微信推送(获取参数)======>', response )
                            })
                         // this.tableSumMoney = response.data.list[0].totlePrice
                        } else {
                          // this.$notify({ title: '失败', message: '消息推送失败', type: 'error', duration: 2000 })
                        }
                      })
    },
    // 查看
    form_see(row) {
      this.form_reset()
      console.log('点击了查看', row)

      // this.$nextTick(() => {
      //   this.$refs.temp.resetFields()
      //   this.create.temp = Object.assign({}, row)

      // })

      this.create.temp = Object.assign({}, row)


      this.create.temp.id = row.id

      if(row.stockupIds){
        this.stockupCodeIdArr = row.stockupIds.split(",")
        this.seeStockupIds = row.stockupIds
      } else {
        this.stockupCodeIdArr = []
        this.seeStockupIds = ""
      }


      this.create.getdataListParmDelivery.parammaps.deliveryId = row.id
      this.getDeliveryList()

      // this.create.getdataListParmCust.parammaps.groupId = row.groupId
      // this.get_customer_list()


      // if (row.stockupIds !== "") {
      //     this.get_stock_select(row.id)
      // } else {
      //     this.tableStockList = []
      // }


      // console.log('点击了编辑', row.stockupIds)

      if (row.stockupIds !== "") {
         this.create.getdataListStockupCode3.parammaps.id = row.id
          this.create.getdataListStockupCode3.parammaps.stockupId = row.stockupIds
          this.getStockNameList3()
      } else {
        this.tableStockList = []
      }


      this.create.dialogStatus = 'see'
      this.create.dialogFormVisible = true

    },


    // 获取查看弹窗中的备货下拉框
    get_stock_select( id) {

      var send_data = {
          name: 'getStockupCodeByDeliveryId',
          returntype: 'Map',
          parammaps: { deliveryId: id }
        }
      GetDataByName(send_data).then(response => {
        console.log("获取查看弹窗中的备货下拉框", response.data.list)
        if (response.data.list !== null) {
          this.create.stockupCodeList = response.data.list


          if(this.create.dialogStatus == 'update'){
            this.create.getdataListStockupCode2.parammaps.id = id
            this.create.getdataListStockupCode2.parammaps.stockupId = response.data.list[0].id
            this.getStockNameList2()
          }

          if(this.create.dialogStatus == 'see'){
            this.create.getdataListStockupCode3.parammaps.id = id
            this.create.getdataListStockupCode3.parammaps.stockupId = response.data.list[0].id
            this.getStockNameList3()
          }


        }else{
          this.create.stockupCodeList = []
        }

      })
    },


    // 编辑
    form_edit(row) {
      this.form_reset()
      console.log('点击了编辑', row)

      // this.$nextTick(() => {
      //   this.$refs.temp.resetFields()
      //   this.create.temp = Object.assign({}, row)

      // })

      this.create.temp = Object.assign({}, row)

      this.create.temp.id = row.id


      if(row.stockupIds){
        this.stockupCodeIdArr = row.stockupIds.split(",")

      } else {
        this.stockupCodeIdArr = []

      }

      this.create.getdataListParmDelivery.parammaps.deliveryId = row.id
      this.getDeliveryList()

      // this.create.getdataListParmCust.parammaps.groupId = row.groupId
      // this.get_customer_list()


      console.log('点击了编辑', row.stockupIds)

      if (row.stockupIds !== "") {
          this.create.getdataListStockupCode2.parammaps.id = row.id
          this.create.getdataListStockupCode2.parammaps.stockupId = row.stockupIds
          this.getStockNameList2()
      } else {
        this.tableStockList = []
      }


      this.create.dialogStatus = 'update'
      this.create.dialogFormVisible = true

    },

    // 获取编辑弹窗中的发货表格
    getDeliveryList() {
      GetDataByName(this.create.getdataListParmDelivery).then(response => {
        console.log("获取编辑弹窗中的发货表格", response.data.list)
        if (response.data.list !== null) {
          this.tableDeliveryList = response.data.list
        } else {
          this.tableDeliveryList = []
        }

      })
    },


    // 编辑保存
    form_edit_save() {
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.$refs['temp'].validate(valid => {
        if (valid) {
          this.isokDisable = true
          setTimeout(() => {
            this.isokDisable = false
          }, 1000)


            var stockupCodeIdArr = this.stockupCodeIdArr

            var customerId = this.create.temp.customerId

            this.tableDeliveryList.map(function (i) {
              return (i.customerId = customerId)
            })

            this.tableStockList.map(function (i) {
              return (i.customerId = customerId)
            })

            this.create.temp.stockupIds = stockupCodeIdArr.join()
            this.create.temp.createrId = Cookies.get('employeid')


            console.log(" this.create.temp.stockupIds ", this.create.temp.stockupIds )


            var send_data1 =  {
              "common": {"returnmap": "0"},
              "data": [
                {
                  "name": "updateDelivery",
                  "type": "e",
                  "parammaps":  this.create.temp
                },
                {
                  "name": "delDeliveryGoods",
                  "type": "e",
                  "parammaps": {
                    "deliveryId":this.create.temp.id
                  }
                },
                {
                  "name": "insertDeliveryGoods",
                  "resultmaps": {
                        "list": this.tableDeliveryList
                  },
                  "children": [
                    {
                      "name": "insertDeliveryGoods",
                      "type": "e",
                      "parammaps": {
                      "deliveryId": this.create.temp.id,
                      "customerId": "@insertDeliveryGoods.customerId",
                      "productsId": "@insertDeliveryGoods.productsId",
                      "nums": "@insertDeliveryGoods.nums",
                      "remark": "@insertDeliveryGoods.remark"
                      }
                    }]
                },

                {
                  "name": "insertDeliveryGoods2",
                  "resultmaps": {
                        "list": this.tableStockList
                  },
                  "children": [{
                        "name": "insertDeliveryGoods2",
                        "type": "e",
                        "parammaps": {
                          "deliveryId":  this.create.temp.id,
                        "customerId": "@insertDeliveryGoods2.customerId",
                          "productsId": "@insertDeliveryGoods2.productsId",
                          "nums": "@insertDeliveryGoods2.nums",
                          "remark": "@insertDeliveryGoods2.remark",
                          "useStockupId": "@insertDeliveryGoods2.useStockupId"
                        }
                      }]
                },


               {
                 "name": "updateStockupOnSendNums",
                 "type": "e",
                 "parammaps": {"id":this.create.temp.stockupIds }
               }
            ]
          }

          var send_data2 =  {
              "common": {"returnmap": "0"},
              "data": [
                {
                  "name": "updateDelivery",
                  "type": "e",
                  "parammaps":  this.create.temp
                },
                {
                  "name": "delDeliveryGoods",
                  "type": "e",
                  "parammaps": {
                    "deliveryId":this.create.temp.id
                  }
                },
                {
                  "name": "insertDeliveryGoods",
                  "resultmaps": {
                        "list": this.tableDeliveryList
                  },
                  "children": [
                    {
                      "name": "insertDeliveryGoods",
                      "type": "e",
                      "parammaps": {
                      "deliveryId": this.create.temp.id,
                      "customerId": "@insertDeliveryGoods.customerId",
                      "productsId": "@insertDeliveryGoods.productsId",
                      "nums": "@insertDeliveryGoods.nums",
                      "remark": "@insertDeliveryGoods.remark"
                      }
                    }]
                },
               {
                 "name": "updateStockupOnSendNums",
                 "type": "e",
                 "parammaps": {"id":this.create.temp.stockupIds }
               }
            ]
          }
            console.log('编辑保存发送参数 - 有备货', send_data1)
            console.log('编辑保存发送参数  - 无备货', send_data2)

          if( this.tableStockList.length == 0){
            ExecDataByConfig(send_data2).then(response => {

              if (response.msg !== 'fail') {
                this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
                this.create.dialogFormVisible = false
                this.get_table_data()

                var rowId = this.create.temp.id


this.get_wxPush(21,'发货',rowId)


              } else {
                this.$notify({ title: '失败', message: '保存失败' + response.data, type: 'error', duration: 2000 })
              }
            })
          } else {

            ExecDataByConfig(send_data1).then(response => {

              if (response.msg !== 'fail') {
                this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
                this.create.dialogFormVisible = false
                this.get_table_data()


                var rowId = this.create.temp.id


              this.get_wxPush(21,'发货',rowId)


              } else {
                this.$notify({ title: '失败', message: '保存失败' + response.data, type: 'error', duration: 2000 })
              }
            })

          }


        }
      })
    },

    // 删除
    form_delete(row) {
      MessageBox.confirm('是否确认删除此信息?', {
        confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
      }).then(() => {


        var send_data =  {
              name: 'delDelivery',
              parammaps: {id:row.id}
        }
        PostDataByName(send_data).then(response => {
          if (response.msg === 'fail') {
            this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
          } else {
            this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
            this.get_table_data()
          }
        })
      }).catch(() => {
        this.$message({ type: 'info', message: '已取消删除' })
      })
    },

    // 撤销
    form_revoke(row) {
      console.log('点击了完成备货', row)
      this.reset_revoke()

      this.revoke.temp.id = row.id
      this.revoke.temp.stockupIds = row.stockupIds
      this.revoke.dialogFormVisible = true
    },
    // 撤销 - 重置
    reset_revoke() {
      this.revoke.temp.revokeReason = ""
    },

    // 完成确认
    form_revoke_save() {
      this.$refs['revoketemp'].validate(valid => {
        if (valid) {
          var send_data = {
            "common": {"returnmap": "0"},
            "data": [
              {
                "name": "revokeDeliveryGoods","type": "e",
                "parammaps": {"id":this.revoke.temp.id}
              },
              {
                "name": "revokeDelivery","type": "e",
                "parammaps": this.revoke.temp
              },
              {
                "name": "updateStockupOnSendNums","type": "e",
                "parammaps": {"id":this.revoke.temp.stockupIds}
              }
            ]
          }
          ExecDataByConfig(send_data).then(response => {
            console.log('撤销发送参数', send_data)
            if (response.msg !== 'fail') {
              this.$notify({ title: '成功', message: '撤销成功', type: 'success', duration: 2000 })
              this.revoke.dialogFormVisible = false
              this.get_table_data()

              var send_weixin_data1 = {
                        name: 'getRemindData',
                        parammaps: {
                          "userId":Cookies.get('g_userId'),
                          "remindId": 22,
                          "remindTypeName":'发货',
                          "rowId":this.revoke.temp.id

                        }
                      }

                      GetDataByName(send_weixin_data1).then(response => {
                        console.log('微信推送(获取参数)======>', response )
                        if (response.data.message == 'ok') {
                          var receiverStr = response.data.list[0].receivers
                          var receiverArr = receiverStr.split(',')
                          var value1 = response.data.list[0].value1
                          var value2 = response.data.list[0].value2
                          var value3 = response.data.list[0].value3
                          var value4 = response.data.list[0].value4
                          var send_weixin_data2 = {
                            "target": receiverArr,
                            "serviceId": 22,
                            "content": [
                              { "color": "#173177","value": value1 },
                              { "color": "#173177", "value": value2 },
                              { "color": "#173177", "value": value3 },
                              { "color": "#173177","value": value4 }
                            ]
                          }


                            wxpush(send_weixin_data2).then(response => {
                              console.log('微信推送(获取参数)======>', response )
                            })
                         // this.tableSumMoney = response.data.list[0].totlePrice
                        } else {
                          // this.$notify({ title: '失败', message: '消息推送失败', type: 'error', duration: 2000 })
                        }
                      })


            } else {
              this.$notify({ title: '失败', message: '撤销失败' + response.data, type: 'error', duration: 2000 })
            }
          })

        }
      })
    },


     //下拉 - 发货详情
    change_receProduct(item) {
      console.log("发货品ID ", item)
      var index = this.receProductNameList.findIndex(obj => obj.productsId == item)
      console.log("备货品index ", index)
      var ifHasId = this.tableDeliveryList.findIndex(obj => obj.productsId == item)
      console.log("备货品是否存在列表 ", ifHasId)

      var addRow = Object.assign({}, this.receProductNameList[index])
      addRow.nums = 1
      addRow.remark = ""
      if (ifHasId == "-1") {
        this.tableDeliveryList.unshift(addRow)
      }


    },

    delivery_delete(row ) {
      console.log('发货小表格中的删除', row )
      var index2 = this.tableDeliveryList.findIndex(obj => obj.id == row.id)
      this.tableDeliveryList.splice(index2, 1)
      console.log('tableDeliveryList', this.tableDeliveryList )
    },


    //选择备货单
    choose_stock(item) {
      console.log('查看备货单详情')
      // this.stockData.id = row.id

      var customerId = this.create.temp.customerId
      var groupId = this.create.temp.groupId

      if(item == "see"){
        this.stockData.title = 'see'
        this.stockData.stockupIds = this.seeStockupIds
        this.seeStock.dialogFormVisible = true


         this.$nextTick(()=>{
          this.$refs.childstock.parent_change_parp(customerId,groupId,'see')
        })


      } else {
        this.stockData.title = 'create'
        if(customerId !== "" && groupId !== "" && customerId !== null && groupId !== null){
        this.seeStock.dialogFormVisible = true
        this.$nextTick(()=>{
          this.$refs.childstock.parent_change_parp(customerId,groupId,'create')
        })

        } else {
          this.$notify({ title: '失败', message: '必须选择集团和客户名称后才能选择合同！' , type: 'error', duration: 2000 })
        }
      }


    },
    //确认备货单
    add_stock_save() {
      console.log('查看备货单子组件传递的信息this.stockData',this.stockData)
      console.log('查看备货单子组件传递的信息this.stockData.selectList',this.stockData.selectList)

      if (this.stockData.selectList.length == 0) {
        this.create.temp.stockupCode = ""
        this.create.stockupCodeList = []

        this.stockupCodeIdArr = []

        this.create.temp.stockupNums = 0
      }  else {

        this.create.temp.stockupNums = this.stockData.selectList.length

        var stockupCodeIdArr = []

        this.stockData.selectList.forEach(function(i){
           stockupCodeIdArr.push(i.id)
        })
        this.stockupCodeIdArr = stockupCodeIdArr


          if(this.create.dialogStatus == 'create'){
              this.create.getdataListStockupCode.parammaps.stockupId = stockupCodeIdArr.join()
              this.getStockNameList()
          } else if(this.create.dialogStatus == 'update'){
              this.create.getdataListStockupCode2.parammaps.id = this.create.temp.id
              this.create.getdataListStockupCode2.parammaps.stockupId = stockupCodeIdArr.join()
              this.getStockNameList2()
          } else {
              this.create.getdataListStockupCode3.parammaps.id = this.create.temp.id
              this.create.getdataListStockupCode3.parammaps.stockupId = stockupCodeIdArr.join()
              this.getStockNameList3()
          }
      }
      this.$refs.childstock.form_clear()

      this.seeStock.dialogFormVisible = false

    },

    add_stock_cancel(){
      this.$refs.childstock.form_clear()
      this.seeStock.dialogFormVisible = false
      this.get_table_data()

    },


    //备货清单小表格删除
    stock_delete(row ) {
      console.log('小表格中的删除', row )
      var index2 = this.tableStockList.findIndex(obj => obj.id == row.id)
      this.tableStockList.splice(index2, 1)
      console.log('tableStockList', this.tableStockList )
    },


    //监听 - 备货单号
    change_stockupCode(item) {
      console.log(item)


         if(this.create.dialogStatus == 'create'){
              this.create.getdataListStockupCode2.parammaps.stockupId = item
              this.getStockNameList()
          } else if(this.create.dialogStatus == 'update'){
            this.create.getdataListStockupCode2.parammaps.id = this.create.temp.id
            this.create.getdataListStockupCode2.parammaps.stockupId = item
            this.getStockNameList2()
          } else {
            this.create.getdataListStockupCode3.parammaps.id = this.create.temp.id
            this.create.getdataListStockupCode3.parammaps.stockupId = item
            this.getStockNameList3()
          }


    },

    // 弹窗中的备货单 - 新增用
    getStockNameList() {
      GetDataByName( this.create.getdataListStockupCode).then(response => {
        if (response.data.list !== null) {
          this.tableStockList = response.data.list
          console.log('弹窗中的备货单 - 新增用-', response.data.list)
        } else {
          this.tableStockList = []
        }
      })
    },
    //弹窗中的备货单 - 编辑用
    getStockNameList2() {
      console.log(this.create.getdataListStockupCode2)
      GetDataByName( this.create.getdataListStockupCode2).then(response => {
        if (response.data.list !== null) {
          this.tableStockList = response.data.list
          console.log('弹窗中的备货单 - 编辑用', response.data.list)
        } else {
          this.tableStockList = []
        }
      })
    },

    //弹窗中的备货单 - 查看用
    getStockNameList3() {
      console.log(this.create.getdataListStockupCode3)
      GetDataByName( this.create.getdataListStockupCode3).then(response => {
        if (response.data.list !== null) {
          this.tableStockList = response.data.list
          console.log('弹窗中的备货单 - 查看用', response.data.list)
        } else {
          this.tableStockList = []
        }
      })
    },

    dialog_close(){
      this.create.dialogFormVisible = false
      this.get_table_data()
      if(this.isHome == 'home'){
       // 返回首页
       this.$router.push({ name: 'Dashboard', params: { isTodo: 'delivery' }})
      }
    },


    // 导出
    form_export(item) {

       this.download.getdataListParm.parammaps = this.tableObj.getdataListParm.parammaps

       GetDataByName(this.download.getdataListParm).then(response => {
         if (response.data.list !== null) {
           this.download.list = response.data.list
         } else {
           this.download.list = []
         }
         var excelDatas = [
           {
             tHeader: ['序号', '发货单号', '单据状态', '客户名称', '客户集团', '发货日期', '收件人名称', '快递名称', '快递单号', '备货单号', '备注', '录入日期' ],
             filterVal: ['sort',  'deliveryCode', 'statusName', 'customerName', 'groupName', 'sendDate', 'receiverName', 'postName', 'postCode', 'remark', 'createrDate'  ],
             tableDatas: this.download.list,
             sheetName: 'Sheet1'
           }
         ]
         json2excel(excelDatas, '发货记录', true, 'xlsx')
       })

     },

    // 导入
    form_inport() {
      console.log('点击了导入')
    }

  }
}
</script>
<style lang="scss" scoped>
.search {
  padding-top: 10px;
  clear: both;
}
.table {
  margin-top: 10px;
}
</style>
