<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="订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品名称" prop="goodsTitle">
        <el-input
          v-model="queryParams.goodsTitle"
          placeholder="请输入商品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户姓名" prop="realName">
        <el-input
          v-model="queryParams.realName"
          placeholder="请输入用户姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phonenumber">
        <el-input
          v-model="queryParams.phonenumber"
          placeholder="请输入用户手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单状态" prop="orderStatus">
        <el-select v-model="queryParams.orderStatus" placeholder="请选择订单状态" clearable>
          <el-option
            v-for="dict in dict.type.order_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="时间区间" prop="partnerName">
        <el-date-picker
          v-model="queryParams.startTime"
          type="datetime"
          placeholder="选择日期时间">
        </el-date-picker>
        <span style="margin: 0 5px">至</span>
        <el-date-picker
          v-model="queryParams.endTime"
          type="datetime"
          placeholder="选择日期时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="金额大于" prop="partnerName">
        <el-input-number v-model="queryParams.realPayMoney"  :min="1" :max="999" label="描述文字"></el-input-number>
      </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:info: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:info: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:info:remove']"-->
    <!--        >删除</el-button>-->
    <!--      </el-col>-->
    <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    <!--    </el-row>-->

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单id" align="center" prop="id" width="80" />
      <el-table-column label="订单号" align="center" prop="orderNo" width="300" />
      <el-table-column label="商品名称" align="center" prop="goodsTitle" />
      <el-table-column label="用户姓名" align="center" prop="realName" />
      <el-table-column label="用户手机号" align="center" prop="phonenumber" />
<!--      <el-table-column label="车牌号" align="center" prop="carNo" />-->
      <el-table-column label="商品原价 (元)" align="center" prop="goodsPrice" >
        <template slot-scope="scope">
          <span>{{ scope.row.goodsPrice /100 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实付金额 （元）" align="center" prop="payMoney" >
        <template slot-scope="scope">
          <span>{{ scope.row.payMoney /100 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="使用账户余额(元)" align="center" prop="balance" >
        <template slot-scope="scope">
          <span>{{(scope.row.balance/100) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付时间" align="center" prop="payTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payTime, '{y}-{m}-{d} ') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="orderStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_status" :value="scope.row.orderStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="评价" align="center">
        <el-table-column label="评价星级" align="center" prop="commentStar" >
          <template slot-scope="scope">
            <el-rate
              v-model="scope.row.commentStar"
              disabled
              v-if="scope.row.commentStar != null"
            >
            </el-rate>
          </template>
        </el-table-column>
        <el-table-column label="评价内容" align="center" prop="commentDesc" show-overflow-tooltip />
      </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-edit"-->
      <!--            @click="handleUpdate(scope.row)"-->
      <!--            v-hasPermi="['system:info:edit']"-->
      <!--          >修改</el-button>-->
      <!--          <el-button-->
      <!--            size="mini"-->
      <!--            type="text"-->
      <!--            icon="el-icon-delete"-->
      <!--            @click="handleDelete(scope.row)"-->
      <!--            v-hasPermi="['system:info:remove']"-->
      <!--          >删除</el-button>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      </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 { listInfo, getInfo, delInfo, addInfo, updateInfo } from "./api/ordermanagement";
  import moment from 'moment';
  import request from "@/utils/request";
  import DictTag from "@/components/DictTagOld/index.vue";
  export default {
    name: "Info",
    components:{DictTag},
    dicts: ['order_status', 'all_order_type'],
    data() {
      return {
        value1: '',
        value2: '',
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 订单表格数据
        infoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNo: 1,
          pageSize: 10,
          orderNo: null,
          goodsTitle: null,
          realName: null,
          orderStatus: null,
          orderType: null,
          partnerName: null,
          DateTimeFormat:null,
          JsonFormat:null,
          TableField:null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.dict = {type:{}}
      for (let i = 0; i < this.$options.dicts.length; i++) {
        request({
          url: '/rescue/dict/data/type/'+this.$options.dicts[i],
          method: 'get'
        }).then(res=>{
          this.$set(this.dict.type,this.$options.dicts[i],res.data)
        })
      }
      this.getList();
    },
    methods: {
      /** 查询订单列表 */
      getList() {
        this.loading = true;
        if (this.queryParams.startTime){
          this.queryParams.startTime =  moment(this.queryParams.startTime).format('YYYY-MM-DD HH:mm');
        }
        if (this.queryParams.endTime){
          this.queryParams.endTime =  moment(this.queryParams.endTime).format('YYYY-MM-DD HH:mm');
        }
        listInfo(this.queryParams).then(response => {
          this.infoList = response.data.records;
          this.total = response.data.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          orderNo: null,
          goodsId: null,
          goodsTitle: null,
          goodsType: null,
          userId: null,
          realName: null,
          phonenumber: null,
          goodsPrice: null,
          payMoney: null,
          orderTime: null,
          balance: null,
          payTime: null,
          orderStatus: null,
          commentDesc: null,
          commentStar: null,
          orderType: null,
          partnerId: null,
          partnerName: null,
          createTime: null,
          createBy: null,
          deptId: null,
          updateTime: null,
          updateBy: null,
          validationTime: null,
          validationRealName: null,
          validationUserId: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNo = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.queryParams.startTime = null
        this.queryParams.endTime = null
        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
        getInfo(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) {
              updateInfo(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addInfo(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 delInfo(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('system/info/export', {
          ...this.queryParams
        }, `info_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
