<template>
  <ifrm ref="ifrm">
    <!-- 工序报工 -->
    <uni-forms ref="wrForm" :modelValue="formData">
      <uni-forms-item name="allegation"
        ><input
          type="text"
          v-model="formData.cardNo"
          @confirm="confirm"
          class="uni-input-border"
          :focus="twoInputFcous"
          placeholder="流程卡"
      /></uni-forms-item>
    </uni-forms>
    <t-table style="margin-bottom: 120rpx">
      <t-tr>
        <t-td>车间订单号</t-td>
        <t-td>{{ tableObj.woCode }}</t-td>
      </t-tr>
      <t-tr>
        <t-td>流程卡号</t-td>
        <t-td>{{ tableObj.cardNo }}</t-td>
      </t-tr>
      <t-tr>
        <t-td>批次号</t-td>
        <t-td>{{ tableObj.batchNo }}</t-td>
      </t-tr>
      <t-tr>
        <t-td>产品号</t-td>
        <t-td>{{ tableObj.partCode }}</t-td>
      </t-tr>
      <t-tr>
        <t-td>产品型号</t-td>
        <t-td>{{ tableObj.productType }}</t-td>
      </t-tr>
      <t-tr>
        <t-td>产品名称</t-td>
        <t-td>{{ tableObj.partName }}</t-td>
      </t-tr>
      <t-tr>
        <t-td>镀种信息</t-td>
        <t-td>{{ tableObj.plate }}</t-td>
      </t-tr>
      <t-tr>
        <t-td>当前工序</t-td>
        <t-td>{{ tableObj.currentWpTitle }}</t-td>
      </t-tr>
      <t-tr>
        <t-td>订单数量</t-td>
        <t-td>{{ tableObj.makeQty }}</t-td>
      </t-tr>
      <t-tr>
        <t-td>已合格数量</t-td>
        <t-td>{{ tableObj.workQty }}</t-td>
      </t-tr>
      <t-tr>
        <t-td>已报废数量</t-td>
        <t-td>{{ tableObj.scrapQty }}</t-td>
      </t-tr>
      <template
        v-if="tableObj.currentWpId != null && tableObj.frontMakeTeam == null"
      >
        <t-tr>
          <t-td>自检是否合格</t-td>
        </t-tr>
        <t-tr>
          <t-td
            ><uni-data-checkbox v-model="formData.line" :localdata="lineList"
          /></t-td>
        </t-tr>
      </template>

      <t-tr>
        <t-tr>
          <t-td>合格数量</t-td>
          <t-td><input type="number" v-model="formData.workQty" /></t-td>
        </t-tr>
        <t-tr>
          <t-td>报废数量</t-td>
          <t-td><input type="number" v-model="formData.scrapQty" /></t-td>
        </t-tr>
      </t-tr>
      <t-tr>
        <t-tr>
          <t-td>色标数量</t-td>
          <t-td><input type="number" v-model="formData.flagQty" /></t-td>
        </t-tr>
        <t-tr>
          <t-td>颜色1</t-td>
          <t-td><input type="text" v-model="formData.flagColourOne" /></t-td>
        </t-tr>
      </t-tr>
      <t-tr>
        <t-tr>
          <t-td>颜色2</t-td>
          <t-td><input type="text" v-model="formData.flagColourTwo" /></t-td>
        </t-tr>
        <t-tr>
          <t-td>油墨</t-td>
          <t-td><input type="text" v-model="formData.flagInk" /></t-td>
        </t-tr>
      </t-tr>
      <t-tr>
        <t-tr>
          <t-td>色带数量</t-td>
          <t-td><input type="number" v-model="formData.beltQty" /></t-td>
        </t-tr>
        <t-tr>
          <t-td>颜色1</t-td>
          <t-td><input type="text" v-model="formData.beltColourOne" /></t-td>
        </t-tr>
      </t-tr>
      <t-tr>
        <t-tr>
          <t-td>颜色2</t-td>
          <t-td><input type="text" v-model="formData.beltColourTwo" /></t-td>
        </t-tr>
        <t-tr>
          <t-td>油墨</t-td>
          <t-td><input type="text" v-model="formData.beltInk" /></t-td>
        </t-tr>
      </t-tr>
      <!-- 水墨连续性的展示 -->
      <template v-if="formData.isBinging">
        <!-- <template> -->
        <t-tr>
          <t-td>水墨连续性</t-td>
        </t-tr>
        <t-tr>
          <t-td
            ><uni-data-checkbox
              v-model="formData.isBingingBool"
              :localdata="lineList"
          /></t-td>
        </t-tr>
      </template>
      <template v-if="heatTreatmentShow">
        <t-tr>
          <t-td>试片数量/个</t-td>
          <t-td
            ><uni-data-checkbox
              v-model="heatTreatment.resource"
              :localdata="resourceList"
          /></t-td>
          <t-td><input type="text" v-model="heatTreatment.num" /></t-td>
        </t-tr>
        <t-tr>
          <t-td>材料厚度/mm</t-td>
          <t-td><input type="text" v-model="heatTreatment.thickness" /></t-td>
        </t-tr>
        <t-tr>
          <t-td>热处理工装编号</t-td>
          <t-td><input type="text" v-model="heatTreatment.code" /></t-td>
        </t-tr>
        <t-tr>
          <t-td>材料检验编号</t-td>
          <t-td><input type="text" v-model="heatTreatment.inspectCode" /></t-td>
        </t-tr>
        <t-tr>
          <t-td>合金材料及状态</t-td>
          <t-td><input type="text" v-model="heatTreatment.status" /></t-td>
        </t-tr>
        <t-tr>
          <t-td>原材料制品形式</t-td>
          <t-td><input type="text" v-model="heatTreatment.shape" /></t-td>
        </t-tr>
      </template>
    </t-table>
    <view class="buttonBox"
      ><button
        class="button"
        type="primary"
        :disabled="!(Object.keys(tableObj).length > 0)"
        @click="submitClick"
      >
        报工
      </button></view
    >
  </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 {
      tableObj: {},
      heatTreatment: {
        resource: "是",
      },
      formData: {
        cardNo: "",
        workQty: "",
        scrapQty: "",
        flagQty: null,
        flagColourOne: null,
        flagColourTwo: null,
        flagInk: null,
        beltQty: null,
        beltColourOne: null,
        beltColourTwo: null,
        beltInk: null,
        prWorkPlan: {
          wpId: null,
        },
        resource: true,
        isBinging: false,
        isBingingBool: 1,
      },
      lineList: [
        {
          text: "合格",
          value: 1,
        },
        {
          text: "不合格",
          value: 0,
        },
      ],
      resourceList: [
        {
          text: "是",
          value: "是",
        },
        {
          text: "否",
          value: "否",
        },
      ],
      heatTreatmentShow: false,
      twoInputFcous: true,
    };
  },
  methods: {},
  onNavigationBarButtonTap(btn) {
    this.$refs.ifrm.topMenuClick(btn);
  },
  onShow() {},
  methods: {
    getBarCode(code, isConfirm = false) {
      this.getData(code);
    },
    confirm(e) {
      this.getBarCode(e.target.value, true);
    },
    getData(code) {
      this.twoInputFcous = false;
      if (!code) return;
      this.formData.cardNo = code;
      this.$u.api.loadCurrentWp({ cardNo: code }).then((res) => {
        let data = res.data;
        this.formData.cardNo = "";
        this.tableObj = data;
        if (
          this.tableObj != null &&
          this.tableObj.currentWpTitle != null &&
          this.tableObj.currentWpTitle.split("|")[1] === "热处理"
        ) {
          this.heatTreatmentShow = true;
        }
        this.formData.prWorkPlan.wpId = data.currentWpId;
        this.formData.workQty = data.notWorkQty;
        this.formData.scrapQty = 0;
        uni.showToast({
          title: "数据获取成功",
        });
      });
      // this.$ajax.request({
      //     url: 'pdaLoad/loadCurrentWp/' + code,
      //     method: 'GET',
      //     success: data => {
      // this.formData.cardNo = '';
      // this.tableObj = data;
      // if (
      //     this.tableObj != null &&
      //     this.tableObj.currentWpTitle != null &&
      //     this.tableObj.currentWpTitle.split('|')[1] === '热处理'
      // ) {
      //     this.heatTreatmentShow = true;
      // }
      // this.formData.prWorkPlan.wpId = data.currentWpId;
      // this.formData.workQty = data.notWorkQty;
      // this.formData.scrapQty = 0;
      // uni.showToast({
      //     title: '数据获取成功'
      // });
      //     }
      // });
    },
    submitClick() {
      let isShow = false;
      let title = "";
      if (
        Number(this.formData.workQty) + Number(this.formData.scrapQty) >
        Number(this.tableObj.notWorkQty)
      ) {
        isShow = true;
        title = "合格数量与报废数量已超过总数量";
      }
      if (this.formData.workQty <= 0 && this.formData.scrapQty <= 0) {
        isShow = true;
        title = "请填写合格数量与报废数量";
      }
      if (isShow) {
        return uni.showToast({
          title,
          icon: "none",
        });
      }
      this.$u.api
        .saveMakeRec({ ...this.tableObj,...this.formData, ...this.heatTreatment })
        .then((res) => {
          this.tableObj = {};
          uni.showToast({
            title: "报工成功",
          });
          this.heatTreatment = {
            resource: "是",
          };
          this.heatTreatmentShow = false;
          this.formData = {
            cardNo: "",
            workQty: "",
            scrapQty: "",
            flagQty: null,
            flagColourOne: null,
            flagColourTwo: null,
            flagInk: null,
            beltQty: null,
            beltColourOne: null,
            beltColourTwo: null,
            beltInk: null,
            prWorkPlan: {
              wpId: null,
            },
            resource: true,
          };
          this.twoInputFcous = true;
        });
      //   this.$ajax.request({
      //     url: "prMakeRec/saveMakeRec",
      //     data: {
      //       prMakeRec: this.formData,
      //       heatTreatment: this.heatTreatment,
      //     },
      //     method: "POST",
      //     success: (data) => {
      //   this.tableObj = {};
      //   uni.showToast({
      //     title: "报工成功",
      //   });
      //   this.heatTreatment = {
      //     resource: "是",
      //   };
      //   this.heatTreatmentShow = false;
      //   this.formData = {
      //     cardNo: "",
      //     workQty: "",
      //     scrapQty: "",
      //     flagQty: null,
      //     flagColourOne: null,
      //     flagColourTwo: null,
      //     flagInk: null,
      //     beltQty: null,
      //     beltColourOne: null,
      //     beltColourTwo: null,
      //     beltInk: null,
      //     prWorkPlan: {
      //       wpId: null,
      //     },
      //     resource: true,
      //   };
      //   this.twoInputFcous = true;
      //     },
      //   });
    },
  },
};
</script>

<style scoped lang="scss">
.buttonBox {
  position: fixed;
  bottom: 10rpx;
  left: 50%;
  transform: translate(-50%);
}
</style>