<!--轿车看板-发出未结算-->
<template>
  <div class="cr-body-content">
    <flexbox class="content-header">
      <el-input
        v-model="searchContent"
        clearable
        size="small"
        placeholder="按照单据号搜索..."
        style="width: 200px"
        class="search-container"
        @keyup.enter.native="handleFilter"
      />
      <el-button
        size="mini"
        type="success"
        icon="el-icon-search"
        @click="handleFilter"
        >搜索
      </el-button>
      <el-button
        class="filter-item"
        size="mini"
        type="warning"
        icon="el-icon-upload2"
        @click="handleImportExcel()"
        >导入文件（Excel）
      </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"
      size="small"
      stripe
      border
      highlight-current-row
      style="width: 100%"
      @sort-change="sortChange"
      @selection-change="handleSelectionChange"
      @row-click="handleRowClick"
      @cell-dblclick="dblhandleCurrentChange"
    >
      <el-table-column
        label="单据号"
        prop="billNum"
        sortable="custom"
        align="center"
        width="250px"
      >
        <template slot-scope="scope">
          <el-tooltip :content="scope.row.billNum" placement="bottom-end">
            <span class="link-type" @click="handleDrawerOpen(scope.row)">{{
              scope.row.billNum
            }}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <!-- <el-table-column type="selection" width="44px"></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-column label="备注" width="400" align="center">
        <template slot-scope="scope">
          <el-input
            ref="inputRef"
            v-if="scope.row.isEditCell"
            v-model="scope.row.remark"
            class="el-input"
            v-focus
            @blur="cellBlur(scope.row, scope.column)"
          />
          <span v-else>{{ scope.row.remark }}</span>
          <el-button
            style="margin-left: 5px"
            v-if="scope.row.isEditCell"
            type="success"
            icon="el-icon-check"
            size="small"
            circle
            @click="submitName(scope.row)"
          ></el-button>
          <el-button
            v-show="scope.row.isEditCell"
            class="cancel-btn"
            size="mini"
            icon="el-icon-refresh"
            type="warning"
            @click.native.prevent="handleCancel(scope.row)"
          >
            cancel
          </el-button>
        </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"
      />
      <!-- 导入Excel组件 -->
      <importExcel
        ref="importexcel"
        :show="showExcelImport"
        :crmType="crmType"
        @close="importExcelData"
      />
      <!-- 抽屉控件 -->
      <el-drawer
        title="信息详细页"
        size="75%"
        direction="rtl"
        :visible.sync="drawer"
        :before-close="handleDrawerClose"
      >
        <div>
          <Detail
            v-bind:customerInfos="customerInfos"
            style="margin-top: -35px"
          ></Detail>
        </div>
      </el-drawer>
    </div>
  </div>
</template>

<script>
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
import permission from "@/directive/permission/index.js";
import Detail from "./detail";
import moment from "moment";
import importExcel from "@/components/ImportExcel-base";
import { formatTimeToTimestamp } from "@/utils/index";

export default {
  name: "sendUnsettledDiffReport",
  components: { Pagination, Detail,importExcel },
  directives: { permission },
  data() {
    return {
      crmType: "kanbanoutorder",
      rules: {
        // version: [{ required: true, message: "必须输入！", trigger: "change" }],
        // beginTime: [{ required: true, message: "选择日期！", trigger: "change" }],
        // endTime: [{ required: true, message: "选择日期！", trigger: "change" }],
      },
      customerInfos: [],
      searchContent: "", // 输入内容
      drawer: false,
      form: {
        version: "",
        customerCode: "",
        customerName: "",
        beginTime: "",
        endTime: "",
      },
      versionValue: "",
      versionList: [],
      startTimeVale: "",
      endTimeVale: "",
      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,
      },
      page: 1,
      dialogFormVisible: false,
      multipleSelection: [],
      formTitle: "",
      drawer: false,
      showExcelImport: false,
      tableHeight: document.documentElement.clientHeight - 200,
      isEdit: false,
    };
  },
  mounted() {
    var self = this;
    window.onresize = function () {
      var offsetHei = document.documentElement.clientHeight;
      self.tableHeight = offsetHei - 200;
    };
  },
  created() {
    this.getList();
    //this.getVersionInfo();
  },
  computed: {
    /** 列表字段 */
    getDefaultField() {
      var tempsTabs = [];
      tempsTabs.push({
        label: "版本",
        prop: "version",
        width: 120,
      });
      //tempsTabs.push({ label: "单据号", prop: "billNum", width: 150 });
      tempsTabs.push({ label: "创建人", prop: "creator", width: 160 });
      tempsTabs.push({ label: "创建时间", prop: "creationTime", width: 160 });
      //tempsTabs.push({ label: "备注", prop: "remark", width: 120 });
      return tempsTabs;
    },
  },
  methods: {
     dblhandleCurrentChange(row, column, cell, event) {
      if (column.label === "备注") {
        row.isEditCell = true;
        this.$set(row, "isEditCell", true);
        this.$nextTick(() => {
          this.$refs["inputRef"].focus();
        });
      }
      this.list = this.list.filter((item) => {
        return item;
      });
    },
    // 可以编辑框失去焦点
    cellBlur(row, column) {
      row.isEditCell = false;
      this.$set(row, "isEditCell", false);
    },
    // 在线编辑中提交
    submitName(row) {
      let getguid = row.id;
      let getremark = row.remark;
      this.$axios
        .gets("/api/settleaccount/wmskanbanoutput/UpdateRemark", {
          id: getguid,
          remark: getremark,
        })
        .then((response) => {
          if (response == true) {
            this.$notify({
              title: "成功",
              message: "更新成功",
              type: "success",
              duration: 2000,
            });
            this.getList();
          }
        })
        .catch(() => {
          this.listLoading = false;
        });
    },
    // 取消
    handleCancel(row) {
      row.isEditCell = false;
      //row.stockQty = row.originalstockQty;
      this.$set(row, "isEditCell", false);
      // this.$message({
      //   message: "取消后，恢复当前原值！",
      //   type: "warning",
      // });
      this.getList();
    },
    handleImportExcel() {
      //导入
      this.showExcelImport = true;
      this.$refs.importexcel.handleImportExcelClick();
    },
    getVersionInfo() {
      //取版本列表信息
      this.listLoading = true;
      this.listQuery.SkipCount = (this.page - 1) * 1000;
      this.$axios
        .posts("/api/settleaccount/CentralizedControl/openlist")
        .then((response) => {
          this.versionList = [];
          response.forEach((element) => {
            let options = {};
            options.value = element.version;
            options.label = element.version;
            this.versionList.push(options);
          });
        })
        .catch(() => {
          this.listLoading = false;
        });
    },
    //抽屉
    handleDrawerOpen(param) {
      this.drawer = true;
      var parentId = param.billNum; //单据号
      var version = param.version; //版本
      this.customerInfos = [
        {
          ParentId: parentId,
          Version: version,
        },
      ];
    },
    handleDrawerClose(done) {
      done();
    },
    /** 格式化字段 */
    fieldFormatter(row, column) {
      if (column.property == "creationTime") {
        var date = row[column.property];
        if (date == undefined) {
          return "";
        }
        return moment(date).format("YYYY-MM-DD HH:mm:ss");
      }
      if (column.property == "state") {
        return { 0: "已提交", 1: "已出库", 2: "不能出库" }[
          row[column.property]
        ];
      }
      return row[column.property] || "--";
    },
    importExcelData() {
      //关闭导入窗体时调用
      this.showExcelImport = false;
      this.getList();
    },
    getList(data) {
      this.listLoading = true;
      if (data != undefined) {
        this.listQuery.SkipCount = (this.page - 1) * data.limit;
      } else {
        this.listQuery.SkipCount = (this.page - 1) * 15;
      }
      this.$axios
        .posts("/api/settleaccount/wmskanbanoutput/WmsKanbanList", this.listQuery)
        .then((response) => {
          this.list = response.items;
          //alert(JSON.stringify(response.Items))
          this.totalCount = response.totalCount;
           //动态加一个是否编辑的标识
          this.list.forEach((element) => {
            element["isEditCell"] = false;
          });
          setTimeout(() => {
            //大数据量加载时
            this.listLoading = false;
          }, 500);
        })
        .catch(() => {
          this.listLoading = false;
        });
    },
    /** 筛选操作 */
    handleFilter() {
      this.page = 1;
      this.getList();
      this.listQuery.Filters = [];
      if (this.searchContent != "") {
        var column = "billNum";
        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" };
    },
    handleRowClick(row, column, event) {
      this.$refs.multipleTable.clearSelection();
      this.$refs.multipleTable.toggleRowSelection(row);
    },
  },
};
</script>


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

