import { UPCLOUD_RDC_TMS_MAINDATA_SERVICE, UPCLOUD_RDC_TMS_BUSINESS_SERVICE } from '@/config/serviceSettings.js';

export default {
  components: {
    searchBar: require(/* webpackChunkName: "[request]" */ '../searchBar/index.searchBar.vue').default,
    // planCalendar: require(/* webpackChunkName: "plan-calendar" */ '../../../../../blocks/components/planCalendar/index.vue').default,
    // mainTable: require('../mainTable/index.mainTable.vue').default,
    orderView: () => import(/* webpackChunkName: "components-orderView" */ '@/blocks/components/orderView/index.orderView.vue'),
  },
  data() {
    return {
      mainId: '',
      mainCurrent: null,
      mainsSelectedRowKeys: [],
    }
  },

  methods: {
    searchSubmit(data) {
      this.$refs.mainTable.reload({ data })
    },
    clearChildrenTableAll(isClearCurrent = false) {
      if (isClearCurrent) {
        this.mainCurrent = null
        this.mainId = ''
      }
      const {  parcelTable, shipbillTable, shipmentsTable, stockUpTable, closeTable,evaluateTable } = this.$refs
      let arr = [ parcelTable, shipbillTable, shipmentsTable, stockUpTable, closeTable,evaluateTable]
      arr.forEach((item) => {
        if (item) {
          item.dataSource = []
        }
      });
    },
    onBack(formName, id, isReload) {
      this.lastDetailsState = 0
      this.detailsState = 0
      this.currentMainData = null

      if (isReload) {
        if (this.$refs.childrenTable) {
          this.$refs.childrenTable.dataSource = []
        }
        this.clearChildrenTableAll()
        this.$refs[formName + 'Table'].reload().then(() => {
          if (id) {
            if (formName == 'main') {
              this.mainId = id
            } else {
              this.childrenId = id
            }
          }
        })
      }
    },
    handleView(data) {
      this.detailsState = 1;
      this.mainCurrent = data;
      this.card_title = '计划单查看'

      // let routeUrl = this.$router.resolve({
      //   path: '/localDetails',
      //   query: { shipbillId:data.shipbillId, messageType:null },
      // });
      // return window.open(routeUrl.href, '_blank');
    },
    handPrint(data) {
      let _this = this;
      let confirmLoading = true;
      return new Promise((resolve) => {
        _this.$confirm({
          title: '是否打印订单？',
          confirmLoading,
          onOk() {
            confirmLoading = true;
            return _this
              .axios({
                url: UPCLOUD_RDC_TMS_BUSINESS_SERVICE + '/allShipbill/print',
                method: 'post',
                data: { shipbillIds: data || _this.mainsSelectedRowKeys },
              })
              .then((response) => {
                if (response.success) {
                  _this.$message.success(response.message)
                  // let ulr = response.data.url.split(',')
                  // ulr = ulr.map(str => window.location.origin + str)
                  // response.data.url=ulr.join(',')

                  response.data.url=window.location.origin+response.data.url
                  return _this.axios({
                    url: 'http://127.0.0.1:6060/print',
                    method: 'post',
                    data:response.data
                  })

                } else {
                  _this.$exception(response);
                }
              })
              .finally(() => {
                confirmLoading = false;
              });
          },
        });
      });

      console.log(url);
    },
    viewRemoteBefore(vnode, config) {
      config.data.shipbillIds = [config.data.shipbillId]
      delete config.data.shipbillId
    },
  },
}
