<template>
  <div class="batchChangeWMS">
    <Form
      ref="formModel"
      :model="formModel"
      :rules="formRule"
      :label-width="110"
    >
      <FormItem
        label="请选择退回仓库"
        prop="warehouseId"
      >
        <Select
          v-model="formModel.warehouseId"
          placeholder="请选择"
          filterable
        >
          <Option
            v-for="(option,index) in WarehousesList"
            :key="index"
            :value="option.value"
          >
            {{ option.label }}
          </Option>
        </Select>
      </FormItem>
    </Form>
    <footer style="display: flex; justify-content: flex-end; margin-top: 16px">
      <Button
        type="fcdefault"
        @click="cancel()"
      >
        取消
      </Button>
      <Button
        type="posdefault"
        style="margin-left: 8px;"
        @click="submit()"
      >
        确定
      </Button>
    </footer>
  </div>
</template>

<script>
  const R3 = window.R3;
  const { network, urlSearchParams, store } = R3;
  export default {
    name: 'batchChangeWMS',
    props: {
      selectRowData: { // 获取选择行的数据
        type: Array,
        default: () => []
      },
      idArray: {// 获取ID用于多选
        type: [Array, Object],
        default: () => {
        }
      },
    },
    created() {
      this.getWarehousesList();
    },
    data() {
      return {
        WarehousesList: [],
        formModel: {
          warehouseId: '',
        },
        formRule: {
          warehouseId: [
            {
              required: true,
              message: '请选择退回仓库',
              trigger: 'blur'
            }
          ]
        }
      };
    },
    methods: {
      getWarehousesList() {
        let virtual = {
          searchdata: {
            table: 'T_IESWAREHOUSE', 
            startindex: 0, 
            range: 1000, 
            fixedcolumns: {}, 
            column_include_uicontroller: true, 
            isolr: false, 
            isfresh: true 
          }
        };
        network.post('/p/cs/QueryList', urlSearchParams(virtual)).then((res) => {
          let list = [];
          res.data.data.row.forEach(item => {
            let obj = {
              label: item.WAREHOUSENAME.val,
              value: item.ID.val
            };
            list.push(obj);
          });
          this.WarehousesList = list;
        });
        // network.post('/p/cs/store/getStoreList', {}).then(res => {
        //   let list = [];
        //   res.data.data.forEach(item => {
        //     let obj = {
        //       label: item.WAREHOUSENAME,
        //       value: item.ID
        //     };
        //     list.push(obj);
        //   });
        //   this.WarehousesList = list;
        // });
      },
      submit() {
        if (this.formModel.warehouseId == '') {
          return this.$Message.warning('请选择退回仓库');
        }
        let params = {
          ids: this.idArray,
          warehouseid: this.formModel.warehouseId
        };
        network.post('/p/cs/refund/batch/modify/warehouse', params).then(res => {
          if (res.data.code == 0) {
            this.$Modal.fcSuccess({
              title: '提示',
              mask: true,
              content: res.data.message,
            });
            this.closeDialog();
          } else {
            this.$Modal.fcError({
              title: '提示',
              mask: true,
              content: res.data.message,
            });
          }
        });
      },
      cancel() {
        this.closeDialog();
      },
      closeDialog() { // 关闭弹窗
        this.$emit('closeActionDialog', true);
      },
    }
  };
</script>
<style>
  .batchChangeWMS .ark-select-single .ark-select-selection {
    height: 34px;
  }
</style>
<style scoped>
  .batchChangeWMS form {
    margin-right: 30px;
  }
</style>
