<template>
  <div class="zxDiffOrderDetail pagePadding">
    <div style="width: 100%" v-if="powers.some((i) => i == '007')">
      <!-- <div class="detail-page-title">
        <span>工差单详情：</span>
      </div> -->
      <!-- <status-bar
        v-if="newTime !== ''"
        :newTime="newTime"
        :options="statusOptions"
        :status="status"
      /> -->
      <el-tabs v-model="activeTabs">
        <el-tab-pane label="业务详情" name="1">
          <el-collapse v-model="activeNames" style="margin: -18px 0 0 0">
            <el-collapse-item title="工差单信息" name="1">
              <show-data-table
                style="margin: 0; padding: 0"
                v-if="newTime !== ''"
                :newTime="newTime"
                :sitem="sitem"
                :columns="showColumns"
              >
                <template slot="status">
                  <el-tag
                    :size="'mini'"
                    v-text="
                      (statusOptions.find((item) => item.value == sitem.status) || {})
                        .label || '--'
                    "
                  ></el-tag>
                </template>
                <template slot="order_type">
                  <el-tag
                    :size="'mini'"
                    v-text="
                      (
                        xs_order_type_options.find(
                          (item) => item.id == sitem.order_type
                        ) || {}
                      ).label || '--'
                    "
                  ></el-tag>
                </template>
                <template slot="is_act">
                  <el-tag
                    :size="'mini'"
                    v-text="
                      (is_act_options.find((item) => item.value == sitem.is_act) || {})
                        .label || '--'
                    "
                  ></el-tag>
                </template>
                <template slot="customer_remark">
                  <el-tag
                    :size="'mini'"
                    v-if="sitem.is_act === '1'"
                    v-text="
                      (
                        customer_remark_options.find(
                          (item) => item.value == sitem.customer_remark
                        ) || {}
                      ).label || '--'
                    "
                  ></el-tag>
                  <el-tag :size="'mini'" v-else v-text="'--'"></el-tag>
                </template>
              </show-data-table>
            </el-collapse-item>
            <el-collapse-item title="商品信息" name="2">
              <show-goods-data-table
                :newTime="newTime"
                v-if="newTime !== ''"
                :type="sitem.order_type"
                :skucode="sitem.skuCode"
                :spucode="sitem.good_code"
                :iscgd="true"
              />
            </el-collapse-item>
            <el-collapse-item
              title="业务审核"
              name="3"
              v-if="sitem && sitem.status === '1'"
            >
              <add-form
                :sitem="sitem"
                :newTime="newTime"
                v-if="newTime !== ''"
                @refresh="initData()"
              />
            </el-collapse-item>
          </el-collapse>
        </el-tab-pane>
        <el-tab-pane label="审批记录" name="2">
          <process-time-line
            v-if="newTime !== ''"
            :newTime="newTime"
            :type="'XSGCD'"
            :orderCode="queryId"
          />
        </el-tab-pane>

        <el-tab-pane label="流程图" name="3">
          <flow-chart process_id="9" type="XSGCD" :orderCode="queryId" />
       </el-tab-pane>
      </el-tabs>
    </div>
    <div v-else>
      <no-auth></no-auth>
    </div>
  </div>
</template>
<script>
import mixinPage from "@/mixins/elPaginationHandle";
import resToken from "@/mixins/resToken";
import asyncRequest from "@/apis/service/sellOut/zxDiffOrder";
import addForm from "./components/addForm";
import { showColumns } from "./columns";
import { xs_order_type_options } from "@/assets/js/statusList";
export default {
  name: "zxDiffOrderDetail",
  mixins: [mixinPage, resToken],
  components: {
    addForm,
  },
  computed: {
    powers() {
      const tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "zxDiffOrderDetail"
        ) || {};
      const { action } = tran ?? {};
      return action ?? [];
    },
  },
  data() {
    return {
      showModel: false,
      showColumns: showColumns,
      activeTabs: "1",
      activeNames: ["-1", "0", "1", "2", "3", "4", "5", "10"],
      statusOptions: [
        { value: "1", label: "待业务部门审核" },
        { value: "2", label: "审批已完成" },
      ],
      xs_order_type_options,
      customer_remark_options: [
        {
          value: "1",
          label: "竞价订单减工差",
        },
        {
          value: "2",
          label: "竞价订单不减工差",
        },
      ],
      is_act_options: [
        {
          value: "1",
          label: "接受工差",
        },
        {
          value: "2",
          label: "不接受工差-退回重做",
        },
      ],
      sitem: null,
      status: "",
      newTime: "",
      loading: false,
      queryId: "",
    };
  },
  mounted() {
    this.status = "";
    this.queryId = this.$route.query.id;
    this.initData();
  },
  methods: {
    getNewTime() {
      this.newTime = new Date().valueOf() + "";
    },

    async setStatus() {
      if (!this.loading) {
        this.loading = true;

        let model = {
          id: this.queryId,
          remark: "",
          status: "",
        };
        const res = await asyncRequest.fstatus(model);
        this.loading = false;
        if (res && res.code === 0) {
          this.$notify.success({
            title: "通知成功！",
            message: "",
          });
          this.initData();
        } else if (res && res.code >= 100 && res.code <= 104) {
          await this.logout();
        } else {
          this.$message.warning(res.message);
        }
      }
    },
    async initData() {
      const res = await asyncRequest.detail({ id: this.queryId });
      if (res && res.code === 0 && res.data) {
        this.sitem = res.data;
        const { can, status } = res.data;
        this.status = status;
        this.sitem.class_cat = "";
        if (can && can.length > 0) {
          can.forEach((x, i) => {
            this.sitem.class_cat += i === 0 ? x.name : "/" + x.name;
          });
        }
        this.getNewTime();
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.zxDiffOrderDetail {
}
</style>
