<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="订单状态" prop="trainingOrderStatus">
        <el-select
          v-model="queryParams.trainingOrderStatus"
          placeholder="请选择订单状态"
          clearable
        >
          <el-option
            v-for="item in trainingOrderStatusoptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </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
        label="护理员姓名"
        align="center"
        prop="nursePersonName"
      />
      <el-table-column label="订单编号" align="center" prop="trainingOrderNo" />
      <el-table-column
        property="trainingItemTitle"
        label="培训课程名称"
        align="center"
      />
      <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
          >
        </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="trainingItemTitle">
          <el-input
            style="width: 260px"
            v-model="query.trainingItemTitle"
            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="1200px"
      append-to-body
    >
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="100px"
        :inline="true"
      >
        <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-table
          :data="form.trainingOrderDetailsList"
          align="center"
          style="margin: 10px 0 20px 0; padding-bottom: 20px"
        >
          <el-table-column
            prop="trainingItemTitle"
            label="培训项目名称"
            align="center"
          ></el-table-column>
          <el-table-column
            prop="trainingItemDetails"
            label="培训项目详情"
            align="center"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="trainingItemContent"
            label="培训项目内容"
            align="center"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="trainingItemType"
            label="项目类型"
            align="center"
          >
            <template slot-scope="scope">
              {{
                scope.row.trainingItemType == "VIDEO_LEARNING" ? "视频学习" : ""
              }}
              {{
                scope.row.trainingItemType == "GRAPHIC_LEARNING"
                  ? "图文学习"
                  : ""
              }}
              {{
                scope.row.trainingItemType == "LIVE_COURSES" ? "直播课程" : ""
              }}
              {{
                scope.row.trainingItemType == "OFFLINE_TRAINING"
                  ? "线下培训"
                  : ""
              }}
              {{
                scope.row.trainingItemType == "LEARNING_ITEM_GROUP"
                  ? "学习培训课程组"
                  : ""
              }}
            </template>
          </el-table-column>
          <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="handlelook(scope.row)"
                >查看</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <!-- <el-form-item label="培训项目名称" prop="trainingItemTitle">
            <el-input
              style="width: 250px"
              v-model="item.trainingItemTitle"
              placeholder="请输入培训项目名称"
            />
          </el-form-item>
          <el-form-item label="培训项目详情" prop="trainingItemDetails">
            <el-input
              type="textarea"
              :rows="5"
              style="width: 340px"
              placeholder="请输入培训项目详情"
              v-model="item.trainingItemDetails"
            ></el-input>
          </el-form-item>
          <el-form-item label="培训项目内容" prop="trainingItemContent">
            <el-input
              type="textarea"
              :rows="5"
              style="width: 340px"
              placeholder="请输入培训项目详情"
              v-model="item.trainingItemContent"
            ></el-input>
          </el-form-item>
          <el-form-item label="项目类型" prop="trainingItemType">
            <el-select
              style="width: 250px"
              v-model="item.trainingItemType"
              placeholder="请选择项目类型"
              clearable
            >
              <el-option
                v-for="item in trainingItemTypeoptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item> -->
        <!-- </div> -->
      </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>
    <!-- 查看视频图片 -->
    <el-dialog
      title="查看视频图片"
      :visible.sync="innerrefundvideo"
      append-to-body
      width="1000px"
    >
      <el-form :inline="true" :rules="rules" label-width="130px">
        <el-form-item label="培训课程海报图片" prop="trainingItemCoverUrl">
          <img class="img" :src="baseurl + formlist.trainingItemCoverUrl" alt />
        </el-form-item>
        <el-form-item label="培训课程海报图片" prop="trainingItemPosterUrl">
          <img
            class="img"
            :src="baseurl + formlist.trainingItemPosterUrl"
            alt
          />
        </el-form-item>
        <el-form-item label="视频" prop="itemDirectoryUrl">
          <video
            class="img"
            v-for="(item, index) in list"
            :key="index"
            :src="baseurl + item.itemDirectoryUrl"
            controls="controls"
          >
            您的浏览器不支持视频播放
          </video>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
  
  <script>
import {
  listTrainingOrder,
  getTrainingOrder,
  orderItemDirectory,
  refundInformation,
  delTrainingOrder,
  xylWeChatRefundNotify,
  addTrainingOrder,
  updateTrainingOrder,
} from "@/api/system/trainingOrder";
import baseurl from "@/api/baseurl.js";
export default {
  name: "TrainingOrder",
  data() {
    return {
      baseurl: null,
      trainingOrderStatusoptions: [
        {
          value: "WAIT_PAY",
          label: "待付款",
        },
        {
          value: "PAY",
          label: "已付款",
        },
        {
          value: "WAIT_REFUND",
          label: "退款中",
        },
        {
          value: "REFUNDED",
          label: "已退款",
        },
        {
          value: "CANCEL",
          label: "已取消",
        },
      ],
      // 遮罩层
      loading: true,
      innerrefund: false,
      innerrefundvideo: false,
      query: {},
      formlist: [],
      trainingItemTypeoptions: [
        {
          value: "GRAPHIC_LEARNING",
          label: "图文学习",
        },
        {
          value: "LEARNING_ITEM_GROUP",
          label: "学习培训项目组",
        },
        {
          value: "VIDEO_LEARNING",
          label: "视频学习",
        },
      ],
      // 选中数组
      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: {},
      list: [],
      trainingOrderDetailsList: [],
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
    this.baseurl = baseurl;
  },
  methods: {
    // 取消按钮
    cencelbtn() {
      this.innerrefund = false;
    },
    // // 确认退款
    cencel(row) {
      console.log(row);
      refundInformation(row.id).then((response) => {
        this.query = response.data;
        this.innerrefund = true;
      });
    },
    //退款确定按钮
    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(row) {
      this.innerrefundvideo = true;
      console.log(row);
      this.formlist.trainingItemCoverUrl = row.trainingItemCoverUrl;
      this.formlist.trainingItemPosterUrl = row.trainingItemPosterUrl;
      orderItemDirectory(row.trainingOrderDetailsId).then((response) => {
        this.list = response.rows;
      });
    },

    // 表单重置
    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.form.trainingOrderDetailsList =
          response.data.trainingOrderDetailsList;
        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>
  <style lang="scss">
.img {
  width: 150px;
  height: 150px;
  margin-left: 10px;
}
</style>