<template>
  <div class="work-diff-table">
    <el-table
      ref="addrForm"
      :data="tableData"
      border
      :size="'mini'"
      style="width: 100%"
      row-key="key"
    >
      <el-table-column
        show-overflow-tooltip
        prop="diff_weight"
        label="工差克重(g)"
      />

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

      <el-table-column show-overflow-tooltip prop="apply_name" label="创建人" />
      <el-table-column show-overflow-tooltip prop="addtime" label="创建时间" />

      <el-table-column fixed="right" width="50">
        <template slot="header" slot-scope="scope">
          <span>操作</span>
        </template>

        <template slot-scope="scope">
          <el-tooltip
            effect="dark"
            content="查看"
            v-if="!scope.row.edit"
            placement="top"
          >
            <i
              class="el-icon-view tb-icon"
              @click="
                routeGoto('purchaseDiffOrderDetail', {
                  id: scope.row.id,
                })
              "
            ></i>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
   <script>
import resToken from "@/mixins/resToken";
// import asyncRequest from "@/apis/service/sellOut/salesOrder/detail";
// import outOrderAddModel from "./out-order-add-model";
// import addEdit from "@/views/sellOut/sellAfterApply/components/addEdit.vue";

import { mapGetters } from "vuex";

export default {
  name: "workDiffTable",
  mixins: [resToken],
  props: ["newTime", "id", "sitem"],
  //   components: { addEdit, outOrderAddModel },
  watch: {
    newTime: function (val) {
      if (val) {
        this.initForm();
      }
    },
  },
  computed: {
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
  },

  data() {
    return {
      orderCode: "",
      outCode: "",
      // 状态
      statusOptions: [
        { id: "1", label: "已出库" },
        { id: "2", label: "验收中" },
        { id: "3", label: "验收完成" },
      ],
      showGoodsModel: false,
      stock_code: "",
      tableData: [],
      loading: false,
      diffStatusOptions: [
        { id: "1", label: "待业务部门审核" },
        { id: "2", label: "工差单审核完成" },
      ],
      queryId: "",
      status: "",
      showModel: null,
      modelId: "",
      modelItem: null,
      s_sitem: null,
    };
  },
  mounted() {
    // console.log(this.sitem);
    // console.log(this.sitem.bum);
    this.initForm();
  },
  methods: {
    refresh() {
      this.$emit("refresh");
    },
    async initForm() {
      // console.log("12");
      this.status = "";
      this.queryId = this.$route.query.id;
      // this.rulesThis = this.rules;
      this.resetForm();
    },
    getNewTime() {
      this.newTime = new Date().valueOf();
    },
    async resetForm() {
      // 重置
      await this.$nextTick(() => {
        this.tableData = [];
        const { purcheasediff } = this.sitem;
        console.log(purcheasediff);
        if (purcheasediff) {
          this.tableData.push(purcheasediff);
        }
      });
    },

    editRow(index) {
      let findex = this.stockForm.good_stock.findIndex((v) => v.edit === true);
      if (findex !== -1) {
        this.$message.warning("当前已有发货仓库信息在编辑，请保存后再试！");
        return;
      } else {
        this.stockForm.good_stock[index].edit = true;
      }
    },
    checkStockRow(index) {
      let total = parseInt(this.stockForm.good_stock[index].usable_stock),
        num = parseInt(this.stockForm.good_stock[index].num);
      if (total === 0) {
        this.$message.warning("该仓库已无该商品库存！不能销售！");
        return;
      } else {
        if (num > total) {
          this.$message.warning("销售数量不能大于可用库存！");
          return;
        } else {
          this.stockForm.good_stock[index].edit = false;
        }
      }
    },

    openHouseModal() {
      this.modelId = "add";
      this.modelItem = this.sitem;
      this.modelShowModel = true;
    },

    //省市区保存某一行
    checkRow(rowIndex) {
      this.$refs.addrForm.validate((valid) => {
        if (valid) {
          this.tableData[rowIndex].edit = false;
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    // 省市区删除行操作
    deleteRow(index, rows) {
      rows.splice(index, 1);
    },
    // async submitForm() {
    //   await this.$refs.ruleForm.validate(async (valid) => {
    //     if (valid) {
    //    if (this.loading) {
    //        return;
    //      }
    //       this.loading = true;
    //       const { order_addr } = JSON.parse(JSON.stringify(this.addrForm));
    //       let model = {
    //         id: this.queryId,
    //         order_addr: [],
    //       };
    //       order_addr.forEach((v2) => {
    //         let model2 = {
    //           post_fee: v2.post_fee,
    //           id: v2.id,
    //         };
    //         model.order_addr.push(model2);
    //       });
    //       let res = await asyncRequest.salefee(model);
    //       this.loading = false;
    //       if (res && res.code === 0) {
    //         this.$notify.success({
    //           title: "反馈物流费用成功！",
    //           message: "",
    //         });
    //         this.showModelThis = false;
    //         // 刷新
    //         this.$emit("refresh");
    //       } else if (res && res.code >= 100 && res.code <= 104) {
    //         await this.logout();
    //       } else {
    //         this.$message.warning(res.message);
    //       }
    //     } else {
    //       console.log("error submit!!");
    //       return false;
    //     }
    //   });
    // },
    openModal(code, sitem, outcode) {
      console.log(sitem);
      this.s_sitem = sitem;
      this.modelId = code;
      this.showModel = true;
    },
  },
};
</script>
   <style lang="scss" scoped>
</style>