<!--FIS发运数据对比输出表-明细数据-->
<template>
  <div class="cr-body-content">
    <flexbox class="content-header">
      <!-- <el-button
        class="filter-item"
        size="mini"
        type="info"
        icon="el-icon-download"
        @click="handleDownload()"
        >导出全部
      </el-button>
      <el-input
        v-model="searchContent"
        clearable
        size="small"
        placeholder="支持模糊搜索..."
        style="width: 230px"
        class="search-container"
        @keyup.enter.native="handleFilter"
      />
      <el-button
        size="mini"
        type="success"
        icon="el-icon-search"
        @click="handleFilter"
        >搜索
      </el-button> -->
    </flexbox>
    <!--表格渲染-->
    <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 prop="partCode" label="客户零件代码"> </el-table-column>
      <el-table-column prop="description" label="客户零件名称"> </el-table-column>
      <el-table-column prop="partNum" label="客户零件数量"> </el-table-column>
      <el-table-column prop="isKey" label="是否Key件">
        <template slot-scope="scope">
          <span v-if="scope.row.isKey == true">
            <span style="color: #00b46d">是</span>
          </span>
          <span v-else>
            <span style="color: #d75c89">否</span>
          </span>
        </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",
          }, //默认查询可用的
        ],
        //OrgID:"",
        SkipCount: 0,
        MaxResultCount: 15,
        assemblyProductID: "",
      },
      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(this.searchContent);
          }
        }
      },
      immediate: true,
    },
  },
  computed: {
    /** 列表字段 */
    getDefaultField() {
      var tempsTabs = [];
      tempsTabs.push({ label: "客户零件代码", prop: "partCode ", width: 120 });
      tempsTabs.push({ label: "客户零件数量", prop: "partNum", width: 160 });
      tempsTabs.push({ label: "是否Key件", prop: "isKey", width: 95 });
      tempsTabs.push({ label: "描述", prop: "description", width: 280 });
      return tempsTabs;
    },
  },
  methods: {
    /** 刷新列表 */
    handleHandle(data) {
      if (data.type !== "edit") {
        this.getList();
      }
    },
    /** 格式化字段 */
    fieldFormatter(row, column) {
      if (column.property === "isKey") {
        return { 0: "未生效", 1: "已生效" }[row[column.property]];
      }
      return row[column.property] || "--";
    },
    importExcelData() {
      //关闭导入窗体时调用
      this.showExcelImport = false;
      this.getList();
    },
    getList(partCode) {
      this.listLoading = true;
      console.log("详表条件：" + JSON.stringify(this.customerInfo.parentId));
      this.$axios
        .gets("/api/newjit/assembly-cfg-erp/" + this.customerInfo.parentId)
        .then((response) => {
          console.log(partCode)
          if(partCode !== "" && partCode !== undefined)
          {
            //console.log(partCode)
            this.list = response.item.details.filter(u => u.partCode === partCode);
          }
          else
          {
            this.list = response.item.details;
          }
          //alert(JSON.stringify(response.Items))
          //this.totalCount = response.totalCount;
          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);
      }
      //console.log(this.searchContent)
      this.getList(this.searchContent);
    },
    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 }) {
      if (
        column.property === "fisQty" ||
        column.property === "diffQty" ||
        column.property === "stockQty"
      ) {
        return { textAlign: "right" };
      } else {
        return { textAlign: "left" };
      }
    },
    /** 通过回调控制表头style */
    headerRowStyle({ row, column, rowIndex, columnIndex }) {
      if (
        column.property === "fisQty" ||
        column.property === "diffQty" ||
        column.property === "stockQty"
      ) {
        return { textAlign: "right", background: "#FAFAFA" };
      } else {
        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>

