<template>
  <ifrm ref="ifrm">
    <!-- 解绑 -->
    <uni-forms ref="wrForm" class="formBox">
      <uni-forms-item name="allegation"
        ><input
          type="text"
          :focus="oneInputFcous"
          @input="oneInputBlur"
          v-model="oneInput"
          class="uni-input-border"
          :disabled="oneFlag"
          placeholder="挂具"
      /></uni-forms-item>
      <uni-forms-item name="allegation"
        ><input
          type="text"
          :focus="twoInputFcous"
          v-model="twoInput"
          @input="twoInputBlur"
          :disabled="twoFlag"
          class="uni-input-border"
          placeholder="飞靶"
      /></uni-forms-item>
      <uni-forms-item name="allegation"
        ><input
          type="text"
          :focus="therrInputFcous"
          v-model="therrInput"
          @input="therrInputBlur"
          :disabled="therrFlag"
          class="uni-input-border"
          placeholder="设备"
      /></uni-forms-item>
    </uni-forms>
    <view class="tableBox">
      <uni-card title="挂具信息" v-if="Object.keys(bsRackSet).length > 0">
        <t-table>
          <t-tr>
            <t-td>编号</t-td>
            <t-td>{{ bsRackSet.rsCode }}</t-td>
          </t-tr>
          <t-tr>
            <t-td>名称</t-td>
            <t-td>{{ bsRackSet.rsType }}</t-td>
          </t-tr>
          <t-tr>
            <t-td>状态</t-td>
            <t-td>{{ bsRackSet.statusName }}</t-td>
          </t-tr>
        </t-table>
      </uni-card>
      <uni-card title="飞靶信息" v-if="Object.keys(feibaObj).length > 0">
        <t-table>
          <t-tr>
            <t-td>编号</t-td>
            <t-td>{{ feibaObj.fsCode }}</t-td>
          </t-tr>
          <t-tr>
            <t-td>名称</t-td>
            <t-td>{{ feibaObj.fsType }}</t-td>
          </t-tr>
          <t-tr>
            <t-td>状态</t-td>
            <t-td>{{ feibaObj.statusName }}</t-td>
          </t-tr>
        </t-table>
      </uni-card>
      <uni-card title="设备信息" v-if="Object.keys(facilityObj).length > 0">
        <t-table>
          <t-tr>
            <t-td>编号</t-td>
            <t-td>{{ facilityObj.deviceCode }}</t-td>
          </t-tr>
          <t-tr>
            <t-td>名称</t-td>
            <t-td>{{ facilityObj.deviceName }}</t-td>
          </t-tr>
          <t-tr>
            <t-td>状态</t-td>
            <t-td>{{ facilityObj.usedText }}</t-td>
          </t-tr>
        </t-table>
      </uni-card>
    </view>

    <view class="buttonBox"
      ><button
        class="button"
        type="primary"
        :disabled="
          !(
            !Object.keys(bsRackSet).length == 0 ||
            !Object.keys(feibaObj).length == 0 ||
            !Object.keys(facilityObj).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 inputBlur from "@/mixin/inputBlur.js";
export default {
  mixins: [inputBlur],
  components: {
    ifrm,
    tTable,
    tTh,
    tTr,
    tTd,
  },
  data() {
    return {
      therrInput: "",
      bsRackSet: {},
      feibaObj: {},
      facilityObj: {},
      oneFlag: false,
      twoFlag: false,
      therrFlag: false,
    };
  },
  methods: {},
  onNavigationBarButtonTap(btn) {
    this.$refs.ifrm.topMenuClick(btn);
  },
  onShow() {},
  methods: {
    oneInputData(code) {
      uni.hideKeyboard();
      this.getData(code, 1);
    },
    twoInputData(code) {
      uni.hideKeyboard();
      this.getData(code, 2);
    },
    therrInputData(code) {
      uni.hideKeyboard();
      this.getEcByDeviceCode(code);
    },
    getData(code, num) {
      this.bsRackSet = {};
      this.feibaObj = {};
      this.facilityObj = {};
      this.clearInput();

      if (num == 1) {
        this.$u.api.getBsRackSetByCode(code).then((res) => {
          let data = res.data;
          this.bsRackSet = data;
          this.twoFlag = true;
          this.therrFlag = true;
          this.clearOneInput();

          uni.showToast({
            title: "数据获取成功",
            icon: "none",
          });
        });
      }
      if (num == 2) {
        this.$u.api.getBsFeiBaSetByCode().then((res) => {
          let data = res.data;

          this.feibaObj = data;
          this.oneFlag = true;
          this.therrFlag = true;
          this.clearTwoInput();

          uni.showToast({
            title: "数据获取成功",
            icon: "none",
          });
        });
      }
      //   this.$ajax.request({
      //     url,
      //     method: "GET",
      //     success: (data) => {
      //       console.log(data);
      //   if (num == 1) {
      //     this.bsRackSet = data;
      //     this.twoFlag = true;
      //     this.therrFlag = true;
      //     this.clearOneInput();
      //   } else if (num == 2) {
      //     this.feibaObj = data;
      //     this.oneFlag = true;
      //     this.therrFlag = true;
      //     this.clearTwoInput();
      //   }
      //   uni.showToast({
      //     title: "数据获取成功",
      //     icon: "none",
      //   });
      //     },
      //   });
    },
    getEcByDeviceCode(code) {
      this.therrInput = code;
      this.$u.api.getEcByDeviceCode(code).then((res) => {
        let data = res.data;
        this.facilityObj = data;
        this.oneFlag = true;
        this.twoFlag = true;
        this.clearTherrInput();
      });
      //   this.$ajax.request({
      //     url: "pdaLoad/getEcByDeviceCode",
      //     method: "POST",
      //     data: {
      //       deviceCode: code,
      //     },
      //     success: (data) => {
      //   this.facilityObj = data;
      //   this.oneFlag = true;
      //   this.twoFlag = true;
      //   this.clearTherrInput();
      //     },
      //   });
    },
    submitClick() {
      this.$u.api
        .unBind({
          rsCode: this.bsRackSet.rsCode,
          fsCode: this.feibaObj.fsCode,
          deviceCode: this.facilityObj.deviceCode,
        })
        .then((res) => {
          this.bsRackSet = {};
          this.feibaObj = {};
          this.facilityObj = {};
          this.clearInput();
          this.clearFcous();
          uni.showToast({
            title: "解绑成功",
          });
          this.oneFlag = false;
          this.twoFlag = false;
          this.therrFlag = false;
        });
      // this.$ajax.request({
      //   url: "pdaSave/unBind",
      // data: {
      // rsCode: this.bsRackSet.rsCode,
      // fsCode: this.feibaObj.fsCode,
      // deviceCode: this.facilityObj.deviceCode,
      //   },
      //   method: "POST",
      //   success: (data) => {
      // this.bsRackSet = {};
      // this.feibaObj = {};
      // this.facilityObj = {};
      // this.clearInput();
      // this.clearFcous();
      // uni.showToast({
      //   title: "解绑成功",
      // });
      // this.oneFlag = false;
      // this.twoFlag = false;
      // this.therrFlag = false;
      //   },
      // });
    },
  },
};
</script>

<style scoped lang="scss">
.uni-forms-item {
  margin-bottom: 6px !important;
}
</style>