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

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


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

      <el-table-column show-overflow-tooltip prop="is_sale_return_child" label="是否设置售前退货工单" width="145">
        <template slot-scope="scope">
          <el-tag size="mini">{{scope.row.is_sale_return_child === '0' ? '未设置' : '已设置'}}</el-tag>
        </template>
      </el-table-column>

      <el-table-column show-overflow-tooltip prop="contactor" label="联系人" width="120" />
      <el-table-column show-overflow-tooltip prop="mobile" label="手机号" width="140" />
      <el-table-column show-overflow-tooltip prop="addr_code_cn" label="省市区" min-width="140" />
      <el-table-column show-overflow-tooltip prop="addr" label="详细地址" min-width="140" />
    </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="15"
        :size="'mini'"
        layout="total, prev, pager, next, jumper"
        :total="pageInfo.total"
        @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/sellReturn";
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"]),
    isStock() {
      const { order_type } = this.sitem || {}
      return order_type === '1'
    },
    powers() {
      const tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "salesOrderDetail"
        ) || {};
      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();
      });
    },
    page_curr_change(page){
      console.log(page)
      this.pageInfo.curr = page;
      this.searchList();
    },
    // 列表搜索
    async searchList() {
      this.loading = true
      const { code, data } = await asyncRequest.reorderRool({returnCode: this.sitem.returnCode,page : this.pageInfo.curr,size : 15});
      this.loading = false
      if (code === 0) {
        const { list ,count, is_sale_return_child_count} = data;
        this.tableData = list;
        this.pageInfo.total = count 
        this.$emit("getWorkOrderCount", count)
        this.$emit("getCurrentWorkOrderCount", is_sale_return_child_count)
        /* 从发货信息中拿到第一条数据 **/
        this.$emit('getSendInfoFirst', list[0])
      } 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>
