<template>
  <div class="purchaseDiffOrderDetail pagePadding">
    <div style="width: 100%" v-if="powers.some((i) => i == '007')">
      <!-- <div class="detail-page-title">
        <span>采购工差单编号：</span><span v-if="sitem">{{ sitem.id }}</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="0">
              <show-data-table
                :newTime="newTime"
                v-if="newTime !== ''"
                :sitem="sitem"
                :columns="ShowDataTableColumns"
              >
                <template slot="status">
                  <el-tag
                    :size="'mini'"
                    :type="sitem.status == '0' ? 'warning' : ''"
                    v-text="
                      (statusOptions.find((item) => item.id === sitem.status) || {})
                        .label || '--'
                    "
                  ></el-tag>
                </template>
                <template slot="order_type">
                  <el-tag
                    :size="'mini'"
                    v-text="
                      (
                        cg_order_type_options.find(
                          (item) => item.id === sitem.order_type
                        ) || {}
                      ).label || '--'
                    "
                  ></el-tag>
                </template>
                <template slot="diff_is_act">
                  <el-tag
                    :size="'mini'"
                    v-text="
                      (
                        is_act_options.find((item) => item.value === sitem.diff_is_act) ||
                        {}
                      ).label || '--'
                    "
                  ></el-tag>
                </template>
                <template slot="diff_customer_remark">
                  <el-tag
                    :size="'mini'"
                    v-if="sitem.diff_is_act === '1'"
                    v-text="
                      (
                        customer_remark_options.find(
                          (item) => item.value === sitem.diff_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>
        </el-tab-pane>
        <el-tab-pane label="审批记录" name="2">
          <process-time-line
            v-if="newTime !== ''"
            :newTime="newTime"
            :type="'CGGCD'"
            :orderCode="queryId"
          />
        </el-tab-pane>

        <el-tab-pane label="流程图" name="3">
          <flow-chart process_id="9" type="CGGCD" :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/purchaseIn/purchaseDiffOrder";
import ShowDataTableColumns from "./ShowDataTableColumns";
import { cg_order_type_options } from "@/assets/js/statusList";
export default {
  name: "purchaseDiffOrderDetail",
  mixins: [mixinPage, resToken],
  components: {},
  computed: {
    powers() {
      const tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "purchaseDiffOrderDetail"
        ) || {};
      const { action } = tran ?? {};
      return action ?? [];
    },
  },
  data() {
    return {
      customer_remark_options: [
        {
          value: "1",
          label: "竞价订单减工差",
        },
        {
          value: "2",
          label: "竞价订单不减工差",
        },
      ],
      is_act_options: [
        {
          value: "1",
          label: "接受工差",
        },
        {
          value: "2",
          label: "不接受工差-退回重做",
        },
      ],
      activeTabs: "1",
      ShowDataTableColumns: ShowDataTableColumns,
      statusOptions: [
        { id: "1", label: "待业务部门审核" },
        { id: "2", label: "工差单审核完成" },
      ],
      cg_order_type_options,
      finishStatus: "finish",
      activeNames: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
      sitem: null,
      status: "",
      newTime: "",
      loading: false,
      queryId: "",
      orderCode: "", //审批记录的code
      order_type: "", //用于判断订单是备库单还是竞价单
      type: "", //审批记录
    };
  },
  mounted() {
    this.queryId = this.$route.query.id;
    this.initData();
  },
  methods: {
    async statusConfirm(status, message, remark) {
      await this.$confirm(`确定要${message}？`, {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          if (status === "-1") {
            await this.delete(message);
          } else {
            console.log(status, message, remark);
            await this.setstatus(status, message, remark);
          }
        })
        .catch(() => {
          console.log("取消");
        });
    },
    async setstatus(status, message, remark = "") {
      let _model = {
        id: this.queryId,
        status: status,
      };
      let res = await asyncRequest.status(_model);
      if (res && res.code === 0) {
        this.$notify.success({
          title: "修改成功！",
          message: "",
        });
        await this.initData();
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message);
      }
    },

    getNewTime() {
      this.newTime = new Date().valueOf();
    },

    async examForm(e) {
      if (!this.loading) {
        let type = e.state === "1" ? "2" : "0";
        await this.setStatus(type, "提交入库方审核", e.remark);
      }
    },
    async initData() {
      this.loading = true;
      const res = await asyncRequest.detail({ id: this.queryId });
      if (res && res.code === 0 && res.data) {
        this.sitem = res.data;

        const { can, status, cgdNo } = this.sitem;
        this.status = status;
        this.orderCode = cgdNo;
        if (can && can.length > 0) {
          this.sitem.class_cat = "";
          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);
      }
      this.loading = false;
    },
  },
};
</script>
<style lang="scss" scoped></style>
