<template>
  <ifrm ref="ifrm">
    <!-- 大仓派活 -->
    <uni-forms ref="form">
      <uni-forms-item
        ><input
          type="text"
          v-model="cradNo"
          @confirm="cradConfirm"
          class="uni-input-border"
          placeholder="请扫描流程卡"
      /></uni-forms-item>
    </uni-forms>
    <t-table style="margin-top: 20rpx">
      <t-tr>
        <t-td>厂内生产</t-td>
        <t-td>
          <switch :checked="unFsBool" @change="switchChange" />
        </t-td>
      </t-tr>
      <!-- <t-tr>
        <t-td>流程卡</t-td>
        <t-td>{{ cradNoText }}</t-td>
      </t-tr> -->
      <!-- <t-tr>
        <t-td>处理班组/供应商</t-td>
        <t-td>{{ makeTeam }}</t-td>
      </t-tr> -->
    </t-table>
    <t-table style="margin-top: 20rpx">
      <t-tr>
        <t-td>工序号</t-td>
        <t-td> 工序名称 </t-td>
        <t-td> 作业中心/供应商 </t-td>
      </t-tr>
      <t-tr v-for="(item, index) in makeTeam" :key="index">
        <t-td>{{ item.processNo }}</t-td>
        <t-td> {{ item.processName }} </t-td>
        <t-td> {{ item.workCenterName }} </t-td>
      </t-tr>
    </t-table>
  </ifrm>
</template>

<script>
import ifrm from "@/pages/index/ifrm";
import tTable from "@/components/t-table/t-table.vue";
import tTh from "@/components/t-table/t-th.vue";
import tTr from "@/components/t-table/t-tr.vue";
import tTd from "@/components/t-table/t-td.vue";
import scan from "../../mixin/scan.js";
export default {
  mixins: [scan],
  components: {
    ifrm,
    tTable,
    tTh,
    tTr,
    tTd,
  },
  data() {
    return {
      cradNo: "",
      makeTeam: [],
      cradNoText: "",
      unFsBool: false,
      getDataFun: true,
      tableData: [],
    };
  },
  methods: {
    switchChange(e) {
      this.unFsBool = e.target.value;
    },
    cradConfirm(e) {
      this.getBarCode(e.target.value);
    },
    getBarCode(code, isConfirm = false) {
      if (this.getDataFun) {
        this.getData(code);
      }
    },
    getData(code) {
      this.cradNo = code;
      this.cradNoText = code;
      if (!this.cradNo) return;
      this.getDataFun = false;
      uni.showLoading({
        title: "提交中...",
      });
      let query = {
        cardNo: this.cradNo,
        mark: this.unFsBool ? 1 : 0,
      };
      this.$u.api
        .yieldOrderConfirm(query)
        .then((res) => {
          let data = res.data;
          this.makeTeam = data;
          if (this.makeTeam.length <= 0) {
            this.$message.error("订单分派失败，请到异常订单管理页面处理!");
          }
          uni.hideLoading();
          uni.showToast({
            title: "操作成功",
          });
          this.cradNo = "";
          this.unFsBool = false;
        })
        .catch((err) => {
           this.cradNo = "";
          this.getDataFun = true;
        });
      // this.$ajax.request({
      //     url: 'pdaLoad/loadBigWmsSend/' + code + '/' + this.unFsBool,
      //     method: 'GET',
      //     success: data => {
      // this.makeTeam = data;
      // uni.showToast({
      //     title: '派活成功'
      // });
      // this.cradNo = ''
      // this.unFsBool = false
      //     },
      //     complete: () => {
      //         this.getDataFun = true
      //     }
      // });
    },
  },
  onNavigationBarButtonTap(btn) {
    this.$refs.ifrm.topMenuClick(btn);
  },
};
</script>

<style scoped>
.tabsBox {
  margin-top: 40rpx;
}

.contentBox {
}
</style>