<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px" size="medium" class="ry_form">
      <el-form-item label="伴宠师编号" prop="certificationId">
        <el-input
          v-model="queryParams.certificationId"
          placeholder="请输入伴宠师编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="删除标记" prop="deiFlag">
        <el-input
          v-model="queryParams.deiFlag"
          placeholder="请输入删除标记"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单金额" prop="orderAmount">
        <el-input
          v-model="queryParams.orderAmount"
          placeholder="请输入订单金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="下单时间" prop="orderPlaceTime">
        <el-date-picker
            clearable
            size="small"
            v-model="queryParams.orderPlaceTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择下单时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="订单数量" prop="orderQuantity">
        <el-input
          v-model="queryParams.orderQuantity"
          placeholder="请输入订单数量"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="服务日期" prop="orderServiceDate">
        <el-date-picker
            clearable
            size="small"
            v-model="queryParams.orderServiceDate"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择服务日期">
        </el-date-picker>
      </el-form-item>
<!--      <template v-if="showMoreCondition">-->
      <el-form-item label="服务时间,1==早上,2==午后,3==晚间" prop="orderServiceTime">
        <el-input
          v-model="queryParams.orderServiceTime"
          placeholder="请输入服务时间,1==早上,2==午后,3==晚间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单状态,0=待接单,1=待上门,2=已完成" prop="orderState">
        <el-input
          v-model="queryParams.orderState"
          placeholder="请输入订单状态,0=待接单,1=待上门,2=已完成"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单总金额" prop="orderTotalAmount">
        <el-input
          v-model="queryParams.orderTotalAmount"
          placeholder="请输入订单总金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上门地址" prop="orderVisitAddress">
        <el-input
          v-model="queryParams.orderVisitAddress"
          placeholder="请输入上门地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="宠物编号" prop="petId">
        <el-input
          v-model="queryParams.petId"
          placeholder="请输入宠物编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item class="flex_one tr">
        <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="['model:AppOrder: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="['model:AppOrder: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="['model:AppOrder:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['model:AppOrder:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="AppOrderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单编号" align="center" prop="orderId" />
      <el-table-column label="伴宠师编号" align="center" prop="certificationId" v-if="columns[0].visible"/>
      <el-table-column label="删除标记" align="center" prop="deiFlag" v-if="columns[1].visible"/>
      <el-table-column label="订单金额" align="center" prop="orderAmount" v-if="columns[2].visible"/>
      <el-table-column label="下单时间" align="center" prop="orderPlaceTime" width="180" v-if="columns[3].visible">
        <template slot-scope="scope">
            <span>{{ parseTime(scope.row.orderPlaceTime, '')}}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单数量" align="center" prop="orderQuantity" v-if="columns[4].visible"/>
      <el-table-column label="服务内容" align="center" prop="orderServiceContent" v-if="columns[5].visible"/>
      <el-table-column label="服务日期" align="center" prop="orderServiceDate" width="180" v-if="columns[6].visible">
        <template slot-scope="scope">
            <span>{{ parseTime(scope.row.orderServiceDate, '')}}</span>
        </template>
      </el-table-column>
      <el-table-column label="服务时间,1==早上,2==午后,3==晚间" align="center" prop="orderServiceTime" v-if="columns[7].visible"/>
      <el-table-column label="订单状态,0=待接单,1=待上门,2=已完成" align="center" prop="orderState" v-if="columns[8].visible"/>
      <el-table-column label="订单总金额" align="center" prop="orderTotalAmount" v-if="columns[9].visible"/>
      <el-table-column label="上门地址" align="center" prop="orderVisitAddress" v-if="columns[10].visible"/>
      <el-table-column label="宠物编号" align="center" prop="petId" v-if="columns[11].visible"/>
      <el-table-column label="备注" align="center" prop="remark" v-if="columns[12].visible"/>
      <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="handleUpdate(scope.row)"
            v-hasPermi="['model:AppOrder:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['model:AppOrder: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="title" :visible.sync="open" width="50%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="108px" inline class="dialog-form-two">
        <el-form-item label="伴宠师编号" prop="certificationId">
          <el-input v-model="form.certificationId" placeholder="请输入伴宠师编号" />
        </el-form-item>
        <el-form-item label="删除标记" prop="deiFlag">
          <el-input v-model="form.deiFlag" placeholder="请输入删除标记" />
        </el-form-item>
        <el-form-item label="订单金额" prop="orderAmount">
          <el-input v-model="form.orderAmount" placeholder="请输入订单金额" />
        </el-form-item>
        <el-form-item label="下单时间" prop="orderPlaceTime">
          <el-date-picker clearable size="small"
                        v-model="form.orderPlaceTime"
                        type="datetime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择下单时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="订单数量" prop="orderQuantity">
          <el-input v-model="form.orderQuantity" placeholder="请输入订单数量" />
        </el-form-item>
        <el-form-item label="服务内容">
          <editor v-model="form.orderServiceContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="服务日期" prop="orderServiceDate">
          <el-date-picker clearable size="small"
                        v-model="form.orderServiceDate"
                        type="datetime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择服务日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="服务时间,1==早上,2==午后,3==晚间" prop="orderServiceTime">
          <el-input v-model="form.orderServiceTime" placeholder="请输入服务时间,1==早上,2==午后,3==晚间" />
        </el-form-item>
        <el-form-item label="订单状态,0=待接单,1=待上门,2=已完成" prop="orderState">
          <el-input v-model="form.orderState" placeholder="请输入订单状态,0=待接单,1=待上门,2=已完成" />
        </el-form-item>
        <el-form-item label="订单总金额" prop="orderTotalAmount">
          <el-input v-model="form.orderTotalAmount" placeholder="请输入订单总金额" />
        </el-form-item>
        <el-form-item label="上门地址" prop="orderVisitAddress">
          <el-input v-model="form.orderVisitAddress" placeholder="请输入上门地址" />
        </el-form-item>
        <el-form-item label="宠物编号" prop="petId">
          <el-input v-model="form.petId" placeholder="请输入宠物编号" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </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 { listAppOrder, getAppOrder, delAppOrder, addAppOrder, updateAppOrder, exportAppOrder } from "@/api/model/AppOrder";

export default {
  name: "AppOrder",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      AppOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        certificationId: null,

        deiFlag: null,

        orderAmount: null,

        orderPlaceTime: null,

        orderQuantity: null,

        orderServiceContent: null,

        orderServiceDate: null,

        orderServiceTime: null,

        orderState: null,

        orderTotalAmount: null,

        orderVisitAddress: null,

        petId: null,

      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      columns: [
    { key: 1, label: "伴宠师编号", visible:  true  },
    { key: 4, label: "删除标记", visible:  true  },
    { key: 5, label: "订单金额", visible:  true  },
    { key: 6, label: "下单时间", visible:  true  },
    { key: 7, label: "订单数量", visible:  true  },
    { key: 8, label: "服务内容", visible:  true  },
    { key: 9, label: "服务日期", visible:  true  },
    { key: 10, label: "服务时间,1==早上,2==午后,3==晚间", visible:  false  },
    { key: 11, label: "订单状态,0=待接单,1=待上门,2=已完成", visible:  false  },
    { key: 12, label: "订单总金额", visible:  false  },
    { key: 13, label: "上门地址", visible:  false  },
    { key: 14, label: "宠物编号", visible:  false  },
    { key: 15, label: "备注", visible:  false  },
     ],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单列表 */
    getList() {
      this.loading = true;
      listAppOrder(this.queryParams).then(response => {
        this.AppOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderId: null,

        certificationId: null,

        createBy: null,

        createTime: null,

        deiFlag: null,

        orderAmount: null,

        orderPlaceTime: null,

        orderQuantity: null,

        orderServiceContent: null,

        orderServiceDate: null,

        orderServiceTime: null,

        orderState: null,

        orderTotalAmount: null,

        orderVisitAddress: null,

        petId: null,

        remark: 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.orderId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const orderId = row.orderId || this.ids
      getAppOrder(orderId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.orderId != null) {
            updateAppOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAppOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderIds = row.orderId || this.ids;
      this.$modal.confirm('是否确认删除订单编号为"' + orderIds + '"的数据项？').then(function() {
        return delAppOrder(orderIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有订单数据项？').then(() => {
        this.exportLoading = true;
        return exportAppOrder(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
