<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item :label="$t('table.commodityType')">
		<el-select v-model="queryParams.typeName" :placeholder="$t('placeholder.commodityType')">
			<el-option
				v-for="item,index in commodityTypeList"
				:key="index"
				:label="item.typeName"
				:value="item.typeName">
			</el-option>
		</el-select>
      </el-form-item>
	  <el-form-item :label="$t('table.orderyNo')">
        <el-input
          v-model="queryParams.orderyNo"
          :placeholder="$t('placeholder.orderyNo')"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
	  <el-form-item :label="$t('table.beginDate')" >
        <el-date-picker clearable
          v-model="queryParams['params[beginDate]']"
          type="date"
          value-format="yyyy-MM-dd"
          :placeholder="$t('placeholder.beginDate')">
        </el-date-picker>
      </el-form-item>
      <el-form-item :label="$t('table.endDate')">
        <el-date-picker clearable
          v-model="queryParams['params[endDate]']"
          type="date"
          value-format="yyyy-MM-dd"
          :placeholder="$t('placeholder.endDate')">
        </el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="客户id" prop="customerId">
        <el-input
          v-model="queryParams.customerId"
          placeholder="请输入客户id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="商品id" prop="commodityId">
        <el-input
          v-model="queryParams.commodityId"
          placeholder="请输入商品id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="出发地" prop="departurePlace">
        <el-input
          v-model="queryParams.departurePlace"
          placeholder="请输入出发地"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="出发日期" prop="departureDate">
        <el-input
          v-model="queryParams.departureDate"
          placeholder="请输入出发日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="是否使用优惠券  0-否  1-是" prop="isCoupon">
        <el-input
          v-model="queryParams.isCoupon"
          placeholder="请输入是否使用优惠券  0-否  1-是"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="成人数量" prop="adultNum">
        <el-input
          v-model="queryParams.adultNum"
          placeholder="请输入成人数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="儿童数量" prop="childNum">
        <el-input
          v-model="queryParams.childNum"
          placeholder="请输入儿童数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="订单金额" prop="orderMoney">
        <el-input
          v-model="queryParams.orderMoney"
          placeholder="请输入订单金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="支付宝支付号" prop="aipayNo">
        <el-input
          v-model="queryParams.aipayNo"
          placeholder="请输入支付宝支付号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="bus公司id" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入bus公司id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{$t('btn.search')}}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{$t('btn.Reset')}}</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="['order:order: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="['order:order: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="['order:order: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="['order:order:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
	  <el-table-column :label="$t('table.SerialNumber')" width="50px" align="center">
		<template slot-scope="scope">
			{{ scope.$index + (queryParams.pageNum - 1) * queryParams.pageSize + 1 }}
		</template>
	  </el-table-column>
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <!-- <el-table-column label="id" align="center" prop="id" /> -->
	  <el-table-column :label="$t('table.customerName1')" align="center" prop="customerName" />
	   <!-- <el-table-column :label="$t('table.phone')" align="center" prop="phone" />-->
	  <el-table-column :label="$t('table.orderTime1')" align="center" :formatter="dateFormat" prop="createTime" />
      <el-table-column :label="$t('table.orderyNo')" align="center" prop="orderNo" />
	  <el-table-column :label="$t('table.commodityType')" align="center" prop="typeName" />
	  <el-table-column :label="$t('table.commodityName')" align="center" prop="commodityName" />
      <!-- <el-table-column label="客户id" align="center" prop="customerId" /> -->
      <!-- <el-table-column label="商品id" align="center" prop="commodityId" /> -->
      <!-- <el-table-column label="出发地" align="center" prop="departurePlace" /> -->
      <!-- <el-table-column label="出发日期" align="center" prop="departureDate" /> -->
      <!-- <el-table-column label="是否使用优惠券  0-否  1-是" align="center" prop="isCoupon" /> -->
      <!-- <el-table-column label="成人数量" align="center" prop="adultNum" /> -->
      <!-- <el-table-column label="儿童数量" align="center" prop="childNum" /> -->
      <el-table-column :label="$t('table.orderMoney')" align="center" prop="orderMoney" />
      <!-- <el-table-column label="支付宝支付号" align="center" prop="aipayNo" /> -->
      <el-table-column :label="$t('table.status2')" align="center" prop="status">
		<template slot-scope="scope">
			<!-- {{ scope.row.status=='1'?'已支付':'待支付'}} -->
			<span v-if="scope.row.status=='0'">{{$t('table.orderstatus1')}}</span>
			<span v-if="scope.row.status=='1'">{{$t('table.orderstatus2')}}</span>
			<span v-if="scope.row.status=='2'">{{$t('table.orderstatus3')}}</span>
			<span v-if="scope.row.status=='9'">{{$t('table.orderstatus4')}}</span>
			<span v-if="scope.row.status=='99'">{{$t('table.orderstatus5')}}</span>
		</template>
	  </el-table-column>
      <!-- <el-table-column label="bus公司id" align="center" prop="deptId" /> -->
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column :label="$t('table.operation')" 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="['order:order:edit']"
          >{{$t('table.detail')}}</el-button>
          <el-button
          v-if="scope.row.status=='0'||scope.row.status=='1'"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['order:order:cancelOrder']"
          >取消</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="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="140px" style="display:flex;flex-wrap:wrap;">
		<el-form-item :label="$t('table.commodityType')">
          <el-input disabled v-model="form.typeName" />
        </el-form-item>
		<el-form-item :label="$t('table.commodityName')">
          <el-input disabled v-model="form.commodityName" />
        </el-form-item>
		<el-form-item :label="$t('table.departurePlace')">
          <el-input disabled v-model="form.departurePlaceArr" />
        </el-form-item>
		<el-form-item :label="$t('table.adultPrice')">
          <el-input disabled v-model="form.adultPrice" />
        </el-form-item>
		<el-form-item :label="$t('table.childPrice')">
          <el-input disabled v-model="form.childPrice" />
        </el-form-item>

		<el-divider content-position="center">{{$t('dialog.orderTitel')}}</el-divider>
		<el-form-item :label="$t('table.status2')">
          <el-input disabled v-if="form.status=='0'" :value="$t('table.orderstatus1')" />
		  <el-input disabled v-if="form.status=='1'" :value="$t('table.orderstatus2')" />
		  <el-input disabled v-if="form.status=='2'" :value="$t('table.orderstatus3')" />
		  <el-input disabled v-if="form.status=='9'" :value="$t('table.orderstatus4')" />
		  <el-input disabled v-if="form.status=='99'" :value="$t('table.orderstatus5')" />
        </el-form-item>
		<el-form-item :label="$t('table.customerName1')">
          <el-input disabled v-model="form.customerName" />
        </el-form-item>
		<el-form-item :label="$t('table.phone')">
          <el-input disabled v-model="form.phone" />
        </el-form-item>
		<el-form-item :label="$t('table.departurePlace')">
          <el-input disabled v-model="form.departurePlace" />
        </el-form-item>
        <el-form-item :label="$t('dialog.departureDate')">
          <el-input disabled v-model="form.departureDate" />
        </el-form-item>
		<el-form-item :label="$t('dialog.adultNum')">
          <el-input disabled v-model="form.adultNum" />
        </el-form-item>
        <el-form-item :label="$t('dialog.childNum')">
          <el-input disabled v-model="form.childNum" />
        </el-form-item>
		<el-form-item :label="$t('table.createTime1')">
          <el-input disabled v-model="form.createTime" />
        </el-form-item>
		<el-form-item :label="$t('dialog.isCoupon')">
          <el-input disabled v-if="form.isCoupon=='1'" :value="$t('dialog.yes')" />
		  <el-input disabled v-if="form.isCoupon=='0'" :value="$t('dialog.no')" />
        </el-form-item>
		<el-form-item :label="$t('dialog.couponDeduction')">
          <el-input disabled v-model="form.couponDeduction" />
        </el-form-item>
		<el-form-item :label="$t('dialog.integralDeduction')">
          <el-input disabled v-model="form.integralDeduction" />
        </el-form-item>
		<el-form-item :label="$t('table.orderMoney')">
          <el-input disabled v-model="form.orderMoney"  />
        </el-form-item>
		<el-form-item v-if="form.status!='0'" :label="$t('dialog.payDate')">
          <el-input disabled v-model="form.payDate"  />
        </el-form-item>
		<el-form-item v-if="form.status!='0'" :label="$t('dialog.payFn')">
          <el-input disabled :value="$t('dialog.Alipay')" />
        </el-form-item>
		<el-form-item :label="$t('table.orderyNo')" >
          <el-input disabled v-model="form.orderNo" />
        </el-form-item>
		<el-form-item v-if="form.status=='2'" :label="$t('dialog.updateTime')">
          <el-input disabled v-model="form.updateTime" />
        </el-form-item>
		<el-form-item v-if="form.status=='99'" :label="$t('dialog.orderMoney2')">
          <el-input disabled v-model="form.orderMoney" />
        </el-form-item>
		<el-form-item v-if="form.status=='99'" :label="$t('dialog.returnDate')">
          <el-input disabled v-model="form.returnDate" />
        </el-form-item>
		<el-form-item v-if="form.status=='99'" :label="$t('dialog.RefundDestination')">
          <el-input disabled :value="$t('dialog.ReturnSameRoute')" />
        </el-form-item>
        
        <!-- <el-form-item label="客户id" prop="customerId">
          <el-input v-model="form.customerId" placeholder="请输入客户id" />
        </el-form-item>
        <el-form-item label="商品id" prop="commodityId">
          <el-input v-model="form.commodityId" placeholder="请输入商品id" />
        </el-form-item><el-form-item label="支付宝支付号" prop="aipayNo">
          <el-input v-model="form.aipayNo" placeholder="请输入支付宝支付号" />
        </el-form-item>
        <el-form-item label="bus公司id" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入bus公司id" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
        <el-button @click="cancel">{{$t('btn.cancel')}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder,newDelOrder } from "@/api/order/order";
import { listCommodityType } from "@/api/commodityType/commodityType";

export default {
  name: "Order",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单管理表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
	  // 商品类型列表
	  commodityTypeList:[],  
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderyNo: null,
		typeName:null,
		'params[beginDate]':null,
		'params[endDate]':null,
        // customerId: null,
        // commodityId: null,
        // departurePlace: null,
        // departureDate: null,
        // isCoupon: null,
        // adultNum: null,
        // childNum: null,
        // orderMoney: null,
        // aipayNo: null,
        // status: null,
        // deptId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单管理列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
	  listCommodityType().then(response => {
        this.commodityTypeList = response.rows;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderyNo: null,
        customerId: null,
        commodityId: null,
        departurePlace: null,
        departureDate: null,
        isCoupon: null,
        adultNum: null,
        childNum: null,
        orderMoney: null,
        aipayNo: null,
        status: "0",
        deptId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: 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
      getOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = this.$t('dialog.orderTitel2')
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认取消此订单？').then(function() {
        return newDelOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("取消成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('order/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    },
    dateFormat:function(row,column){
      var date = row[column.property]; 
      if (date === undefined) { 
        return ""; 
      } 
      var moment = require("moment");
      return moment(date).format("YYYY-MM-DD");
    }
  }
};
</script>
