<template>
  <div class="app-container">
    <div class="search-bx">
      <div class="search">
        <el-row :gutter="0">
          <el-input
            v-model="tableObj.getdataListParm.parammaps.stockupCode"
            placeholder="备货单号"
            class="filter-item"
            style="width: 120px; padding-bottom: 10px"
          />

          <!-- <el-autocomplete v-model="tableObj.getdataListParm.parammaps.customerName" :fetch-suggestions="customer_search" placeholder="客户名称" style="width: 200px;margin-right:10px" @select="changeCustomer0" @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-input
            v-model="tableObj.getdataListParm.parammaps.contractCode"
            placeholder="合同编号"
            class="filter-item"
            style="width: 120px"
          />

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

          <el-input
            v-model="tableObj.getdataListParm.parammaps.beginProgress"
            placeholder="发货进度"
            style="width: 90px"
            onkeyup="this.value=this.value.replace(/[^\d.]/g,'');"
          ></el-input>
          -
          <el-input
            v-model="tableObj.getdataListParm.parammaps.endProgress"
            placeholder="发货进度"
            style="width: 90px"
            onkeyup="this.value=this.value.replace(/[^\d.]/g,'');"
          ></el-input>

          <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-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.sourceName"
            placeholder="订单来源"
            class="filter-item"
            style="width: 120px"
            clearable
          >
            <el-option
              v-for="item in sourceNameList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>

          <el-select
            v-model="tableObj.getdataListParm.parammaps.employeeId"
            placeholder="创建人"
            class="filter-item"
            style="width: 120px"
            clearable
          >
            <el-option
              v-for="item in employeeNameList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>

          <el-button class="successBorder" @click="form_search">查询</el-button>
          <el-button class="successBorder" @click="form_clear">重置</el-button>

          <el-button
            v-if="isStockAdd"
            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>
      </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-row>
      </div> -->
    </div>

    <div class="table">
      <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"
        :max-height="myHeight"
      >
        <!-- <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.stockupCode }}</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="90px"
          align="center"
          fixed="left"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.progress }}</span>
          </template>
        </el-table-column>
        <el-table-column label="预定发货时间" min-width="120px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.planSendDate }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户名称" min-width="180px" align="center">
          <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.orderDate }}</span>
          </template>
        </el-table-column>

        <el-table-column
          label="订单来源"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.sourceName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="单据编号"
          min-width="130px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span
              v-if="scope.row.contractCodeType == 'hetong'"
              style="color: #409eff; cursor: pointer"
              @click="on_contractCode_tap(scope.row.contractCode)"
              >{{ scope.row.contractCode }}</span
            >
            <span
              v-else
              style="color: #409eff; cursor: pointer"
              @click="on_contractCodeWei_tap(scope.row.contractCode)"
              >{{ scope.row.contractCode }}</span
            >
          </template>
        </el-table-column>
        <el-table-column
          label="备货原因"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.reasonName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="创建人"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.createName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="录入日期"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.createDate }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="发货日期"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.successDate }}</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="120px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.statusName }}</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
              class="miniPrimary"
              v-if="row.isFeedBack == 1 && isStockFeedback"
              @click="form_see(row)"
              >备货反馈</el-button
            >
            <el-button
              class="miniSuccess"
              v-if="row.isModify == 1 && isStockAdd"
              @click="form_edit(row)"
              >编辑</el-button
            >
            <el-button
              class="miniDanger"
              v-if="row.isDel == 1 && isStockAdd"
              @click="form_delete(row)"
              >删除</el-button
            >
            <el-button
              v-if="row.isRevoke == 1 && isStockAdd"
              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-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-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
                v-if="
                  create.dialogStatus === 'create' ||
                  create.dialogStatus === 'update'
                "
              >
                <el-form-item label="选择合同：" prop="contractCode">
                  <el-input
                    ref="contractCode"
                    v-model="create.temp.contractCode"
                    class="filter-item"
                    style="width: 100%"
                    disabled
                  />
                  <el-button
                    v-show="isHome !== 'home'"
                    class="miniPrimary"
                    @click="choose_contract()"
                    >选择合同</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
                  />
                </el-form-item>
              </el-row>

              <!-- 这里改先选集团再选客户 -->

              <el-row>
                <!-- <el-form-item label="客户名称：" prop="customerName">

                      <el-autocomplete ref="customerName" v-model="create.temp.customerName" :fetch-suggestions="customer_search" placeholder="客户名称" style="width: 100%;margin-right:10px" @select="changeCustomer" :disabled="create.dialogStatus=='see' || create.dialogStatus=='update'" @clear="clear_customer_selectTemp" @blur="customer_search_blurTemp" clearable >
                        <template slot-scope="{ item }">
                          <span class="name">{{ item.name }}</span>
                        </template>
                      </el-autocomplete>


                    </el-form-item> -->
                <!-- <el-form-item label="客户名称：" prop="customerName">
                        <el-autocomplete v-model="create.temp.customerName" :fetch-suggestions="customer_search" placeholder="客户名称" style="width: 100%;margin-right:10px" @select="changeCustomer" v-if="create.dialogStatus=='create'" @clear="clear_customer_selectTemp" @blur="customer_search_blurTemp" clearable>
                          <template slot-scope="{ item }">
                            <span class="name">{{ item.name }}</span>
                          </template>
                        </el-autocomplete>
                        <el-input ref="customerName" v-model="create.temp.customerName" class="filter-item" style="width: 100%;" disabled v-else/>
                      </el-form-item> -->
              </el-row>
              <!-- <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-form-item label="下单日期：" prop="orderDate">
                  <el-date-picker
                    v-model="create.temp.orderDate"
                    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="reasonName">
                  <el-select
                    ref="reasonName"
                    v-model="create.temp.reasonName"
                    filterable
                    placeholder="请选择备货原因"
                    class="filter-item"
                    style="width: 100%"
                    allow-create
                    :disabled="create.dialogStatus == 'see'"
                  >
                    <el-option
                      v-for="item in reasonNameList"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    />
                  </el-select>
                </el-form-item>
              </el-row>

              <el-row>
                <el-form-item label="订单来源：" prop="sourceName">
                  <el-select
                    ref="sourceName"
                    v-model="create.temp.sourceName"
                    filterable
                    placeholder="请选择订单原因"
                    class="filter-item"
                    style="width: 100%"
                    allow-create
                    :disabled="create.dialogStatus == 'see'"
                    clearable
                  >
                    <el-option
                      v-for="item in sourceNameList"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    />
                  </el-select>
                </el-form-item>
              </el-row>

              <el-row>
                <el-form-item label="关联接收快递：" prop="postalId">
                  <el-select
                    ref="postalId"
                    v-model="create.temp.postalId"
                    filterable
                    placeholder="请选择接收快递"
                    class="filter-item"
                    style="width: 100%"
                    :disabled="create.dialogStatus == 'see'"
                    @change="changePostalName"
                    clearable
                  >
                    <el-option
                      v-for="item in create.postalNameList"
                      :key="item.id"
                      :label="item.postCode"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-row>

              <el-row>
                <el-form-item label="预定发货时间：" prop="planSendDate">
                  <el-date-picker
                    v-model="create.temp.planSendDate"
                    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 v-if="create.dialogStatus == 'see'">
                <!-- <el-form-item label="创建人：" prop="employeeName">
                        <el-input ref="employeeName" v-model="create.temp.employeeName" class="filter-item" style="width: 100%;" disabled/>
                      </el-form-item> -->
                <el-form-item label="创建人：" prop="createName">
                  <el-input
                    ref="createName"
                    v-model="create.temp.createName"
                    class="filter-item"
                    style="width: 100%"
                    disabled
                  />
                </el-form-item>
              </el-row>

              <el-row v-if="create.dialogStatus == 'see'">
                <el-form-item label="录入日期：" prop="createDate">
                  <el-input
                    ref="createDate"
                    v-model="create.temp.createDate"
                    class="filter-item"
                    style="width: 100%"
                    disabled
                  />
                </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-row v-if="create.dialogStatus=='see'">
                    <el-col :span="24">
                      <el-form-item label="备货状态：" prop="statusName">
                        <el-input ref="statusName" v-model="create.temp.statusName" class="filter-item" style="width: 100%;" disabled/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item label="录入日期：" prop="created">
                        <el-input ref="created" v-model="create.temp.created" class="filter-item" style="width: 100%;" disabled/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row v-if="create.dialogStatus=='see'">
                    <el-col :span="24">
                      <el-form-item label="备货人：" prop="employeeName">
                        <el-input ref="employeeName" v-model="create.temp.employeeName" class="filter-item" style="width: 100%;" disabled/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="24">
                      <el-form-item label="备货日期：" prop="successDate">
                        <el-input ref="successDate" v-model="create.temp.successDate" class="filter-item" style="width: 100%;" disabled/>
                      </el-form-item>
                    </el-col>
                  </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="visiterId">
                  <el-select
                    ref="visiterId"
                    v-model="create.temp.visiterId"
                    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>
                <el-table
                  :key="contact.tableKey"
                  v-loading="contact.listLoading"
                  element-loading-text="给我一点时间"
                  :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.$index + 1 }}</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>{{ 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 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="form_delete2(row)"
                        >删除</el-button
                      >
                    </template>
                  </el-table-column>
                </el-table>
              </el-row>

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

              <h3 v-if="create.dialogStatus == 'see'">反馈记录</h3>
              <el-row v-if="create.dialogStatus == 'see'">
                <div v-for="item in feedRecordList">
                  <div>
                    <span>{{ item.num }}</span>
                    <span>{{ item.remark }}</span>
                  </div>
                  <el-row type="flex" justify="end">
                    <el-col :span="6">
                      {{ item.createDate }}
                    </el-col>
                    <el-col :span="6"> 反馈人：{{ item.employeeName }} </el-col>
                  </el-row>
                  <el-divider></el-divider>
                </div>

                <el-input
                  type="textarea"
                  :rows="4"
                  placeholder="请输入内容"
                  v-model="feedRecordTemp.parammaps.remark"
                >
                </el-input>

                <el-button class="success" @click="feedRecord_save()"
                  >确认</el-button
                >
              </el-row>
            </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="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>

    <!-- 合同详情 -->
    <el-dialog
      title="合同详情"
      :visible.sync="seeContract.dialogFormVisible"
      top="10px"
      :close-on-click-modal="false"
      width="95%"
    >
      <div class="app-add">
        <ContractDetail :contract-data="contractData" ref="childcontract" />

        <div slot="footer" class="dialog-footer">
          <el-button class="cancelClose" @click="close_contract()"
            >关闭</el-button
          >
          <el-button class="success" @click="add_contract_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 Pagination from "@/components/Pagination";
import { MessageBox } from "element-ui";

import ContractDetail from "@/componentView/ContractDetail.vue";

export default {
  name: "StockNotice",
  components: { Pagination, ContractDetail },
  data() {
    return {
      myHeight: document.documentElement.clientHeight - 85 - 160,
      employeid: Cookies.get("employeid"),
      isStockAdd: [],
      isStockFeedback: [],
      isRoleEdit: [],

      rowData: {},
      isHome: "",

      send_select_list: [
        { name: "getCustomerSelect", offset: 0, pagecount: 0, parammaps: {} },
        {
          name: "getDictListSelect1",
          offset: 0,
          pagecount: 0,
          parammaps: { pid: "54" },
        },
        { name: "getEmployeesSelect", offset: 0, pagecount: 0, parammaps: {} },
        {
          name: "getDictListSelect2",
          offset: 0,
          pagecount: 0,
          parammaps: { pid: "58" },
        },
        {
          name: "getDictListSelect3",
          offset: 0,
          pagecount: 0,
          parammaps: { pid: "59" },
        },

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

      // 下拉框 - 客户名称
      customerNameList: [
        // {id: 1425, name: "测试12"},
        // {id: 1423, name: "朝日牧场（唯品牧场）"},
        // {id: 1422, name: "富源牧业（眉山）有限公司（眉山富源）"}
      ],
      //  下拉框 - 集团
      groupNameList: [
        // {id: 253, name: "无"},
        // {id: 207, name: "星连星牧业"},
        // {id: 208, name: "海高牧业"},
        // {id: 254, name: "完达山"}
      ],
      // 下拉框 - 备货人
      employeeNameList: [
        // {id: 18, name: "韩佳佳"},
        // {id: 19, name: "多秋阳"},
        // {id: 20, name: "张明星"},
      ],
      statusNameList: [
        { name: "待备货", id: "待备货" },
        { name: "已完成", id: "已完成" },
      ],
      // 下拉框 - 单据状态
      billStatusNameList: [
        { name: "正常", id: "正常" },
        { name: "已撤销", id: "已撤销" },
      ],
      //下拉框 - 订单来源
      sourceNameList: [
        { name: "电话", id: "电话" },
        { name: "网络", id: "网络" },
        { name: "销售", id: "销售" },
      ],
      //下拉框 - 备货原因
      reasonNameList: [
        { name: "购买", id: "购买" },
        { name: "维修", id: "维修" },
        { name: "更换", id: "更换" },
      ], //

      // 收件货品
      receProductNameList: [
        //  {"Specifications":"CC","categoryId":39,"categoryName":"铲车表","model":"套","price":"0.00","productsId":73,"productsName":"显示终端","remark":"质保期1年","sort":49},
        //  {"Specifications":"AWT15-0115","categoryId":40,"categoryName":"称重表","model":"套","price":"0.00","productsId":74,"productsName":"称重显示模组","remark":"质保期1年","sort":50},
        //  {"Specifications":"TMR","categoryId":38,"categoryName":"TMR表","model":"套","price":"0.00","productsId":76,"productsName":"新TMR表","remark":"","sort":1},
        //  {"Specifications":"CZB","categoryId":40,"categoryName":"称重表","model":"套","price":"0.00","productsId":77,"productsName":"称重表","remark":"","sort":1}
      ],

      //表格请求参数~~
      tableObj: {
        getdataListParm: {
          name: "getStockup",
          page: 1,
          offset: 1,
          pagecount: parseInt(Cookies.get("pagecount")),
          returntype: "Map",
          parammaps: {
            roleId: Cookies.get("g_roleId"),
            userId: Cookies.get("g_userId"),
            stockupCode: "",
            customerId: "",
            customerName: "",
            groupId: "",
            contractCode: "",
            beginProgress: "",
            endProgress: "",
            employeeId: "",
            statusName: "",
            sourceName: "",
            inputDatetime: "",
            beginDate: "",
            endDate: "",
          },
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        temp: {},
      },

      download: {
        getdataListParm: {
          name: "getStockup",
          page: 1,
          offset: 1,
          pagecount: 0,
          returntype: "Map",
          parammaps: {
            roleId: Cookies.get("g_roleId"),
            userId: Cookies.get("g_userId"),
            stockupCode: "",
            customerId: "",
            customerName: "",
            groupId: "",
            contractCode: "",
            beginProgress: "",
            endProgress: "",
            employeeId: "",
            statusName: "",
            sourceName: "",
            inputDatetime: "",
            beginDate: "",
            endDate: "",
          },
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        temp: {},
      },

      // 新增/编辑
      create: {
        dialogFormVisible: false,
        dialogStatus: "",
        temp: {
          customerId: "",
          customerName: "",
          groupId: "",
          groupName: "",
          sdate: parseTime(new Date(), "{y}-{m}-{d}"),
          reasonId: "",
          sourceId: "",
          remark: "",
          id: "",
          modifyName: "add",
          receiverChoose: "true",
          statusName: "",
          createDate: "",
          createName: "",
          employeeName: "",
          successDate: "",
          contractCode: "",
          orderDate: "",
          reasonName: "",
          sourceName: "",
          postalId: "",
          postalName: "",
          planSendDate: "",
        },

        rules: {
          customerId: [{ required: true, message: "必填", trigger: "blur" }],
          // groupId: [{ required: true, message: '必填', trigger: 'blur' }],
          // reasonId: [{ required: true, message: '必填', trigger: 'blur' }],
          // visiterId: [{ required: true, message: '必填', trigger: 'blur' }]
        },
        // 关联接收快递名称
        getdataListParm1: {
          name: "getPostalsByCustomerId",
          page: 1,
          offset: 1,
          pagecount: 10,
          returntype: "Map",
          parammaps: { customerId: "" },
        },
        postalNameList: [], //关联接收快递名称
        // 集团
        getdataListParm2: {
          name: "getgroupNameById",
          page: 1,
          offset: 1,
          pagecount: 10,
          returntype: "Map",
          parammaps: { id: "" },
        },
        // 弹窗里的表格，关联快递下拉时调用
        getdataListParm3: {
          name: "getPostalGoodsById",
          page: 1,
          offset: 1,
          pagecount: 10,
          returntype: "Map",
          parammaps: { postalId: "" },
        },
        // 弹窗里的表格，仅编辑查看时调用
        getdataListParm4: {
          name: "getStockGoodsBySid",
          page: 1,
          offset: 1,
          pagecount: 10,
          returntype: "Map",
          parammaps: { id: "" },
        },
        // 客户名称、
        getdataListParmCust: {
          name: "getCustomerByGroupId",
          returntype: "Map",
          parammaps: { groupId: "" },
        },
        customerNameList: [],
      },
      textMap: {
        create: "新增",
        see: "查看",
        update: "编辑",
      },

      //客户资料详情组件
      contractData: { id: "", groupId: "", customerId: "" },
      seeContract: {
        dialogFormVisible: false,
      },

      // 管理
      contact: {
        dialogFormVisible: false,
        dialogStatus: "",
        temp: {
          id: "",
          contactName: "",
          telephone: "",
          address: "",
          remark: "",
        },
        rules: {},
        getdataListParm: {
          name: "getContacts",
          page: 1,
          offset: 1,
          pagecount: 10,
          returntype: "Map",
          parammaps: { customerId: "" },
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: false,
      },
      //备货表格
      tableStockList: [],

      //获取反馈记录
      getFeedRecordParm: {
        name: "getStockFeedbackBySid",
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: "Map",
        parammaps: { id: "" },
      },
      //保存反馈记录
      feedRecordTemp: {
        name: "insertStockFeedback",
        page: 1,
        offset: 1,
        pagecount: 1000,
        returntype: "Map",
        parammaps: {
          stockupId: "",
          createrId: "",
          remark: "",
        },
      },

      //反馈记录
      feedRecordList: [
        // {id:1, num: 1, txt: '主板缺失零件，疫情关系，无法采购，延期1天',   director:'epans', date:"2022-12-01"},
        // {id:1, num: 1, txt: '主板缺失零件，疫情关系，无法采购，延期1天',   director:'epans', date:"2022-12-01"},
        // {id:1, num: 1, txt: '主板缺失零件，疫情关系，无法采购，延期1天',   director:'epans', date:"2022-12-01"},
      ],

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

      autoWidth: 130,

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

  watch: {
    tableStockList: {
      deep: true,
      handler: function (item) {
        //计算总价格
        var sum = 0;
        this.tableStockList.forEach(function (i) {
          sum = parseInt(i.nums) * parseFloat(i.price) + sum;
        });
        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.rowData.customerId = 1146;
      this.form_add();
    } else {
      this.rowData = {};
      this.isHome = "";
    }
  },

  methods: {
    //获取按钮权限
    get_auto_buttons() {
      const Edit = "stockNotice";
      const isRoleEdit = checkButtons(
        JSON.parse(sessionStorage.getItem("buttons")),
        Edit
      );
      this.isRoleEdit = isRoleEdit;

      const StockAdd = "business:stocknotice:add";
      const isStockAdd = checkButtons(this.$store.state.user.buttons, StockAdd);
      this.isStockAdd = isStockAdd;

      const StockFeedback = "business:stocknotice:feedback";
      const isStockFeedback = checkButtons(
        this.$store.state.user.buttons,
        StockFeedback
      );
      this.isStockFeedback = isStockFeedback;

      //操作的宽度
      // var widthCount = calculativeWidth(isStockFeedback,isStockAdd,isStockAdd,isStockAdd)
      // 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.employeeNameList = response.data.getEmployeesSelect.list;
        console.log("备货人下拉框", this.employeeNameList);
        // this.reasonNameList = response.data.getDictListSelect2.list
        // console.log("备货原因下拉框", this.reasonNameList)
        // this.sourceNameList = response.data.getDictListSelect3.list
        // console.log("订单来源下拉框", this.sourceNameList)

        // response.data.getProductsEnable.list.map(function (i) {
        //   return (i.productsId = i.id)
        // })
        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.msg !== "fail") {
          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 (row.isFeedBack == 1 && me.isStockFeedback) {
                itemBtnNum = itemBtnNum + 1;
              }
              if (row.isModify == 1 && me.isStockAdd) {
                itemBtnNum = itemBtnNum + 1;
              }
              if (row.isDel == 1 && me.isStockAdd) {
                itemBtnNum = itemBtnNum + 1;
              }
              if (row.isRevoke == 1 && me.isStockAdd) {
                itemBtnNum = itemBtnNum + 1;
              }
              console.log(itemBtnNum);
              if (itemBtnNum > btnNum) {
                btnNum = itemBtnNum;
              }
            });
            console.log("btnNum=============", btnNum);
            me.autoWidth = btnNum * 90;
          } else {
            this.tableObj.list = [];
          }
        } else {
          this.$notify({
            title: "查询列表失败",
            message: response.data,
            type: "error",
            duration: 2000,
          });
        }
        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 = "";
      }

      if (
        this.tableObj.getdataListParm.parammaps.beginProgress !== "" &&
        this.tableObj.getdataListParm.parammaps.endProgress !== ""
      ) {
        if (
          parseFloat(this.tableObj.getdataListParm.parammaps.beginProgress) >
          parseFloat(this.tableObj.getdataListParm.parammaps.endProgress)
        ) {
          this.$notify({
            title: "失败",
            message: "起始发货进度需要小于终止发货进度!",
            type: "error",
            duration: 2000,
          });
        } else {
          this.tableObj.getdataListParm.offset = 1;
          this.get_table_data();
        }
      } else {
        this.tableObj.getdataListParm.offset = 1;
        this.get_table_data();
      }
    },
    form_clear() {
      console.log("点击了重置");
      this.tableObj.getdataListParm.parammaps.stockupCode = "";
      this.tableObj.getdataListParm.parammaps.customerId = "";
      this.tableObj.getdataListParm.parammaps.customerName = "";
      this.tableObj.getdataListParm.parammaps.groupId = "";
      this.tableObj.getdataListParm.parammaps.contractCode = "";
      this.tableObj.getdataListParm.parammaps.beginProgress = "";
      this.tableObj.getdataListParm.parammaps.endProgress = "";
      this.tableObj.getdataListParm.parammaps.statusName = "";
      this.tableObj.getdataListParm.parammaps.beginDate = "";
      this.tableObj.getdataListParm.parammaps.endDate = "";
      this.tableObj.getdataListParm.parammaps.sourceName = "";

      this.tableObj.getdataListParm.parammaps.employeeId = "";

      this.tableObj.getdataListParm.parammaps.inputDatetime = "";
      this.tableObj.getdataListParm.offset = 1;
      this.get_table_data();
    },

    // 新增
    form_reset() {
      this.create.temp = {
        customerId: "",
        customerName: "",
        groupId: "",
        groupName: "",
        sdate: parseTime(new Date(), "{y}-{m}-{d}"),
        reasonId: "",
        sourceId: "",
        remark: "",
        id: "",
        modifyName: "add",
        receiverChoose: "true",
        statusName: "",
        created: "",
        employeeName: "",
        createName: "",
        successDate: "",
      };
      this.tableStockList = [];
    },

    clear_customer_selectTemp(item) {
      document.activeElement.blur();
      this.create.temp.customerId = "";
      this.create.temp.customerName = "";
      this.create.temp.groupName = "";
      this.$forceUpdate();
    },

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

    //模糊查询客户
    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);
      });
    },
    //模糊查询客户选择
    changeCustomer0(item) {
      console.log("客户名称模糊查询选中值", item);
      this.tableObj.getdataListParm.parammaps.customerId = item.id;
      this.tableObj.getdataListParm.parammaps.customerName = item.name;
    },

    //清空客户选择
    clear_customer_select(item) {
      this.tableObj.getdataListParm.parammaps.customerId = "";
      this.tableObj.getdataListParm.parammaps.customerName = "";
      document.activeElement.blur();
    },

    //监听 - 下拉中客户名称
    changeCustomer(item) {
      console.log(item);
      this.create.temp.customerId = item.id;
      this.create.temp.customerName = item.name;
      this.$forceUpdate();
      this.create.getdataListParm1.parammaps.customerId = item.id;
      // this.create.temp.barname = this.houseNameList.find(obj => obj.id === item).bname
      this.get_postalNameList();
      this.create.getdataListParm2.parammaps.id = item.id;
      this.getGroupNameId();
    },

    //监听 - 集团
    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.create.temp.contractCode = "";
      this.tableStockList = [];

      this.get_customer_list();
      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.create.temp.contractCode = "";
      this.tableStockList = [];

      this.$forceUpdate();
      this.create.getdataListParm1.parammaps.customerId = item;
      // this.create.temp.barname = this.houseNameList.find(obj => obj.id === item).bname
      this.get_postalNameList();
      this.get_groupName(item);
    },
    // 获取集团名称
    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 = "";
        }
      });
    },

    //获取 - 关联接收快递查询
    get_postalNameList() {
      GetDataByName(this.create.getdataListParm1).then((response) => {
        if (response.data.list !== null) {
          this.create.postalNameList = response.data.list;
          console.log("关联接收数据", response.data.list);
        } else {
          this.create.postalNameList = [];
        }
      });
    },

    // 集团名称
    getGroupNameId() {
      GetDataByName(this.create.getdataListParm2).then((response) => {
        if (response.data.list !== null) {
          this.create.temp.groupName = response.data.list[0].groupName;
          this.create.temp.groupId = response.data.list[0].groupId;
          console.log("集团名称", response.data.list);
        }
      });
    },
    //下拉 - 关联接收快递
    // changePostalName(item) {
    //   console.log("关联接收快递ID ", item)
    //   this.create.getdataListParm3.parammaps.postalId = item
    //   this.contact.list = []
    //   this.getReceProduct()
    // },

    changePostalName(item) {
      console.log("关联接收快递ID ", item);
      this.create.getdataListParm3.parammaps.postalId = item;

      var itemname = "";
      this.create.postalNameList.forEach(function (i) {
        if (item == i.id) {
          itemname = i.postCode;
        }
      });

      this.create.temp.postalId = item;
      this.create.temp.postalName = item.name;
      this.tableStockList = [];
      this.getReceProduct();
    },

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

      var addRow = Object.assign({}, this.receProductNameList[index]);
      addRow.nums = 1;
      addRow.remark = "";
      if (ifHasId == "-1") {
        this.tableStockList.unshift(addRow);
      }
    },
    //小表格中的删除
    form_delete2(row) {
      console.log("小表格中的删除", row);
      var productsId = row.productsId;
      console.log("小表格中的删除tableStockList", this.tableStockList);
      var index = this.tableStockList.findIndex(
        (obj) => obj.productsId == productsId
      );
      console.log("index", index);
      this.tableStockList.splice(index, 1);
    },

    //选择合同
    choose_contract() {
      // console.log('查看合同')
      console.log("customerId", this.create.temp.customerId);
      console.log("groupId", this.create.temp.groupId);
      // var customerId = this.create.temp.customerId
      // var groupId = this.create.temp.groupId

      // this.seeContract.dialogFormVisible = true

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

      if (
        customerId !== "" &&
        groupId !== "" &&
        customerId !== null &&
        groupId !== null
      ) {
        this.seeContract.dialogFormVisible = true;
        this.$nextTick(() => {
          this.$refs.childcontract.parent_change_parp(customerId, groupId);
        });
      } else {
        this.$notify({
          title: "失败",
          message: "必须选择集团和客户名称后才能选择合同！",
          type: "error",
          duration: 2000,
        });
      }
    },

    close_contract() {
      // this.contractData.id = row.id
      this.$refs.childcontract.form_clear();
      this.seeContract.dialogFormVisible = false;
    },

    //确认合同
    add_contract_save() {
      console.log("查看合同子组件传递的信息", this.contractData);
      if (this.contractData.selectList.length == 0) {
        this.$message({
          type: "error",
          message: "请选择合同信息",
          duration: 2000,
        });
      } else if (this.contractData.selectList.length > 1) {
        this.$message({
          type: "error",
          message: "请选择1条合同信息",
          duration: 2000,
        });
      } else {
        this.$refs.childcontract.form_clear();
        this.seeContract.dialogFormVisible = false;
        this.create.temp.contractCode =
          this.contractData.selectList[0].contractCode;
        var send_data = {
          name: "getContractGoodsByCid",
          page: 1,
          offset: 1,
          pagecount: 10,
          returntype: "Map",
          parammaps: {
            id: this.contractData.selectList[0].id,
          },
        };

        GetDataByName(send_data).then((response) => {
          console.log("table数据======>", response.data.list);
          if (response.data.list !== null) {
            this.tableStockList = response.data.list;
            console.log("弹窗中的备货单 - 新增用-", response.data.list);
          } else {
            this.tableStockList = [];
          }
        });
      }
    },

    //新增
    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.contractCode = this.rowData.contractCode;
          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()

          var send_data = {
            name: "getContractGoodsByCid",
            page: 1,
            offset: 1,
            pagecount: 10,
            returntype: "Map",
            parammaps: {
              id: this.rowData.id,
            },
          };

          GetDataByName(send_data).then((response) => {
            console.log("table数据======>", response.data.list);
            if (response.data.list !== null) {
              this.tableStockList = response.data.list;
              console.log("弹窗中的备货单 - 新增用-", response.data.list);
            } else {
              this.tableStockList = [];
            }
          });
        }
      });
    },
    //新增保存
    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 customerId = this.create.temp.customerId;
          this.tableStockList.map(function (i) {
            return (i.customerId = customerId);
          });
          this.tableStockList.map(function (i) {
            return (i.postalId = "");
          });

          this.create.temp.createrId = Cookies.get("employeid");
          console.log("点击了新增保存", this.create.temp);
          console.log("点击了新增保存", this.tableStockList);

          var send_data = {
            common: { returnmap: "0" },
            data: [
              {
                name: "insertStockup",
                type: "e",
                parammaps: this.create.temp,
              },
              {
                name: "insertStockupGoods",
                resultmaps: {
                  list: this.tableStockList,
                },
                children: [
                  {
                    name: "insertStockupGoods",
                    type: "e",
                    parammaps: {
                      productsId: "@insertStockupGoods.productsId",
                      nums: "@insertStockupGoods.nums",
                      remark: "@insertStockupGoods.remark",
                      useContractId: "@insertStockupGoods.useContractId",
                      customerId: "@insertStockupGoods.customerId",
                      stockupId: "@insertStockup.LastInsertId",
                    },
                  },
                ],
              },
            ],
          };

          var isEmpty = this.tableStockList.find((i) => i.nums == "");
          console.log(isEmpty);
          if (isEmpty) {
            this.$message({
              type: "error",
              message: "货品数量不可为空",
              duration: 2000,
            });
          } else {
            ExecDataByConfig(send_data).then((response) => {
              console.log("新增保存发送参数", this.requestParam);
              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(18, "备货", rowId);

                if (this.isHome == "home") {
                  // 回到首页
                  this.$router.push({
                    name: "Dashboard",
                    params: { isTodo: "stock" },
                  });
                }
              } 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();
      this.reset_feedRecord();

      this.create.temp = Object.assign({}, row);
      console.log("点击了查看", row);

      this.create.getdataListParm1.parammaps.customerId = row.customerId;
      // this.create.temp.barname = this.houseNameList.find(obj => obj.id === item).bname
      this.get_postalNameList();

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

      this.create.getdataListParm4.parammaps.id = row.id;
      this.getReceProduct2();

      this.getFeedRecordParm.parammaps.id = row.id;
      this.feedRecordTemp.parammaps.stockupId = row.id;
      this.get_feedRecord();

      this.create.dialogStatus = "see";
      this.create.dialogFormVisible = true;
    },

    // 查看中的反馈记录
    get_feedRecord() {
      GetDataByName(this.getFeedRecordParm).then((response) => {
        console.log("查看中的反馈记录", response.data.list);
        if (response.data.list !== null) {
          this.feedRecordList = response.data.list;
        } else {
          this.feedRecordList = [];
        }
      });
    },

    on_contractCode_tap(item) {
      this.$router.push({ name: "ContractInfo", params: { num: item } });
    },

    on_contractCodeWei_tap(item) {
      this.$router.push({ name: "RepairService", params: { num: item } });
    },

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

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

      this.create.getdataListParm1.parammaps.customerId = row.customerId;
      this.get_postalNameList();
      this.create.getdataListParm4.parammaps.id = row.id;
      this.getReceProduct2();

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

      this.create.dialogStatus = "update";
      this.create.dialogFormVisible = true;
    },

    // 查看和编辑中的小表格
    getReceProduct() {
      GetDataByName(this.create.getdataListParm3).then((response) => {
        console.log("查看和编辑中的小表格", response.data.list);
        if (response.data.list !== null) {
          this.tableStockList = response.data.list;
        }
      });
    },

    // 查看和编辑中的小表格
    getReceProduct2() {
      GetDataByName(this.create.getdataListParm4).then((response) => {
        console.log("查看和编辑中的小表格", response.data.list);
        if (response.data.list !== null) {
          this.tableStockList = response.data.list;
        }
      });
    },

    // 反馈记录 - 保存
    feedRecord_save() {
      if (
        this.feedRecordTemp.parammaps.remark == "" ||
        this.feedRecordTemp.parammaps.remark == null
      ) {
        this.$notify({
          title: "反馈失败！",
          message: "请输入反馈内容！",
          type: "warning",
          duration: 2000,
        });
      } else {
        this.feedRecordTemp.parammaps.createrId = Cookies.get("employeid");
        PostDataByName(this.feedRecordTemp).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.create.dialogFormVisible = false
            // this.get_table_data()

            this.get_feedRecord();
            this.feedRecordTemp.parammaps.remark = "";
            this.$forceUpdate();

            var rowId = this.create.temp.id;

            this.get_wxPush(20, "备货", rowId);
          }
        });
      }
    },

    reset_feedRecord() {
      this.feedRecordList = [];
      this.feedRecordTemp.parammaps.stockupId = "";
      this.feedRecordTemp.parammaps.createrId = "";
      this.feedRecordTemp.parammaps.remark = "";
    },

    // 编辑保存
    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);

          this.create.temp.modifyName = "update";
          var customerId = this.create.temp.customerId;
          var postalId = this.create.temp.id;
          this.tableStockList.map(function (i) {
            return (i.customerId = customerId);
          });
          this.tableStockList.map(function (i) {
            return (i.postalId = postalId);
          });
          this.tableStockList.map(function (i) {
            return (i.stockupId = postalId);
          });

          var send_data = {
            common: { returnmap: "0" },
            data: [
              {
                name: "updateStockup",
                type: "e",
                parammaps: this.create.temp,
              },
              {
                name: "delStockupGoods",
                type: "e",
                parammaps: { stockupId: this.create.temp.id },
              },
              {
                name: "insertStockupGoods",
                resultmaps: {
                  list: this.tableStockList,
                },
                children: [
                  {
                    name: "insertStockupGoods",
                    type: "e",
                    parammaps: {
                      stockupId: this.create.temp.id,
                      productsId: "@insertStockupGoods.productsId",
                      nums: "@insertStockupGoods.nums",
                      remark: "@insertStockupGoods.remark",
                      useContractId: "@insertStockupGoods.useContractId",
                      customerId: "@insertStockupGoods.customerId",
                    },
                  },
                ],
              },
            ],
          };

          ExecDataByConfig(send_data).then((response) => {
            console.log("编辑保存发送参数", this.requestParam);
            if (response.msg !== "fail") {
              this.$notify({
                title: "成功",
                message: "保存成功",
                type: "success",
                duration: 2000,
              });
              this.create.dialogFormVisible = false;
              this.get_table_data();

              var send_weixin_data1 = {
                name: "getRemindData",
                parammaps: {
                  userId: Cookies.get("g_userId"),
                  remindId: 18,
                  remindTypeName: "备货",
                  rowId: this.create.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: 18,
                    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: "保存失败",
                type: "error",
                duration: 2000,
              });
            }
          });
        }
      });
    },

    // 删除
    form_delete(row) {
      MessageBox.confirm("是否确认删除此信息?", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          var send_data = {
            name: "delStockup",
            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);
      if (row.isUsed == 1) {
        this.$notify({
          title: "失败",
          message: "撤销失败,请先撤销相关发货单!",
          type: "error",
          duration: 2000,
        });
      } else {
        this.reset_revoke();
        this.revoke.temp = Object.assign({}, row);
        this.revoke.temp.id = row.id;
        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: "revokeStockupGoods",
                type: "e",
                parammaps: { id: this.revoke.temp.id },
              },
              {
                name: "revokeStockup",
                type: "e",
                parammaps: this.revoke.temp,
              },
            ],
          };

          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: 19,
                  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: 19,
                    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,
              });
            }
          });
        }
      });
    },

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

    // 导出
    form_export(item) {
      // if (item == 1) {
      //   console.log('点击了导出模板')
      // } else {
      //   console.log('点击了导出数据')
      // }

      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",
              "stockupCode",
              "statusName",
              "progress",
              "planSendDate",
              "customerName",
              "groupName",
              "orderDate",
              "sourceName",
              "contractCode",
              "reasonName",
              "createName",
              "createDate",
              "successDate",
              "remark",
            ],
            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;
}

/deep/ .el-input.is-disabled .el-input__inner {
  color: #000000 !important;
}
/deep/ .el-textarea.is-disabled .el-textarea__inner {
  color: #000000 !important;
}
/deep/ .el-radio__input.is-disabled + span.el-radio__label {
  color: #000000 !important;
}
/deep/ .el-checkbox__input.is-disabled + span.el-checkbox__label {
  color: #000000 !important;
}
</style>
