<template>
  <div class="aacontainer">

    <el-tabs type="card" v-model="actName" @tab-click="handleClickX">
      <el-tab-pane label="全部订单" name="10"></el-tab-pane>
      <el-tab-pane v-for="(item,index) in orderOptions" :label="item.dictLabel" :name="item.dictValue"></el-tab-pane>
    </el-tabs>
    <el-table v-loading="loading" :data="orderList" >
      <el-table-column label="订单号" align="center" prop="orderCode" width="180px"/>
      <el-table-column label="所属店铺" align="center" prop="storeName" width="180px"/>
      <el-table-column label="用户昵称" align="center" prop="nickName" show-overflow-tooltip width="100px"/>
      <el-table-column label="收货人" align="center" prop="userName" />
      <el-table-column label="医生姓名" align="center" prop="doctorName" />
      <el-table-column label="患者姓名" align="center" prop="patientName" />
      <el-table-column label="订单总价" align="center" prop="totalPrice" />
      <el-table-column label="应付金额" align="center" prop="payPrice" />
      <el-table-column label="实付金额" align="center" prop="payMoney" />
      <el-table-column label="订单状态" align="center" prop="status" >
        <template slot-scope="scope">
              <dict-tag :options="orderOptions" :value="scope.row.status"/>
         </template>
      </el-table-column>
      <el-table-column label="支付状态 " align="center" prop="isPay" >
        <template slot-scope="scope">
              <dict-tag :options="payStatusOptions" :value="scope.row.isPay"/>
            </template>
      </el-table-column>
      <el-table-column label="支付时间" align="center" prop="payTime" width="180" />
      <el-table-column label="支付方式" align="center" prop="payType" >
        <template slot-scope="scope">
              <dict-tag :options="PayOptions" :value="scope.row.payType"/>
         </template>
      </el-table-column>
      <el-table-column label="订单类型" align="center" prop="orderType" >
        <template slot-scope="scope">
              <dict-tag :options="orderTypeOptions" :value="scope.row.orderType"/>
         </template>
      </el-table-column>
      <el-table-column label="退款状态" align="center" prop="refundStatus" >
        <template slot-scope="scope">
              <dict-tag :options="refundOptions" :value="scope.row.refundStatus"/>
         </template>
      </el-table-column>
      <el-table-column label="快递名称" align="center" prop="deliveryName" />
      <el-table-column label="快递单号" align="center" prop="deliverySn" />
      <el-table-column label="是否开处方" align="center" prop="isPrescribe" >
        <template slot-scope="scope">
              <dict-tag :options="orOptions" :value="scope.row.isPrescribe"/>
         </template>
      </el-table-column>
      <el-table-column label="处方编号" align="center" prop="prescribeCode" width="170px"/>
      <el-table-column label="发货时间" align="center" prop="deliveryTime" />
      <el-table-column label="推广佣金" align="center" prop="tuiMoney" />
      <el-table-column label="推广佣金状态" align="center" prop="tuiMoneyStatus" >
        <template slot-scope="scope">
              <dict-tag :options="tuiOptions" :value="scope.row.tuiMoneyStatus"/>
         </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime"  width="150px"/>
      <el-table-column label="修改时间" align="center" prop="updateTime"  width="150px"/>
    </el-table>

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



  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder, exportOrder,importTemplate } from "@/api/his/storeOrder";
import { getToken } from "@/utils/auth";
import {listStore} from "@/api/his/storeProduct";
export default {
  name: "userInquir",
  props:["data"],
  data() {
    return {
      actName:"10",
      show:{
              title:"订单详情",
              open:false,
            },
      upload: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/his/order/importData"
      },
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      createTime:null,
      payTime:null,
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        storeId: null,
        orderCode: null,
        userId: null,
        userName: null,
        userPhone: null,
        userAddress: null,
        cartId: null,
        totalNum: null,
        totalPrice: null,
        payPrice: null,
        payMoney: null,
        isPay: null,
        payTime: null,
        payType: null,
        status: null,
        refundStatus: null,
        refundImg: null,
        refundExplain: null,
        refundTime: null,
        refundReason: null,
        refundMoney: null,
        deliveryCode: null,
        deliveryName: null,
        deliverySn: null,
        isDel: null,
        costPrice: null,
        verifyCode: null,
        shippingType: null,
        isChannel: null,
        isPrescribe: null,
        prescribeId: null,
        finishTime: null,
        patientName: null,
        doctorName: null,
        sTime:null,
        eTime:null,
        paysTime:null,
        payeTime:null,
        deliveryTime: null,
        tuiMoney: null,
        tuiMoneyStatus: null,
        tuiUserId: null,
        orderCreateType: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
       PayOptions:[],
       orderOptions:[],
       payStatusOptions:[],
       refundOptions:[],
       channelOptions:[],
       orderTypeOptions:[],
       tuiOptions:[],
       orOptions:[],
       storeOPtions:[],
    };
  },
  created() {
    this.getDicts("sys_inquiry_pay").then(response => {
        this.PayOptions = response.data;
      });
    this.getDicts("store_order_type").then(response => {
        this.orderTypeOptions = response.data;
      });
    this.getDicts("sys_order_status").then(response => {
        this.orderOptions = response.data;
      });
    this.getDicts("sys_order_pay").then(response => {
        this.payStatusOptions = response.data;
      });
    this.getDicts("sys_refund_status").then(response => {
        this.refundOptions = response.data;
      });
    this.getDicts("sys_channel").then(response => {
        this.channelOptions = response.data;
      });
    this.getDicts("sys_tui_money_status").then(response => {
          this.tuiOptions = response.data;
        });
    this.getDicts("sys_company_or").then(response => {
          this.orOptions = response.data;
        });
  },
  methods: {
    getUserDetails(id){
      this.queryParams.userId=id
      this.getList();
    },


    /** 查询订单列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });

    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderId: null,
        storeId: null,
        orderCode: null,
        userId: null,
        userName: null,
        userPhone: null,
        userAddress: null,
        cartId: null,
        totalNum: null,
        totalPrice: null,
        payPrice: null,
        payMoney: null,
        isPay: null,
        payTime: null,
        payType: null,
        createTime: null,
        updateTime: null,
        status: null,
        refundStatus: "0",
        refundImg: null,
        refundExplain: null,
        refundTime: null,
        refundReason: null,
        refundMoney: null,
        deliveryCode: null,
        deliveryName: null,
        deliverySn: null,
        remark: null,
        isDel: null,
        costPrice: null,
        verifyCode: null,
        shippingType: null,
        isChannel: null,
        isPrescribe: null,
        prescribeId: null,
        finishTime: null,
        deliveryTime: null,
        tuiMoney: null,
        tuiMoneyStatus: 0,
        tuiUserId: null,
        orderCreateType: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
   handleClickX(tab, event) {
    if(tab.name=="10"){
      this.queryParams.status=null;
    }else{
      this.queryParams.status=tab.name;
    }
     this.handleQuery();
   },
  changeTime(){
        if(this.createTime!=null){
          this.queryParams.sTime=this.createTime[0];
          this.queryParams.eTime=this.createTime[1];
        }else{
          this.queryParams.sTime=null;
          this.queryParams.eTime=null;
        }

      },
  changePayTime(){
      if(this.payTime!=null){
        this.queryParams.sTime=this.payTime[0];
        this.queryParams.eTime=this.payTime[1];
      }else{
        this.queryParams.paysTime=null;
        this.queryParams.payeTime=null;
      }

    },


    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
       this.createTime=null;
      this.queryParams.sTime=null;
      this.queryParams.eTime=null;
       this.payTime=null;
      this.queryParams.paysTime=null;
      this.queryParams.payeTime=null;
      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
      getOrder(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) {
            updateOrder(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderIds = row.orderId || this.ids;
      this.$confirm('是否确认删除订单编号为"' + orderIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delOrder(orderIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有订单数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportOrder(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
