<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="searchData.id" placeholder="请输入合并订单" class="filter-item" />
      <el-select v-model="searchData.type" class="filter-item" filterable clearable placeholder="请选择合并类型">
        <el-option v-for="item in mergeType" :key="item.F_Value" :label="item.F_Value" :value="item.F_Value"/>
      </el-select>
      <el-button type="primary" class="filter-item" icon="el-icon-search" @click="btn_search">搜索</el-button>
    </div>
    <el-tabs v-model="activeName" type="card" @tab-click="handleTabClick" >
      <el-tab-pane label="全部" name="-2"></el-tab-pane>
      <el-tab-pane label="无效" name="-1"></el-tab-pane>
      <el-tab-pane label="暂存" name="0"></el-tab-pane>
      <el-tab-pane label="提交" name="1"></el-tab-pane>
      <el-tab-pane label="退回" name="2"></el-tab-pane>
      <el-tab-pane label="通过" name="3"></el-tab-pane>
    </el-tabs>
    <el-table v-loading="loading" :data="dataLists" border stripe  @selection-change="handleSelectionChange">
      <el-table-column type="selection"></el-table-column>
      <el-table-column type="index" label="编号" align="center" fixed width="80" />
      <el-table-column prop="F_OrderList" label="合并订单" align="center" min-width="180" />
      <el-table-column prop="F_Type" label="合并类型" align="center" />
      <el-table-column prop="F_Gift" label="赠送商品" align="center" />
      <el-table-column prop="F_AddTime" label="下单日期" align="center" />
      <el-table-column label="订单状态" align="center" >
        <template slot-scope="scope">
          {{ scope.row.F_State | judgmentStateName }}
        </template>
      </el-table-column>
      <el-table-column prop="F_AddUserName" label="下单员工" align="center" />
      <el-table-column label="操作" width="240" align="center" class-name="oparate_btn" fixed="right">
        <template slot-scope="scope">
          <el-button v-permission="'HY_audit'" type="text" v-if="isadopt(scope.row.F_State)" @click="btn_audit(scope.row.F_Id)">审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="pageParams.total > 0"
      :total="pageParams.total"
      :pageindex.sync="pageParams.pageindex"
      :pagesize.sync="pageParams.pagesize"
      class="pagination"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getDictionaryValueList } from '@/api/commonAPI'
import { getConsolidateOrderList, deleteConsolidateOrderList } from "@/api/orderManagement/consolidateOrderList";
import { getConsolidateOrderListCustomerService } from "@/api/customerServiceManagement/orderListCustomerService";
import { pickerOptions, formatterContent } from "@/utils";
import Pagination from "@/components/Pagination"; // 对el-pagination 二次封装
import audit from "./audit"

export default {
  name: "ConsolidateOrderListCustomerService",
  components: {
    Pagination
  },
  filters: {
    judgmentStateName(status) {
      const statusMap = {
        '-1': '无效',
        '0': '暂存',
        '1': '提交',
        '2': '退回',
        '3': '通过',
        '4': '无货',
        '5': '已分拣',
        '6': '已发货'
      }
      return statusMap[status]
    },
  },
  data() {
    return {
      loading: false,
      searchData: {
        adFrom: '', //消息/广告媒体来源
        type: '', //订单类型
        id: '', //订单号
      },
      activeName: "-2", //标签切换首页
      pickerOptions, // 日期数据
      pageParams: {
        pageindex: 1, // 当前第几页
        pagesize: Number(this.$store.getters.serverConfig.PAGESIZE), // 每页几条数据
        total: 0 // 总共多少数据
      },
      dataLists: [], // 列表数据
      multipleSelection: [], // 选中的数据
      selectedId: [], // 选中的数据的id
      mergeType: [],//合并类型
    };
  },
  created() {
    this.getOrderType()
    this.getList()
    document.onkeyup = e => {
      if (e.keyCode === 13) {
        this.getList();
      }
    };
  },
  methods: {
    getList() {
      this.loading = true;
      return new Promise(resolve => {
        const params = {
          F_State: this.activeName, //订单状态
          pageindex: this.pageParams.pageindex, // int 第几页
          pagesize: this.pageParams.pagesize, // int 每页几条信息
          F_OrderList: this.searchData.id,
          F_Type: this.searchData.type
        };
        getConsolidateOrderListCustomerService(params).then(response => {
          this.loading = false;
          if (response.state.toLowerCase() === "success") {
            this.pageParams.total = response.data.Totals;
            this.dataLists = response.data.Rows;
          }
        });
        resolve();
      });
    },
    // 获取合并类型
    getOrderType() {
      return new Promise(resolve=>{
        const params={
          isleaf:true,
          code:'MERGETYPE'
        }
        getDictionaryValueList(params).then(response=>{
          if(response.state.toLowerCase() === 'success'){
            this.mergeType = response.data.Rows
          }
        })
      })
    },
    handleTabClick(tab, event) {
      this.getList()
    },
    //合并订单审核
    btn_audit(auditId) {
      this.$layer.iframe({
        content: {
          content: audit, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { rowid: auditId } // props
        },
        area: ["30%", "30%"],
        title: "合并订单审核"
      });
    },
    btn_search() {
      this.pageParams.pageindex = 1;
      this.getList();
    },
    //权限设置
    isadopt(state){
      if(state==3){
        return false
      }else{
        return true
      }
    },
    //选择多个
    handleSelectionChange(val) {
      const ids = []
      this.multipleSelection = val
      for (let i=0; i<this.multipleSelection.length; i++) {
        ids.push(this.multipleSelection[i].id)
      }
      this.selectedPhone = ids;
    }, 
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.el{
  cursor: pointer;
}
</style>
