<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <!-- <el-form-item label="护理站id" prop="nurseStationId">
          <el-input
            v-model="queryParams.nurseStationId"
            placeholder="请输入护理站id"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="护理员表id" prop="nurseStationPersonId">
          <el-input
            v-model="queryParams.nurseStationPersonId"
            placeholder="请输入护理员表id"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item> -->
      <el-form-item label="护理员姓名" prop="nursePersonName">
        <el-input
          v-model="queryParams.nursePersonName"
          placeholder="请输入护理员姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单编号" prop="trainingOrderNo">
        <el-input
          v-model="queryParams.trainingOrderNo"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单金额" prop="trainingOrderAmount">
        <el-input
          v-model="queryParams.trainingOrderAmount"
          placeholder="请输入订单金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="下单方式，手机App：MOBILE_APP，微信小程序：WECHAT_APPLET，支付宝小程序：ALI_PAY_APPLET" prop="trainingOrderChannel">
          <el-input
            v-model="queryParams.trainingOrderChannel"
            placeholder="请输入下单方式，手机App：MOBILE_APP，微信小程序：WECHAT_APPLET，支付宝小程序：ALI_PAY_APPLET"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item> -->
      <!-- <el-form-item label="下单时间，yyyy-MM-dd HH:mm:ss" prop="trainingOrderTime">
          <el-date-picker clearable
            v-model="queryParams.trainingOrderTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择下单时间，yyyy-MM-dd HH:mm:ss">
          </el-date-picker>
        </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:trainingOrder:add']"
          >新增</el-button
        >
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:trainingOrder:edit']"
          >修改</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:trainingOrder:remove']"
          >删除</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:trainingOrder:export']"
          >导出</el-button
        >
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="trainingOrderList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="主键id" align="center" prop="id" />
        <el-table-column label="护理站id" align="center" prop="nurseStationId" />
        <el-table-column label="护理员表id" align="center" prop="nurseStationPersonId" /> -->
      <el-table-column
        label="护理员姓名"
        align="center"
        prop="nursePersonName"
      />
      <el-table-column label="订单编号" align="center" prop="trainingOrderNo" />
      <el-table-column
        label="订单状态"
        align="center"
        prop="trainingOrderStatus"
      >
        <template slot-scope="scope">
          <el-button v-if="scope.row.trainingOrderStatus == 'WAIT_PAY'"
            >待付款</el-button
          >
          <el-button
            type="primary"
            v-if="scope.row.trainingOrderStatus == 'PAY'"
            >已付款</el-button
          >
          <el-button
            type="warning"
            v-if="scope.row.trainingOrderStatus == 'WAIT_REFUND'"
            >退款中</el-button
          >
        
          <el-button
            type="danger"
            v-if="scope.row.trainingOrderStatus == 'CANCEL'"
            >已取消</el-button
          >
          <el-button
            type="success"
            v-if="scope.row.trainingOrderStatus == 'REFUNDED'"
            >已退款</el-button
          >
          <!-- {{ scope.row.trainingOrderStatus == "WAIT_PAY" ? "待付款" : "" }}
            {{ scope.row.trainingOrderStatus == "PAY" ? "已付款" : "" }}
            {{ scope.row.trainingOrderStatus == "WAIT_REFUND" ? "退款中" : "" }}
            {{ scope.row.trainingOrderStatus == "REFUNDED" ? "已退款" : "" }}
            {{ scope.row.trainingOrderStatus == "CANCEL" ? "已取消" : "" }} -->
        </template>
      </el-table-column>

      <el-table-column
        label="订单金额"
        align="center"
        prop="trainingOrderAmount"
      />
      <el-table-column
        label="下单方式"
        align="center"
        prop="trainingOrderChannel"
      >
        <template slot-scope="scope">
          {{ scope.row.trainingOrderChannel == "MOBILE_APP" ? "手机App" : "" }}
          {{
            scope.row.trainingOrderChannel == "WECHAT_APPLET"
              ? "微信小程序"
              : ""
          }}
          {{
            scope.row.trainingOrderChannel == "ALI_PAY_APPLET"
              ? "支付宝小程序"
              : ""
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="下单时间"
        align="center"
        prop="trainingOrderTime"
        width="180"
      >
        <!-- <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.trainingOrderTime, "{y}-{m}-{d}")
          }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="备注信息" align="center" prop="remark" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-zoom-in"
            @click="handleUpdate(scope.row)"
            >查看</el-button
          >

          <el-button
            size="mini"
            type="text"
            icon="el-icon-error"
            @click="cencel(scope.row)"
            v-if="scope.row.trainingOrderStatus == 'PAY'"
            >退款</el-button
          >
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:trainingOrder:edit']"
            >修改</el-button
          > -->
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:trainingOrder:remove']"
            >删除</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 退款弹框 -->
    <el-dialog
      title="退款"
      :visible.sync="innerrefund"
      append-to-body
      width="500px"
    >
      <el-form :inline="true" :rules="rules" label-width="120px">
        <el-form-item label="订单编号" prop="trainingOrderNo">
          <el-input
            style="width: 260px"
            v-model="query.trainingOrderNo"
            clearable
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="护理站名称" prop="nurseStationName">
          <el-input
            style="width: 260px"
            v-model="query.nurseStationName"
            clearable
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="退款金额" prop="trainingOrderAmount">
          <el-input
            v-model="query.trainingOrderAmount"
            style="width: 260px"
            clearable
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="护理员姓名" prop="nursePersonName">
          <el-input
            v-model="query.nursePersonName"
            style="width: 260px"
            clearable
            :disabled="true"
          />
        </el-form-item>
        <!-- <el-form-item label="退款原因" prop="cancelAppointmentReason">
          <el-input
            style="width: 260px"
            v-model="query.cancelAppointmentReason"
            placeholder
            clearable
            type="textarea"
            :rows="5"
            disabled
          />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cencelbtn">取 消</el-button>
        <el-button type="primary" @click="ordercacenl">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改学习培训订单主对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="护理员姓名" prop="nursePersonName">
          <el-input
            v-model="form.nursePersonName"
            style="width: 250px"
            placeholder="请输入护理员姓名"
          />
        </el-form-item>
        <el-form-item label="订单编号" prop="trainingOrderNo">
          <el-input
            style="width: 250px"
            v-model="form.trainingOrderNo"
            placeholder="请输入订单编号"
          />
        </el-form-item>
        <el-form-item label="订单金额" prop="trainingOrderAmount">
          <el-input
            style="width: 250px"
            v-model="form.trainingOrderAmount"
            placeholder="请输入订单金额"
          />
        </el-form-item>
        <el-form-item label="下单方式" prop="trainingOrderChannel">
          <el-select
            style="width: 250px"
            v-model="form.trainingOrderChannel"
            placeholder="请选择下单方式"
            clearable
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="下单时间" prop="trainingOrderTime">
          <el-date-picker
            style="width: 250px"
            clearable
            v-model="form.trainingOrderTime"
            type="datetime"
            placeholder="请选择下单时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注信息" prop="remark">
          <el-input
            v-model="form.remark"
            style="width: 250px"
            placeholder="请输入备注信息"
          />
        </el-form-item>
        <!-- <el-form-item label="是否删除标识" prop="delFlag">
          <el-select
            style="width: 250px"
            v-model="form.trainingOrderChannel"
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="item in optiondeflag"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
          
        </el-form-item> -->
      </el-form>
      <!-- <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div> -->
    </el-dialog>
  </div>
</template>
  
  <script>
import {
  listTrainingOrder,
  getTrainingOrder,
  refundInformation,
  delTrainingOrder,
  trainingOrder,
  xylWeChatRefundNotify,
  addTrainingOrder,
  updateTrainingOrder,
} from "@/api/system/trainingOrder";

export default {
  name: "TrainingOrder",
  data() {
    return {
      // 遮罩层
      loading: true,
      innerrefund: false,
      query: {},

      // 选中数组
      ids: [],
      optiondeflag: [
        {
          value: 0,
          label: "否",
        },
        {
          value: 1,
          label: "是",
        },
      ],
      options: [
        {
          value: "MOBILE_APP",
          label: "手机App",
        },
        {
          value: "WECHAT_APPLET",
          label: "微信小程序",
        },
        {
          value: "ALI_PAY_APPLET",
          label: "支付宝小程序",
        },
      ],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学习培训订单主表格数据
      trainingOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nurseStationId: null,
        nurseStationPersonId: null,
        nursePersonName: null,
        trainingOrderNo: null,
        trainingOrderStatus: null,
        trainingOrderAmount: null,
        trainingOrderChannel: null,
        trainingOrderTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 取消按钮
    cencelbtn() {
      this.innerrefund = false;
    },
    // // 确认退款
    cencel(row) {
      console.log(row);
      refundInformation(row.id).then((response) => {
        this.query = response.data;
        this.innerrefund = true;
        this.title = "退款";
      });
    },
    //退款确定按钮
    ordercacenl() {
      var obj = {
        orderNo: this.query.trainingOrderNo,
        refundPrice: this.query.trainingOrderAmount,
        trainingOrderFlag: "TRAINING",
      };
      xylWeChatRefundNotify(obj).then((res) => {
        if (res.code == 200) {
          this.$modal.msgSuccess("退款有延迟，请耐心等待");
        }
        this.getList();
        this.innerrefund = false;
      });
    },
    /** 查询学习培训订单主列表 */
    getList() {
      this.loading = true;
      listTrainingOrder(this.queryParams).then((response) => {
        this.trainingOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    handlelook() {},
    // 表单重置
    reset() {
      this.form = {
        id: null,
        nurseStationId: null,
        nurseStationPersonId: null,
        nursePersonName: null,
        trainingOrderNo: null,
        trainingOrderStatus: null,
        trainingOrderAmount: null,
        trainingOrderChannel: null,
        trainingOrderTime: null,
        remark: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加学习培训订单主";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getTrainingOrder(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "查看学习培训订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateTrainingOrder(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTrainingOrder(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除学习培训订单主编号为"' + ids + '"的数据项？')
        .then(function () {
          return delTrainingOrder(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/trainingOrder/export",
        {
          ...this.queryParams,
        },
        `trainingOrder_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
  