import pick from 'lodash.pick'
import request from '@/utils/request'
import { upcloud_base_strategy } from "@/config/serviceSettings";

export const setwarehouse = {
  mounted() {
    this.SetWarehouse()
    this.aaa()
  },
  methods: {
    gettype(parameter) {
      //  批量录入销毁信息 POST
      return request({
        method: 'get',
        url: upcloud_base_strategy+'/registry/by-code',
        params: parameter
      })
    },
    SetWarehouse() {
      let warehouse = this.$store.state.user.warehouse
      console.log(this.$refs, '====')
      if (Object.keys(warehouse).length > 0) {
        // if (this.$refs.itemsRef) {
        this.$refs.form.form.setFieldsValue(pick(warehouse, 'warehouseId', 'warehouseCode', 'warehouseName'))
        // }
        // if (this.$refs.modelFormType) {
        //   this.$refs.modelFormType.form.setFieldsValue(pick(warehouse, 'warehouseId', 'warehouseCode', 'warehouseName'))
        // }
        // modelFormType
      }
    },
    async aaa() {
      let a = [
        { label: '待审核', value: '10' },
        { label: '通过', value: '20' },
        { label: '驳回', value: '30' }
      ]
      let b = [
        { label: '待审核', value: '10' },
        { label: '通过', value: '20' },
        { label: '驳回', value: '30' },
        { label: '销毁', value: '40' }
      ]
      let c = [
        { label: '待审核', value: '10' },
        { label: '通过', value: '20' },
        { label: '销毁', value: '40' }
      ]
      let d = [
        { label: '待审核', value: '10' },
        { label: '通过', value: '20' }
      ]
      let warehouseId = this.$refs.form.form.getFieldValue('warehouseId')
      //   console.log(warehouseId)
      if (warehouseId) {
        let items = this.tablecolumns.gridform.items
        let data = {
          regCode: 'WMS_GSP_UNQUALIFIED_CAN_AUDIT_NO',
          warehouseId
        }
        let res = await this.gettype(data)
        // console.log(res)
        if (res.data) {
          if (res.data.regValue == '1') {
            items.forEach(item => {
              if (item.name == 'status' && item.options.length == 4) {
                item.options = b
                this.$emit('SetRegvalue', true)
              } else if (item.name == 'status' && item.options.length == 3) {
                item.options = a
                this.$emit('SetRegvalue', true)
              }
            })
          } else {
            items.forEach(item => {
              if (item.name == 'status' && item.options.length == 4) {
                console.log(item, '===')
                item.options = c
                this.$emit('SetRegvalue', false)
              } else if (item.name == 'status' && item.options.length == 3) {
                console.log(item, '111')
                item.options = d
                this.$emit('SetRegvalue', false)
              }
            })
          }
        } else {
          items.forEach(item => {
            if (item.name == 'status') {
              item.options = b
              this.$emit('SetRegvalue', false)
            }
          })
        }
      }
      //   let a = [
      //     { label: '待审核', value: '10' },
      //     { label: '通过', value: '20' },
      //     { label: '驳回', value: '30' },
      //     { label: '销毁', value: '40' }
      //   ]
      //   let b = [
      //     { label: '待审核', value: '10' },
      //     { label: '通过', value: '20' },
      //     { label: '销毁', value: '40' }
      //   ]
      //   if (this.$refs.itemsRef) {
      //     let items = this.tablecolumns.gridform.items
      //     items.forEach(item => {
      //       if (item.name == 'status') {
      //         item.options = b
      //       }
      //     })
      //   }
    }
  }
}
