import API from '@/utils/sha256/myHttpClient'
const imInOutAssitApi = {
  data() {
    return {
      Global_data_select: {},
      summaryAttr: ['quantity', 'volumes', 'out_quantity', 'retreat_quantity', 'use_quantity', 'use_volume', 'total_volumn', 'volumn', 'arrive_count', 'supplementary', 'supplementary_rate', 'volume', 'quantity_box'], // 配置合计项
      page_sizes: this.$appConfig.pagination_page_sizes,
      querySkuBoolean: false,
      material_lot: [],
      dialogFormVisible: false,
      searchParams: {
        page: 1,
        per_page: 10
      },
      mesURL: '/mesAPI',
      sInDate: null,
      slStoreId: '',
      slStoreList: [],
      all_list: [],
      slSupplierList: [],
      sDataList: [],
      iPageDataCount: 0,
      sCreateDate: null,
      material_category_id: '', // 物料大类id
      material_category_type: '', // 物料大类的类型
      sDataList_all: [] // 物料大类的类型
    }
  },
  methods: {
    // 导出所有数据的xlxe
    exportExcel_all() {
      API.get(`${this.mesURL}/${this.material_category_type}/export_data/`).then(res => {
        this.all_list = res.data
        this.exportExcel(this.all_list)
      })
    },
    // 导出细码检验结果的文字转换
    check_result_item() {
      this.material_lot.map(item => {
        switch (item.check_result) {
          case '0':
            this.$set(item, 'check_result_item', '未检验')
            break
          case '1':
            this.$set(item, 'check_result_item', '合格')
            break
          case '-1':
            this.$set(item, 'check_result_item', '不合格')
            break
        }
      })
    },
    // 分页size cb
    handleSizeChange(pageSize) {
      this.searchParams.per_page = pageSize
      this.getDataList(true)
    },
    // 当前页 change cb
    handleCurrentChange(currentPage) {
      this.searchParams.page = currentPage
      this.getDataList(true)
    },
    // 获取sku详情
    querySku(row) {
      this.material_lot = []
      this.currentId = row[this.row_id]
      this.stockSkuQuery(row[this.row_id]).then((res) => {
        if (res.status === 200) {
          this.querySkuBoolean = true
          this.material_lot = res.data
        }
      })
    },
    // 获取数据列表
    getDataList(bPage) {
      if (!bPage) this.searchParams.page = 1
      this.searchParams.storage_id = this.slStoreId
      this.searchParams.start_date = this.sInDate === null ? '' : this.$pub_fun.getStringDate(this.sInDate[0])
      this.searchParams.end_date = this.sInDate === null ? '' : this.$pub_fun.getStringDate(this.sInDate[1])
      this.materialQuery(this.searchParams).then((res) => {
        this.sDataList = res.data.table
        this.iPageDataCount = res.data.paging.total
      })
    },
    // 获取仓库列表
    getStoreList() {
      this.slStoreList = []
      this.getStoreData().then((res) => {
        if (res.status !== 200) return
        res.data.forEach((i) => {
          this.slStoreList.push(i)
        })
      })
    },
    // 合计
    getSummaries(param) {
      const {
        columns,
        data
      } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        }
        this.summaryAttr.forEach(attr => {
          if (column.property === attr) {
            const values = data.map(item => Number(item[column.property]))
            if (!values.every(value => isNaN(value))) {
              sums[index] = values.reduce((prev, curr) => {
                const value = Number(curr)
                if (!isNaN(value)) {
                  return prev + curr
                } else {
                  return prev
                }
              }, 0)
              // sums[index] += ' '
            } else {
              sums[index] = '-'
            }
          }
        })
      })
      return sums
      // bill_dtl
    },
    // mes查询 获取列表
    materialQuery(param) {
      return API.get(`${this.mesURL}/${this.material_category_type}/`, {}, param)
    },
    // 获取仓库列表
    getStoreData(parm) {
      const routerParam = {
        routerUrl: 'store_id',
        data: {
          store_id: this.material_category_id
        }
      }
      return API.get(`${this.mesURL}/store/query_list/`, routerParam)
    },
    // mes 获取详细的数据
    stockSkuQuery(stockId) {
      // const routerParam = {}
      // if (this.get_one_id) {
      //   routerParam.routerUrl = this.get_one_id
      //   const datas = {}
      //   datas[this.get_one_id] = stockId
      //   routerParam.data = datas
      // } else {
      //   routerParam.routerUrl = 'id'
      //   routerParam.data = {
      //     id: stockId
      //   }
      // }
      const data = {
        serial_ids: stockId
      }
      return API.post(`${this.mesURL}/${this.material_category_type}/`, {}, {}, data)
    }
    // 修改数据，生产线
  }
}
export default imInOutAssitApi
