/**
 * @param {*} self vue
 * @returns tableConfig
 */
const setQueryFormItmes = (self) => {
  let options= [
    { label: "小程序", value: "wechat" },
    { label: "设备", value: "device" },
  ]
  if (self.$auth('deviceLink')) {
    options.push({ label: "设备直连", value: "deviceLink" })
  }
  return [
    {
      name: 'carNumber', label: '车牌号', type: 'input',
      value: process.env.NODE_ENV === 'development' ? '鄂AZF288' : ''
    },
    {
      //  车牌号   鄂A10005   手机号  13667200006
      name: 'mobilePhone', label: '司机手机号', type: 'input',
      value: process.env.NODE_ENV === 'development' ? '' : ''
    },
    self.type === 'path' && {
      label: '日期',
      name: 'date',
      required: true,
      type: 'a-range-picker',
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      showTime:true,
      value: [self.moment().startOf('day').format('YYYY-MM-DD HH:mm:ss'), self.moment().endOf('day').format('YYYY-MM-DD HH:mm:ss')],
      placeholder: ['开始时间', '结束时间']

    },
    {
      type: "radio",
      name: "urlType",
      label: "",
      value: "wechat",
      options,

    },
  ].filter(item => item)
}
import { UPCLOUD_RDC_TMS_BUSINESS_SERVICE } from '@/config/serviceSettings.js'

import { getLocationMapData,getPathMapData } from '../js/api.js'
export default {
  data() {
    return {
      mx_queryFromItems: setQueryFormItmes(this),
    }
  },
  methods: {
    getFieldsValue() {
      return this.$refs.searchBar.getFieldsValue()
    },
    searchSubmit(data) {
      if (data.date) {
        data.startDate = data.date[0]
        data.endDate = data.date[1]
      }
      delete data.date
      const { carNumber, mobilePhone } = data
      if (!carNumber && !mobilePhone) {
        return this.$exception({
          message: '车牌号、司机手机号不能同时为空',
          code: 200
        })
      }
      this.mapData = null
      this.$refs.mainTable.dataSource=[]
      if (this.type == 'path') {
        this.mode !== 3 && this.$refs.mainTable.reload({ data });
        this.$refs.mainTable.$refs.mainTable.vLoading = true
        getPathMapData(this, data).then(response => {
          if (response.success) {
             this.mapData = {
              tmsVehicleGpsDTOList:response.data,
              desc:null,
             };
            if (this.mode === 3) {
              this.$refs.mainTable.dataSource = response.data
            }
           } else {
             this.mapData = null
             this.$message.error(response.message);
          }
        }).finally(() => {
          this.confirmLoading = false
          this.$refs.mainTable.$refs.mainTable.vLoading = false
          this.$nextTick(() => {
            this.$refs.mainTable.$forceUpdate()
          })

        })
      } else if (this.type == 'location') {
        this.confirmLoading = true
        getLocationMapData(this, data).then(response => {
          if (response.success) {
              this.mapData = response.data
              this.$refs.mainTable.reload({ data });
              this.$refs.shipBillTable.reload({
                url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE + '/inTransit/position/getPositionShipBill',
                data
              });
          } else {
            this.$message.error(response.message);
          }
        }).finally(() => {
          this.confirmLoading = false
        })
      }



    },
  }
}
