<template>
  <div class="mod-config">

    <!-- 收藏 -->
    <div>
      <span @click="favoriteFunction()">
        <icon-svg :name="favorite?'xiangqufill':'xiangqu'" class="sl-svg"></icon-svg>
      </span>
    </div>

    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
      <el-form-item :label="'采购订单号'">
        <el-input v-model="searchData.orderNo" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'生产订单号'">
        <el-input v-model="searchData.orderRef1" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'工序号'">
        <el-input v-model="searchData.orderRef2" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'工序名称:'">
        <el-input v-model="searchData.operationDesc" clearable style="width: 120px"></el-input>
      </el-form-item>
      <!--        <el-form-item label="外协订单领料状态">-->
      <!--          <el-select v-model="searchData.outworkorderPartReqStatus" placeholder="请选择外协订单领料状态">-->
      <!--            <el-option label="未发料" value="C"></el-option>-->
      <!--            <el-option label="全部发料" value="B"></el-option>-->
      <!--            <el-option label="部分发料" value="A"></el-option>-->
      <!--          </el-select>-->
      <!--        </el-form-item>-->
      <el-form-item :label="'要求送货日期'">
        <el-date-picker
          style="width: 120px"
          v-model="searchData.wantedDelStartDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
        -
        <el-date-picker
          style="width: 120px"
          v-model="searchData.wantedDelEndDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="送货地点" prop="site">
        <el-select v-model="searchData.delPlace" clearable placeholder="请选择" style="width: 120px">
          <el-option label = "常熟" value = "常熟"></el-option>
          <el-option label = "响水" value = "响水"></el-option>
          <el-option label = "其他" value = "其他"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
<!--      <el-form-item>-->
<!--        <span style="cursor: pointer" slot="label" @click="getBaseList(3)"><a herf="#">供应商编码</a></span>-->
<!--        <el-input v-model="searchData.supplierId" placeholder="输入或选择供应商编码"></el-input>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="供应商名称">-->
<!--        <el-input v-model="searchData.supplierName"></el-input>-->
<!--      </el-form-item>-->
      <el-form-item :label="'状态'">
        <el-select v-model="searchData.statusList" multiple style="width: 387px">
          <el-option label="未发货" value="未发货"></el-option>
          <el-option label="部分发货" value="部分发货"></el-option>
          <el-option label="已发货" value="已发货"></el-option>
          <el-option label="已关闭" value="已关闭"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="物料编码">
        <el-input v-model="searchData.partNo" style="width: 160px"></el-input>
      </el-form-item>
      <el-form-item label="物料描述">
        <el-input v-model="searchData.partDescription" style="width: 213px"></el-input>
      </el-form-item>
      <el-form-item>
        <span style="cursor: pointer" slot="label" @click="getBaseList(9)"><a herf="#">采购员</a></span>
        <el-input v-model="searchData.userName" clearable placeholder="输入或选择采购员" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button v-if="!authSearch" type="primary" @click="getDataList()">查询</el-button>
        <download-excel
          :fields="fields()"
          :data="exportData"
          type="xls"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{ "导出" }}
        </download-excel>
      </el-form-item>
    </el-form>

    <el-table
      :height="height - 280"
      :data="dataList"
      border
      style="width: 100%;"
      class="custom-table"
    >
      <el-table-column
        v-for="(item, index) in columnList"
        :key="index"
        :prop="item.columnProp"
        :label="item.columnLabel"
        :sortable="item.columnSortable"
        :header-align="item.headerAlign"
        :align="item.align"
        :fixed="item.fixed == '' ? false : item.fixed"
        :width="item.columnWidth"
      >
        <template slot-scope="scope">
          <span v-if="!item.columnHidden">{{ scope.row[item.columnProp] }}</span>
          <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[20, 50, 100, 200, 500]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>

    <el-tabs style="margin-top: 0px; width: 100%; height: 100%;" v-model="activeName" class="customer-tab" type="border-card">
      <el-tab-pane label="汇总" name="first">
          <el-table
            :height="height - 325"
            :data="collectDataList"
            border
            style="width: 100%">
          <el-table-column
            v-for="(item, index) in columnCollectList"
            :key="index"
            :prop="item.columnProp"
            :label="item.columnLabel"
            :sortable="item.columnSortable"
            :header-align="item.headerAlign"
            :align="item.align"
            :fixed="item.fixed == '' ? false : item.fixed"
            :width="item.columnWidth"
          >
            <template slot-scope="scope">
              <span v-if="!item.columnHidden">{{ scope.row[item.columnProp] }}</span>
              <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>

    <Chooselist ref="baseList"  @getBaseData="getBaseData"></Chooselist>
    <!-- 数据表格部分 -->
    <!--    <el-table :data="dataList" border style="width: 100%">-->
    <!--      <el-table-column prop="orderNumber" label="订单号" width="150"></el-table-column>-->
    <!--      <el-table-column prop="material" label="物料编码" width="150"></el-table-column>-->
    <!--      <el-table-column prop="supplier" label="供应商" width="150"></el-table-column>-->
    <!--      <el-table-column prop="quantity" label="待送货数量" width="150"></el-table-column>-->
    <!--      <el-table-column prop="deliveryQuantity" label="此次送货数量" width="150">-->
    <!--        <template slot-scope="scope">-->
    <!--          <el-input-->
    <!--            v-model.number="scope.row.deliveryQuantity"-->
    <!--            :max="scope.row.remainingQuantity"-->
    <!--          />-->
    <!--        </template>-->
    <!--      </el-table-column>-->
    <!--      <el-table-column prop="status" label="状态" width="150"></el-table-column>-->
    <!--    </el-table>-->

    <!-- 汇总部分 -->
    <!--    <div class="summary-section">-->
    <!--      <h3>汇总</h3>-->
    <!--      <p>总待送货数量: {{ totalRemaining }}</p>-->
    <!--      <p>此次送货总数量: {{ totalDelivery }}</p>-->
    <!--    </div>-->
  </div>
</template>

<script>
import {removeUserFavorite, saveUserFavorite, userFavoriteList} from "../../../api/userFavorite";
import {getSiteAndBuByUserName} from "../../../api/qc/qc";
import {
  addSupplierDeliveryPlan, autoReservationInitiateHandler,
  searchSupplierDeliverySchedule,
  updateSupplierDeliveryScheduleDeliveryQty
} from "../../../api/deliverySchedule/supplierDeliverySchedule";
import {searchSupplierDeliveryPlan} from "../../../api/deliverySchedule/supplierDeliveryPlan";
import {getTableDefaultListLanguage, getTableUserListLanguage} from "../../../api/table";
import Chooselist from "../common/Chooselist.vue";

export default {
  components: {
    Chooselist
  },
  data() {
    return {
      // 是否收藏
      favorite: false,
      // 导出 start
      exportData: [],
      exportName: "供应商送货计划信息" + this.dayjs().format('YYYYMMDDHHmmss'),
      exportHeader: ["供应商送货计划信息"],
      exportFooter: [],
      exportList: [],
      modalData: {
        WantedDelDate: new Date(),
        DelPlace: '',
        Remark: '',
        SupplierDeliveryScheduleList: [],
      },
      // 导出 end
      searchData: {
        orderNo: '',
        orderRef1: '',
        orderRef2: '',
        operationDesc: '',
        status: '',
        statusList: ['未送货','部分送货','已送货'],
        wantedDelStartDate: '',
        wantedDelEndDate: '',
        delPlace: '',
        supplierId: this.$store.state.user.name,
        supplierName: '',
        partNo: '',
        partDescription: '',
        userName: '',
        site: this.$store.state.user.site,
        page: 1,
        limit: 20,
      },
      columnList: [
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableWantedDelDate',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 120,
          columnProp: 'WantedDelDate',
          headerAlign: 'center',
          align: "center",
          columnLabel: '要求送货日期',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableUserName',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 120,
          columnProp: 'userName',
          headerAlign: 'center',
          align: "center",
          columnLabel: '采购员',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableDelPlace',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 120,
          columnProp: 'delPlace',
          headerAlign: 'center',
          align: "center",
          columnLabel: '送货地点',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableStatus',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 120,
          columnProp: 'status',
          headerAlign: 'center',
          align: "center",
          columnLabel: '状态',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableSupplierId',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 80,
          columnProp: 'supplierId',
          headerAlign: 'center',
          align: "left",
          columnLabel: '供应商编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableSupplierName',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 182,
          columnProp: 'supplierName',
          headerAlign: 'center',
          align: "left",
          columnLabel: '供应商名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableOrderNo',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 100,
          columnProp: 'orderNo',
          headerAlign: 'center',
          align: "center",
          columnLabel: '采购订单号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableOrderRef1',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 182,
          columnProp: 'orderRef1',
          headerAlign: 'center',
          align: "left",
          columnLabel: '生产订单号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableOrderItemNo',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 80,
          columnProp: 'orderItemNo',
          headerAlign: 'center',
          align: "center",
          columnLabel: '序号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TablePartNo',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 182,
          columnProp: 'partNo',
          headerAlign: 'center',
          align: "left",
          columnLabel: '物料编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TablePartDescription',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 182,
          columnProp: 'partDescription',
          headerAlign: 'center',
          align: "left",
          columnLabel: '物料名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableSpec',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 183,
          columnProp: 'spec',
          headerAlign: 'center',
          align: "left",
          columnLabel: '规格型号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableOrderRef2',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 70,
          columnProp: 'orderRef2',
          headerAlign: 'center',
          align: "center",
          columnLabel: '工序号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableOperationDesc',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 120,
          columnProp: 'operationDesc',
          headerAlign: 'center',
          align: "left",
          columnLabel: '工序名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableNotifyQty',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 120,
          columnProp: 'notifyQty',
          headerAlign: 'center',
          align: "right",
          columnLabel: '要求送货数量',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableActualTotalDelQty',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 120,
          columnProp: 'actualTotalDelQty',
          headerAlign: 'center',
          align: "right",
          columnLabel: '实际送货数量',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableActualOntimeDelQty',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 120,
          columnProp: 'actualOntimeDelQty',
          headerAlign: 'center',
          align: "right",
          columnLabel: '实际准时送货数量',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableActualFirstDelDate',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 120,
          columnProp: 'ActualFirstDelDate',
          headerAlign: 'center',
          align: "center",
          columnLabel: '实际首次送货日期',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableActualLatestDelDate',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 120,
          columnProp: 'ActualLatestDelDate',
          headerAlign: 'center',
          align: "center",
          columnLabel: '实际最后送货日期',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableCreateDate',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 150,
          columnProp: 'CreateDate',
          headerAlign: 'center',
          align: "center",
          columnLabel: '创建时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003TableCreateBy',
          tableId: "109003Table",
          tableName: "供应商送货计划信息表",
          columnWidth: 120,
          columnProp: 'createBy',
          headerAlign: 'center',
          align: "center",
          columnLabel: '创建人',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
      ],
      columnCollectList:[
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003Table1delPlace',
          tableId: "109003Table1",
          tableName: "供应商送货计划信息表",
          columnWidth: 120,
          columnProp: 'delPlace',
          headerAlign: 'center',
          align: "center",
          columnLabel: '送货地点',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003Table1PartNo',
          tableId: "109003Table1",
          tableName: "供应商送货计划信息表",
          columnWidth: 202,
          columnProp: 'partNo',
          headerAlign: 'center',
          align: "left",
          columnLabel: '物料编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003Table1PartDescription',
          tableId: "109003Table1",
          tableName: "供应商送货计划信息表",
          columnWidth: 282,
          columnProp: 'partDescription',
          headerAlign: 'center',
          align: "left",
          columnLabel: '物料名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003Table1Spec',
          tableId: "109003Table1",
          tableName: "供应商送货计划信息表",
          columnProp: 'spec',
          headerAlign: 'center',
          align: "left",
          columnLabel: '规格型号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          userId: this.$store.state.user.name,
          functionId: 109003,
          serialNumber: '109003Table1NotifyQty',
          tableId: "109003Table1",
          tableName: "供应商送货计划信息表",
          columnWidth: 120,
          columnProp: 'notifyQty',
          headerAlign: 'center',
          align: "right",
          columnLabel: '要求送货数量',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
      ],
      rules: {
        wantedDelDate: [
          { required: true, message: '要求送货日期不能为空', trigger: 'blur' }
        ],
        delPlace: [
          { required: true, message: '送货地点不能为空', trigger: 'blur' }
        ],
        allotmentQty: [
          { required: true, message: '此次分配的送货数量不能为空', trigger: 'blur' }
        ],
      },
      pageIndex: 1,
      pageSize: 20,
      totalPage: 0,
      height: 200,
      activeName: 'first',
      dataList: [],
      collectDataList: [],
      modalFlag: false,
      modalDisableFlag: false,
      autoReservationFlag: false,
      options: [],
      userBuList: [],
      authSearch: false,
      authSave: false,
      authUpdate: false,
      authDelete: false,
      menuId: this.$route.meta.menuId,
    };
  },

  mounted () {
    this.$nextTick(() => {
      this.height = window.innerHeight - 180
    })
  },

  created() {
    // 按钮控制
    this.getButtonAuthData()
    // 获取用户的 site 和 bu
    this.getSiteAndBuByUserName()
    // 校验用户是否收藏
    this.favoriteIsOk()
    // 动态列
    this.getTableUserColumn(this.$route.meta.menuId+'table',1)
    if (!this.authSearch) {
      // 获取数据列表
      this.getDataList()
    }
  },

  methods: {
    // 获取基础数据列表
    getBaseList (val) {
      this.tagNo = val
      this.$nextTick(() => {
        let strVal = ''
        let conSql = ''
        if (val === 3) {
          strVal = this.searchData.supplierId
          conSql = " and site = '" + this.searchData.site + "'"
          this.$refs.baseList.init(val, strVal, conSql)
        } else if (val === 9) {
          strVal = this.searchData.userName
          conSql = " and site = '" + this.searchData.site + "'"
          this.$refs.baseList.init(val, strVal, conSql)
        }
      })
    },

    // 列表方法的回调
    getBaseData (val) {
      if (this.tagNo === 3) {
        this.searchData.supplierId = val.SupplierID
        this.searchData.supplierName = val.SupplierName
      } else if (this.tagNo === 9) {
        this.searchData.userName = val.EmployeeName
      }
    },

    // 获取用户的bu
    getSiteAndBuByUserName () {
      let tempData = {
        username: this.$store.state.user.name,
      }
      getSiteAndBuByUserName(tempData).then(({data}) => {
        if (data.code === 0) {
          this.userBuList = data.rows
        }
      })
    },

    // 校验用户是否收藏
    favoriteIsOk () {
      let userFavorite = {
        userId: this.$store.state.user.id,
        languageCode: this.$i18n.locale
      }
      userFavoriteList(userFavorite).then(({data}) => {
        for (let i = 0; i < data.list.length; i++) {
          if(this.$route.meta.menuId === data.list[i].menuId){
            this.favorite = true
          }
        }
      })
    },

    // 收藏 OR 取消收藏
    favoriteFunction () {
      let userFavorite = {
        userId: this.$store.state.user.id,
        functionId: this.$route.meta.menuId,
      }
      if (this.favorite) {
        removeUserFavorite(userFavorite).then(({data}) => {
          this.$message.success(data.msg)
          this.favorite = false
        })
      } else {
        // 收藏
        saveUserFavorite(userFavorite).then(({data}) => {
          this.$message.success(data.msg)
          this.favorite = true
        })
      }
    },

    getDataList() {
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex
      searchSupplierDeliveryPlan(this.searchData).then(({data}) => {
        if (data.code === 0) {
          this.dataList = data.page.list
          this.collectDataList = data.list1
          this.pageIndex = data.page.currPage
          this.pageSize = data.page.pageSize
          this.totalPage = data.page.totalCount
        }
      })
    },


    saveData () {
      let inData = {
        site: this.$store.state.user.site,
        userId: this.$store.state.user.id,
        delPlace: this.modalData.DelPlace,
        wantedDelDate: this.modalData.WantedDelDate,
        remark: this.modalData.Remark,
        supplierDeliveryScheduleList: this.modalData.SupplierDeliveryScheduleList,
        createBy: this.$store.state.user.name,
      }
      addSupplierDeliveryPlan(inData).then(({data}) => {
        if (data.code === 0) {
          this.modalFlag = false
          this.$message.success(data.msg)
        } else {
          this.$message.error(data.msg)
        }
      })
    },

    handleSelectionChange(val) {
      this.selectionList = val;
    },

    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },

    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },

    //导出excel
    async createExportData() {
      if(this.selectionList.length > 0) {
        return this.exportList = this.selectionList
      } else {
        // 提示
        this.$message({
          message: '请选择要导出的数据',
          type: 'warning'
        })
      }
    },

    startDownload() {},

    finishDownload() {},

    fields () {
      let json = "{"
      this.columnList.forEach((item, index) => {
        if (index == this.columnList.length - 1) {
          json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\""
        } else {
          json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\"" + ","
        }
      })
      json += "}"
      let s = eval("(" + json + ")")
      return s
    },

    // 动态列开始 获取 用户保存的 格式列
    async getTableUserColumn (tableId, columnId) {
      let queryTableUser = {
        userId: this.$store.state.user.name,
        functionId: this.$route.meta.menuId,
        tableId: tableId,
        status: true,
        languageCode: this.$i18n.locale
      }
      await getTableUserListLanguage(queryTableUser).then(({data}) => {
        if (data.rows.length > 0) {
          //this.columnList1 = []
          switch (columnId) {
            case 1:
              this.columnList = data.rows
              break;
            // case 2:
            //   this.columnDetailList = data.rows
            //   break;
            // case 3:
            //   this.columnList2 = data.rows
            //   break;
            // case 4:
            //   this.columnList3 = data.rows
            //   break;
          }
        } else {
          this.getColumnList(tableId, columnId)
        }
      })
    },

    // 获取 tableDefault 列
    async getColumnList (tableId, columnId) {
      let queryTable = {
        functionId: this.$route.meta.menuId,
        tableId: tableId,
        languageCode: this.$i18n.locale
      }
      await getTableDefaultListLanguage(queryTable).then(({data}) => {
        if (!data.rows.length == 0) {
          switch (columnId) {
            case 1:
              this.columnList = data.rows
              break;
            // case 2:
            //   this.columnDetailList = data.rows
            //   break;
            // case 3:
            //   this.columnList2 = data.rows
            //   break;
            // case 4:
            //   this.columnList3 = data.rows
            //   break;
          }
        } else {
          // this.showDefault = true.
        }
      })
    },

    //获取按钮的权限数据
    getButtonAuthData () {
      let searchFlag = this.isAuth(this.menuId+":search")
      let saveFlag = this.isAuth(this.menuId+":save")
      let updateFlag = this.isAuth(this.menuId+":update")
      let deleteFlag = this.isAuth(this.menuId+":delete")
      //处理页面的权限数据
      this.authSearch = !searchFlag
      this.authSave = !saveFlag
      this.authUpdate = !updateFlag
      this.authDelete = !deleteFlag
    },
  },
};
</script>

<style scoped lang="scss">
/deep/ .customer-tab .el-tabs__content {
  padding: 0px !important;
}
.custom-table /deep/ .el-table__row {
  height: 30px;
  line-height: 1.5;
}
.el-input-number /deep/ .el-input__inner {
  text-align: right;
  padding-right: 5px !important;
}
#delivery-plan {
  padding: 20px;
}
.filter-section {
  margin-bottom: 20px;
}
.summary-section {
  margin-top: 20px;
}
</style>
