<script>
export default {
  props: {
    user: {
      default: () => ({
        avatar: "",
        factory: {}
      }),
      type: Object
    },
    factoryType: { type: String, default: "CN" }
  },
  data() {
    return {
      searchForm: { batchArrangeNumber: "", layoutStatus: "", startTime: "" }
    };
  },
  computed: {},
  mounted() {},
  created() {},

  methods: {
    dropdownCommand(v) {
      switch (v) {
        case "logout":
          this.$confirm("是否退出登录?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
            .then(() => {
              this.$dataStore.delete("user");
              this.$router.push("/");
            })
            .catch(() => {});
          break;

        case "cache":
          this.checkList = [];
          this.cacheVisible = true;
          break;
      }
    },
    getCountryName(code) {
      if (code) {
        const item = this.countryList?.find(el => el.countryCode == code);
        if (item) {
          return `(${item.nameCn})`;
        }
      }

      return "";
    },

    goSetting() {
      this.$router.push({
        name: "dtf-setting"
      });
    },
    goSetting1() {
      this.$router.push({
        name: "dtf-batch-detail"
      });
    },
    getDataInfo() {
      this.$emit("search", this.searchForm);
    }
  }
};
</script>

<template>
  <div>
    <div class="page-header">
      <el-form
        style="display: flex;flex-wrap: nowrap;"
        inline
        :model="searchForm"
      >
        <el-form-item label="批次号">
          <el-input
            v-model="searchForm.batchArrangeNumber"
            placeholder="请输入批次号"
          ></el-input
        ></el-form-item>
        <el-form-item label="排版状态">
          <el-select
            v-model="searchForm.layoutStatus"
            placeholder="请选择排版状态"
          >
            <el-option label="待排版" :value="1"></el-option>
            <el-option label="排版中" :value="2"> </el-option>
            <el-option label="排版成功" :value="3"> </el-option>
            <el-option label="排版失败" :value="4"> </el-option>
            <el-option label="部分成功" :value="5"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="创建时间">
          <el-date-picker
            v-model="searchForm.startTime"
            type="datetime"
            placeholder="选择创建时间"
            format="yyyy 年 MM 月 dd 日"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker
        ></el-form-item>
        <el-form-item>
          <el-button @click="getDataInfo" type="primary"
            >查询
          </el-button></el-form-item
        >
        <el-form-item>
          <el-button @click="goSetting" type="success"
            >DTF排版设置
          </el-button></el-form-item
        >
      </el-form>

      <div class="right-user">
        <div
          v-if="user && user.factory"
          style="font-weight: 700;margin-left: 8px;"
        >
          {{
            user.factory.countryCode
              ? `${user.factory.countryCode}${getCountryName(
                  user.factory.countryCode
                )}`
              : "CN(中国)"
          }}
        </div>
        <p v-if="user && user.factory">{{ user.factory.title }}</p>
        <el-dropdown @command="dropdownCommand">
          <div style="margin-right: 20px">
            <b style="cursor:pointer;">{{ user.account }}</b>
            <i class="el-icon-arrow-down"></i>
          </div>

          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="logout">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
.right-user {
  display: flex;
  align-items: center;

  b {
    margin: 0 3px;
    display: inline-block;
    color: black;
    font-size: 15px;
    font-weight: bold;
  }

  p {
    margin: 0 10px;
    font-weight: bold;
    display: inline-block;
    font-size: 15px;
    color: #e6a23c;
  }
}

.page-header {
  display: flex;
  justify-content: space-between;
  background-color: #ececec;
  padding: 5px;
  .el-form-item {
    margin-bottom: 0;
  }
}
</style>
