<template>
  <div id="orderList">
    <search-box :formList="formList" @search="search" @init="init" />
    <table-list
      :tableSets="tableSet"
      :tableData="tableData"
      :navText="navText"
      @addClick="addClick"
      :loading="loading"
    >
      <template slot="btn" slot-scope="props">
        <el-button type="text" @click="addClick(props.scope.row)"
          >详情订单</el-button
        >
      </template>
    </table-list>
    <pagination
      :total="total"
      :pageSize="pageSize"
      :currentPage="currentPage"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    />
    <el-dialog
      :visible.sync="dialogBox"
      width="920px"
      :show-close="false"
      :destroy-on-close="true"
      :before-close="closeBefore"
      :fullscreen="fullscreen"
    >
      <div slot="title" class="hearders">
        <div class="leftTitle">详情</div>
        <div class="rightBoxs">
          <img
            src="@/assets/images/Max@2x.png"
            alt=""
            @click="fullscreen = !fullscreen"
          />
          <img src="@/assets/images/Close@2x.png" alt="" @click="closeBefore" />
        </div>
      </div>
      <el-row class="contentBox" :span="24">
        <el-steps
          :active="
            poppleData.orderStatus === -2
              ? 1
              : poppleData.orderStatus === -1
              ? 1
              : poppleData.orderStatus === 0
              ? 1
              : poppleData.orderStatus === 1
              ? 2
              : poppleData.orderStatus === 3
              ? 2
              : 1
          "
          style="width: 480px; margin: 0px auto"
          align-center
        >
          <el-step
            title="确定订单"
            :description="$methodsTools.onlyForma(poppleData.createTime)"
          ></el-step>
          <el-step
            title="支付订单"
            :description="
              poppleData.payTime === null
                ? '未支付'
                : $methodsTools.onlyForma(poppleData.payTime)
            "
          ></el-step>
        </el-steps>
        <div class="statusBox" style="padding-left: 20px">
          当前订单状态：
          {{
            poppleData.orderStatus === -2
              ? "超时关闭"
              : poppleData.orderStatus === -1
              ? "手动关闭"
              : poppleData.orderStatus === 0
              ? "待付款"
              : poppleData.orderStatus === 1
              ? "已付款"
              : poppleData.orderStatus === 3
              ? "订单完成"
              : "未知"
          }}
        </div>
        <div style="margin-bottom: 10px">
          <header style="margin-bottom: 10px">基本信息</header>
          <el-table :data="tableData1" border>
            <el-table-column
              v-for="(item, index) in tableSet1"
              :key="index"
              align="center"
              header-align="center"
              :label="item.label"
            >
              <template slot-scope="scope">
                <span v-if="item.scope === 'typeStatus'">{{
                  scope.row[item.prop] === 1
                    ? "微信"
                    : scope.row[item.prop] === 2
                    ? "支付宝"
                    : scope.row[item.prop] === 3
                    ? "金币"
                    : "未知"
                }}</span>
                <span v-else-if="item.scope === 'activeInfo'">
                  {{ tableData1[0].orderInfos }}
                </span>
                <span v-else>{{ scope.row[item.prop] }}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- <div style="margin-bottom: 10px;">
          <header style="margin-bottom: 10px;">发票信息</header>
          <el-table :data="tableData2" border>
            <template slot-scope="scope">
              <el-table-column
                v-for="(item, index) in tableSet2"
                :key="index"
                align="center"
                header-align="center"
                :label="item.label"
              >
              <span v-if="item.scope === 'asd'">123</span>
              <span v-else>123123</span>
              </el-table-column>
            </template>
          </el-table>
        </div> -->
        <div style="margin-bottom: 10px">
          <header style="margin-bottom: 10px">费用信息</header>
          <table
            style="width: 100%; border-color: #f2f6fc"
            border="1"
            cellpadding="0"
            cellspacing="0"
          >
            <tr class="trs">
              <th>商品图片</th>
              <th>商品名称</th>
              <th>价格</th>
              <th>属性</th>
              <th>数量</th>
              <th>小计</th>
            </tr>
            <tr class="trs" v-for="(items, indexs) in tableData3" :key="indexs">
              <td style="width: 160px; heigth: 90px">
                <img
                  style="width: 100%; heigth: 100%"
                  :src="$methodsTools.splitImgHost(items.coverUrl)"
                  alt="加载失败..."
                />
              </td>
              <td>{{ items.goodsName }}</td>
              <td>￥{{ items.goodsPrice }}</td>
              <td>类型：{{ items.categoryName }}</td>
              <td>{{ items.num }}</td>
              <td>￥{{ items.goodsPrice }}</td>
            </tr>
            <tr class="yh">
              <td style="text-align: right" colspan="5">优惠</td>
              <td style="text-align: center">
                ￥{{
                  Number(poppleData.payPrice) - Number(poppleData.orderPrice)
                }}
              </td>
            </tr>
            <tr class="yh" style="background-color: rgb(249, 250, 252)">
              <td style="text-align: right" colspan="6">
                合计：<span style="font-weight: bold; color: red"
                  >￥{{ poppleData.payPrice }}</span
                >
              </td>
            </tr>
          </table>
        </div>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeBefore">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import searchBox from "@/components/searchBox";
import tableList from "@/components/tableList";
import pagination from "@/components/pagination";
export default {
  components: { searchBox, tableList, pagination },
  data() {
    return {
      loading: false, //当前表单加载是否加载动画
      navText: {
        title: "订单列表",
        index: 0,
        ch: "条",
        num: true,
        choice: true,
        addHide: true,
        backFatherBtn: {
          status: false,
          title: "未定义",
        },
      },
      poppleData: {},
      statusPop: 0,
      fullscreen: false,
      dialogBox: false,
      //搜索
      formList: [
        {
          label: "订单编号",
          prop: "oderSn",
          placeholder: "请输入订单编号",
        },
        {
          label: "订单状态",
          prop: "orderStatus",
          placeholder: "请选择订单状态",
          scope: "select",
          options: [
            {
              label: "超时关闭",
              value: -2,
            },
            {
              label: "手动关闭",
              value: -1,
            },
            {
              label: "待付款",
              value: 0,
            },
            {
              label: "已付款",
              value: 1,
            },
          ],
        },
        {
          label: "确定时间",
          prop: "finishTime",
          scope: "datePicker",
        },
        {
          label: "姓名",
          prop: "nickname",
          placeholder: "请输入姓名",
        },
        {
          label: "手机号",
          prop: "telphone",
          placeholder: "请输入手机号",
        },
        {
          label: "订单金额",
          prop: "payType",
          placeholder: "请输入订单金额",
        },
      ],
      // 表单
      tableSet: [
        {
          label: "确定时间",
          prop: "finishTime",
          hidden: true,
          scope: "aTimeList",
        },
        {
          label: "姓名",
          prop: "nickname",
          hidden: true,
        },
        {
          label: "用户手机号",
          prop: "telphone",
          hidden: true,
        },
        {
          label: "订单金额",
          prop: "orderPrice",
          hidden: true,
        },
        {
          label: "订单状态",
          prop: "orderStatus",
          hidden: true,
          scope: "statusOrder",
        },
      ],
      //基本信息表格
      tableSet1: [
        {
          label: "订单编号",
          prop: "oderSn",
        },
        {
          label: "用户账号",
          prop: "telphone",
        },
        {
          label: "支付方式",
          prop: "payType",
          scope: "typeStatus",
        },
        {
          label: "活动信息",
          prop: "orderInfos",
          scope: "activeInfo",
        },
      ],
      //发票信息
      tableSet2: [
        {
          label: "发票类型",
          prop: "finishTime",
        },
        {
          label: "发票抬头",
          prop: "telphone",
        },
        {
          label: "发票内容",
          prop: "orderPrice",
        },
        {
          label: "收票人信息",
          prop: "orderStatus",
        },
      ],
      //费用信息
      tableSet3: [
        // {
        //   label: "商品图片",
        //   prop: "finishTime",
        // },
        {
          label: "商品名称",
          prop: "goodsName",
        },
        {
          label: "价格",
          prop: "goodsPrice",
        },
        {
          label: "属性",
          prop: "categoryName",
          scope: "type",
        },
        {
          label: "数量",
          prop: "num",
        },
        {
          label: "小计",
          prop: "goodsPrice",
        },
      ],
      tableData: [], //表单数据
      tableData1: [],
      tableData2: [],
      tableData3: [],
      total: 0, //一共多少条
      pageSize: 10, //每页多少条数据
      currentPage: 1, //当前页码
    };
  },
  mounted() {
    this.search();
  },
  methods: {
    rulesTableSumbit() {},
    closeBefore() {
      this.dialogBox = false;
      this.fullscreen = false;
      this.poppleData = {};
    },
    search(v) {
      this.loading = true;
      if (v === undefined) {
        v = {
          pageSize: this.pageSize,
          pageNum: this.currentPage,
        };
      }
      var data = {
        oderSn: v.oderSn,
        orderStatus: v.orderStatus || "",
        startTime: v.finishTime ? (v.finishTime[0] / 1000).toFixed(0) : "",
        endTime: v.finishTime ? (v.finishTime[1] / 1000).toFixed(0) : "",
        pageSize: this.pageSize,
        pageNum: this.currentPage,
      };
      this.$api.inquireorderlistAll(data).then((res) => {
        this.tableData = res.rows;
        this.total = res.total;
        this.navText.index = res.total;
      });
      this.loading = false;
    },
    init() {
      this.search();
    },
    async addClick(v) {
      console.log(v);
      var self = this;
      this.poppleData = v;
      var tableDatalist = [];
      tableDatalist.push(v);
      const awizti = await this.$api.ordercouponlist({ orderSn: v.oderSn });
      if (awizti.data.length) {
        console.log(123);
        var ins = awizti.data[0].couponType === 0 ? "元" : "折";
        tableDatalist[0].orderInfos =
          awizti.data[0].activityName + awizti.data[0].price + ins;
        this.tableData1 = tableDatalist;
      } else {
        this.tableData1 = tableDatalist;
      }
      this.$api.ordergoodslist({ orderSn: v.oderSn }).then((res) => {
        if (res.code === 200) {
          this.tableData3 = res.data;
        }
      });
      this.dialogBox = true;
    },
    handleSizeChange(v) {
      this.pageSize = v;
      this.currentPage = 1;
      this.search();
    },
    handleCurrentChange(v) {
      this.currentPage = v;
      this.search();
    },
  },
};
</script>

<style lang="less" scoped>
.trs {
  height: 40px;
  td {
    text-align: center;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    max-width: 150px;
    padding: 6px;
  }
  th {
    background-color: rgb(249, 250, 252);
  }
}
.yh {
  height: 40px;
  td {
    padding: 0px 6px;
  }
}
.statusBox {
  height: 60px;
  line-height: 60px;
  color: red;
  background-color: #eee;
  margin: 20px 0px;
}
/deep/.el-button {
  border-radius: 8px;
}
/deep/.el-dialog {
  border-radius: 8px;
  .el-dialog__header {
    padding: 0;
    .hearders {
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0px 18px 0px 20px;
      border-bottom: 1px solid #e2e2e2;
      .leftTitle {
        font-size: 14px;
        font-weight: bold;
        color: #2f4378;
      }
      .rightBoxs {
        display: flex;
        align-items: center;
        img {
          width: 14px;
          height: 14px;
          margin-left: 13px;
          cursor: pointer;
        }
      }
    }
  }
  .el-dialog__body {
    padding: 0;
    .contentBox {
      padding: 20px 20px 5px;
      .el-col {
        padding: 0px 20px;
        margin-bottom: 30px;
        header {
          margin-bottom: 6px;
          color: #2f4378;
          font-size: 14px;
        }
      }
    }
  }
  .el-dialog__footer {
    padding: 0;
    .dialog-footer {
      padding: 0px 40px;
      height: 70px;
      border-top: 1px solid #e2e2e2;
      display: flex;
      align-items: center;
      justify-content: flex-end;
    }
  }
}
.imgBox {
  width: 100%;
  // height: 210px;
  border: 1px solid #e2e2e2;
  border-radius: 8px;
  padding: 8px 8px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  .imgLabel {
    flex: 1;
    width: 100%;
    border: 1px dotted #e2e2e2;
    color: #999;
    font-size: 14px;
    cursor: pointer;
    border-radius: 8px;
    .msPhoto {
      display: flex;
      justify-content: center;
      align-items: center;
      max-width: 100%;
      max-height: 270px;
      img {
        max-width: 100%;
        max-height: 270px;
      }
    }
    .imgbbx {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 100%;
      i {
        font-weight: bold;
        margin: 14px 0;
        font-size: 24px;
      }
    }
  }
  p {
    margin: 5px 0px;
  }
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>

