<template>
  <div class="app-container">
    <div class="search-bx">
      <div class="search">
        <el-row :gutter="0">
          <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.posterName"
            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-button class="successBorder" @click="form_search">查询</el-button>
          <el-button class="successBorder" @click="form_clear">重置</el-button>

          <el-button
            v-if="isExpressAdd"
            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-col :span="3">

            </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">
          <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
        >
          <template slot-scope="scope">
            <span>{{ scope.row.customerName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="集团" min-width="110px" align="center">
          <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.pdate }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="寄件人"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.posterName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="寄件电话" min-width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.posterTel }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="寄件单号"
          min-width="120px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.postCode }}</span>
          </template>
        </el-table-column>
        <el-table-column label="快递寄出原因" min-width="120px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.reason }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="处理方式"
          min-width="110px"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span>{{ scope.row.handletypeName }}</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">
          <template slot-scope="scope">
            <span>{{ scope.row.created }}</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="isRoleEdit" class="miniSuccess" @click="form_edit(row)">编辑</el-button>
            <el-button v-if="isRoleEdit" class="miniDanger" @click="form_delete(row)">删除</el-button> -->
            <el-button class="miniPrimary" @click="form_see(row)"
              >查看</el-button
            >
            <el-button
              v-if="
                isExpressAdd &&
                row.isModify == '1' &&
                row.createrId == employeid
              "
              class="miniSuccess"
              @click="form_edit(row)"
              >编辑</el-button
            >
            <el-button
              v-if="
                isExpressAdd && row.isDel == '1' && row.createrId == employeid
              "
              class="miniDanger"
              @click="form_delete(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="60%"
    >
      <div class="app-add">
        <el-form
          ref="temp"
          :rules="create.rules"
          :model="create.temp"
          label-position="right"
          label-width="150px"
          style="width: 80%; margin: 0 auto 50px"
        >
          <el-row>
            <el-col :span="12">
              <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'
                  "
                >
                  <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="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' " >
                      <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="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-col>
            <el-col :span="12">
              <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-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="接收日期：" prop="pdate">
                <el-date-picker
                  v-model="create.temp.pdate"
                  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-col>
            <el-col :span="12">
              <el-form-item label="寄件人：" prop="posterId">
                <el-select
                  ref="posterId"
                  v-model="create.temp.posterId"
                  filterable
                  placeholder="请选择寄件人"
                  class="filter-item"
                  style="width: 100%"
                  @change="changeReceiver"
                  :disabled="create.dialogStatus == 'see'"
                >
                  <el-option
                    v-for="item in create.posterNameList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="寄件电话：" prop="posterTel">
                <el-input
                  ref="posterTel"
                  v-model="create.temp.posterTel"
                  class="filter-item"
                  style="width: 100%"
                  maxlength="11"
                  placeholder="请输入寄件电话"
                  :disabled="create.dialogStatus == 'see'"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="寄件单号：" prop="postCode">
                <el-input
                  ref="postCode"
                  v-model="create.temp.postCode"
                  class="filter-item"
                  style="width: 100%"
                  maxlength="30"
                  placeholder="请输入寄件单号"
                  :disabled="create.dialogStatus == 'see'"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
              <el-form-item label="寄件原因：" prop="reason">
                <el-input
                  ref="reason"
                  v-model="create.temp.reason"
                  class="filter-item"
                  style="width: 100%"
                  maxlength="11"
                  placeholder="请输入寄件原因"
                  :disabled="create.dialogStatus == 'see'"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="处理方式：" prop="handletypeId">
                <el-select
                  ref="handletypeId"
                  v-model="create.temp.handletypeId"
                  filterable
                  placeholder="请选择处理方式"
                  class="filter-item"
                  style="width: 100%"
                  :disabled="create.dialogStatus == 'see'"
                >
                  <el-option
                    v-for="item in handletypeList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </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>
            <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="contact.list"
              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="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-form>
        <div slot="footer" class="dialog-footer">
          <el-button
            class="cancelClose"
            @click="
              create.dialogFormVisible = false;
              get_table_data();
            "
            >关闭</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>
  </div>
</template>

<script>
import {
  GetDataByName,
  PostDataByName,
  failproccess,
  ExecDataByConfig,
  GetDataByNames,
  checkButtons,
  calculativeWidth,
} 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";
export default {
  name: "expressReception",
  components: { Pagination },
  data() {
    return {
      myHeight: document.documentElement.clientHeight - 85 - 160,
      employeid: Cookies.get("employeid"),
      isExpressAdd: [],
      isRoleEdit: [],

      send_select_list: [
        { name: "getCustomerSelect", offset: 0, pagecount: 0, parammaps: {} },
        {
          name: "getDictListSelect1",
          offset: 0,
          pagecount: 0,
          parammaps: { pid: "54" },
        },
        {
          name: "getProductsEnable",
          offset: 0,
          pagecount: 0,
          parammaps: { enable: "1" },
        },
        {
          name: "getDictListSelect3",
          offset: 0,
          pagecount: 0,
          parammaps: { pid: "57" },
        },
      ],

      customerNameList: [], // 客户名称
      groupNameList: [], // 集团
      //下拉框 - 收件货品
      receProductNameList: [
        // {"Specifications":"SMA连接线","categoryId":14,"categoryName":"易  损  配  件","model":"根","price":"0.00","productsId":25,"productsName":"同轴电缆","remark":"","sort":1},
        // {"Specifications":"SMA转TNC连接线","categoryId":14,"categoryName":"易  损  配  件","model":"根","price":"0.00","productsId":26,"productsName":"同轴电缆","remark":"质保期3个月","sort":2},
        // {"Specifications":"/","categoryId":14,"categoryName":"易  损  配  件","model":"个","price":"0.00","productsId":27,"productsName":"蓄电池","remark":"质保期1年","sort":3},{"Specifications":"/","categoryId":14,"categoryName":"易  损  配  件","model":"个","price":"0.00","productsId":28,"productsName":"充电器","remark":"质保期1年","sort":4},
        // {"Specifications":"200*125 T","categoryId":14,"categoryName":"易  损  配  件","model":"张","price":"0.00","productsId":29,"productsName":"薄膜开关","remark":"质保期3个月","sort":5},
      ],
      handletypeList: [], // 处理方式

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

      download: {
        getdataListParm: {
          name: "getPostal",
          page: 1,
          offset: 1,
          pagecount: 0,
          returntype: "Map",
          parammaps: {
            roleId: Cookies.get("g_roleId"),
            userId: Cookies.get("g_userId"),
            customerName: "",
            customerId: "",
            groupId: "",
            posterName: "",
            inputDatetime: "",
            beginDate: "",
            endDate: "",
          },
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        temp: {},
      },

      // 新增/编辑
      create: {
        dialogFormVisible: false,
        dialogStatus: "",
        temp: {
          customerId: "",
          customerName: "",
          groupId: "",
          visiterId: "",
          groupName: "",
          pdate: parseTime(new Date(), "{y}-{m}-{d}"),
          posterId: "",
          posterName: "",
          posterTel: "",
          postCode: "",
          reason: "",
          handletypeId: "",
          remark: "",
          id: "",
          modifyName: "add",
          receiverChoose: "true",
        },

        rules: {
          customerId: [{ required: true, message: "必填", trigger: "blur" }],
          //  groupId: [{ required: true, message: '必填', trigger: 'blur' }],
          pdate: [{ required: true, message: "必填", trigger: "blur" }],
          posterId: [{ required: true, message: "必填", trigger: "blur" }],
          posterTel: [{ required: true, message: "必填", trigger: "blur" }],
          postCode: [{ required: true, message: "必填", trigger: "blur" }],
        },
        // 寄件人
        getdataListParm: {
          name: "getContacts",
          returntype: "Map",
          parammaps: { customerId: "" },
        },
        posterNameList: [], // 寄件人
        // 客户名称
        getdataListParmCust: {
          name: "getCustomerByGroupId",
          returntype: "Map",
          parammaps: { groupId: "" },
        },
        customerNameList: [],
        // 集团
        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: "getTelById",
          page: 1,
          offset: 1,
          pagecount: 10,
          returntype: "Map",
          parammaps: { id: "" },
        },
      },
      textMap: {
        create: "新增",
        see: "查看",
        update: "编辑",
      },

      // 管理
      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,
      },
      autoWidth: 130,
      requestParam: {},
      isokDisable: false,
      selectList: [],
      rowStyle: { maxHeight: 50 + "px", height: 45 + "px" },
      cellStyle: { padding: 0 + "px" },
    };
  },

  created() {
    this.get_table_data();
    this.get_select_list();
    this.get_auto_buttons();
  },

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

      const ExpressAdd = "business:express:add";
      const isExpressAdd = checkButtons(
        this.$store.state.user.buttons,
        ExpressAdd
      );
      this.isExpressAdd = isExpressAdd;

      //操作的宽度
      // var widthCount = calculativeWidth(isExpressAdd,isExpressAdd) + 90
      // 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);

        // 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);

        this.handletypeList = response.data.getDictListSelect3.list;
        console.log("处理方式下拉框", this.handletypeList);
      });
    },
    //加载表格
    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.isExpressAdd &&
              row.isModify == "1" &&
              row.createrId == me.employeid
            ) {
              itemBtnNum = itemBtnNum + 1;
            }
            if (
              me.isExpressAdd &&
              row.isDel == "1" &&
              row.createrId == me.employeid
            ) {
              itemBtnNum = itemBtnNum + 1;
            }
            console.log(itemBtnNum);
            if (itemBtnNum > btnNum) {
              btnNum = itemBtnNum;
            }
          });
          console.log("btnNum=============", btnNum);
          me.autoWidth = btnNum * 90 + 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.customerId = "";
      this.tableObj.getdataListParm.parammaps.groupId = "";
      this.tableObj.getdataListParm.parammaps.posterName = "";
      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 = {
        customerId: "",
        customerName: "",
        groupId: "",
        visiterId: "",
        groupName: "",
        pdate: parseTime(new Date(), "{y}-{m}-{d}"),
        posterId: "",
        posterName: "",
        posterTel: "",
        postCode: "",
        reason: "",
        handletypeId: "",
        remark: "",
        id: "",
        modifyName: "add",
        receiverChoose: "true",
      };
      this.contact.list = [];
    },

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

    //监听 - 下拉中客户名称
    changeCustomer(item) {
      console.log(item);
      this.create.temp.customerId = item.id;
      this.create.temp.customerName = item.name;
      this.$forceUpdate();

      this.create.getdataListParm.parammaps.customerId = item.id;
      // this.create.temp.barname = this.houseNameList.find(obj => obj.id === item).bname
      this.getPosterNameList();
      this.create.getdataListParm2.parammaps.id = item.id;
      this.getGroupNameId();
    },

    clear_customer_selectTemp(item) {
      document.activeElement.blur();
      this.create.temp.customerId = "";
      this.create.temp.customerName = "";
      this.create.temp.groupName = "";
      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);
      });
    },

    //模糊查询客户选择
    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) {
      this.tableObj.getdataListParm.parammaps.customerId = "";
      this.tableObj.getdataListParm.parammaps.customerName = "";
      document.activeElement.blur();
    },

    //客户失去焦点
    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();
    },

    //
    getPosterNameList() {
      GetDataByName(this.create.getdataListParm).then((response) => {
        if (response.data.list !== null) {
          this.create.posterNameList = response.data.list;
          console.log("寄件人数据", response.data.list);
        } else {
          this.create.posterNameList = [];
        }
      });
    },

    //监听 - 下拉中寄件人
    changeReceiver(item) {
      this.create.getdataListParm4.parammaps.id = item;
      this.create.temp.posterName = this.create.posterNameList.find(
        (obj) => obj.id === item
      ).name;
      this.getTelephoneName();
    },
    // 接待人电话
    getTelephoneName() {
      GetDataByName(this.create.getdataListParm4).then((response) => {
        if (response.data.list !== null) {
          this.create.temp.posterTel = response.data.list[0].telephone;
          console.log("接待人电话", response.data.list);
        }
      });
    },

    // 集团名称
    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);
        }
      });
    },

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

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

    //新增
    form_add() {
      console.log("点击了新增");
      this.form_reset();
      this.create.dialogStatus = "create";
      this.create.dialogFormVisible = true;
    },
    //新增保存
    add_dialog_save() {
      console.log("点击了新增保存", this.create.temp);
      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.contact.list.map(function (i) {
            return (i.customerId = customerId);
          });
          this.contact.list.map(function (i) {
            return (i.postalId = "");
          });

          if (
            this.create.posterNameList.find(
              (obj) => obj.id == this.create.temp.posterId
            )
          ) {
            console.log("posterNameList下拉直接选的！");
            this.create.temp.receiverChoose = "true";
          } else {
            this.create.temp.posterName = this.create.temp.posterId;
            this.create.temp.receiverChoose = "false";
            console.log("posterNameList下拉自己填的！");
          }

          console.log("点击了新增保存", this.create.temp);
          console.log("点击了新增保存", this.contact.list);

          this.create.temp.receiverId2 = "";
          this.create.temp.createrId = Cookies.get("employeid");

          this.create.temp.posterId2 = "@insertContactsNew.LastInsertId";
          var send_data = {
            common: { returnmap: "0" },
            data: [
              {
                name: "insertContactsNew",
                type: "e",
                parammaps: {
                  customerId: this.create.temp.customerId,
                  contactName: this.create.temp.posterName,
                  telephone: this.create.temp.receiverTel,
                  address: "",
                  remark: this.create.temp.remark,
                  receiverChoose: this.create.temp.receiverChoose,
                },
              },
              {
                name: "insertPostal",
                type: "e",
                parammaps: this.create.temp,
              },
              {
                name: "insertPostalGoods",
                resultmaps: {
                  list: this.contact.list,
                },
                children: [
                  {
                    name: "insertPostalGoods",
                    type: "e",
                    parammaps: {
                      postalId: "@insertPostal.LastInsertId",
                      customerId: "@insertPostalGoods.customerId",
                      productsId: "@insertPostalGoods.productsId",
                      nums: "@insertPostalGoods.nums",

                      createrId: "@insertPostalGoods.createrId",
                      remark: "@insertPostalGoods.remark",
                    },
                  },
                ],
              },
            ],
          };

          var isEmpty = this.contact.list.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();
              } else {
                this.$notify({
                  title: "失败",
                  message: "保存失败" + response.data,
                  type: "error",
                  duration: 2000,
                });
              }
            });
          }
        }
      });
    },
    // 查看
    form_see(row) {
      console.log("点击了查看", row);
      this.create.dialogStatus = "see";
      this.create.dialogFormVisible = true;
      this.$nextTick(() => {
        this.$refs.temp.resetFields();
        this.create.temp = Object.assign({}, row);
      });
      this.create.temp.id = row.id;
      this.create.getdataListParm.parammaps.customerId = row.customerId;
      this.getPosterNameList();
      this.create.getdataListParm3.parammaps.postalId = row.id;
      this.getReceProduct();

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

    // 编辑
    form_edit(row) {
      console.log("点击了编辑", row);
      this.create.dialogStatus = "update";
      this.create.dialogFormVisible = true;
      this.$nextTick(() => {
        this.$refs.temp.resetFields();
        this.create.temp = Object.assign({}, row);
      });

      this.create.temp.id = row.id;
      // this.create.getdataListParmCust.parammaps.groupId = row.groupId
      // this.get_customer_list()
      this.create.getdataListParm.parammaps.customerId = row.customerId;
      this.getPosterNameList();
      this.create.getdataListParm3.parammaps.postalId = row.id;
      this.getReceProduct();
    },

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

    // 编辑保存
    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.contact.list.map(function (i) {
            return (i.customerId = customerId);
          });
          this.contact.list.map(function (i) {
            return (i.postalId = postalId);
          });

          if (
            this.create.posterNameList.find(
              (obj) => obj.id == this.create.temp.posterId
            )
          ) {
            console.log("posterNameList下拉直接选的！");
            this.create.temp.receiverChoose = "true";
          } else {
            this.create.temp.posterName = this.create.temp.posterId;
            this.create.temp.receiverChoose = "false";
            console.log("posterNameList下拉自己填的！");
          }

          this.create.temp.receiverId2 = "";

          this.create.temp.posterId2 = "@insertContactsNew.LastInsertId";
          var send_data = {
            common: { returnmap: "0" },
            data: [
              {
                name: "insertContactsNew",
                type: "e",
                parammaps: {
                  customerId: this.create.temp.customerId,
                  contactName: this.create.temp.posterName,
                  telephone: this.create.temp.receiverTel,
                  address: "",
                  remark: this.create.temp.remark,
                  receiverChoose: this.create.temp.receiverChoose,
                },
              },
              {
                name: "updatePostal",
                type: "e",
                parammaps: this.create.temp,
              },
              {
                name: "delPostalGoods",
                type: "e",
                parammaps: { postalId: this.create.temp.id },
              },
              {
                name: "insertPostalGoods",
                resultmaps: {
                  list: this.contact.list,
                },
                children: [
                  {
                    name: "insertPostalGoods",
                    type: "e",
                    parammaps: {
                      postalId: "@insertPostalGoods.postalId",
                      customerId: "@insertPostalGoods.customerId",
                      productsId: "@insertPostalGoods.productsId",
                      nums: "@insertPostalGoods.nums",
                      remark: "@insertPostalGoods.remark",
                    },
                  },
                ],
              },
            ],
          };

          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();
            } else {
              this.$notify({
                title: "失败",
                message: "保存失败",
                type: "error",
                duration: 2000,
              });
            }
          });
        }
      });
    },

    // 删除
    form_delete(row) {
      MessageBox.confirm("是否确认删除此信息?", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.requestParam.name = "delPostal";
          this.requestParam.parammaps = {};
          this.requestParam.parammaps.id = row.id;
          PostDataByName(this.requestParam).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_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",
              "customerName",
              "groupName",
              "pdate",
              "posterName",
              "posterTel",
              "postCode",
              "reason",
              "handletypeName",
              "remark",
              "created",
            ],
            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>
