<template>
  <div class="mod-config">
    <el-form style="display: flex; align-items: center; justify-content: right;" :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-select size="small" v-model="dataForm.idenCardNum" filterable placeholder="标识卡号">
          <el-option
            v-for="item in options1"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-select size="small" v-model="dataForm.orderNo" filterable placeholder="订单号">
          <el-option
            v-for="item in options2"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button size="small" @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      :stripe="true"
      :header-cell-style="{background:'#eef1f6',color:'#606266',height: '56px'}"
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        type="index"
        header-align="center"
        align="center"
        label="序号"
        width="50">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="获取时间">
      </el-table-column>
      <el-table-column
        prop="idenCardNum"
        label="标识卡号">
      </el-table-column>
      <el-table-column
        prop="orderNo"
        label="订单号">
      </el-table-column>
      <el-table-column
        prop="abeginTime"
        label="发起时间">
      </el-table-column>
      <el-table-column
        prop="aendTime"
        label="完成时间">
      </el-table-column>
      <!-- <el-table-column
        prop="orderSource"
        header-align="center"
        align="center"
        label="任务来源">
      </el-table-column> -->
      <el-table-column
        prop="status"
        label="任务状态">
        <template slot-scope="scope">
          {{ scope.row.status >= 0 ? statusList[scope.row.status] : '' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="orderVoid"
        label="订单状态">
        <template slot-scope="scope">
          {{ scope.row.orderVoid >= 0 ? orderVoidList[scope.row.orderVoid] : '' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="customerName"
        label="客户名称">
      </el-table-column>
      <el-table-column
        prop="productName"
        label="产品名称">
      </el-table-column>
      <el-table-column
        prop="materialDes"
        label="材料号牌">
      </el-table-column>
      <el-table-column
        prop="quantity"
        label="数量">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="80"
        label="任务详情">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="LocationBtn(scope.row.idenCardNum,scope.row.orderNo)">任务详情</el-button>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="80"
        label="订单详情">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">订单详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <order-detail v-if="orderDetailVisible" ref="orderDetail"></order-detail>
  </div>
</template>

<script>
  import orderDetail from './components/order-history-detail'
  // 任务状态列表
  const statusList = {
    0: '等待执行',
    1: '执行中',
    2: '执行完成',
    3: '追加后完成'
  }
  // 订单状态列表
  const orderVoidList = {
    0: '不可用',
    1: '可用',
    2: '停止'
  }

  export default {
    data () {
      return {
        dataForm: {
          idenCardNum: '',
          orderNo: ''
        },
        dataList: [],
        options1: [],
        options2: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        orderDetailVisible: false,
        statusList,
        orderVoidList
      }
    },
    components: {
      orderDetail
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/orderInfoHis/page'),
          method: 'post',
          data: this.$http.adornData({
            'current': this.pageIndex,
            'size': this.pageSize,
            'idenCardNum': this.dataForm.idenCardNum,
            'orderNo': this.dataForm.orderNo
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.data.records
            this.totalPage = data.data.total
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.orderDetailVisible = true
        this.$nextTick(() => {
          this.$refs.orderDetail.init(id)
        })
      },
      LocationBtn (idenCardNum, orderNo) {
        this.$router.push({name: 'report-order-history-task', query: {idenCardNum, orderNo}})
      }
    }
  }
</script>
