<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :top-list="topList"
      :moren="defaultSelected"
    />
    <div class="thetopbox">
      <el-form label-width="100px">
        <el-row>
          <el-col :span="4">
            <el-form-item label="订单号" prop="orderCode">
              <el-input v-model="select.orderCode" clearable />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="4">
            <el-form-item label="产品名称" prop="productName">
              <el-input v-model="select.productName" clearable />
            </el-form-item>
          </el-col> -->

          <el-col :span="8">
            <el-form-item label="时间范围" prop="timeRange">
              <el-date-picker
                v-model="timeRange"
                value-format="yyyy-MM-dd"
                type="daterange"
                clearable
                :range-separator="'至'"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                @change="timeRangeHandleChange"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <div class="searchbox">
              <el-button
                class="my_search"
                @click="
                  () => {
                    getSearch();
                    resetPageNum();
                  }
                "
              >
                {{ '搜索' }}</el-button>
              <el-button class="my_reset" @click="resetHandle">
                {{ '重置' }}</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="main">
      <div class="maintop" />
      <div class="maintable">
        <el-table
          v-loading="loading"
          :data="tableData"
          height="700px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          @selection-change="handleSelectionChange"
        >
          <el-table-column
            align="center"
            prop="orderCode"
            label="订单号"
            width="180px"
          />

          <el-table-column
            align="center"
            prop="orderProductDetail"
            label="产品明细列表"
          >
            <template slot-scope="scope">
              <div v-for="item in scope.row.orderProductDetail" :key="item.pkId">
                <span style="font-size: 12px;">仓储编号：{{ item.wmsCode }} </span>
                <span style="margin-left: 8px; font-size: 12px;">变动数量：{{ item.changeNum }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="statusVal"
            label="同步状态"
            width="80px"
          />

          <el-table-column
            align="center"
            prop="creationTime"
            label="创建时间"
            width="170px"
          />
          <el-table-column
            align="center"
            prop="colsele"
            label="操作"
            width="100px"
          >
            <template slot-scope="scope">
              <el-button
                v-if="scope.row.status === 1"
                v-hasButtons="['WholeNetworkOrderSyncFailUpdate']"
                type="text"
                size="small"
                style="color: #48b2fd; padding: 0"
                @click="handleProcessed(scope.row)"
              >
                手动处理
              </el-button>

            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getSearch"
    />

  </div>
</template>

<script>
import { getOrderSyncFailList, updateOrderSyncStatus } from '@/api/wholeNetwork/orderSync'
import topBar from '@/components/topBar'
const initSearch = {
  ordeCode: ''
}
export default {
  name: 'WholeNetworkOrderSyncFail',
  components: {
    topBar
  },
  data() {
    return {
      defaultSelected: 'orderSyncFail',
      topList: [
        {
          name: '同步失败订单',
          path: 'orderSyncFail'
        }
      ],
      tableData: [],
      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 50
      },
      timeRange: [
      ],
      select: {
        ...initSearch
      },
      total: 0,
      multipleSelection: [],
      updateDialogVisible: false,
      isEdit: false,
      productInfo: {
        remark: ''
      },
      updateInventoryVisible: false,
      inventoryInfo: {
        inventory: ''
      }
    }
  },
  created() {
    this.getSearch()
  },
  methods: {
    handleProcessed({ pkId }) {
      this.$confirm('是否确认手动处理该订单?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then((_) => {
        updateOrderSyncStatus({ pkId, status: 0 }).then((res) => {
          if (res.code === 200) {
            this.$message.success('手动处理成功')
            this.getSearch()
          }
        })
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    timeRangeHandleChange(timeRange) {
      this.queryParams.startDate = timeRange?.[0] || null
      this.queryParams.endDate = timeRange?.[1] || null
    },
    resetHandle() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 50
      }
      this.timeRange = []

      this.select = {
        ...initSearch

      }
      this.getSearch()
    },
    getSearch() {
      this.loading = true
      const params = {
        ...this.queryParams,
        ...this.select
      }
      getOrderSyncFailList(params).then((res) => {
        this.loading = false
        if (res.code === 200) {
          this.tableData = res.rows
          this.total = res.total
        }
      })
    },
    resetPageNum() {
      this.queryParams.pageNum = 1
    }
  }
}
</script>

      <style lang="scss" scoped>
::v-deep .el-image-viewer__close {
  right: 500px;
}
::v-deep .dizhi .el-cascader {
  width: 100%;
}
::v-deep .el-range-editor.el-input__inner {
  width: 100%;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}
.page {
  padding: 10px 20px;
  background: #f9f9f9;
  font-size: 14px;
  .thetopbox {
    padding: 15px 20px 15px 0;
    background: #ffffff;
    border-radius: 8px;
    .searchbox {
      display: flex;
      align-items: center;
      margin-left: 40px;
    }
    .searchtitle {
      margin-right: 10px;
    }
    .searchbtn {
      background: #08143f;
      color: #ffffff;
    }
  }
  .main {
    //margin-top: 20px;
    background: #f9f9f9;
    //border-radius: 8px;
    //box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);

    .maintop {
      display: flex;
      // padding: 10px 0;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          color: #ffffff;
          background: #ffad41;
          width: 68px;
          height: 32px;
        }
        .thebtn2 {
          color: #ffffff;
          background: #009b58;
          width: 68px;
          height: 32px;
        }
        .thebtn3 {
          color: #ffffff;
          background: #c8161d;
          width: 68px;
          height: 32px;
        }
      }
    }
  }
}
</style>
