<template>
  <div v-loading="loading">
    <div class="form-box">
      <el-form
        label-position="top"
        :model="form"
        ref="form"
        :rules="formRules"
        label-width="100px"
      >
        <el-form-item label="跟进结果" prop="code">
          <el-radio-group v-model="form.code" size="medium">
            <el-radio-button label="1">完成</el-radio-button>
            <el-radio-button label="2">跟进中</el-radio-button>
          </el-radio-group>
        </el-form-item>

        <el-row>
          <el-col :span="8">
            <el-form-item label="跟进人" prop="code">
              <el-select
                v-model="form.inWarehouseId"
                :placeholder="$t('pleaseSelect')"
                style="width: 100%"
              >
                <el-option
                  v-for="item in warehouseSelectList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="10">
            <el-form-item label="跟进时间" prop="clearancePeriod">
              <el-date-picker
                v-model="form.clearancePeriod"
                type="datetime"
                :placeholder="$t('pleaseSelect')"
                value-format="yyyy-MM-dd HH:mm:ss"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="跟进记录" prop="remark">
          <el-input
            v-model="form.remark"
            placeholder="请输入"
            type="textarea"
            :rows="3"
          >
          </el-input>
        </el-form-item>
      </el-form>
    </div>
    <div style="text-align: center; margin-top: 15px">
      <el-button size="small" @click="handleCancel"
        >{{ $t("cancel") }}
      </el-button>
      <el-button type="primary" size="small" @click="handleSubmit">
        {{ $t("submit") }}</el-button
      >
    </div>
    <!-- <el-dialog
      :title="$t('goodsSelect')"
      v-if="selectDialog"
      :visible.sync="selectDialog"
      width="80%"
      top="60px"
    >
      <selectProduct @select="handleSelect"></selectProduct>
    </el-dialog> -->
  </div>
</template>

<script>
import labelTitle from "@/components/label-title/index.vue";
import selectProduct from "@/components/select-product/index.vue";

import { getToken } from "@/util/auth";

export default {
  name: "addManualOutbound",
  components: { labelTitle, selectProduct },
  props: {
    form: {
      type: Object,
      default: () => {},
    },
    warehouseSelectList: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      uploadHeader: {
        Authorization: "Basic c2FiZXI6c2FiZXJfc2VjcmV0",
        "Blade-Auth": "bearer " + getToken(),
      },
      loading: false,
      selectDialog: false,
      formRules: {
        quantity: [
          {
            required: true,
            message: "请输入质检合格数量",
            trigger: "blur",
          },
        ],
        outWarehouseId: [
          {
            required: true,
            message: "请选择调出仓库",
            trigger: "change",
          },
        ],
        inWarehouseId: [
          {
            required: true,
            message: "请选择调入仓库",
            trigger: "change",
          },
        ],
      },
    };
  },
  created() {},
  methods: {
    handleSubmit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          if (!this.form.changeProductList.length > 0)
            return this.msgInfo("请添加调仓明细");
          this.loading = true;
          this.$emit("submit");
        }
      });
    },
    handleCancel() {
      this.$emit("cancel");
    },
    handleAddProduct() {
      if (this.form.outWarehouseId === this.form.inWarehouseId)
        return this.msgInfo("调出和调入仓库不可一致");
      if (!(this.form.outWarehouseId && this.form.inWarehouseId))
        return this.msgInfo("请先选择要调的仓库");
      this.selectDialog = true;
    },
    handleSelect(row) {
      const flag = this.form.changeProductList.some(
        (x) => x.productId === row.id
      );
      if (flag) return this.msgInfo("该物品已经选择");
      const product = {
        productCode: row.code,
        productName: row.name,
        productId: row.id,
        quantity: "",
      };
      this.form.changeProductList.push(product);
    },
    deleteRow(index) {
      this.form.changeProductList.splice(index, 1);
      this.msgSuccess(this.$t("deleteSuccess"));
    },
  },
};
</script>

<style lang="scss" scoped>
.form-box {
  height: calc(100vh - 280px);
  overflow: auto;
  box-sizing: border-box;
  padding: 10px;
}
::v-deep {
  .el-form-item {
    margin-bottom: 3px;
  }
  .el-form--label-top .el-form-item__label {
    padding: 8px 0 0 0;
  }
}
</style>