<template>
  <div>
    <el-button
      size="small"
      type="primary"
      class="ele-btn-icon"
      style="margin-left: 5px"
      @click="open"
      :disabled="disabled"
      >批量设置到货方式
    </el-button>
    <ele-modal
      :visible.sync="batchVisible"
      title="批量选择"
      width="25vw"
      append-to-body
      @close="handleClose"
      :maxable="true"
    >
      <el-form :model="form" label-width="100px">
        <el-form-item label="到货方式" prop="deliveryMethod">
          <el-select
            clearable
            v-model="form.deliveryMethod"
            placeholder="请选择"
          >
            <el-option label="一次性到货" :value="1" />
            <el-option label="分批到货" :value="2" />
          </el-select>
        </el-form-item>
        <el-form-item label="要求到货时间" prop="requireDeliveryTime">
          <el-date-picker
            clearable
            v-model="form.requireDeliveryTime"
            type="date"
            v-show="form.deliveryMethod == 1"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期"
            :pickerOptions="{
              disabledDate: (time) =>
                time.getTime() <
                new Date(new Date().setHours(0, 0, 0, 0)).getTime()
            }"
          >
          </el-date-picker>
          <el-link
            type="primary"
            :underline="false"
            v-show="form.deliveryMethod == 2"
            @click.native="handleMethod()"
          >
            设置分批时间
          </el-link>
        </el-form-item>
      </el-form>
      <template v-slot:footer>
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="handleConfirm">确认</el-button>
      </template>
      <timeDialog
        @chooseTime="chooseTime"
        ref="timeDialogRef"
        :isAll="true"
      ></timeDialog>
    </ele-modal>
  </div>
</template>

<script>
  import { copyObj } from '@/utils/util';
  import timeDialog from '@/components/timeDialog/index.vue';

  const def = {
    deliveryMethod: '',
    requireDeliveryTime: '',
    arrivalBatch: []
  };
  export default {
    components: { timeDialog },
    computed: {},
    data() {
      return {
        batchVisible: false,
        form: copyObj(def)
      };
    },
    props:{
      disabled:{
        type:Boolean,
        default:true
      }
    },
    methods: {
      open() {
        this.batchVisible = true;
        this.form = copyObj(def);
      },
      handleMethod() {
        this.$refs.timeDialogRef.open({ arrivalBatch:this.form.arrivalBatch});
      },
      chooseTime({ arrivalBatch }) {
        this.form.arrivalBatch = arrivalBatch;
      },
      handleConfirm() {
        console.log(this.form, 'this.form');
        this.$emit('chooseTime', this.form);
        this.handleClose();
      },
      handleClose() {
        this.batchVisible = false;
      }
    }
  };
</script>

<style lang="scss" scoped></style>
