<template>
  <div  style="background-color: #f0f2f5; padding-bottom: 20px; min-height: 100%; ">
    <div style="padding: 20px; background-color: #fff;">
      订单列表
    </div>
    <div class="my-content"  >
      <el-tabs type="card" v-model="actName" @tab-click="tabClick">
        <el-tab-pane label="全部订单" name="0"></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 border v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="订单号" align="center" prop="orderCode" width="180px"/>
        <el-table-column label="店铺" align="center" prop="storeName" />
        <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="companyName" width="180" />
        <!--<el-table-column label="员工" align="center" prop="companyUserName" width="180" />-->
        <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" class-name="small-padding fixed-width" fixed="right" width="100px">
          <template slot-scope="scope">
            <el-button
                      size="mini"
                      type="text"
                      @click="handledetails(scope.row)"
                    >查看
            </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"
      />
    </div>


   <el-drawer

        append-to-body
        :with-header="false"
        size="75%"
         :title="show.title" :visible.sync="show.open">
     <storeOrderDetails  ref="Details" />
   </el-drawer>
  </div>
</template>

<script>
import { getStoreOrderById, getMyStoreOrderList} from "@/api/storeOrder";
import storeOrderDetails from './storeOrderDetails.vue';
import { getToken } from "@/utils/auth";
export default {
  name: "Order",
  components: { storeOrderDetails },
  data() {
    return {
      actName:"10",
      show:{
        title:"订单详情",
        open:false,
      },
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      createTime:null,
      payTime:null,
      deliverySendTime: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,
        companyUserName:null,
        companyName:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      orderOptions:[],
      deliveryStatusOptions:[],
    };
  },
  created() {
    this.getDicts("sys_order_status").then(response => {
      this.orderOptions = response.data;
    });

    this.getDicts("sys_store_order_delivery_status").then(response => {
      this.deliveryStatusOptions = response.data;
    });
  },
  methods: {
    handledetails(row){
      this.show.open=true;
      setTimeout(() => {
            this.$refs.Details.getDetails(row.orderId,row.nickName,row.storeName);
      }, 1);
    },
    getData(userId){
      this.queryParams.userId=userId
      this.getList();
    },
    /** 查询订单列表 */
    getList() {
      this.loading = true;
      getMyStoreOrderList(this.queryParams).then(response => {
        this.orderList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });

    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    tabClick(tab, event) {
      if(tab.name=="0"){
        this.queryParams.status=null;
      }else{
        this.queryParams.status=tab.name;
      }
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orderId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
  }
};
</script>
<style lang="scss" scoped>
.my-content{
    background-color: #fff;
    padding: 20px;
    margin: 20px;
    .my-title{
      margin-bottom: 20px;
      color: #524b4a;
      font-weight: bold;
    }

}
.el-descriptions-item__label.is-bordered-label{
  font-weight: normal;
}
.el-descriptions-item__content {
  max-width: 500px;
  min-width: 100px;
}
</style>

