<script>
import { mapState } from "vuex";
const { getDesktopDevice } = require("@/server/utils/store");
export default {
  props: {
    user: {
      default: () => ({
        avatar: "",
        factory: {}
      }),
      type: Object
    },
    factoryType: { type: String, default: "CN" }
  },
  data() {
    return {};
  },
  computed: {
    ...mapState([
      "defaultProportion",
      "countryList",
      "orderType",
      "grid",
      "imgList"
    ])
  },
  mounted() {
    this.$nextTick(() => {
      this.$refs.searchRef?.focus();
      if (this.desktopDevice !== 3) {
        this.selectGridIndex = 0;
        this.setting.gridValue = 0;
      } else {
        this.selectGridIndex = 5;
        this.setting.gridValue = 5;
      }
    });
    this.$store.commit("changeDesktopDevice", getDesktopDevice());
  },
  created() {
    localStorage.setItem("desktoVersion", "print");
    if (this.$dataStore.get("setting")) {
      this.setting = this.$dataStore.get("setting");
    } else {
      this.$dataStore.set("setting", this.setting);
    }
  },

  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 "";
    },
    goBack() {
      // Vue路由返回
      this.$router.back();
      // 如果需要关闭当前弹窗/子窗口，搭配：
      // ipcRenderer.send("close-current-win");
    },
    goSetting() {
      this.$router.push({
        path: "/DTFsetting",
        query: { id: 123 }
      });
    },
    getDataInfo() {},
    productionCompleted() {
      this.$confirm("确认完成生产?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {})
        .catch(() => {});
    }
  }
};
</script>

<template>
  <div>
    <div class="page-header">
      <el-form style="display: flex;flex-wrap: nowrap;" inline>
        <el-form-item>
          <el-button
            icon="el-icon-arrow-left"
            @click="goBack"
            style="margin-right:12px;"
            type="text"
            >返回</el-button
          ></el-form-item
        >
        <el-form-item> <el-input></el-input></el-form-item>
        <el-form-item label="操作单状态"> <el-input></el-input></el-form-item>

        <el-form-item>
          <el-button @click="getDataInfo" type="primary"
            >查询
          </el-button></el-form-item
        >
        <el-form-item>
          <el-button @click="productionCompleted" type="success"
            >生产完成
          </el-button></el-form-item
        >
        <el-form-item>
          <el-button @click="goSetting" type="success"
            >下载素材
          </el-button></el-form-item
        >
        <el-form-item>
          <el-button @click="goSetting" type="success"
            >排版
          </el-button></el-form-item
        >
        <el-form-item>
          <el-button @click="() => {}" type="success"
            >查看排版文件
          </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>
