<template>
  <ifrm ref="ifrm">
    <!-- 烧结设备解绑-->
    <uni-forms ref="form">
      <uni-forms-item
        ><input
          type="text"
          v-model="oneInput"
          :focus="oneInputFcous"
          class="uni-input-border"
          @input="oneInputBlur"
          placeholder="流程卡"
      /></uni-forms-item>
    </uni-forms>
    <t-table style="margin-top: 20rpx">
      <t-tr>
        <t-td style="max-width: 260rpx">保温开始时间</t-td>
        <t-td>
          <uni-datetime-picker type="datetime" v-model="formData.oneData" />
        </t-td>
      </t-tr>
      <t-tr>
        <t-td style="max-width: 260rpx">设定温度</t-td>
        <t-td><input v-model="formData.dataTwo" /></t-td>
      </t-tr>
      <t-tr>
        <t-td style="max-width: 260rpx">保温结束时间</t-td>
        <t-td
          ><uni-datetime-picker type="datetime" v-model="formData.threeData"
        /></t-td>
      </t-tr>
      <t-tr>
        <t-td style="max-width: 260rpx">温度</t-td>
        <t-td><input v-model="formData.tempSlot" /></t-td>
      </t-tr>
      <t-tr>
        <t-td style="max-width: 260rpx">最小真空度</t-td>
        <t-td><input v-model="formData.dataFourteen" /></t-td>
      </t-tr>
    </t-table>
    <uni-table
      ref="table"
      v-if="loading"
      border
      stripe
      type="selection"
      emptyText="暂无更多数据"
      @selection-change="selectionChange"
    >
      <uni-tr>
        <uni-th align="center">绑定时间</uni-th>
        <uni-th align="center">零件号</uni-th>
        <uni-th align="center">批次号</uni-th>
        <uni-th align="center">数量</uni-th>
        <uni-th align="center">设备</uni-th>
      </uni-tr>
      <uni-tr v-for="(item, index) in tableData" :key="index">
        <uni-td align="center" style="font-size: 34rpx">
          {{ item.createTime }}
        </uni-td>
        <uni-td align="center" style="font-size: 34rpx">
          {{ item.partCode }}
        </uni-td>
        <uni-td align="center" style="font-size: 34rpx">
          {{ item.batchNo }}
        </uni-td>
        <uni-td align="center" style="font-size: 34rpx">
          {{ item.quantity }}
        </uni-td>
        <uni-td align="center" style="font-size: 34rpx">{{
          item.deviceCode
        }}</uni-td>
      </uni-tr>
    </uni-table>
    <view class="buttonBox"
      ><button
        class="button"
        :disabled="!(selectedIndexs.length > 0)"
        type="primary"
        @click="submitClick"
      >
        解绑
      </button></view
    >
  </ifrm>
</template>

<script>
import ifrm from "@/pages/index/ifrm";
import inputBlur from "@/mixin/inputBlur.js";
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";
export default {
  mixins: [inputBlur],
  components: {
    ifrm,
    tTable,
    tTh,
    tTr,
    tTd,
  },
  data() {
    return {
      formData: {},
      tableData: [],
      loading: true,
      selectedIndexs: [],
    };
  },

  methods: {
    // 多选
    selectionChange(e) {
      this.selectedIndexs = e.detail.index;
    },
    oneInputData(code) {
      this.getData(code, 1);
    },
    getData(code, num) {
      this.oneInput = code;
      this.formData.cardNo = code;
      this.$u.api.getUnbindByCard({cardNo:code}).then((res) => {
        console.log(res.data,'87877');
        let data = res.data;
        if (data != null && data.length > 0) {
          this.tableData = data;
          uni.showToast({
            title: "数据获取成功",
          });
        } else {
          uni.showToast({
            title: "此订单无需解绑",
            icon: "none",
          });
        }
      });
      //   this.$ajax.request({
      //     url,
      //     method: "POST",
      //     data: this.formData,
      //     success: (data) => {
      //   if (data != null && data.length > 0) {
      //     this.tableData = data;
      //     uni.showToast({
      //       title: "数据获取成功",
      //     });
      //   } else {
      //     uni.showToast({
      //       title: "此订单无需解绑",
      //       icon: "none",
      //     });
      //   }
      //     },
      //   });
    },
    submitClick() {
      let list = [];
      this.selectedIndexs.forEach((item) => {
        list.push(this.tableData[item]);
      });
      this.$u.api.sjEcUnbinding({ list, ...this.formData }).then((res) => {
        this.loading = false;
        this.clearOneInput();
        this.tableData = [];
        this.selectedIndexs = [];
        this.formData = {};
        uni.showToast({
          title: "解绑成功",
        });
        setTimeout(() => {
          this.loading = true;
        }, 600);
      }).catch(err=>{
         this.loading = false;
      })
      //   this.$ajax.request({
      //     url,
      //     method: "POST",
      //     data: {
      //   list,
      //   ...this.formData,
      //     },
      //     success: (data) => {
      // this.loading = false;
      // this.clearOneInput();
      // this.tableData = [];
      // this.selectedIndexs = [];
      // this.formData = {};
      // uni.showToast({
      //   title: "解绑成功",
      // });
      // setTimeout(() => {
      //   this.loading = true;
      // }, 600);
      //     },
      //   });
    },
  },
  onNavigationBarButtonTap(btn) {
    this.$refs.ifrm.topMenuClick(btn);
  },
};
</script>

<style scoped lang="less">
.tabsBox {
  margin-top: 40rpx;
}

.uni-forms-item {
  margin-bottom: 6px !important;
}

.uni-group {
  display: flex;
  align-items: center;
}
</style>