<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="companyName" />
        <el-table-column label="员工" align="center" prop="companyUserName" />
        <el-table-column label="就诊人" align="center" prop="patientName" />
        <el-table-column label="应收金额" align="center" prop="payPrice" />
        <el-table-column label="实收金额" align="center" prop="payMoney" />
        <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="createTime" width="180" />
          <el-table-column label="支付时间" align="center" prop="payTime" width="180" />
          <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="deliveryStatus" >
         <template slot-scope="scope">
               <dict-tag :options="deliveryStatusOptions" :value="scope.row.deliveryStatus"/>
          </template>
       </el-table-column>
      <el-table-column label="结算状态" align="center" prop="deliveryPayStatus" >
        <template slot-scope="scope">
              <dict-tag :options="deliveryPayStatusOptions" :value="scope.row.deliveryPayStatus"/>
         </template>
      </el-table-column>
    </el-table>

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



  </div>
</template>

<script>
import { userOrderList, getOrder, delOrder, addOrder, updateOrder, exportOrder,importTemplate } from "@/api/store/storeOrder";
import { getToken } from "@/utils/auth";
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:[],
       deliveryStatusOptions:[],
      deliveryPayStatusOptions:[],
      deliveryTypeOptions:[],
       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;
        });
        this.getDicts("sys_store_delivery_pay_status").then(response => {
             this.deliveryPayStatusOptions = response.data;
           });
       this.getDicts("sys_store_order_delivery_status").then(response => {
             this.deliveryStatusOptions = response.data;
           });
        this.getDicts("sys_delivery_type").then(response => {
              this.deliveryTypeOptions = response.data;
            });

  },
  methods: {
    getUserDetails(id){
      this.queryParams.userId=id
      this.getList();
    },


    /** 查询订单列表 */
    getList() {
      this.loading = true;
      userOrderList(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>
