<!--未知总成-明细数据-->
<template>
  <div class="cr-body-content">
    <!--表格渲染-->
    <el-table
      ref="multipleTable"
      v-loading="listLoading"
      element-loading-text="拼命加载中..."
      element-loading-spinner="el-icon-loading"
      class="cr-table"
      :data="list"
      :height="tableHeight"
      :cell-style="cellStyle"
      :header-cell-style="headerRowStyle"
      size="small"
      stripe
      border
      highlight-current-row
      style="width: 100%"
      @sort-change="sortChange"
      @selection-change="handleSelectionChange"
      @row-click="handleRowClick"
    >
      <!-- <el-table-column type="selection" width="44px"></el-table-column> -->
      <el-table-column
        label="客户零件代码"
        prop="partCode "
        sortable="custom"
        align="center"
        width="220px"
      >
        <template slot-scope="scope">
            <span>{{ scope.row.partCode }}</span>
        </template>
      </el-table-column>
      <el-table-column
        v-for="(item, index) in getDefaultField"
        :key="index"
        :prop="item.prop"
        :label="item.label"
        :min-width="item.width"
        :formatter="fieldFormatter"
        sortable="custom"
        show-overflow-tooltip
        :gutter="0"
      >
        <template slot="header" slot-scope="scope">
          {{ scope.column.label }}
        </template>
      </el-table-column>
    </el-table>
    <div class="table-footer">
      <!-- 分页控件 style="margin-top: -25px;margin-bottom:-25px;float:right;"-->
      <pagination
        v-show="totalCount > 0"
        :total="totalCount"
        :page.sync="page"
        :limit.sync="listQuery.MaxResultCount"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
import permission from "@/directive/permission/index.js";
import CRMTableHead from "../../components/CRMTableHead";
import { downloadFile } from "@/utils/crmindex.js";
import Detail from "./detail";

export default {
  name: "sendUnsettledDiffReport",
  components: { Pagination, CRMTableHead, Detail },
  directives: { permission },
  filters: {
    IsCustomerSignFilter(status) {
      //翻译是否签字
      const statusMap = {
        true: "是",
        false: "否",
      };
      return statusMap[status];
    },
  },
  props: {
    customerInfos: {
      type: Array,
      default: () => {
        return [];
      },
    },
  },
  data() {
    return {
      crmType: "stockFisDiffReport",
      rules: {
        //前端定义的规则，后端也有验证
        erpMaterialCode: [
          { required: true, message: "必须输入！", trigger: "blur" },
        ],
      },
      searchContent: "", // 输入内容
      customerInfo: {
        parentId: "",
      },
      form: {
        dicDetailID: "",
        customerId: "",
        projectId: "",
      },
      list: null,
      totalCount: 0,
      listLoading: true,
      formLoading: false,
      // 高级搜索
      filterObj: {
        type: Object,
        default: () => {
          return {};
        },
      },
      listQuery: {
        Filters: [
          {
            logic: 0,
            column: "Enabled",
            action: 0,
            value: "true",
          }, //默认查询可用的
        ],
        SkipCount: 0,
        MaxResultCount: 15,
        id: "",
      },
      page: 1,
      dialogFormVisible: false,
      multipleSelection: [],
      formTitle: "",
      drawer: false,
      showExcelImport: false,
      tableHeight: document.documentElement.clientHeight - 30,
      isEdit: false,
    };
  },
  mounted() {
    var self = this;
    window.onresize = function () {
      var offsetHei = document.documentElement.clientHeight;
      self.tableHeight = offsetHei - 30;
    };
  },
  created() {
    this.getList();
  },
  watch: {
    customerInfos: {
      handler(newVal) {
        if (newVal == "" || newVal == "undefined") {
          //TODO
        } else {
          newVal.forEach((element) => {
            this.customerInfo.parentId = element.ParentId;
          });
          if (this.customerInfo.parentId != "") {
            this.getList();
          }
        }
      },
      immediate: true,
    },
  },
  computed: {
    /** 列表字段 */
    getDefaultField() {
      var tempsTabs = [];
      //tempsTabs.push({ label: "客户零件代码", prop: "partCode ", width: 120 });
      tempsTabs.push({ label: "客户零件数量", prop: "partNum", width: 95 });
      tempsTabs.push({ label: "描述", prop: "description", width: 280 });
      return tempsTabs;
    },
  },
  methods: {
    /** 刷新列表 */
    handleHandle(data) {
      if (data.type !== "edit") {
        this.getList();
      }
    },
    /** 格式化字段 */
    // fieldFormatter(row, column) {
    //   return row[column.property] || "--";
    // },
    importExcelData() {
      //关闭导入窗体时调用
      this.showExcelImport = false;
      this.getList();
    },
    getList() {
      this.listLoading = true;
      console.log("详表条件：" + JSON.stringify(this.customerInfo.parentId));
      this.$axios
        .gets("/api/newjit/unknown-assembly/" + this.customerInfo.parentId)
        .then((response) => {
          this.list = response.item.unknownAssemblyParts;
          setTimeout(() => {
            //大数据量加载时
            this.listLoading = false;
          }, 500);
        })
        .catch(() => {
          this.listLoading = false;
        });
    },
    /** 筛选操作 */
    handleFilter() {
      this.page = 1;
      this.getList();
      this.listQuery.Filters = [];
      if (this.searchContent != "") {
        var column = "partCode";
        let filter = {
          logic: 0,
          column: column,
          action: 6,
          value: this.searchContent,
        };
        this.listQuery.Filters.push(filter);
      }
      this.getList();
    },
    resetQuery() {},

    sortChange(data) {
      const { prop, order } = data;
      if (!prop || !order) {
        this.handleFilter();
        return;
      }
      this.listQuery.Sorting = prop + " " + order;
      this.handleFilter();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    /** 通过回调控制style */
    cellStyle({ row, column, rowIndex, columnIndex }) {
      return { textAlign: "left" };
    },
    /** 通过回调控制表头style */
    headerRowStyle({ row, column, rowIndex, columnIndex }) {
      return { textAlign: "left", background: "#FAFAFA" };
    },
    handleRowClick(row, column, event) {
      this.$refs.multipleTable.clearSelection();
      this.$refs.multipleTable.toggleRowSelection(row);
    },
  },
};
</script>


<style lang="scss" scoped>
@import "../../../pg-fis/styles/crmtable.scss";
</style>

<style lang="scss">
.el-table .cell.el-tooltip {
  white-space: pre-wrap;
}
