<template>
  <div>
    <detail-template 
    :headData="mainAreaData" 
    :title="'订单号:'+orderData.sonum" 
    :tabs="['订单明细','订单进度','发货单','收支明细','出库单','物流单']" 
    :delParam="{id:'20221108152102',content:{sa_orderids:[router.currentRoute.value.query.id]}}" 
    ownertable="sa_order" 
    :disable="utils.isDisabled(orderData.status,[],(orderData.status !== '新建'))"
    >
      <template #operation>
        <a-space>
          <a-dropdown v-if="utils.hasPermission('changeClass')" :disabled="utils.isDisabled(orderData.status,['审核','新建','关闭','手工关闭'])">
            <template #overlay>
              <a-menu @click="handleMenuClick">
                <a-menu-item v-for="(item, index) in mxList" :key="item.value">
                  {{item.value}}
                </a-menu-item>
              </a-menu>
            </template>
            <a-button>
              分类调整
            </a-button>
          </a-dropdown>
          <abstract v-if="utils.hasPermission('abstract')" :disabled="utils.isDisabled(orderData.status,[''],(orderData.status !=='审核'))" :data="orderData" @onSuccess="mianData"></abstract>
          <a-button v-if="canPrintBoolean" type="primary" size="mini" @click="printData">打印</a-button>
          <edit v-if="utils.hasPermission('update')" :disabled="utils.isDisabled(orderData.status,[''],(orderData.status !=='新建'))"  :data="orderData" @onSuccess="mianData"></edit>
          <a-space v-if="utils.isDisabled(orderData.status,[''],(orderData.type =='特殊订单'))">
            <a-button v-if="utils.hasPermission('preSubmissionBack')" type="primary" :disabled="utils.isDisabled(orderData.status,[''],(orderData.status !=='预提交'))" @click="onSpcialSubmit(20230331152503,'预提交撤回',false)">预提撤回</a-button>
            <a-button v-if="utils.hasPermission('preSubmissionConfirm')" type="primary" :disabled="utils.isDisabled(orderData.status,['提交','审核','确认','关闭','手工关闭'])" @click="onSpcialSubmit(20230331102503,'预提交确认',true)">预提交确认</a-button>
            <a-button v-if="utils.hasPermission('preSubmissionConfirmBack')" type="primary" :disabled="utils.isDisabled(orderData.status,[''],(orderData.status !=='确认'))" @click="onSpcialSubmit(20230331102503,'反确认',false)">反确认</a-button>
          </a-space>
          <a-button v-if="utils.hasPermission('submit')" :disabled="utils.isDisabled(orderData.status,[''],canSubmit)" type="primary" size="mini" @click="onSubmit('提交')">提 交</a-button>
          <returnBill :data="orderData" :enddate="enddate" :disabled="utils.isDisabled(orderData.status,['新建','预提交','确认','审核','关闭','手工关闭'])" @onSuccess="mianData"></returnBill>
          <a-button v-if="utils.hasPermission('examine')" type="primary" :disabled="utils.isDisabled(orderData.status,[''],(orderData.status !=='提交'))" @click="checkBill(20221108153502,'审核')">审核</a-button>
          <a-button v-if="utils.hasPermission('unExamine')" type="primary" :disabled="utils.isDisabled(orderData.status,[''],(orderData.status !=='审核'))" @click="checkBill(20230102141502,'反审核')">反审核</a-button>
          <a-button v-if="utils.hasPermission('cancel')" type="primary" :disabled="utils.isDisabled(orderData.status,[''],(orderData.status !== '审核'))" @click="checkBill(20230406155202,'手工关闭')">关闭</a-button>
          <a-button v-if="utils.hasPermission('copy')" type="primary" :disabled="utils.isDisabled(orderData.status,[''],(orderData.type === '促销订单'))">
            <selectEnterprise title="选择经销商" :disabled="utils.isDisabled(orderData.status,[''],(orderData.type === '促销订单'))" :param="{id:20230219195002,content:{ismanage :1,pageNumber:1,pageSize:20,where:{condition:''}}}" @onSelect="copyOrder">
              <template #text>复制</template>
            </selectEnterprise>
          </a-button>
        </a-space>
      </template>
      <template v-if="orderData.sa_accountclassinfos" #customContent>
        <a-divider orientation="left" orientation-margin="0px"><span class="almm">支付信息</span></a-divider>
        <div class="account-item-panel" v-for="item in orderData.sa_accountclassinfos" :key="item.index">
          <div class="account-item-panel-content">
            <p style="color:red;font-weight: bold;">{{item.accountname}}</p><a-divider type="vertical" />
            <p>实时余额: ¥<span class="accountAmount">{{utils.formatAmount(item.realbalance,{name:'hideFields',key:'realbalance'})}}</span></p><a-divider type="vertical" />
            <p>当时余额: ¥<span class="accountAmount">{{utils.formatAmount(item.balance,{name:'hideFields',key:'balance'})}}</span></p><a-divider type="vertical" />
            <p>信用额度: ¥{{utils.formatAmount(item.creditquota,{name:'hideFields',key:'creditquota'})}}</p><a-divider type="vertical" />
            <div>本单支出: <span style="color:red">¥{{utils.formatAmount(item.amount,{name:'hideFields',key:'amount'})}}</span></div>
          </div>
        </div>
      </template>
      <template #tab0>
        <normalTable :tableRowStyle="formatter" rowKey="sa_orderitemsid" ref="prodlist" :columns="utils.TBLayout('orderMxTable')" :tableid="utils.TBLayoutID('orderMxTable')" tableName="orderMxTable" size="small" :param="param" @onSelect="onSelectChange">
          <template v-if="utils.hasPermission('orderMxedit')" #operation>
            <a-space class="mt-10">
              <a-button :disabled="utils.isDisabled(orderData.status,['确认','提交','审核','关闭','手工关闭'])" :type="isEditDisabled?'primary':'dashed'" @click="editRowProd">{{isEditDisabled?'行编辑':'保存'}}</a-button>
              <tableImport :disabled="utils.isDisabled(orderData.status,['确认','提交','审核','关闭','手工关闭'])" :bindData="{ownerid:router.currentRoute.value.query.id,ownertable:'sa_order',usetype:'default'}" :failedData="failedData" :modeParam="{id:20230227194703,content:{}}" @uploadSuccess="importSuccess">
              </tableImport>
              <select-product :columns="utils.TBLayout('orderAddTable')" :tableid="utils.TBLayoutID('orderAddTable')" :disabled="utils.isDisabled(orderData.status,['确认','提交','审核','关闭','手工关闭'])"  :param="{id:20221109153502,content:{sa_orderid:orderData.sa_orderid,pageNumber:1,pageSize:20,where:{condition:'',tablefilter:{}}}}" @onSelectChange="addProductToBody">
                <template #tb_cell="{data}">
                  <template v-if="data.column.dataIndex === 'qty'">
                    <a-input-number style="width:100%" id="inputNumber" :precision="2" v-model:value="data.record.qty" :min="data.record.orderminqty" :step="data.record.orderaddqty"/>
                  </template>
                  <template v-if="data.column.dataIndex === 'length' && data.record.iscustomsize == 1">
                    <a-select v-if="data.record.lengthschemedetails.length > 0" v-model:value="data.record.length" style="width: 150px" placeholder="选择长度">
                      <a-select-option v-for="item in data.record.lengthschemedetails" :key="item.sa_sizeschemedetailid" :value="item.num">{{item.num}}</a-select-option>
                    </a-select>
                    <a-input v-else style="width:200px;" v-model:value="data.record.length" :placeholder="`输入${data.record.lengthmin}到${data.record.lengthmax}长度`" @blur="validInput(data.record,data.record.lengthmin,data.record.lengthmax,'length')">
                    </a-input>
                  </template>
                  <template v-if="data.column.dataIndex === 'width' && data.record.iscustomsize == 1">
                    <a-select v-if="data.record.widthschemedetails.length > 0" v-model:value="data.record.width" style="width: 150px" placeholder="选择宽度">
                      <a-select-option v-for="item in data.record.widthschemedetails" :key="item.sa_sizeschemedetailid" :value="item.num">{{item.num}}</a-select-option>
                    </a-select>
                    <a-input v-else style="width:200px;" v-model:value="data.record.width" :placeholder="`输入${data.record.widthmin}到${data.record.widthmax}宽度`" @blur="validInput(data.record,data.record.widthmin,data.record.widthmax,'width')">
                    </a-input>
                    
                  </template>
                  <template v-if="data.column.dataIndex === 'remarks'">
                    <a-input style="width:100%" v-model:value="data.record.remarks"/>
                  </template>
                </template>
              </select-product>
              <a-button :disabled="utils.isDisabled(orderData.status,['确认','提交','审核','关闭','手工关闭'],(selectProductList.length == 0))" type="primary" @click="deleteProd">删除商品</a-button>
              <order-discount :id="router.currentRoute.value.query.id" :data="selectProductList" :disabled="utils.isDisabled(orderData.status,['确认','提交','审核','关闭','手工关闭'])" @onSuccess="onSuccess"></order-discount>
              <a-button :disabled="utils.isDisabled(orderData.status,['新建','确认','提交','关闭','手工关闭'],(selectProductList.length == 0))" type="primary" @click="quickSendProduct">一键发货</a-button>
              <a-button :disabled="utils.isDisabled(orderData.status,['新建','确认','提交','关闭','手工关闭'],(selectProductList.length == 0))" type="primary" @click="freezeRows(true)">行冻结</a-button>
              <a-button :disabled="utils.isDisabled(orderData.status,['新建','确认','提交','关闭','手工关闭'],(selectProductList.length == 0))" type="primary" @click="freezeRows(false)">解冻行</a-button>
              <!-- <hasSelected :columns="utils.TBLayout('orderMxTable')"></hasSelected> -->
            </a-space>
          </template>
          <template v-if="utils.hasPermission('orderMxedit')" #tb_cell="{data}">
            <template  v-if="data.column.dataIndex === 'qty'">
              <a-input-number v-if="orderData.type == '特殊订单'" v-model:value="data.record.qty" :disabled="utils.isDisabled(orderData.status,['提交','审核','关闭','手工关闭'],isEditDisabled)" @change="inputChange(data.record,'qty',isChange = true)"></a-input-number>
              <a-input-number v-else v-model:value="data.record.qty" :precision="2" :disabled="utils.isDisabled(orderData.status,['提交','审核','关闭','手工关闭'],isEditDisabled)" :min="data.record.orderminqty" :step="data.record.orderaddqty" @change="inputChange(data.record,'qty',isChange = true)"></a-input-number>      
            </template>
            <template v-if="data.column.dataIndex === 'price' && utils.hasPermission('priceChange')">
              <a-input v-if="canEdit" v-model:value="data.record.price" :disabled="utils.isDisabled(orderData.status,['提交','审核','关闭','手工关闭'],isEditDisabled)"  @change="inputChange(data.record,'price',isChange = true)"></a-input>
            </template>
            <template v-if="data.column.dataIndex === 'amount' && utils.hasPermission('priceChange')">
              <a-input v-if="canEdit" v-model:value="data.record.amount" :disabled="utils.isDisabled(orderData.status,['提交','审核','关闭','手工关闭'],isEditDisabled)"  @change="inputChange(data.record,'amount',isChange = true)"></a-input>
            </template>
            <template v-if="data.column.dataIndex === 'remarks'">
              <a-tooltip>
                <template #title>{{data.record.remarks}}</template>
                <a-input style="width:100%" :disabled="utils.isDisabled(orderData.status,['提交','审核','关闭','手工关闭'],isEditDisabled)" v-model:value="data.record.remarks" :min="1"  @change="inputChange(data.record,'remarks',isChange = true)"/>
              </a-tooltip>
            </template>
          </template>
        </normalTable>
      </template>
      <template #tab1>
        <od-progress></od-progress>
      </template>
      <template #tab2>
        <dispatch-temp></dispatch-temp>
      </template>
      <template #tab3>
        <income-mx></income-mx>
      </template>
      <template #tab4>
        <sale-out-bill></sale-out-bill>
      </template>
      <template #tab5>
        <logistics-order></logistics-order>
      </template>
    </detail-template>
    <print ref="printRef" :list="reportList" @onModeClick="onModeClick"></print>
  </div>
</template>

<script setup>
import Api from '@/api/api'
import utils  from '@/utils/utils'
import orderDiscount from './modules/orderDiscount.vue'
import normalTable from '@/template/normalTable/index.vue'
import tableImport from '@/components/tableImport/index.vue'
import SelectProduct from '@/template/selectProduct/index.vue'
import selectEnterprise from '@/template/selectEnterprise/index.vue'
import detailTemplate from '@/components/detailTemplate/index.vue'

import abstract from './modules/abstract.vue'
import edit from './modules/edit.vue'
import returnBill from './modules/returnBill.vue'
import OdProgress from './tabs/progress.vue'
import DispatchTemp from './tabs/dispatch.vue'
import saleOutBill from './tabs/saleOutBill.vue'
import logisticsOrder from './tabs/logisticsOrder.vue'
import IncomeMx from './tabs/income.vue'
import print from '@/components/print/index.vue'

import { Modal } from 'ant-design-vue'
import { message } from 'ant-design-vue';
import { storeToRefs } from 'pinia'
import { useAuthStore } from '@/stores/modules/auth'
import { useBaseStore } from '@/stores/modules/base'

import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { useRouter } from "vue-router";
import { onMounted,ref,createVNode,computed,onBeforeUnmount } from "vue";
const store = useAuthStore()
const base = useBaseStore()

let { app } = storeToRefs(store)
const router = useRouter()
const isChange = ref(false)
const mainAreaData = ref([])
const current = ref(0)
const isEditDisabled = ref(true)
const param = ref({
  "id": 20221109093902,
  "content": {
    "nocache":true,
    "sa_orderid": router.currentRoute.value.query.id, //订单ID
    "pageNumber": 1,
    "pageSize": 20,
    "where": {
      "condition": ""
    }
  },
})
const canSubmit = computed(()=>{
  if (orderData.value.type == '特殊订单' && orderData.value.status !=='确认') {
    return true
  }
  if (orderData.value.type == '标准订单' && orderData.value.status !== '新建') {
    return true
  }
  if (orderData.value.type == '促销订单' && orderData.value.status !== '新建') {
    return true
  }
})
const canEdit = computed(()=>{
  if (orderData.value.type == '特殊订单') {
    return true
  } else {
    return false
  }
})
const orderData = ref({})
const mianData = async (...args)=>{
  const res = await Api.requested({
    "id":'20221108151302',
    "content": {
      "nocache":true,
      "sa_orderid":router.currentRoute.value.query.id,
    }
  })
  orderData.value = res.data

  changeDataStructure(res.data)
  if (orderData.value.type == '促销订单') {
    promotion()
  }
}
const changeDataStructure = (data) => {
  mainAreaData.value = utils.FormLayout('orderBillHead',data)
  console.log(mainAreaData.value)
  if (data.type === '促销订单') {
    mainAreaData.value.splice(0,0,{
      label:'活动名称',
      value:data.promname,
      span:4
    })
    mainAreaData.value.splice(1,0,{
      label:'方案编码',
      value:data.promnum,
      span:2
    })
  }
}
const selectProductList = ref([])
const onSelectChange = (val) =>{
  selectProductList.value = val
}
const prodlist = ref()
const hasChangeData = ref([])
const inputChange = (val,type) =>{
  switch (type){
    case 'qty':
      val.amount = val.qty * val.price
      break;
    case 'price':
      val.amount = val.qty * val.price
      break;
    case 'amount':
       val.price = val.amount / val.qty
      break;
    default:
      break;
  }
  if (hasChangeData.value.some(e=>e.sa_orderitemsid == val.sa_orderitemsid)) {
    hasChangeData.value.filter(e=>{
      if (e.sa_orderitemsid == val.sa_orderitemsid) {
        e = val
        return false
      }
    })
  } else {
    hasChangeData.value = [...hasChangeData.value,...[val]]
  }
}
const editRowProd = ()=>{
  if (isEditDisabled.value) {
    isEditDisabled.value = !isEditDisabled.value
    return false
  }
  if (hasChangeData.value.length == 0) {
    isEditDisabled.value = true
  } else {
    updateProd(hasChangeData.value,'修改成功',()=>{
      hasChangeData.value = []
      isEditDisabled.value = true
    })
  }
 
}
const updateProd = async (data,msg,fn) =>{
  const res = await Api.post({
    id:20221109093602,
    content:{
      sa_orderid:orderData.value.sa_orderid,
      sys_enterpriseid:orderData.value.sys_enterpriseid,
      type:orderData.value.type,
      sa_order_v:orderData.value.sa_order_v,
      sa_contractid: orderData.value.sa_contractid,
      items:data.map(e=>{
        return {
          sa_orderitemsid:e.sa_orderitemsid,
          itemid:e.itemid,
          qty:e.qty,
          price:e.price,
          amount:0,
          sa_orderitems_v:e.sa_orderitems_v,
          defaultprice:e.defaultprice,
          remarks:e.remarks,
          length:e.length ? e.length:0,
          width:e.width ? e.width:0,
          sa_promotion_itemsid:e.sa_promotion_itemsid
        }
      })
    }
  })
  utils.message(res,msg,()=>{
    mianData()
    prodlist.value.listData()
    isChange.value = false
    fn ? fn(): ''
  })
 
}
const validInput = async (record,min,max,type)=>{
  if (record[type] > max) {
    record[type] = max
  } else if (record[type] < min) {
    record[type] = min
  } else {
    record[type] = record[type]
  }
}
const addProductToBody = async (val) =>{
  let param = {
    "id": 2024020201095102,
    "content": {
      "sa_orderid": orderData.value.sa_orderid,
      "sys_enterpriseid": orderData.value.sys_enterpriseid,
      "type":orderData.value.type,
      "sa_contractid": 0,
      "items":val
    }
  }
  base.addRepeatProd(param).then((res)=>{
    let data = val.map(e=>{
      if (e.iscustomsize == 1 && e.length && e.width) {
        return {
          sa_orderitemsid:0,
          itemid:e.itemid,
          qty:e.qty,
          remarks:e.remarks,
          length:e.length ? e.length:0,
          width:e.width ? e.width:0,
        }
      } else if (e.iscustomsize == 0) {
        return {
          sa_orderitemsid:0,
          itemid:e.itemid,
          remarks:e.remarks,
          qty:e.qty,
          length:0,
          width:0
        }
      } else {
        message.error(e.itemname + '定制信息有误,请检查!')
      }
    })
    data.filter(e=>e !== undefined).length > 0 ? updateProd(data.filter(e=>e !== undefined),'添加成功',()=>{
      prodlist.value.tableRecord = []
    }):''
  })
}
const deleteProd = ()=>{
  Modal.confirm({
    title: '删除商品',
    icon: createVNode(ExclamationCircleOutlined),
    content: `当前选中${selectProductList.value.length}个商品,删除${selectProductList.value.length}个商品!`,
    okText: '确认',
    cancelText: '取消',
    async onOk() {
      const res = await Api.post({
        id:20221109093702,
        content:{
          sa_orderid:orderData.value.sa_orderid,
          sa_orderitemsids:selectProductList.value.map(e=>{
            return e.sa_orderitemsid
          })
        }
      })
      utils.message(res,'删除成功',()=>{
        prodlist.value.reloadSelect()
        selectProductList.value = []
        prodlist.value.listData()
        mianData()
      })
    },
    onCancel() {},
  })
}
const onSuccess = ()=>{
  prodlist.value.listData()
  mianData()
}
const onSpcialSubmit = async (id,msg,value)=>{
  if (isChange.value)
    return message.error('商品明细未保存，请先保存后再提交！')
  Modal.confirm({
    title: '提示',
    icon: createVNode(ExclamationCircleOutlined),
    content: `确定${msg}该订单吗!`,
    okText: '确认',
    cancelText: '取消',
    async onOk() {
      const res = await Api.post({
        id:id,
        content:{
          "sa_orderid": orderData.value.sa_orderid,
          "isrecheck":value
        }
      })
      utils.message(res,msg + '成功',()=>{
        mianData()
        isEditDisabled.value = true
      })
    },
    onCancel() {},
  })
}
const checkBill = async (id,msg)=>{
  Modal.confirm({
    title: '提示',
    icon: createVNode(ExclamationCircleOutlined),
    content: `确定${msg}该订单吗?`,
    okText: '确认',
    cancelText: '取消',
    async onOk() {
      const res = await Api.post({
        id:id,
        content:{
          "sa_orderid": orderData.value.sa_orderid,
          "reviewtype":''
        }
      })
      utils.message(res,`${msg}成功`,()=>{
        mianData()
      })
    },
    onCancel() {},
  })
}
const zero_price = ref(false)
const onSubmit = async (id,msg)=>{
  if (orderData.value.type == '特殊订单') {
    const rs = await Api.requested({
      id:2024060515370903,
      content:{
        "sa_orderid": orderData.value.sa_orderid,
      }
    })
    if (rs.data.length > 0) {
      zero_price.value = true
    }
  }
  Modal.confirm({
    title: '提示',
    icon: createVNode(ExclamationCircleOutlined),
    content:zero_price.value?createVNode('div', { style: 'color:red;' }, '存在单价为0的商品，是否继续提交?'):`确定提交该订单吗?`,
    okText: '确认',
    cancelText: '取消',
    async onOk() {
      const res = await Api.post({
        id:20221108153402,
        content:{
          "sa_orderid": orderData.value.sa_orderid,
          "reviewtype":''
        }
      })
      utils.message(res,`提交成功`,()=>{
        mianData()
      })
    },
    onCancel() {},
  })
}

const quickSendProduct = ()=>{
  Modal.confirm({
    title: '一键发货',
    icon: createVNode(ExclamationCircleOutlined),
    content: `当前选中${selectProductList.value.length}个商品!`,
    okText: '确认',
    cancelText: '取消',
    async onOk() {
      const res = await Api.post({
        id:20230220100604,
        content:{
          sa_orderid:orderData.value.sa_orderid,
          sa_orderitemsids:selectProductList.value.map(e=>{
            return e.sa_orderitemsid
          })
        }
      })
      utils.message(res,'创建成功',()=>{
        prodlist.value.reloadSelect()
        selectProductList.value = []
        router.push({path:'/dispatchDetail',query:{id:res.data.sa_dispatchid}})
      })
    },
    onCancel() {},
  })
}
const formatter = (_record, index) => {
  if (_record.undeliqty > 0 && orderData.value.status == '审核') {
    return 'table-striped-red'
  } else {
    return null
  }
}
/**
 * 获取促销订单方案详情
 */
const enddate = ref('')
const promotion = async () =>{
  const res = await Api.requested({
    id:20221230144703,
    content:{
      nocache:true,
      sa_promotionid:orderData.value.sa_promotionid
    }
  })
  enddate.value = res.data.enddate
}

const freezeRows = (bool)=>{
  if (bool && selectProductList.value.some(e=>e.isfreeze == 1)) {
    return message.error('存在已经冻结的行数据,请重新选择!')
  } 
  if (!bool && selectProductList.value.some(e=>e.isfreeze == 0)) {
    return message.error('存在未冻结的行数据,请重新选择!')
  }
  Modal.confirm({
    title: '是否冻结行',
    icon: createVNode(ExclamationCircleOutlined),
    content: `当前选中${selectProductList.value.length}行!`,
    okText: '确认',
    cancelText: '取消',
    async onOk() {
      const res = await Api.post({
        id:20230508093003,
        content:{
          isfreeze:bool,
          sa_orderid:orderData.value.sa_orderid,
          sa_orderitemsids:selectProductList.value.map(e=>{
            return e.sa_orderitemsid
          })
        }
      })
      utils.message(res,`${bool?'冻结':'解冻'}成功`,()=>{
        prodlist.value.reloadSelect()
        selectProductList.value = []
        prodlist.value.listData()
      })
    },
    onCancel() {},
  })
}
const copyOrder = async (val)=>{
  const res = await Api.requested({
    id:20230102144502,
    content:{
      sa_orderid:orderData.value.sa_orderid,
      sys_enterpriseid:val.sys_enterpriseid
    }
  })
  utils.message(res,'复制成功',()=>{
    Modal.confirm({
    title: '提示',
    icon: createVNode(ExclamationCircleOutlined),
    content: `是否跳转到新订单?`,
    okText: '确认',
    cancelText: '取消',
    async onOk() {
      router.replace({path:'/orderDetail_cucu',query:{id:res.data.sa_orderid}})
    },
    onCancel() {},
  })
  })
}
const failedData = ref(null)
const importSuccess = async (res)=>{
  const rs = await Api.requested({
    id:20230227194803,
    content:{
      sa_orderid:orderData.value.sa_orderid,
      attachmentid:res.data.attachmentids[0]
    }
  })
  utils.message(rs,'导入成功',()=>{
    prodlist.value.listData()
    mianData()
    if (rs.data !== '成功') {
      failedData.value = rs.data
    }
  })
}
const canPrintBoolean = ref(false)
const reportList = ref([])
const canPrint = async ()=>{
  const res = await Api.requested({
    id:20221213094401,
    content:{
      systemappid:app.value.systemappid,
    }
  })
  res.data.length > 0 ? canPrintBoolean.value = true : canPrintBoolean.value = false
  reportList.value = res.data
}
const printUrl = async (data)=>{
  const res = await Api.requested({
      id:20221213094501,
      content:{
        sys_reportid:data.sys_reportid,
        dataid: router.currentRoute.value.query.id
      }
    })
    if (res.code == 1) {
      window.open(process.env.BASE_API+res.data)
    }
}
const record = ref({})
const printRef = ref()
const printData = ()=>{
  if (reportList.value.length == 1) {
    printUrl(reportList.value[0])
  } else {
    printRef.value.open = true
  }
  
}

const onModeClick = async (data)=>{
  printUrl(data)
}
const mxList=ref([])
const specOrderMx = async ()=>{
  const res = await Api.optionstype('specordermx')
  mxList.value = res.data
}
const handleMenuClick = async (val)=>{
  const res = await Api.requested({
      "id": 20230706094703,
      "content": {
        "sa_orderid":orderData.value.sa_orderid,
        "typemx":val.key
      }
  })
  utils.message(res,'修改成功',()=>{
    mianData()
  })
}
onMounted (()=>{
  mianData()
  canPrint()
  specOrderMx()
})
onBeforeUnmount (()=>{
  prodlist.value.reloadSelect()
})
</script>
<style scoped>
.account-item-panel-content{
  display: flex;
  align-items: center;
}
.account-item-panel-content p{
  margin: 0;
}
/deep/.ant-input {
  color:#000000;
}
input::placeholder {
  color: #000000 !important;
}
</style>