<template>
  <div class="orderDetail">
    <BaseDialog
      width="1200px"
      :isShow.sync="isShow"
      title="订单详情"
      @close="close"
      :isShowFooter="false"
    >
      <div class="head">
        订单号：<span>{{ detailInfo.orderSn }}</span> 退款状态：<span>{{
          refundStatus(detailInfo.refundStatus)
        }}</span>
        <i v-if="orderFrom === 3" style="font-style: normal"
          >审核状态：<span>{{ checkStatus(detailInfo.checkStatus) }}</span></i
        >
        <i
          v-if="ShowStatus && detailInfo.checkStatus === 0"
          style="float: right"
        >
          <el-button
            type="success"
            size="small"
            @click="success"
            :disabled="orderFrom !== 3"
            >订单审核通过</el-button
          >
          <el-button
            type="danger"
            size="small"
            @click="error"
            :disabled="orderFrom !== 3"
            >订单审核不通过</el-button
          >
        </i>
      </div>
      <div class="mian">
        <el-descriptions class="margin-top" :column="3" border>
          <el-descriptions-item
            :label="desc.label"
            v-for="(desc, index) in descList"
            :key="index"
          >
            <div v-if="desc.type">
              <el-link
                :underline="false"
                :disabled="detailInfo['link'] ? false : true"
                v-if="desc.type === 'dowm'"
                :href="detailInfo['link']"
                target="_blank"
                >资料下载</el-link
              >
              <el-image
                v-if="desc.type === 'image'"
                style="width: 40px; height: 20px"
                :src="detailInfo[desc.key][0]"
                :preview-src-list="detailInfo[desc.key]"
              >
              </el-image>
              <div v-if="desc.type === 'pretax'">
                <span style="margin-right: 20px"
                  >税前佣金：{{
                    detailInfo["pretaxBrokerage"] ||
                    detailInfo["pretaxBrokerage"] == 0
                      ? detailInfo["pretaxBrokerage"].toFixed(2)
                      : detailInfo["pretaxBrokerage"]
                  }}</span
                ><span>税占比：{{ detailInfo["pretaxStr"] }}</span>
              </div>
              <div v-if="desc.type === 'time'">
                {{ $methodsTools.onlyForma(detailInfo[desc.key]) }}
              </div>
              <div v-if="desc.type === 'options'">
                <template v-for="(i, k) in desc.options">
                  <span v-if="i.value === detailInfo[desc.key]">
                    {{ i.label }}
                  </span>
                </template>
              </div>
              <div v-if="desc.type === 'money'">
                {{
                  detailInfo[desc.key] || detailInfo[desc.key] === 0
                    ? detailInfo[desc.key].toFixed(2)
                    : detailInfo[desc.key]
                }}
                <span
                  v-if="desc.key === 'orderProfit'"
                  :style="{
                    color: detailInfo[desc.key] > 0 ? '#409eff' : '#f56c6c',
                  }"
                  >【{{ detailInfo[desc.key] > 0 ? "盈" : "亏" }}】</span
                >
                <span
                  v-if="desc.key === 'orderUncollected'"
                  :style="{
                    color: detailInfo[desc.key] > 0 ? '#f56c6c' : '#409eff',
                  }"
                  >（{{
                    detailInfo[desc.key] > 0 ? "未结清" : "已结清"
                  }}）</span
                >
              </div>
            </div>
            <div v-else>
              {{ detailInfo[desc.key] }}
            </div>
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <student-details
        v-if="isShow"
        :orderSn="orderSn"
        :orderFrom="orderFrom"
        :ShowStatus="ShowStatus"
        :checkStatus="detailInfo.checkStatus"
      ></student-details>
    </BaseDialog>
  </div>
</template>

<script>
import studentDetails from "./studentDetails.vue";
export default {
  name: "dislogOrderDetails",
  props: {
    dialogVisible: {
      type: Boolean,
      default: false,
    },
    orderSn: {
      type: String,
    },
    orderFrom: {
      type: Number,
    },
    ShowStatus: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      descList: [
        { label: "机构名称", key: "tenantName" },
        { label: "业务员", key: "createUsername" },
        { label: "业务号", key: "createNo" },
        { label: "业务分类", key: "schemeName" },
        { label: "订单来源", key: "orderOrg" },
        { label: "申请时间", key: "buyTime", type: "time" },
        { label: "盈亏(元)", key: "orderProfit", type: "money" },
        { label: "成本(元)", key: "orderCost", type: "money" },
        { label: "合同金额(元)", key: "orderPrice", type: "money" },
        { label: "已收账款(元)", key: "orderReceived", type: "money" },
        { label: "申请退款", key: "orderRefund", type: "money" },
        { label: "已退账款(元)", key: "orderRefunded", type: "money" },
        { label: "未收账款(元)", key: "orderUncollected", type: "money" },
        { label: "实际账款(元)", key: "orderPractical", type: "money" },
        { label: "下单企业", key: "tenantName" },
        { label: "转账开户名", key: "openingName" },
        { label: "转账凭证", key: "attachmentList", type: "image" },
        {
          label: "发票状态",
          key: "invoiceStatus",
          type: "options",
          options: [
            {
              label: "未开票",
              value: 0,
            },
            {
              label: "已开票",
              value: 1,
            },
          ],
        },
        { label: "备注", key: "remark" },
        { label: "附件", type: "dowm" },
        { label: "佣金", key: "pretax", type: "pretax" },
      ],
      detailInfo: {
        attachmentList: [],
      },
    };
  },

  mounted() {},

  methods: {
    //退款状态
    refundStatus(i) {
      var str = "";
      switch (i) {
        case 0:
          str = "待审核";
          break;
        case 1:
          str = "正常";
          break;
        case 2:
          str = "未退款";
          break;
        case 3:
          str = "已完成";
          break;
        case 4:
          str = "未通过";
          break;
        case 5:
          str = "支付中";
          break;
        case 6:
          str = "支付失败";
          break;
        default:
          break;
      }
      return str;
    },
    //审核状态
    checkStatus(i) {
      var str = "";
      switch (i) {
        case 0:
          str = "待审核";
          break;
        case 1:
          str = "已通过";
          break;
        case 2:
          str = "未通过";
          break;
        case 3:
          str = "已撤销";
          break;
        default:
          break;
      }
      return str;
    },
    init() {
      this.getOrderDetail();
    },
    getOrderDetail() {
      this.$api.systemtoporderid(this.orderSn).then((res) => {
        if (res.data.attachmentList?.length > 0) {
          let a1 = [];
          for (let i = 0; i < res.data.attachmentList.length; i++) {
            if (res.data.attachmentList[i].attachmentType === 1) {
              a1.push(res.data.attachmentList[i].attachmentUrl);
            }
            if (res.data.attachmentList[i].attachmentType === 2) {
              res.data.link = res.data.attachmentList[i].attachmentUrl;
            }
          }
          res.data.attachmentList = a1;
        } else {
          res.data.attachmentList = [];
        }
        console.log(res.data);
        this.detailInfo = res.data;
      });
    },
    close() {},
    submit() {},
    submitForm() {
      this.isShow = false;
      this.$emit("search");
    },
    success() {
      this.$confirm("确定审核通过吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$api
            .systemtopordercheck({
              checkStatus: 1,
              orderSn: this.orderSn,
            })
            .then((res) => {
              this.$message.success("操作成功");
              this.submitForm();
            });
        })
        .catch(() => {});
    },
    error() {
      this.$prompt("确定审核不通过吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputPlaceholder: "输入不通过原因",
      })
        .then(({ value }) => {
          this.$api
            .systemtopordercheck({
              checkReason: value || "",
              checkStatus: 2,
              orderSn: this.orderSn,
            })
            .then((res) => {
              this.$message.success("操作成功");
              this.submitForm();
            });
        })
        .catch(() => {});
    },
  },
  computed: {
    isShow: {
      get() {
        if (this.dialogVisible) {
          this.init();
        }
        return this.dialogVisible;
      },
      set(val) {
        this.$emit("update:dialogVisible", false);
      },
    },
  },
  components: { studentDetails },
};
</script>

<style lang="scss" scoped>
.orderDetail {
  .head {
    margin-bottom: 20px;
    span {
      padding-right: 20px;
      color: #409eff;
    }
  }
}
</style>
