<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单号" prop="orderNo">
        <el-input v-model="queryParams.orderNo" placeholder="请输入订单号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="服务名称" prop="goodsTitle">
        <el-input v-model="queryParams.goodsTitle" placeholder="请输入服务名称" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="支付方式" prop="payType">
        <el-select v-model="queryParams.payType" placeholder="请选择支付方式" clearable size="small">
          <el-option label="请选择字典生成" value=""/>
        </el-select>
      </el-form-item>
      <el-form-item label="订单状态" prop="orderStatus">
        <el-select v-model="queryParams.orderStatus" placeholder="请选择订单状态" clearable size="small">
          <el-option label="请选择字典生成" value=""/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"/>
    </el-row>

    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="订单号" align="center" prop="orderNo"/>
      <el-table-column label="服务名称" align="center" prop="goodsTitle"/>
      <el-table-column label="消费类型" align="center" prop="goodsType"/>
      <el-table-column label="客户姓名" align="center" prop="cusName"/>
      <el-table-column label="客户手机号" align="center" prop="cusPhone"/>
      <el-table-column label="商品原价（元）" align="center" prop="goodsPrice"/>
      <el-table-column label="实付金额（元）" align="center" prop="payMoney"/>
      <el-table-column label="下单时间" align="center" prop="orderTime" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.orderTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员优惠金额" align="center" prop="reduceMoney"/>
      <el-table-column label="使用会员储值卡的金额" align="center" prop="balance"/>
      <el-table-column label="支付时间" align="center" prop="payTime" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.payTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付方式" align="center" prop="payType"/>
      <el-table-column label="支付信息备注" align="center" prop="payRemark"/>
      <el-table-column label="线上或者线下" align="center" prop="isOnline"/>
      <el-table-column label="收款账号" align="center" prop="receivablesAccount"/>
      <el-table-column label="订单状态" align="center" prop="orderStatus"/>
      <el-table-column label="评价详情" align="center" prop="commentDesc"/>
      <el-table-column label="星级" align="center" prop="commentStar"/>
      <el-table-column label="评论时间" align="center" prop="commentTime" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.commentTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="核销码" align="center" prop="accessCode"/>
      <el-table-column label="核销时间" align="center" prop="validationTime" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.validationTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="核销人" align="center" prop="validationRealName"/>
      <el-table-column label="是否使用优惠券" align="center" prop="isCoupon"/>
      <el-table-column label="优惠券代码" align="center" prop="couponCode"/>
      <el-table-column label="优惠金额" align="center" prop="couponDiscount"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template v-slot="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="toPay(scope.row.id)"
                     v-hasPermi="['repair:order-info:update']">支付
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)"
                     v-hasPermi="['repair:order-info:update']">修改
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['repair:order-info:delete']">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 展示形式：二维码 URL -->
    <el-dialog title="微信扫一扫" :visible.sync="qrCode.visible" width="700px" append-to-body
               :close-on-press-escape="false">
      <qrcode-vue :value="qrCode.url" size="500" level="L" />
    </el-dialog>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>
    <!-- 对话框(添加 / 修改) -->
    <OrderInfoForm ref="formRef" @success="getList"/>
  </div>
</template>

<script>
import * as OrderInfoApi from '@/api/repair/orderinfo';
import OrderInfoForm from './OrderInfoForm.vue';
import QrcodeVue from 'qrcode.vue'
export default {
  name: "OrderInfo",
  components: {
    OrderInfoForm,
    QrcodeVue
  },
  data() {
    return {
      qrCode: { // 展示形式：二维码
        url: '',
        title: '',
        visible: false,
      },
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 维修模块 订单列表
      list: [],
      // 是否展开，默认全部展开
      isExpandAll: true,
      // 重新渲染表格状态
      refreshTable: true,
      // 选中行
      currentRow: {},
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        orderNo: null,
        goodsTitle: null,
        goodsType: null,
        userId: null,
        cusId: null,
        cusName: null,
        cusPhone: null,
        goodsPrice: null,
        payMoney: null,
        orderTime: [],
        reduceMoney: null,
        balance: null,
        payTime: [],
        payType: null,
        payRemark: null,
        isOnline: null,
        receivablesAccount: null,
        orderStatus: null,
        commentDesc: null,
        commentStar: null,
        commentTime: [],
        accessCode: null,
        validationTime: [],
        validationRealName: null,
        validationUserId: null,
        isCoupon: null,
        couponId: null,
        couponCode: null,
        couponDiscount: null,
        deptId: null,
        createTime: [],
        goodsId: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    async getList() {
      try {
        this.loading = true;
        const res = await OrderInfoApi.getOrderInfoPage(this.queryParams);
        this.list = res.data.records;
        this.total = res.data.total;
      } finally {
        this.loading = false;
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    async toPay(orderId){
      let data = {
        orderId:orderId
      }
      const res = await OrderInfoApi.toPay(data);
      console.log(res,208)
      this.qrCode = {
        url: res.data.code_url,
        visible: true
      }
    },
    /** 添加/修改操作 */
    openForm(id) {
      this.$refs["formRef"].open(id);
    },
    /** 删除按钮操作 */
    async handleDelete(row) {
      const id = row.id;
      await this.$modal.confirm('是否确认删除维修模块 订单编号为"' + id + '"的数据项?')
      try {
        await OrderInfoApi.deleteOrderInfo(id);
        await this.getList();
        this.$modal.msgSuccess("删除成功");
      } catch {
      }
    },
    /** 导出按钮操作 */
    async handleExport() {
      await this.$modal.confirm('是否确认导出所有维修模块 订单数据项?');
      try {
        this.exportLoading = true;
        const data = await OrderInfoApi.exportOrderInfoExcel(this.queryParams);
        this.$download.excel(data, '维修模块 订单.xls');
      } catch {
      } finally {
        this.exportLoading = false;
      }
    },
  }
};
</script>
