<template>
  <div class="mod-config">
    <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 0px;">
      <el-form-item :label="'SKU:'">
        <el-input v-model="searchData.sku"  ></el-input>
      </el-form-item>
      <el-form-item :label="'SO:'">
        <el-input v-model="searchData.so"  ></el-input>
      </el-form-item>
      <el-form-item :label="' '" >
        <el-button @click="searchTable()" type="primary" style="margin-left: 2px;margin-top: 0px">{{'查询'}}</el-button>
        <el-button @click="importModel()" type="primary" style="margin-left: 2px;margin-top: 0px">{{'导入'}}</el-button>
        <el-button @click="newModelOpen()" type="primary" style="margin-left: 2px;margin-top: 0px">{{'新增'}}</el-button>
      </el-form-item>
    </el-form>

    <el-table
      @row-click="changeData"
      highlight-current-row
      :height="height"
      :data="dataList"
      ref="mainTable"
      border
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        header-align="center"
        align="center"
        width="100"
        fixed="left"
        label="操作">
        <template slot-scope="scope">
          <a type="text" size="small"  @click="updateModelOpen(scope.row)">编辑</a>
          <a type="text" size="small"  @click="deleteWalMartOrder(scope.row)">删除</a>
        </template>
      </el-table-column>
      <el-table-column
        v-for="(item,index) in columnList1" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed==''?false:item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <span v-if="!item.columnHidden"> {{scope.row[item.columnProp]}}</span>
          <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                             style="width: 100px; height: 80px"/></span>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[20, 50, 100, 1000]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <el-dialog title="沃尔玛信息维护" :close-on-click-modal="false" v-drag :visible.sync="addModelFlag" width="500px">
      <el-form  label-position="top"  style="margin-left: 2px;margin-top: -5px;">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="'SKU'" >
              <el-input v-model="addModel.sku"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'SO'" >
              <el-input v-model="addModel.so"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'数量'" >
              <el-input v-model="addModel.qty"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'卷数'" >
              <el-input v-model="addModel.rolls"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'重量'" >
              <el-input v-model="addModel.grossWeight"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'核销单号'" >
              <el-input v-model="addModel.verificationSheet"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="saveWalMartOrder()">保存</el-button>
        <el-button type="primary" @click="addModelFlag=false">关闭</el-button>
      </el-footer>
    </el-dialog>
    <!-- 导入 -->
    <wal-upload-excel ref="walUploadExcel" @refreshTable="searchTable" v-drag></wal-upload-excel>
    <!--列表的组件-->
    <Chooselist ref="baseList" @getBaseData="getBaseData"></Chooselist>
  </div>
</template>

<script>
import walUploadExcel from "./walmart_upload_excel.vue";
  import Chooselist from '@/views/modules/common/Chooselist_eam'
  import {} from "@/api/sysLanguage.js"
  import {
    searchWalMartOrderData,
    saveWalMartOrderData,
    deleteWalMartOrder,
  }from "@/api/ecss/ecss.js"
  export default {
    name: "null",
    components:{
      walUploadExcel,
      Chooselist,
    },
    data() {
      return {
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        height: 200,
        buList:[],
        dataList:[],
        dataListLoading: false,
        searchData: {
          page: 1,
          limit: 100,
          buNo:'',
          sku:'',
          so:'',
        },
        buttons:{
          search:'查询',
        },
        addModelFlag:false,
        addModel:{
          addFlag:0,
          site:'',
          buNo:'',
          sku:'',
          so:'',
          qty:'',
          rolls:'',
          grossWeight:'',
          verificationSheet:'',
        },
        addDisabledFlag:true,
        activeName:'attribute',
        columnList1: [
          {
            userId: this.$store.state.user.name,
            functionId: 801007,
            serialNumber: '801007Table1BuDesc',
            tableId: "801007Table1",
            tableName: "WalMartOrder基础信息",
            columnProp: "sku",
            headerAlign: "center",
            align: "center",
            columnLabel: "SKU",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801003,
            serialNumber: '801007Table1WalMartOrderNo',
            tableId: "801007Table1",
            tableName: "WalMartOrder基础信息",
            columnProp: "so",
            headerAlign: "center",
            align: "center",
            columnLabel: "SO",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 160
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801003,
            serialNumber: '801007Table1WalMartOrderType',
            tableId: "801007Table1",
            tableName: "WalMartOrder基础信息",
            columnProp: "qty",
            headerAlign: "center",
            align: "center",
            columnLabel: "数量",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801003,
            serialNumber: '801007Table1WalMartOrderType',
            tableId: "801007Table1",
            tableName: "WalMartOrder基础信息",
            columnProp: "rolls",
            headerAlign: "center",
            align: "center",
            columnLabel: "卷数",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801003,
            serialNumber: '801007Table1WalMartOrderType',
            tableId: "801007Table1",
            tableName: "WalMartOrder基础信息",
            columnProp: "grossWeight",
            headerAlign: "center",
            align: "center",
            columnLabel: "重量(KG)",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801003,
            serialNumber: '801007Table1WalMartOrderType',
            tableId: "801007Table1",
            tableName: "WalMartOrder基础信息",
            columnProp: "verificationSheet",
            headerAlign: "center",
            align: "center",
            columnLabel: "核销单号",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801003,
            serialNumber: '801007Table1CreateBy',
            tableId: "801007Table1",
            tableName: "WalMartOrder基础信息",
            columnProp: "createBy",
            headerAlign: "center",
            align: "center",
            columnLabel: "创建人",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801003,
            serialNumber: '801007Table1CreateDate',
            tableId: "801007Table1",
            tableName: "WalMartOrder基础信息",
            columnProp: "createDate",
            headerAlign: "center",
            align: "center",
            columnLabel: "创建日期",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 140
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801003,
            serialNumber: '801007Table1UpdateBy',
            tableId: "801007Table1",
            tableName: "WalMartOrder基础信息",
            columnProp: "updateBy",
            headerAlign: "center",
            align: "left",
            columnLabel: "修改人",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801003,
            serialNumber: '801007Table1UpdateDate',
            tableId: "801007Table1",
            tableName: "WalMartOrder基础信息",
            columnProp: "updateDate",
            headerAlign: "center",
            align: "center",
            columnLabel: "修改日期",
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 140
          },
        ],
        currentRow:{},
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.height = (window.innerHeight - 200);
      })
    },
    methods: {
      // 获取基础数据列表S
      getBaseList(val, type) {
        this.tagNo = val
        this.$nextTick(() => {
          let strVal = ''
          if (val === 33) {
            strVal = this.addModel.codeNo
          }
          this.$refs.baseList.init(val, strVal)
        })
      },

      /* 列表方法的回调 */
      getBaseData(val) {
        if (this.tagNo === 33) {
          this.addModel.codeNo = val.Code_No
        }
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.searchTable()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.searchTable()
      },
      searchTable(){
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        searchWalMartOrderData(this.searchData).then(({data}) => {
          //区分请求成功和失败的状况
          if (data && data.code == 0) {
            this.dataList = data.page.list
            this.pageIndex = data.page.currPage
            this.pageSize = data.page.pageSize
            this.totalPage = data.page.totalCount
            if(this.dataList.length>0){
              this.$refs.mainTable.setCurrentRow(this.dataList[0]);
              this.changeData(this.dataList[0])
            }else {
              this.changeData(null)
            }
          } else {
            this.dataList = [];
          }
        });
      },
      changeData(row){
        this.currentRow = JSON.parse(JSON.stringify(row));
        this.headerData=row;
        this.refreshCurrentTabTable ();
      },
      refreshCurrentTabTable(){
        if(this.currentRow===''||this.currentRow===null){
          this.currentRow={site:'',hsCode:'',buNo:'',recordType:'',codeNo:''}
        }
      },
      tabClick (tab, event) {
        // 刷新列表数据
        this.refreshCurrentTabTable()
      },

      getBu () {
        let tempData = {
          username: this.$store.state.user.name,
        }
        getBuList(tempData).then(({data}) => {
          if (data.code === 0) {
            this.buList = data.row2
          }
        })
      },
      newModelOpen(){
        this.addDisabledFlag=false
        this.addModel={
          addFlag:0,
          site:'',
          buNo:'03-RFID',
          sku:'',
          so:'',
          qty:'',
          rolls:'',
          grossWeight:'',
          verificationSheet:'',
        }
        this.addModelFlag=true
      },
      updateModelOpen(row){
        this.addDisabledFlag=false
        this.addModel={
          addFlag:1,
          site:row.site,
          buNo:row.buNo,
          sku:row.sku,
          so:row.so,
          qty:row.qty,
          rolls:row.rolls,
          grossWeight:row.grossWeight,
          verificationSheet:row.verificationSheet,
        }
        this.addModelFlag=true
      },
      deleteWalMartOrder(row){
        this.$confirm('确认删除？', '提示').then(() => {
          deleteWalMartOrder(row).then(({data}) => {
            if (data && data.code === 0) {
              this.searchTable()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        })
      },
      saveWalMartOrder(){
        if(this.addModel.sku==null||this.addModel.sku===''){
          this.$alert('请输入SKU！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        saveWalMartOrderData(this.addModel).then(({data}) => {
          if (data && data.code === 0) {
            this.searchTable()
            this.addModelFlag = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      importModel(){
        this.$nextTick(() => {
          this.$refs.walUploadExcel.init()
        })
      },
    },
    activated() {
      this.searchTable()
    },
    created() {
      this.getBu ()
    }
  }
</script>

<style scoped>

</style>
