<template>
  <div id="card-1">
    <el-row>
      <el-col :span="24" class="main animate__animated animate__backInRight">
        <span v-if="view === 'list'">
          <el-col :span="24" class="one"> <span>尊荣订单</span> </el-col>
          <detail-1 v-if="num == '1'" @toDeliver="toDeliver" :statusList="statusList" @toDetail="toDetail"></detail-1>
          <detail-2 v-else-if="num == '2'" :deliverList="list" @toBack="toBack"></detail-2>
        </span>
        <detail_orderDetail v-if="view === 'info'" :id="id" @toBack="toBacks"></detail_orderDetail>
      </el-col>
    </el-row>
  </div>
</template>

<script>
const _ = require('lodash');
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: dictData } = createNamespacedHelpers('dictData');

export default {
  name: 'card-1',
  props: {},
  components: {
    detail1: () => import('./parts/detail-1.vue'),
    detail2: () => import('./parts/detail-2.vue'),
    detail_orderDetail: () => import('./detail_orderDetail.vue'),
  },
  data: function () {
    return {
      view: 'list',
      num: '1',
      list: [],
      // 订单状态
      statusList: [],
      id: '',
    };
  },
  async created() {
    await this.searchOther();
  },
  methods: {
    ...dictData({ dictQuery: 'query' }),
    // 查询其他信息
    async searchOther() {
      let res;
      // 类型
      res = await this.dictQuery({ code: 'order_process' });
      if (this.$checkRes(res)) this.$set(this, `statusList`, res.data);
    },
    // 生成发货清单
    toDeliver({ data }) {
      if (data.length == '0') this.$message('请选择订单');
      else {
        this.$set(this, 'list', data);
        this.$set(this, 'num', '2');
      }
    },
    toDetail(data) {
      this.$set(this, `id`, data);
      this.$set(this, `view`, 'info');
    },
    toBack() {
      this.$set(this, 'num', '1');
    },
    toBacks() {
      this.view = 'list';
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  .one {
    margin: 0 0 10px 0;
    span:nth-child(1) {
      font-size: 20px;
      font-weight: 700;
      margin-right: 10px;
    }
  }
  .two {
    margin: 0 0 10px 0;
  }
  .thr {
    margin: 0 0 10px 0;
  }
}
</style>
