<template>
  <view class="content">
    <view class="">
      <u-subsection
        :list="list"
        :current="curNow"
        active-color="red"
        @change="sectionChange"></u-subsection>
    </view>
    <view class="" v-if="curNow == 0">
      <view class="confirm-view">
        <text class="text">起始点位：</text>
        <!-- focus -->
        <uni-easyinput
          style="margin: 0 11px"
          errorMessage
          v-model="sourceLocationId"
          :adjust-position="false"
          :class="recshow ? 'rec' : ''"
          class="uni-mt-5"
          trim="all"
          @focus="focusFunc"
          placeholder-style="font-size:16px;color: #a7a7a7;"
          placeholder="请输入起始点位"
          @input="input"></uni-easyinput>
        <button
          type="default"
          @click="goto('/pages/Warehousing/select/index?show=1')">
          选择
        </button>
      </view>
      <!-- <view class="confirm-views">
        <view class="title" @click="inputDialogToggle">
          <view class="">
            <text>任务优先级:</text>
          </view>
          <view class="view_icon">
            <text>{{ value }}</text>
            <u-icon name="arrow-right" color="#6e6860" size="20"></u-icon>
          </view>
        </view>
      </view> -->
      <view class="confirm-view">
        <text class="text">终点点位：</text>
        <!-- focus -->
        <uni-easyinput
          style="margin: 0 11px"
          errorMessage
          v-model="targetLocationId"
          :class="recshowto ? 'rec' : ''"
          :adjust-position="false"
          @focus="focusFunvac"
          placeholder-style="font-size:16px;color: #a7a7a7;"
          placeholder="请输入终点点位"
          @input="inputEimt"></uni-easyinput>
        <button
          type="default"
          @click="goto('/pages/Warehousing/select/index?show=2')">
          选择
        </button>
      </view>
    </view>
    <view class="" v-else>
      <uni-data-select
        v-model="value"
        :localdata="range"
        @change="change"></uni-data-select>
      <view class="confirm-view">
        <text class="text">{{ nameOut }}：</text>
        <!-- focus -->
        <uni-easyinput
          style="margin: 0 11px"
          errorMessage
          v-model="valueSian"
          :adjust-position="false"
          :class="recshowminu ? 'rec' : ''"
          class="uni-mt-5"
          trim="all"
          @focus="focusFuncemyi"
          placeholder-style="font-size:16px;color: #a7a7a7;"
          :placeholder="'请输入' + nameOut"
          @input="inputSupport"></uni-easyinput>
        <button type="default" @click="naviga">选择</button>
      </view>
    </view>
    <view class="border-buttons" @click="subfeom">
      <view class="buttons2">
        <text>移动</text>
      </view>
    </view>

    <uni-popup ref="inputDialog" type="dialog">
      <uni-popup-dialog
        ref="inputClose"
        title="任务优先级"
        value="对话框预置提示内容!"
        placeholder="请输入内容"
        @confirm="dialogInputConfirm">
        <u-radio-group
          placement="column"
          :borderBottom="true"
          v-model="value"
          iconPlacement="right">
          <u-radio
            :customStyle="{ marginBottom: '8px' }"
            v-for="(item, index) in radiolist1"
            :key="index"
            :label="item.name"
            :name="item.name"
            @change="radioChange"></u-radio>
        </u-radio-group>
      </uni-popup-dialog>
    </uni-popup>
    <xw-scan></xw-scan>
  </view>
</template>

<script>
export default {
  data() {
    return {
      valueSian: "",
      range: [
        { value: "out", text: "空托出库" },
        { value: "in", text: "空托入库" },
      ],
      list: [
        {
          name: "其他移库",
        },
        {
          name: "空托移库",
        },
      ],
      curNow: 0,
      nameOut: "起始点位",
      valueSianid: "",
      recshow: false,
      sourceLocationIdcode: "",
      targetLocationIdcode: "",
      host: "",
      rangeValue: "in",
      sourceLocationId: "",
      targetLocationId: "",
      recshowminu: false,
      recshowto: false,
      type: "center",
      msgType: "success",
      messageText: "这是一条成功提示",
      value: "in",
      rangeValueto: "",
      value3: "",
      testdata: {},
      radiolist1: [
        {
          name: "普通",
          disabled: false,
        },
        {
          name: "紧急",
          disabled: false,
        },
      ],
    };
  },
  onShow() {
    let that = this;
    let pages = getCurrentPages();
    let currPage = pages[pages.length - 1];
    console.log("json", currPage.testdata);
    let json = currPage._data.testdata;
    this.testdata = json;
  },
  onUnload() {
    uni.$off("xwscan");
  },
  mounted() {
    let _this = this;
    uni.getStorage({
      key: "hostappst",
      success(res) {
        console.log("获取成功", res.data);
        _this.host = res.data;
      },
    });
  },
  methods: {
    otherFun(obj) {
      console.log(obj);
      if (obj.show == 1) {
        this.sourceLocationId = obj.locationNo;
        this.sourceLocationIdcode = obj.id;
      } else if (obj.show == 2) {
        this.targetLocationId = obj.locationNo;
        this.targetLocationIdcode = obj.id;
      } else if (obj.show == 4) {
        this.valueSian = obj.locationNo;
        this.valueSianid = obj.id;
      }
    },
    focusFunc(e) {
      this.recshow = true;
      this.recshowto = false;
      uni.$off("xwscan");
      uni.$on("xwscan", (res) => {
        console.log("扫码结果：", res.code);
        this.sourceLocationId = res.code;
        this.sourceLocationIdcode = res.code;
      });
      console.log("focus事件");
    },
    focusFuncemyi(e) {
      this.recshowminu = true;
      uni.$off("xwscan");
      uni.$on("xwscan", (res) => {
        console.log("扫码结果：", res.code);
        this.valueSian = res.code;
      });
      console.log("focus事件");
    },
    change(e) {
      console.log("e", e, "1");
      this.rangeValue = e;
      if (e == "emptyPalletTargetOut") {
        this.nameOut = "目标点位";
      } else {
        this.nameOut = "起始点位";
      }
    },
    naviga() {
      if (this.rangeValue == "in") {
        this.rangeValueto = "emptyPalletSourceIn";
      } else {
        this.rangeValueto = "emptyPalletTargetOut";
      }
      uni.navigateTo({
        url:
          "/pages/Warehousing/select/index?show=4&rangeValue=" +
          this.rangeValueto,
      });
    },

    sectionChange(index) {
      console.log("index", index);
      this.curNow = index;
    },
    focusFunvac(e) {
      this.recshow = false;

      this.recshowto = true;
      uni.$off("xwscan");
      uni.$on("xwscan", (res) => {
        console.log("扫码结果：", res.code);
        this.targetLocationId = res.code;
        this.targetLocationIdcode = res.code;
      });
      console.log("focus事件");
    },
    goto(data) {
      uni.navigateTo({
        url: data,
      });
    },
    input(e) {
      console.log(e);
      this.sourceLocationIdcode = e;
    },
    inputEimt(e) {
      this.targetLocationIdcode = e;
    },
    inputSupport(e) {
      this.valueSianid = e;
    },
    subfeom() {
      let params = {
        locationId: this.valueSianid,
        moveType: this.rangeValue,
      };

      let dataobj = {
        sourceLocationId: this.sourceLocationIdcode,
        targetLocationId: this.targetLocationIdcode,
      };
      let that = this;
      uni.getStorage({
        key: "GetPhone_Token",
        success: function (res) {
          if (that.curNow == 0) {
            uni.request({
              url: `http://${that.host}` + "/ams/invLotLocId/moveLocInv",
              header: {
                Authorization: res.data,
                "content-type": "application/x-www-form-urlencoded",
              },
              data: dataobj,
              method: "POST",
              success(respenon) {
                console.log("chaoShiPanDuan", respenon);
                if (respenon.data.code == 200) {
                  uni.showToast({
                    title: respenon.data.msg,
                    icon: "none",
                  });
                  uni.navigateTo({
                    url: "/pages/index/tabbar/tabbar",
                  });
                } else {
                  uni.showToast({
                    title: respenon.data.msg,
                    icon: "none",
                  });
                }
                console.log("res", res);
              },
            });
          } else {
            uni.request({
              url: `http://${that.host}` + "/ams/invLotLocId/moveEmptyPallet",
              header: {
                Authorization: res.data,
                "content-type": "application/x-www-form-urlencoded",
              },
              data: params,
              method: "POST",
              success(respenon) {
                console.log("chaoShiPanDuan", respenon);
                if (respenon.data.code == 200) {
                  uni.showToast({
                    title: respenon.data.msg,
                    icon: "none",
                  });
                  uni.navigateTo({
                    url: "/pages/index/tabbar/tabbar",
                  });
                } else {
                  uni.showToast({
                    title: respenon.data.msg,
                    icon: "none",
                  });
                }
                console.log("res", res);
              },
            });
          }
        },
      });
    },
    inputDialogToggle() {
      this.$refs.inputDialog.open();
    },
    radioChange(val) {
      console.log(val);
      this.targetLocationId = val;
    },
    dialogInputConfirm(val) {
      console.log(this.value);
      setTimeout(() => {
        uni.hideLoading();
        console.log(val);
        this.value = this.value3;
        this.$refs.inputDialog.close();
      }, 100);
    },
  },
};
</script>
<style scoped>
/deep/.uni-select {
  font-size: 16px;
  border: 1px solid #e5e5e5;
  box-sizing: border-box;
  border-radius: 4px;
  padding: 13px 5px;
  padding-left: 10px;
  position: relative;
  display: flex;
  -webkit-user-select: none;
  user-select: none;
  flex-direction: row;
  align-items: center;
  border-bottom: solid 1px #e5e5e5;
  width: 100%;
  flex: 1;
  height: 35px;
}
/deep/.uni-select__input-placeholder {
  color: #6a6a6a;
  font-size: 16px;
}
/deep/.uni-icons {
  font-family: uniicons;
  text-decoration: none;
  text-align: center;
  font-size: 20px !important;
}
/deep/.u-subsection__item__text {
  font-size: 12px;
  line-height: 12px;
  display: flex;
  flex-direction: row;
  font-size: 15px !important;
  align-items: center;
  transition-property: color;
  transition-duration: 0.3s;
}
/deep/.is-input-border {
  display: flex;
  box-sizing: border-box;
  flex-direction: row;
  align-items: center;

  border-radius: 4px;
  background-color: rgb(245 245 245) !important;
  /* background: #24bdbd; */
}
/deep/.u-radio-label--right {
  flex-direction: row-reverse;
  justify-content: space-between;
  margin-bottom: 12px;
}
/deep/uni-button {
  color: #000;
  border: 1px solid #ff0000;
  border-radius: 31px;
  width: 21%;
  background-color: #f5f5f5;
  height: 42px;
  font-size: 16px;
  color: #ff0000;
}
/deep/.uni-easyinput__content-input[data-v-abe12412] {
  width: auto;
  position: relative;
  overflow: hidden;
  flex: 1;
  line-height: 1;
  font-size: 14px;
  height: 35px;
  /* border-bottom: 1px solid #ff0000 !important; */
}
/deep/.is-input-border {
  display: flex;
  box-sizing: border-box;
  flex-direction: row;
  align-items: center;
  border: none !important;
  border-radius: 4px;
}
</style>
<style lang="scss" scoped>
.content {
  // padding: 15px;
  .confirm-view {
    display: flex;
    padding: 15px;
    margin: 5px 0;
    align-items: center;
    border-bottom: 1px solid #d5d5d5;
    height: 56px;
    .text {
      font-size: 16px;
      color: #6e6860;
      font-weight: 500;
    }
  }
  .confirm-views {
    .title {
      display: flex;
      justify-content: space-between;
      font-size: 15px;
      color: #525151;
      padding: 15px;
      margin: 5px 0;
      align-items: center;
      border-bottom: 1px solid #d5d5d5;
      height: 56px;
      .view_icon {
        display: flex;
        align-content: center;
        align-items: center;
      }
    }
  }
  .border-buttons {
    display: flex;
    position: absolute;
    button: 0;
    bottom: 32px;
    padding: 0 15px;
    justify-content: space-between;
    width: 100%;
    text-align: center;

    .buttons2 {
      width: 100%;
      border: 1px solid #ff0505;
      border-radius: 34px;
      height: 42px;
      background: red;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 18px;
      color: white;
      font-weight: 500;
    }
  }
}
</style>
