<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="护理站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="patientId">
        <el-input
          v-model="queryParams.patientId"
          placeholder="请输入会员id"
          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="totalPrice">
        <el-input
          v-model="queryParams.totalPrice"
          placeholder="请输入订单总金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="收货人" prop="receiver">
        <el-input
          v-model="queryParams.receiver"
          placeholder="请输入收货人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收货地址" prop="receiveAddress">
        <el-input
          v-model="queryParams.receiveAddress"
          placeholder="请输入收货地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="联系电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>  -->
      <!-- <el-form-item label="下单时间" prop="orderTime">
        <el-date-picker clearable
          v-model="queryParams.orderTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择下单时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="下班方式，手机App：MOBILE_APP，微信小程序：WECHAT_APPLET，支付宝小程序：ALI_PAY_APPLET" prop="orderChannel">
        <el-input
          v-model="queryParams.orderChannel"
          placeholder="请输入下班方式，手机App：MOBILE_APP，微信小程序：WECHAT_APPLET，支付宝小程序：ALI_PAY_APPLET"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </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-table
      v-loading="loading"
      :data="goodsOrderList"
      @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="patientId" /> -->
      <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 == "PAY" ? "已付款" : "" }}
          {{ scope.row.orderStatus == "CANCEL" ? "已取消" : "" }}
          {{ scope.row.orderStatus == "WAIT_RECEIVED" ? "待收货" : "" }}
          {{ scope.row.orderStatus == "RECEIVED" ? "已收货" : "" }}
          {{ scope.row.orderStatus == "WAIT_REFUND" ? "待退款" : "" }}

          {{ scope.row.orderStatus == "REFUNDED" ? "已退款" : "" }}
          {{ scope.row.orderStatus == "WAIT_RETURNED" ? "待退货" : "" }}
          {{ scope.row.orderStatus == "RETURNED" ? "已退货" : "" }}
        </template>
      </el-table-column>
      <el-table-column label="订单总金额" align="center" prop="totalPrice" />
      <el-table-column label="收货人" align="center" prop="receiver" />
      <el-table-column label="收货地址" align="center" prop="receiveAddress" />
      <el-table-column label="联系电话" align="center" prop="phone" />
      <el-table-column
        label="下单时间"
        align="center"
        prop="orderTime"
        width="180"
      />
      <el-table-column
        label="下单方式"
        align="center"
        prop="orderChannel"
      > <template slot-scope="scope">
          {{ scope.row.orderChannel == "MOBILE_APP" ? "手机APP" : "" }}
          {{ scope.row.orderChannel == "WECHAT_APPLET" ? "微信小程序" : "" }}
          {{ scope.row.orderChannel == "ALI_PAY_APPLET" ? "支付宝" : "" }}
        </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-edit"
            @click="seeOrder(scope.row)"
            v-hasPermi="['system:nurseType:edit']"
            >查看</el-button
          >
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:goodsOrder:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:goodsOrder: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="innerorder"
      append-to-body
      width="1048px"
    >
          <el-table
            :data="orderList"
            align="center"
            style="margin: 10px 0 20px 0; padding-bottom: 20px"
          >
           <el-table-column
              prop="orderNo"
              label="订单编号"
              width="120"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="receiveAddress"
              label="地址"
              width="120"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="receiver"
              label="收货人"
               width="120"
              align="center"
            >
            </el-table-column>
              <el-table-column
              prop="phone"
              label="手机号"
                width="120"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="goodsName"
              label="商品名称"
                width="120"
              align="center"
            >
            </el-table-column>
              <el-table-column
              prop="goodsAttributeName"
              label="商品属性"
                width="120"
              align="center"
            >
            </el-table-column>
             <el-table-column
              prop="goodsPrice"
              label="商品价格"
               width="120"
              align="center"
            >
            </el-table-column>
          </el-table>
    </el-dialog>
    <!-- 添加或修改商品订单对话框 -->
    <!-- <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="护理站id" prop="nurseStationId">
          <el-input
            v-model="form.nurseStationId"
            placeholder="请输入护理站id"
          />
        </el-form-item>
        <el-form-item label="会员id" prop="patientId">
          <el-input v-model="form.patientId" placeholder="请输入会员id" />
        </el-form-item>
        <el-form-item label="订单编号" prop="orderNo">
          <el-input v-model="form.orderNo" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="订单总金额" prop="totalPrice">
          <el-input v-model="form.totalPrice" placeholder="请输入订单总金额" />
        </el-form-item>
        <el-form-item label="收货人" prop="receiver">
          <el-input v-model="form.receiver" placeholder="请输入收货人" />
        </el-form-item>
        <el-form-item label="收货地址" prop="receiveAddress">
          <el-input
            v-model="form.receiveAddress"
            placeholder="请输入收货地址"
          />
        </el-form-item>
        <el-form-item label="联系电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="下单时间" prop="orderTime">
          <el-date-picker
            clearable
            v-model="form.orderTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择下单时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="下班方式，手机App：MOBILE_APP，微信小程序：WECHAT_APPLET，支付宝小程序：ALI_PAY_APPLET"
          prop="orderChannel"
        >
          <el-input
            v-model="form.orderChannel"
            placeholder="请输入下班方式，手机App：MOBILE_APP，微信小程序：WECHAT_APPLET，支付宝小程序：ALI_PAY_APPLET"
          />
        </el-form-item>
        <el-form-item label="备注信息" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注信息" />
        </el-form-item>
        <el-form-item label="是否删除，0：否，1：是" prop="delFlag">
          <el-input
            v-model="form.delFlag"
            placeholder="请输入是否删除，0：否，1：是"
          />
        </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 { listGoodsOrder, getGoodsOrder, delGoodsOrder, addGoodsOrder, updateGoodsOrder,getGoodsOrderlist} from "@/api/system/goodsOrder";

export default {
  name: "GoodsOrder",
  data() {
    return {
      innerorder:false,
      orderList:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品订单表格数据
      goodsOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nurseStationId: null,
        patientId: null,
        orderNo: null,
        orderStatus: null,
        totalPrice: null,
        receiver: null,
        receiveAddress: null,
        phone: null,
        orderTime: null,
        orderChannel: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商品订单列表 */
    getList() {
      this.loading = true;
      listGoodsOrder(this.queryParams).then(response => {
        this.goodsOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    seeOrder(row){
      console.log(row);
      this.innerorder=true
      const id = row.orderNo;
      getGoodsOrderlist(id).then(res =>{
        this.orderList=[res.data]
      })
  
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        nurseStationId: null,
        patientId: null,
        orderNo: null,
        orderStatus: "0",
        totalPrice: null,
        receiver: null,
        receiveAddress: null,
        phone: null,
        orderTime: null,
        orderChannel: 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
      getGoodsOrder(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) {
            updateGoodsOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGoodsOrder(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 delGoodsOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/goodsOrder/export', {
        ...this.queryParams
      }, `goodsOrder_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
