<script>
const { getUser } = require("@/server/utils/store");

export default {
  data() {
    return {
      searchForm: { batchArrangeNumber: "", layoutStatus: "", startTime: "" },
      userData: getUser()
    };
  },
  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="请输入批次号"
            clearable
          ></el-input
        ></el-form-item>
        <el-form-item label="排版状态">
          <el-select
            v-model="searchForm.layoutStatus"
            placeholder="请选择排版状态"
            clearable
          >
            <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
            style="width: 380px;"
            clearable
            v-model="searchForm.timeRange"
            type="datetimerange"
            placeholder="选择时间"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </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="userData.user && userData.user.factory"
          style="font-weight: 700;margin-left: 8px;"
        >
          {{
            userData.user.countryCode
              ? `${userData.user.countryCode}${getCountryName(
                  userData.user.countryCode
                )}`
              : "CN(中国)"
          }}
        </div>
        <p v-if="userData.user && userData.user.factory">
          {{ userData.user.factory.title }}
        </p>
        <el-dropdown @command="dropdownCommand">
          <div style="margin-right: 20px">
            <b style="cursor:pointer;">{{ userData.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>
