<template>
  <div id="transferOrder">
    <div v-if="isList">
      <el-card style="position: relative" v-loading="loading">
        <el-super-search
          v-model="params"
          :size="size"
          :dict="dict"
          :columns="SearchColumns"
          @reset="resetList"
          @submit="getList(params, Pages)"
        ></el-super-search>

        <el-row class="my-4" style="text-align: right">
          <el-button-group style="margin-right: 5px">
            <el-button type="primary" :size="size" @click="back"
              >返回</el-button>
            <el-button type="primary" :size="size" @click="verify"
              >确认</el-button
            >
          </el-button-group>
        </el-row>

        <el-super-ux-table
          v-model="tableList"
          :size="size"
          :dict="dict"
          :page="Pages"
          :columns="TableColumns"
          index
          pagination
          height="400"
          showSummary
          convenitentOperation
          storage-key="TransferOrderSuperTable"
          @row-click="select"
          @pagination="getList(params, Pages)"
        >
        </el-super-ux-table>

        <el-tabs v-model="tabName" style="margin-top: 10px">
          <el-tab-pane
            v-for="({ item, TableColumns: columns }, index) in TabColumns"
            :key="index"
            :label="item.title"
            :name="item.key"
            lazy
          >
            <el-super-ux-table
              v-loading="itemLoading"
              index
              v-model="tabParams[item.key]"
              :ref="tabName"
              :height="tabHeight"
              :columns="columns"
              :size="size"
            ></el-super-ux-table>
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import useColumns from "../columns";
import { dicts } from "../dicts";
import { getOrderList,listStAllotItem,bipPullVerify} from "@/api/purchase/transferOrder.js";
export default {
  name: "transferOrder",
  dicts: [...dicts, "oa_templete_id"],
  components: {
    ElSuperUxTable: () => import("@/components/super-ux-table/index.vue"),
    BatchImport: () => import("@/components/BatchImport/index.vue"),
    ElSuperSearch: () => import("@/components/super-search/index.vue"),
  },
  data() {
    const { TableColumns, TabColumns, SearchColumns } = useColumns();
    const Pages = this.$init.page();
    const params = this.$init.params(SearchColumns);
    return {
      params: {
        ...params,
        code: this.$route.query.billCode,
      },
      TableColumns: TableColumns,
      TabColumns: TabColumns,
      SearchColumns: SearchColumns,
      tabName: "materialInfo",
      size: "mini",
      Pages: Pages,
      loading: false,
      itemLoading: false,
      // 页面配置
      isList: true,
      // 页面状态
      page: "",
      referCondition: {
        type: "",
        isPage: true,
        title: "",
      },
      options: [
        {
          value: "1",
          label: "是",
        },
        {
          value: "0",
          label: "否",
        },
      ],
      tableList: [],
      // total: 0,
      tabParams: {
        materialInfo: [],
        receiveInfo: [],
        priceList: [],
        resultList: [],
      },
      rowDetail: {},
      disable: false,
      ids: [],
      //选择的行
      selectedRow:null
    };
  },
  computed: {
    tabHeight: {
      get() {
        let { materialInfo } = this.tabParams;
        return `${
          materialInfo.length
            ? materialInfo.length > 8
              ? 500
              : materialInfo * 36 + 120
            : 120
        }px`;
      },
      set() {},
    },
  },
  created() {
    this.params.status = '2';
    this.getList(this.params, this.Pages);
  },
  methods: {
    resetList() {
      this.Pages = this.$init.page();
      const { SearchColumns } = useColumns();
      this.params = {
        ...this.$init.params(SearchColumns),
        code: this.$route.query.billCode,
      };
      this.getList(this.params, this.Pages);
    },
    getList(params, Pages) {
      this.loading = true;
      getOrderList({
        ...this.addDateRange(params, params.billDates),
        ...Pages,
      })
        .then((res) => {
          if (res.code === 200) {
            this.tableList = res.rows;
            this.Pages.total = res.total;
          }
          this.loading = false;
        })
        .then(() => {
          // 合计不显示重绘
          this.$refs.multipleTable.doLayout();
        })
        .catch((err) => {});
    },
    getlistStAllotItem(pid) {
      this.itemLoading = true;
      listStAllotItem(pid).then((response) => {
        this.tabParams.materialInfo = response.rows;
        this.itemLoading = false;
      });
    },
    //确认
    verify() {
      if(this.selectedRow){
        this.$modal.loading("处理中...");
        bipPullVerify(this.selectedRow).then((response) => {
          if (response.code === 200) {
            this.$modal.notifySuccess("拉单成功");
          }
          this.$modal.closeLoading();
        }).catch(() => {
          this.$modal.closeLoading();
        });
      }else{
        this.$modal.msgWarning("请选择一条数据！");
      }
    },
    //返回
    back(){
      var userAgent = navigator.userAgent;
      if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") !=-1) {
        window.location.href="about:blank";
        window.close();
      } else {
        window.opener = null;
        window.open("", "_self");
        window.close();
      }
    },
    // 选中某行
    select(row) {
      this.getlistStAllotItem(row.id);
      this.selectedRow = row;
    },
  },
};
</script>

<style lang="scss" scoped>
#transferOrder {
  padding: 12px;
  box-sizing: border-box;
  overflow-y: scroll;
}
</style>
