<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="客户" prop="patientName">
        <el-input
          v-model="queryParams.patientName"
          placeholder="请输入客户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <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="orderStatus">
        <el-select
          v-model="queryParams.orderStatus"
          placeholder="请选择订单状态"
        >
          <el-option
            v-for="item in orderStatuslist"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </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>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>

      <el-table
        v-loading="loading"
        :data="OrderDetailsList"
        @selection-change="handleSelectionChange"
      >
        <el-table-column label="客户" align="center" prop="patientName" />
        <el-table-column label="订单编号" align="center" prop="orderNo" />
        <el-table-column label="订单状态" align="center" prop="orderStatus">
          <template slot-scope="scope">
            {{ scope.row.orderStatus == "WAIT_PAY" ? "待付款" : "" }}
            {{ scope.row.orderStatus == "WAIT_DISPATCH" ? "待派单" : "" }}
            {{ scope.row.orderStatus == "NOT_FINISH" ? "未完成" : "" }}
            {{ scope.row.orderStatus == "COMPLETE" ? "服务完成" : "" }}
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" />
        <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-edit"
              @click="seeLook(scope.row)"
              v-hasPermi="['system:nurseType:edit']"
              >查看</el-button
            >
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['system:nurseType: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="innerVisible4"
        append-to-body
        width="1048px"
      >
        <div v-for="(item, index) in query" :key="index">
          <el-row>
            <el-col :span="8">
              <el-form-item label="订单编号" prop="orderNo">
                <el-input
                  v-model="item.orderNo"
                  :disabled="true"
                  style="width: 160px"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="订单状态" prop="orderStatus">
                <el-input
                  :value="switchOrderStatus(item.orderStatus)"
                  disabled
                  style="width: 150px"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="护理站名称" prop="nurseStationName">
                <el-input
                  v-model="item.nurseStationName"
                  clearable
                  @keyup.enter.native="handleQuery"
                  :disabled="true"
                  style="width: 225px"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="订单数量" prop="orderCount">
                <el-input
                  v-model="item.orderCount"
                  clearable
                  @keyup.enter.native="handleQuery"
                  :disabled="true"
                  style="width: 160px"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="服务时间" prop="serviceDate">
                <el-input
                  v-model="item.serviceDate"
                  clearable
                  @keyup.enter.native="handleQuery"
                  :disabled="true"
                  style="width: 150px"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="服务地址" prop="serviceAddress">
                <el-input
                  v-model="item.serviceAddress"
                  clearable
                  @keyup.enter.native="handleQuery"
                  :disabled="true"
                  style="width: 225px"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="护理项目名称" prop="nurseItemName">
                <el-input
                  v-model="item.nurseItemName"
                  clearable
                  @keyup.enter.native="handleQuery"
                  :disabled="true"
                  style="width: 160px"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="护理项目价格" prop="nurseItemPrice">
                <el-input
                  v-model="item.nurseItemPrice"
                  clearable
                  @keyup.enter.native="handleQuery"
                  :disabled="true"
                  style="width: 150px"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="护理项目时长" prop="itemServeDurationUnit">
                <el-input
                  v-model="item.itemServeDurationUnit"
                  clearable
                  @keyup.enter.native="handleQuery"
                  :disabled="true"
                  style="width: 225px"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-table
            :data="item.appointmentOrderConsumableList"
            align="center"
            style="margin: 10px 0 20px 0; padding-bottom: 20px"
          >
            <el-table-column
              prop="orderConsumableName"
              label="耗材包名称"
              width="200"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="orderConsumableCount"
              label="耗材包数量"
              width="200"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="orderConsumablePrice"
              label="耗材包价格"
              width="200"
              align="center"
            >
            </el-table-column>
          </el-table>
        </div>
      </el-dialog>
    </el-form>
  </div>
</template>
<script>
import {
  appointmentOrderDetailsList,
  Detailed,
  deldetailed,
} from "@/api/system/order";
export default {
  name: "order",
  data() {
    return {
      orderStatuslist: [
        {
          value: "WAIT_PAY",
          label: "待付款",
        },
        {
          value: "WAIT_DISPATCH",
          label: "待派单",
        },
        {
          value: "NOT_FINISH",
          label: "未完成",
        },
        {
          value: "COMPLETE",
          label: "服务完成",
        },
      ],
      value: "",
      // 遮罩层
      loading: true,
      innerVisible4: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      input: "",
      // 总条数
      total: 0,
      // 护理类型信息表格数据
      OrderDetailsList: [],
      OrderDetailsLists: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open2: false,
      // 查询参数
      queryParams: {
        patientName: null,
        orderNo: null,
        // orderStatus: null,
        orderStatus: "",
        pageNum: 1,
        pageSize: 10,
      },
      query: [],
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    switchOrderStatus(orderStatus) {
      switch (orderStatus) {
        case "WAIT_PAY":
          return "待付款";
        case "WAIT_DISPATCH":
          return "待派单";
        case "NOT_FINISH":
          return "未完成";
        case "COMPLETE":
          return "服务完成";
        default:
          break;
      }
    },

    seeLook(row) {
      this.innerVisible4 = true;
      const id = row.orderNo;
      // console.log(row);
      Detailed(id).then((res) => {
        this.OrderDetailsLists = res.data;
        // console.log(this.OrderDetailsLists)
        this.query = res.data;
        console.log(this.query);
        // console.log(res);
      });
    },
    /** 查询护理类型信息列表 */
    getList() {
      this.loading = true;
      appointmentOrderDetailsList(this.queryParams).then((response) => {
        this.OrderDetailsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        patientName: "",
        orderNo: "",
        orderStatus: "",
        createTime: 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;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm('是否确认删除订单编号为"' + row.orderNo + '"的数据项？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deldetailed(row.appointOrderDetailsId).then((res) => {
            this.$message.success("删除成功");
            this.getList();
          })
        })
        .catch(() => {}); 
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/nurseType/export",
        {
          ...this.queryParams,
        },
        `nurseType_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>