/** pubConsignor货主弹出查询配置 */
import axios from '@/utils/request'

export function getZone(fatherid = '01') {
  let _this = this
  return axios({
    url: '/api/oms-std-maindata/zone/get-by-pid',
    method: 'post',
    data: {
      fatherid
    }
  }).then(respose => {
    if (respose.success) {
      respose.data.forEach(item => {
        if (item.zlevel < 4) {
          item.isLeaf = false
        } else {
          item.isLeaf = true
        }
      })
      return respose.data
    } else {
      _this.$error(respose.message)
    }
  })
}
//商品选择setPopupIteminfo

// cascader-zone
export function setAddress(obj) {
  let baseObject = { itemcode: true, label: '选择线路', remoteData: {}, required: false, ...obj }
  let { options, change, loadData, itemcode, label, remoteData, search, ok, required } = baseObject
  this.zoneOptions = []
  let _this = this
  return [
    {
      type: (h, context, form) => {
        const { on } = context
        let name = context.directives[0].value[0]
        return h('p-cascader', {
          props: {
            options: context.props.options,
            showSearch: true,
            placeholder: '省/市/区',
            changeOnSelect: true,
            fieldNames: { label: 'zname', value: 'zoneid', children: 'children' },

            loadData: selectedOptions => {
              const targetOption = selectedOptions[selectedOptions.length - 1]
              targetOption.loading = true
              getZone(targetOption.zoneid).then(data => {
                targetOption.loading = false
                targetOption.children = data
                form.vNodeItems[name].$emit('loadData', context.props.options)
              })
            }
          },
          on
        })
      },
      label,
      on: {
        change,
        loadData
      },
      options,
      required,
      value: [],
      name: ' '
    }
  ]
}

//export default { setAddress, getZone }
