<template>
  <div class="outOrderTable">
    <el-table
      ref="addrForm"
      :data="tableData"
      border
      :size="'mini'"
      style="width: 100%"
      row-key="key"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column type="selection" width="42"> </el-table-column> -->
      <el-table-column
        show-overflow-tooltip
        prop="outChildCode"
        label="发货工单编号"
        width="160"
      />

      <el-table-column
        show-overflow-tooltip
        prop="outCode"
        label="发货单编号"
        width="160"
      />


      <el-table-column
        show-overflow-tooltip
        prop="orderCode"
        label="确认单编号"
        width="160"
      />

      <el-table-column show-overflow-tooltip prop="send_status" label="状态" width="105">
        <template slot-scope="scope">
          <el-tag
            :size="tablebtnSize"
            :type="scope.row.status == '0' ? 'warning' : ''"
            v-text="
              (statusOptions.find((item) => item.id == scope.row.status) || {}).label ||
              '--'
            "
          ></el-tag>
        </template>
      </el-table-column>

      <el-table-column
        show-overflow-tooltip
        prop="num"
        label="发货数量"
        width="80"
      />

      <el-table-column show-overflow-tooltip prop="post_code" label="物流单号" min-width="160" />
      <el-table-column show-overflow-tooltip prop="post_name" label="物流公司" min-width="160" />
      <el-table-column show-overflow-tooltip prop="wsm_name" label="仓库名称" min-width="160" />
      <el-table-column show-overflow-tooltip prop="wsm_code" label="仓库编号" min-width="160" />
      <el-table-column show-overflow-tooltip prop="addtime" label="下单时间" width="140" />
      <el-table-column show-overflow-tooltip prop="apply_name" label="申请人" width="110" />

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-tooltip
            effect="dark"
            content="查看"
            placement="top"
            v-if="powers.some((i) => i == '007')"
          >
            <i
              class="el-icon-view tb-icon"
              @click="routeGoto('supplierDeliveryWorkOrderDetail', { id: scope.row.outChildCode })"
            ></i>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <div
      v-if="tableData && tableData.length > 0"
      class="Pagination"
      style="text-align: right; margin-top: 10px"
    >
      <el-pagination
        :current-page="parmValue.page"
        :page-size="parmValue.size"
        :size="'mini'"
        layout="total,  prev, pager, next, jumper"
        :total="pageInfo.total"
        @size-change="page_size_change"
        @current-change="page_curr_change"
      />
    </div>
  </div>
</template>
<script>
import mixinPage from "@/mixins/elPaginationHandle";
import resToken from "@/mixins/resToken";
import asyncRequest from "@/apis/service/sellOut/salesOrder/detail";
import { mapGetters } from "vuex";

export default {
  name: "salesOrderDetail",
  mixins: [mixinPage, resToken],
  props: ["newTime", "id", "sitem"],
  watch: {
    newTime: function (val) {
      if (val) {
        this.initForm();
      }
    },
  },
  computed: {
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
   powers() {
      const tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "supplierDeliveryWorkOrder"
        ) || {};
      const { action } = tran ?? {};
      return action ?? [];
    }
  },

  data() {
    return {
      orderCode: "",
      outCode: "",
      addr_res: 0,
      batch_num: 0,
      addrmodel: false,
      // 状态
      statusOptions: [
        { id: "1", label: "待发货" },
        { id: "2", label: "发货完成" },
        { id: "3", label: "已收货" },
        { id: "4", label: "已全部退货" },
      ],
      showGoodsModel: false,
      stock_code: "",
      tableData: [],
      loading: false,
      queryId: "",
      status: "",
      showModel: null,
      modelId: "",
      modelItem: null,
      s_sitem: null,
      returnId: "",
      returnItem: null,
      returnModel: false,
      wsend_num: "",
      orderCode: "",
      returnAllId: "",
      returnAllSitem: null,
      returnAllShowModel: false,
      parmValue: {},
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      multipleSelection: [],
      resModel: null,
    };
  },
  watch:{
    sitem:{
      handler(){
        if(!this.sitem) return
        this.initForm();
      },
      immediate:true
    }
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    closeModel() {
      this.modelId = "";
      this.modelShowModel = false;
    },
    refresh() {
      this.$emit("refresh");
      this.modelId = "";
      this.modelShowModel = false;
    },
    async initForm() {
      this.status = "";
      this.queryId = this.$route.query.id;
      // this.rulesThis = this.rules;
      this.resetForm();
    },
    async resetForm() {
      // 重置
      await this.$nextTick(async () => {
        await this.searchList();
      });
    },
    // 列表搜索
    async searchList() {
      const { code, data } = await asyncRequest.child_list({outCode: this.sitem.outCode});
      if (code === 0) {
        this.tableData = data;
      } else if (code >= 100 && code <= 104) {
        await this.logout();
      } else {
        this.tableData = [];
        this.pageInfo.total = 0;
      }
      this.loading = false;
    },
  },
};
</script>
<style lang="scss" scoped></style>
