<template>
  <u-popup :show="searchVisible" mode="bottom" @close="searchVisible = false">
    <view class="handle-wrapper">
      <uni-table border>
        <uni-tr>
          <uni-td align="center">处置方式</uni-td>
          <uni-td align="center">改型</uni-td>
        </uni-tr>
        <uni-tr>
          <uni-td align="center">仓库</uni-td>
          <uni-td align="center">
            <uni-easyinput
              type="text"
              @click.native="openWarehouse"
              :value="formData.warehouse"
              placeholder="请选择"
            />
          </uni-td>
        </uni-tr>
        <uni-tr>
          <uni-td align="center">数量</uni-td>
          <uni-td align="center">
            <uni-number-box
              v-model="formData.disposeWeight"
              :min="0"
              :max="Infinity"
            >
            </uni-number-box>
          </uni-td>
        </uni-tr>
      </uni-table>
      <view class="footer">
        <button type="default" plain="true" size="mini" @click="cancel">
          取消
        </button>
        <button type="primary" size="mini" @click="confirm">确认</button>
      </view>
    </view>
    <u-action-sheet
      :closeOnClickAction="true"
      :actions="warehouseList"
      title="选择仓库"
      @close="warehouseShow = false"
      @select="warehouseSelect"
      :show.sync="warehouseShow"
    ></u-action-sheet>
  </u-popup>
</template>

<script>
import { getByCode } from "@/api/production/extrusion.js";
export default {
  data() {
    return {
      warehouseShow: false,
      searchVisible: false,
      warehouseList: [],
      pickerIndex: 0,
      formData: {
        warehouseCode: "",
        warehouse: "",
        disposeWeight: "",
      },
      callback: null,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    openWarehouse() {
      this.warehouseShow = true;
    },
    async getList() {
      const data = await getByCode("modificatiWnarehouse");
      const list = [];
      if (data.length) {
        data.map((item, index) => {
          for (var key in data[index]) {
            list.push({
              name: data[index][key],
              code: key,
            });
          }
        });
      }
      this.warehouseList = list;
    },
    confirm() {
      this.$emit("confirm", this.formData);
      this.callback && this.callback(this.formData);
      this.cancel();
    },
    cancel() {
      this.searchVisible = false;
    },
    open(disposeType, callback) {
      this.searchVisible = true;
      this.formData.disposeType = disposeType;
      this.callback = callback;
    },
    warehouseSelect(e) {
      this.formData.warehouse = e.name;
      this.formData.warehouseCode = e.code;
    },
  },
};
</script>

<style lang="scss" scoped>
.handle-wrapper {
  padding: 20rpx 0;
  /deep/.uni-numbox__value {
    width: 100%;
  }
}

.footer {
  padding: 20rpx 0;
  display: flex;
  justify-content: space-around;
}
</style>
