<!--  -->
<template>
  <div class="m-container">
    <h2>
      <div class="squrt"></div>
      订单审核
    </h2>
    <div class="m-core">
      <saveform
        ref="searchForm"
        :model.sync="searchForm"
        inline
        style="margin-top: 20px"
      >
        <el-form-item>
          <el-input
            v-model.trim="searchForm.transNo"
            @keyup.enter.native="transNo"
            clearable
            placeholder="交易流水号"
          ></el-input>
        </el-form-item>

        <el-form-item prop="organId">
          <el-select
            class="multiple"
            v-model.trim="searchForm.organId"
            filterable
            clearable
            placeholder="请选择分部"
          >
            <el-option
              v-for="(item, index) in selects.branchs"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            class="multiple"
            v-model.trim="searchForm.type"
            filterable
            clearable
            placeholder="请选择申请类型"
          >
            <el-option
              v-for="(item, index) in orderServerList"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            class="multiple"
            v-model.trim="searchForm.auditStatus"
            placeholder="请选择审核状态"
          >
            <el-option
              v-for="(item, index) in orderAuditTypeList"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="search" type="danger">搜索</el-button>
          <el-button @click="onReSet" type="primary">重置</el-button>
        </el-form-item>
      </saveform>
      <div class="tableWrap">
        <el-table
          style="width: 100%"
          :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
          :data="tableList"
        >
          <el-table-column align="center" prop="transNo" label="交易流水号">
            <template slot-scope="scope">
              <div>
                <copy-text>{{ scope.row.transNo }}</copy-text>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="organ.name"
            label="分部"
          >
 <template slot-scope="scope">
              <div>
                <copy-text>{{ scope.row.organ.name }}</copy-text>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="cooperationOrgan.name"
            label="学校名称"
          ></el-table-column>
          <el-table-column align="center" prop="serviceAmount" label="服务收入">
          </el-table-column>
          <el-table-column
            align="center"
            prop="saleAmount"
            label="销售收入"
          ></el-table-column>
          <!-- <el-table-column align="center"
                           prop="memo"
                           label="备注">
            <template slot-scope="scope">
              <Tooltip :content="scope.row.memo?scope.row.memo:''" />
            </template>
          </el-table-column> -->
          <el-table-column
            align="center"
            prop="operator.username"
            label="申请人"
          ></el-table-column>
          <el-table-column align="center" prop="auditStatus" label="状态">
            <template slot-scope="scope">
              <div>
                <p v-if="scope.row.auditStatus">
                  {{ scope.row.auditStatus | orderAuditType }}
                </p>
                <p v-else>{{ "审核通过" }}</p>
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="payTime" label="交易日期">
            <template slot-scope="scope">
              <div>
                {{ scope.row.payTime | dateForMinFormat }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="createTime" label="申请时间">
            <template slot-scope="scope">
              <div>
                {{ scope.row.createTime | dateForMinFormat }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="studentId" label="操作">
            <template slot-scope="scope">
              <div>
                <auth :auths="scope.row.auditStatus == 'ING' ? 'routeOrder/auditOutOrder/shenghe' : 'routeOrder/query/detail'">
                  <el-button
                    type="text"
                    @click="lookDetail(scope.row)"
                    >{{ scope.row.auditStatus == 'ING' ? '审核' : '查看' }}</el-button>
                </auth>
                <auth auths="routeOrder/update" v-if="scope.row.auditStatus == 'REJECT'">
                  <el-button
                    type="text"
                    @click="resetDetail(scope.row)"
                    >修改</el-button>
                </auth>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          sync
          :total.sync="rules.total"
          :page.sync="rules.page"
          :limit.sync="rules.limit"
          :page-sizes="rules.page_size"
          @pagination="getList"
        />
      </div>
    </div>
    <el-dialog title="审核详情" :visible.sync="orderVisible" width="600px">
      <orderAuditDetail
        :orderId="activceId"
        :shopList="shopList"
        :organList="organList"
        :isLook="isLook"
        ref="orderAuditDetail"
        v-if="orderVisible"
        @getList="getList"
      />
      <span slot="footer" class="dialog-footer">
        <el-button
          v-if="activeRow && activeRow.auditStatus == 'ING'"
          v-permission="'routeOrder/auditOutOrder/REJECT'"
          @click="submit('REJECT')"
          >驳回</el-button
        >
        <el-button
          v-if="activeRow && activeRow.auditStatus == 'ING'"
          v-permission="'routeOrder/auditOutOrder/PASS'"
          @click="submit('PASS')"
          type="primary"
          >审核通过</el-button
        >
        <el-button
          @click="orderVisible = false"
          v-if="activeRow && activeRow.auditStatus == 'REJECT' && !isLook"
          >取 消</el-button
        >
        <el-button
          v-if="activeRow && activeRow.auditStatus == 'REJECT' && !isLook"
          v-permission="'routeOrder/update'"
          @click="submitReaet"
          type="primary"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
// import axios from "axios";
// import { getToken } from "@/utils/auth";
import pagination from "@/components/Pagination/index";
// import load from "@/utils/loading";
// import { getEmployeeOrgan, getAddress, getCooperation } from "@/api/buildTeam";
import { orderServerList, orderAuditTypeList } from "@/utils/searchArray";
import orderAuditDetail from "./orderAuditDetail";
import { getRouteOrderList } from "@/api/orderManager";
import { goodsQuery } from "@/api/businessManager";
// import { formatData } from "@/utils/utils";
import Tooltip from "@/components/Tooltip/index";
import saveform from "@/components/save-form";
export default {
  components: { pagination, orderAuditDetail, Tooltip, saveform },
  data() {
    return {
      searchForm: {
        transNo: null,
        organId: null,
        auditStatus: "ING",
        type: null,
      },
      tableList: [],
      organList: [],
      orderServerList,
      orderAuditTypeList,
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
      orderVisible: false,
      activceId: null,
      activeRow: null,
      isLook: null,
    };
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    // getEmployeeOrgan().then((res) => {
    //   if (res.code == 200) {
    //     this.organList = res.data;
    //   }
    // });
    // 获取分部
     this.$store.dispatch("setBranchs");
    goodsQuery({ rows: 99999 }).then((res) => {
      if (res.code === 200) {
        this.shopList = res.data.rows;
      }
    });

    this.init();
  },
  activated() {
    this.init();
  },
  methods: {
    init() {
      this.getList();
    },
    search() {
      this.$refs.searchForm.save(this.searchForm);
      this.rules.page = 1;
      this.getList();
    },
    onReSet() {
      this.searchForm = {
        transNo: null,
        organId: null,
        auditStatus: "ING",
        type: null,
      };
      this.search();
    },
    getList() {
      let params = this.searchForm;
      params.rows = this.rules.limit;
      params.page = this.rules.page;
      params.noneTqType = 1
      getRouteOrderList(params).then((res) => {
        if (res.code == 200) {
          this.tableList = res.data.rows;
          this.rules.total = res.data.total;
          this.orderVisible = false;
        }
      });
    },
    lookDetail(row) {
      this.activceId = row.id;
      this.activeRow = row;
      this.isLook = true;
      this.orderVisible = true;
    },
    resetDetail(row) {
      this.activceId = row.id;
      this.activeRow = row;
      this.isLook = false;
      this.orderVisible = true;
    },
    submit(str) {
      let message;
      str == "REJECT" ? (message = "驳回") : (message = "同意");
      this.$confirm(`是否${message}审核`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$refs.orderAuditDetail.auditOutOrder(str);
        })
        .catch(() => {});
    },
    submitReaet() {
      this.$confirm(`是否提交修改`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$refs.orderAuditDetail.submitReaet();
        })
        .catch(() => {});
    },
  },
};
</script>
<style lang='scss' scoped>
</style>
