123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305 |
- <template>
- <div class="w-[100vw] bg-white page-cargo-consolidation">
- <div
- v-loading="loading"
- class="pt-2 w-[100%] min-h-[100vh]"
- >
- <el-form
- style="width: 100%"
- inline
- :loading="loading"
- @submit.prevent="getList"
- >
- <el-form-item label="ETD Range">
- <el-date-picker
- v-model="dateRange"
- type="daterange"
- unlink-panels
- clearable
- start-placeholder="Start date"
- end-placeholder="End date"
- :shortcuts="dateShortcuts"
- />
- </el-form-item>
- <el-form-item>
- <el-tooltip content="时间范围最好不要选太大, 不然数据太多会卡">
- <el-button
- class="custom-button"
- @click="getList"
- >
- Search
- </el-button>
- </el-tooltip>
- </el-form-item>
- </el-form>
- <el-tabs v-model="currentTab">
- <el-tab-pane
- v-for="tab in finalTabs"
- :key="tab.value"
- :label="tab.label"
- :name="tab.value"
- ></el-tab-pane>
- </el-tabs>
- <el-table
- border
- :header-cell-style="{ backgroundColor: 'rgb(227, 241, 253)' }"
- :data="computedList"
- highlight-current-row
- style="width: 100%"
- max-height="330"
- @row-click="($e) => getSubList($e)"
- >
- <el-table-column
- prop="Name"
- label="船名&航次"
- min-width="500"
- />
- <el-table-column
- prop="Forwarder"
- label="货代"
- width="110"
- />
- <el-table-column
- prop="ETD"
- label="ETD"
- width="110"
- />
- <el-table-column
- prop="ATD"
- label="ATD"
- width="110"
- />
- <el-table-column
- prop="ETA"
- label="ETA"
- width="110"
- />
- <el-table-column
- prop="ATA"
- label="ATA"
- width="110"
- />
- <el-table-column
- prop="Cut_Off_Date"
- label="入仓时间"
- width="120"
- />
- <el-table-column
- prop="Status"
- label="状态"
- width="100"
- />
- <!-- <el-table-column
- label="修改时间"
- min-width="190"
- >
- <template #default="scope">
- {{ dayjs(scope.row.Modified_Time).format('YYYY-MM-DD HH:mm:ss') }}
- </template>
- </el-table-column> -->
- <el-table-column
- prop="GRN"
- label="入仓单号"
- min-width="200"
- />
- <el-table-column
- prop="Booking_Number"
- label="订舱号"
- min-width="120"
- />
- <el-table-column
- prop="Carrier"
- label="船东"
- min-width="120"
- />
- <el-table-column label="操作">
- <template #default="scope">
- <el-button
- size="small"
- type="warning"
- link
- :disabled="!scope.row.SubscriptionId"
- @click="openMapDrawer(scope.row)"
- >
- 查看轨迹
- </el-button>
- </template>
- </el-table-column>
- </el-table>
- <div
- v-show="currentRow.Name?.length"
- class="flex justify-between mt-8"
- >
- <div class="flex">
- <div class="flex items-center mr-2">
- <span class="min-w-[150px]">选中的船名&航次: </span>
- <div class="text-red-700 font-bold">
- {{ currentRow.Name }}
- </div>
- </div>
- <div class="flex flex-wrap min-w-[800px] mr-2">
- <el-input
- v-if="
- currentTab === 'Arrangement' &&
- ['可用', '已截仓'].includes(currentRow.Status) &&
- [
- '4791186000259693001',
- '4791186000022965001',
- '4791186000052269001',
- ].includes(currentUser)
- "
- style="width: 200px; height: 24px; margin-right: 10px"
- size="small"
- v-model="bookingNumber"
- >
- <template #append>
- <el-button
- class="custom-button"
- size="small"
- style="padding-top: 0; padding-bottom: 0"
- @click="updateBookingNumber"
- >
- 更新订舱号
- </el-button>
- </template>
- </el-input>
- <el-button
- v-if="
- ['可用', '已截仓'].includes(currentRow.Status) &&
- [
- '4791186000259693001',
- '4791186000022965001',
- '4791186000052269001',
- ].includes(currentUser)
- "
- size="small"
- type="danger"
- @click="ensure"
- >
- 确认集货
- </el-button>
- <el-button
- class="custom-button"
- v-if="['Arrangement', 'my_request'].includes(currentTab)"
- size="small"
- @click="addBulkProduct"
- >
- 提交大货集货申请
- </el-button>
- <el-button
- class="custom-button"
- v-if="['Arrangement', 'my_request'].includes(currentTab)"
- size="small"
- @click="addSample"
- >
- 提交样品集货申请
- </el-button>
- <el-button
- v-if="['Arrangement', 'my_request'].includes(currentTab)"
- :disabled="subList.length < 1"
- size="small"
- type="danger"
- @click="generateSubList"
- >
- 放弃下方表格改动
- </el-button>
- <el-button
- class="custom-button"
- size="small"
- :disabled="subList.length < 1"
- @click="exportSubTable"
- >
- 导出Excel文档
- </el-button>
- <el-button
- v-if="['Arrangement', 'my_request'].includes(currentTab)"
- :disabled="subList.length < 1"
- size="small"
- type="primary"
- class="custom-button small"
- @click="commit"
- >
- 保存更改
- </el-button>
- </div>
- </div>
- <div class="flex flex-wrap min-w-[380px] gap-2">
- <div class="flex">总重量: {{ computedWeight }}</div>
- <div class="flex">总体积: {{ computedCube }}</div>
- <div class="flex">总离岸价: {{ computedTotalFOB }}</div>
- </div>
- </div>
- <el-table
- class="mt-4"
- size="small"
- :data="subList"
- style="width: 100%"
- :row-style="calcRowStyle"
- :header-cell-style="{ backgroundColor: 'rgb(227, 241, 253)' }"
- :empty-text="
- currentRow.Name?.length
- ? '暂无数据'
- : '请点击voyage表格其中一行以查询相应记录'
- "
- border
- >
- <el-table-column
- fixed
- type="index"
- width="50"
- ></el-table-column>
- <el-table-column
- fixed
- label="CRM批次记录"
- width="220"
- >
- <template #default="scope">
- <el-select
- v-model="scope.row.batchRecord"
- size="small"
- :remote-method="debounce(search, 1500)"
- remote
- style="width: 100%"
- :loading="loading2"
- filterable
- clearable
- :placeholder="scope.row.Sample ? 'Sample' : ''"
- :disabled="scope.row.Sample"
- @change="($e) => onBatchRecordChange($e, scope.$index)"
- >
- <el-option
- v-for="option in computedOption as any[]"
- :disabled="
- (!option.isSearch && scope.row.addFlag) ||
- (option.isSearch && !scope.row.addFlag)
- "
- :key="option.id"
- :value="option.id"
- :label="
- option.Name +
- (option.Reference ? ` - ${option.Reference}` : '')
- "
- ></el-option>
- </el-select>
- </template>
- </el-table-column>
- <el-table-column
- label="备注"
- width="110"
- fixed
- >
- <template #default="scope">
- <el-input
- v-model="scope.row.User_Notes"
- size="small"
- :rows="2"
- type="textarea"
- @change="scope.row.editFlag = true"
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column
- label="箱数"
- width="80"
- >
- <template #default="scope">
- <el-input
- v-model="scope.row.Carton"
- size="small"
- @change="scope.row.editFlag = true"
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column
- label="唛头"
- width="220"
- >
- <template #default="scope">
- <el-input
- v-model="scope.row.Marks_Nos"
- size="small"
- @change="scope.row.editFlag = true"
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column
- label="货物名称"
- width="180"
- >
- <template #default="scope">
- <el-input
- v-model="scope.row.Description_of_Goods"
- size="small"
- @change="scope.row.editFlag = true"
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column
- label="货物材质"
- width="220"
- >
- <template #default="scope">
- <el-select
- v-model="scope.row.Material_of_Goods"
- size="small"
- multiple
- @change="scope.row.editFlag = true"
- >
- <el-option
- v-for="i in goodMaterialOption"
- :key="i"
- :value="i"
- :label="i"
- ></el-option>
- </el-select>
- </template>
- </el-table-column>
- <el-table-column
- label="数量"
- width="100"
- >
- <template #default="scope">
- <el-input
- v-model="scope.row.Quantity"
- size="small"
- @change="changeTotal(scope.row)"
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column
- label="单价(澳币/AUD)"
- width="120"
- >
- <template #default="scope">
- <el-input
- v-model="scope.row.Unit_Price"
- size="small"
- @change="changeTotal(scope.row)"
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column
- label="负责人"
- fixed="right"
- width="120"
- >
- <template #default="scope">
- <el-input
- v-model="scope.row.Requester.name"
- size="small"
- disabled
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column
- label="申请人"
- fixed="right"
- width="120"
- >
- <template #default="scope">
- <el-input
- v-model="scope.row.Sales_Person"
- size="small"
- disabled
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column
- v-show="['Arrangement', 'my_request'].includes(currentTab)"
- fixed="right"
- label="更新时间"
- width="90"
- >
- <template #default="scope">
- <div v-if="scope.row.id">
- {{
- dayjs(scope.row.update_time || new Date()).format(
- 'YYYY-MM-DD HH:mm:ss',
- )
- }}
- </div>
- </template>
- </el-table-column>
- <el-table-column
- v-show="
- [
- '4791186000259693001',
- '4791186000022965001',
- '4791186000052269001',
- ].includes(currentUser)
- "
- fixed="right"
- label="操作"
- width="90"
- >
- <template #default="scope">
- <el-tooltip
- content="新增未commit的行会被直接移除; 已commit的行只会标记, 正式commit后才会删除"
- >
- <el-button
- v-if="['Arrangement', 'my_request'].includes(currentTab)"
- type="danger"
- size="small"
- link
- @click="() => onDeleteRow(scope.row, scope.$index)"
- >
- 删除
- </el-button>
- </el-tooltip>
- <el-button
- size="small"
- link
- type="primary"
- @click="print(scope.row)"
- >
- 打印
- </el-button>
- </template>
- </el-table-column>
- <el-table-column
- fixed="right"
- label="重量 (KG)"
- width="70"
- >
- <template #default="scope">
- <el-input
- v-model="scope.row.Weight"
- size="small"
- @change="scope.row.editFlag = true"
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column
- fixed="right"
- label="体积 m³"
- width="70"
- >
- <template #default="scope">
- <el-input
- v-model="scope.row.Cube"
- size="small"
- @change="scope.row.editFlag = true"
- ></el-input>
- </template>
- </el-table-column>
- <el-table-column
- fixed="right"
- label="总离岸价 (澳币/AUD)"
- width="140"
- >
- <template #default="scope">
- <el-input
- v-model="scope.row.Total_FOB"
- size="small"
- disabled
- ></el-input>
- </template>
- </el-table-column>
- </el-table>
- <el-drawer
- v-model:model-value="printDrawerVisible"
- :size="'1050px'"
- :title="'打印唛 (注意先写完唛内容和宽高最后再调页数, 不然可能会很卡)'"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- >
- <comp-print
- v-if="printDrawerVisible"
- :autoOpenQRCode="false"
- :content="[currentPrintRow.Marks_Nos || '']"
- :scene="'QC'"
- />
- </el-drawer>
- <el-drawer
- v-model:model-value="mapDrawerVisible"
- :size="'1050px'"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- :destroy-on-close="true"
- :with-header="false"
- header-class="mb-1"
- >
- <div class="relative h-[20px]">
- <span
- @click="closeMapDrawer"
- class="absolute top-[-16px] right-0 text-gray-600 text-sm cursor-pointer"
- >
- 关闭地图窗口
- </span>
- </div>
- <div
- id="mapDrawer"
- class="h-[100%]"
- ></div>
- </el-drawer>
- </div>
- </div>
- </template>
- <script lang="ts" setup>
- import { defineComponent, ref, watch, computed, nextTick } from 'vue'
- import {
- ElButton,
- ElForm,
- ElFormItem,
- ElInput,
- ElTabs,
- ElTabPane,
- ElTable,
- ElTableColumn,
- ElDatePicker,
- ElTooltip,
- ElSelect,
- ElOption,
- ElMessage,
- ElMessageBox,
- ElNotification,
- ElDrawer,
- } from 'element-plus'
- import cloneDeep from 'lodash.clonedeep'
- import dayjs from 'dayjs'
- import * as XLSX from 'xlsx'
- import debounce from 'lodash.debounce'
- import compPrint from '@/components/print.vue'
- import request from '@/utils/axios'
- defineComponent({
- name: 'ComponentCargoConsolidationRequest',
- })
- const currentUser = ref('')
- const currentUserName = ref('')
- const currentUserRawData = ref({} as any)
- let loading = ref(false)
- let list = ref([] as any[])
- let currentTab = ref('all')
- let tabs = [
- {
- label: 'All',
- value: 'all',
- },
- {
- label: 'Avaliable',
- value: 'avaliable',
- },
- {
- label: 'Closed Voyage',
- value: 'voyage_closed',
- },
- {
- label: 'My Request',
- value: 'my_request',
- },
- ]
- let finalTabs = ref([] as any[])
- finalTabs.value = cloneDeep(tabs)
- let computedList = computed(() => {
- return list.value.filter((i: any) => {
- let condition = true
- switch (currentTab.value) {
- case 'avaliable':
- condition = i.Status && i.Status === '可用'
- break
- case 'voyage_closed':
- condition = ['已截仓', '已确认', '已发出', '已到达'].includes(i.Status)
- break
- }
- return condition
- })
- })
- let dateRange = ref([] as any[])
- const generateDateRange = (days = 7) => {
- const today = new Date()
- const endDate = new Date()
- endDate.setDate(today.getDate() + days)
- return [today, endDate]
- }
- const dateShortcuts = ref([
- {
- text: 'Next 3 days',
- value: generateDateRange(3),
- },
- {
- text: 'Next week',
- value: generateDateRange(7),
- },
- {
- text: 'Next 14days',
- value: generateDateRange(14),
- },
- ] as any[])
- function getDefaultRange() {
- const today = dayjs()
- const lastMonthFirstDay = today
- .subtract(1, 'month')
- .startOf('month')
- .format('YYYY-MM-DD')
- const nextMonthLastDay = today
- .add(1, 'month')
- .endOf('month')
- .format('YYYY-MM-DD')
- return [lastMonthFirstDay, nextMonthLastDay]
- }
- dateRange.value = getDefaultRange()
- const clearSubList = () => {
- subList.value = []
- subListBackup = []
- currentRow.value = {}
- }
- let getList = () => {
- loading.value = true
- zoho.CRM.API.coql({
- select_query:
- 'select Name,Forwarder,ETD,ATD,ETA,ATA,Cut_Off_Date,Owner,Status,Modified_Time,SubscriptionId,Carrier,Booking_Number,GRN from Sea_Freight_Table' +
- " where ETD between '" +
- `${dateRange.value.map((i) => dayjs(i).format('YYYY-MM-DD')).join("' and '")}` +
- "'",
- })
- .then((res: any) => {
- if (Array.isArray(res.data) && res.data.length) {
- list.value = res.data.sort(
- (a: any, b: any) =>
- new Date(b.Cut_Off_Date).getTime() -
- new Date(a.Cut_Off_Date).getTime(),
- )
- } else if (res.status === 204) {
- ElNotification({
- type: 'warning',
- title: 'No Data Found',
- message: res.statusText || `zoho api return: ${res.status}`,
- duration: 3000,
- })
- list.value = []
- clearSubList()
- }
- })
- .finally(() => (loading.value = false))
- }
- let currentRow = ref({} as any)
- let subList = ref([] as any[])
- // 未经过滤的crm数据
- let subListBackup: any[] = []
- watch(currentTab, (value: string) => {
- // 切到可用tab, 但是当前行是不是 可用 状态
- let notAvaliable = value === 'avaliable' && currentRow.value.Status !== '可用'
- // 切到关闭tab, 但当前行不是‘关闭’状态
- let notClose =
- value === 'voyage_closed' &&
- !['已截仓', '已确认', '已发出'].includes(currentRow.value.Status)
- if (notAvaliable || notClose) {
- clearSubList()
- } else {
- generateSubList()
- }
- })
- const generateSubList = () => {
- // clonedeep 是因为数据里面有 object array, 担心浅复制到表单变量会影响到原始数据
- subList.value = cloneDeep(
- subListBackup
- .filter(
- (i: any) =>
- i.Parent_Id.id === currentRow.value.id &&
- (currentTab.value === 'my_request'
- ? i.Sales_Person === currentUserName.value
- : true),
- )
- .map((i: any) => ({
- ...i,
- Requester: i.Requester?.id
- ? {
- name: i.Requester.name || '',
- id: i.Requester.id,
- }
- : { name: '', id: '' },
- Sample: i.Sample || false,
- batchRecord: i.Batch_Record?.id || '',
- addFlag: false,
- editFlag: false,
- deleteFlag: false,
- })),
- )
- }
- const changeTotal = (row: any) => {
- row.editFlag = true
- row.Total_FOB = (Number(row.Unit_Price) * Number(row.Quantity)).toFixed(2)
- }
- /**
- * 用来增加新行的数据模版
- */
- const newLineTemplate = {
- addFlag: true,
- editFlag: true,
- deleteFlag: false,
- batchRecord: '',
- // 提交表单前删掉以上字段
- // id: '',
- Sample: false,
- Batch_Record: {
- name: '',
- id: '',
- } as any,
- Parent_Id: {
- name: '',
- id: '',
- } as any,
- Carton: '',
- Marks_Nos: '',
- Description_of_Goods: '',
- Material_of_Goods: [],
- Quantity: '',
- Unit_Price: '',
- Weight: '',
- Cube: '',
- Total_FOB: '',
- Requester: { name: '', id: '' } as any,
- Sales_Person: '', // 申请人
- User_Notes: '',
- }
- // 用在弹窗里面给批次记录做候选项
- let batchListOption = computed(() =>
- subList.value
- .filter(
- (i) =>
- i.Batch_Record && i.Batch_Record.name && i.Batch_Record.name.length > 0,
- )
- .map((i) => {
- return {
- Name: i.Batch_Record.name || '',
- id: i.Batch_Record.id || '',
- isSearch: false, // 用来区分是搜索出来的还是原始数据
- }
- })
- // ai生成的去重逻辑.
- .filter(
- (item, index, self) =>
- index ===
- self.findIndex((t) => t.Name === item.Name && t.id === item.id),
- ),
- )
- let computedOption = computed(() => {
- return qcList.value.concat(batchListOption.value)
- })
- let getSubList = (e: any = {}) => {
- if (e.id) currentRow.value = e
- loading.value = true
- zoho.CRM.API.searchRecord({
- Entity: 'Sea_Freight_Details',
- Type: 'criteria',
- Query: `(Parent_Id:equals:${currentRow.value.id})`,
- delay: false,
- })
- .then((res: any) => {
- if (Array.isArray(res.data) && res.data.length) {
- subListBackup = cloneDeep(res.data)
- } else {
- subListBackup = []
- }
- generateSubList()
- newLineTemplate.Parent_Id = { id: currentRow.value.id }
- newLineTemplate.Sales_Person = currentUserName.value
- newLineTemplate.Requester = {
- id: currentUser.value,
- name: currentUserName.value,
- }
- })
- .finally(() => (loading.value = false))
- }
- // 货物材质候选数据
- const goodMaterialOption = ref([
- 'Cotton 棉',
- 'Iron 铁',
- 'Neoprene 潜水料',
- 'Paper 纸质',
- 'Plastic 塑料',
- 'Polyester Fibre 聚酯纤维',
- 'PU 聚氨酯',
- 'PVC 聚氯乙烯',
- 'Velvet 天鹅绒',
- 'Zinc alloy 锌合金',
- 'Aluminum alloy 铝合金',
- 'Glass 玻璃',
- 'Rubber 橡胶',
- 'Stainless Steel 不锈钢',
- ])
- // 动态获取货物材质候选数据
- let getGoodMaterialOption = () => {
- request
- .post('/common/getWebsiteSubform', { id: '4791186000359651051' })
- .then((resp: any) => {
- // console.log(resp, 'res')
- const res = resp.data.result || {}
- if (Array.isArray(res.data) && res.data.length) {
- console.log(res.data, 'res.data')
- goodMaterialOption.value =
- res.data[0].Website_Subform.map(
- (i: any) => i.Website_Subform_Value,
- ) || []
- }
- })
- }
- getGoodMaterialOption()
- const addBulkProduct = () => {
- let temp = cloneDeep(newLineTemplate)
- temp.Sample = false
- subList.value.unshift(temp)
- }
- const addSample = () => {
- let temp = cloneDeep(newLineTemplate)
- temp.Sample = true
- subList.value.unshift(temp)
- }
- const onDeleteRow = (row: any, index: number = -1) => {
- if (row.addFlag) {
- subList.value.splice(index, 1)
- } else {
- row.deleteFlag = true
- ElNotification({
- type: 'warning',
- title: '已标记删除',
- duration: 3000,
- message: '点 提交 按钮后会正式删除. 误操作请点击 放弃改动.',
- })
- }
- }
- const onBatchRecordChange = ($e: string, line = -1) => {
- const temp = qcList.value.filter((i) => i.id === $e)
- let result: any = {}
- if (temp.length) {
- result = cloneDeep(temp[0])
- }
- if (line > -1) {
- // 主页面数据编辑
- subList.value[line].editFlag = true
- subList.value[line].Batch_Record = { id: result.id, name: result.Name }
- if (result.Owner) {
- subList.value[line].Requester = {
- name: result.Owner.name,
- id: result.Owner.id,
- }
- }
- }
- }
- // 给子表格加红绿背景. 颜色用的tailwind的 red green
- const calcRowStyle = ($e: any) => {
- const result = {} as any
- if ($e.row.addFlag) result['background-color'] = 'rgb(187, 247, 208)'
- if ($e.row.editFlag) result['background-color'] = 'rgb(187, 247, 208)'
- if ($e.row.deleteFlag) result['background-color'] = 'rgb(254, 202, 202)'
- return result
- }
- const commit = () => {
- let temp = cloneDeep(subList.value)
- let result = temp
- .filter((i) => !i.deleteFlag)
- .map((i) => {
- return {
- id: i.id,
- Sample: i.Sample || false,
- Batch_Record: i.batchRecord
- ? {
- name: i.Batch_Record.name,
- id: i.Batch_Record.id,
- }
- : '',
- Parent_Id: {
- name: i.Parent_Id.name,
- id: i.Parent_Id.id || '',
- },
- Material_of_Goods: i.Material_of_Goods,
- Requester: i.Requester.name
- ? {
- name: i.Requester.name,
- id: i.Requester.id || '',
- }
- : '',
- Sales_Person: i.Sales_Person || '',
- Carton: i.Carton || '',
- Marks_Nos: i.Marks_Nos || '',
- Description_of_Goods: i.Description_of_Goods || '',
- Quantity: i.Quantity || '',
- Unit_Price: i.Unit_Price || '',
- Weight: i.Weight || '',
- Cube: i.Cube || '',
- Total_FOB: i.Total_FOB || '',
- User_Notes: i.User_Notes || '',
- }
- }) as any[]
- result = result.concat(
- temp
- .filter((i) => i.deleteFlag)
- .map((i) => ({ id: i.id, _delete: null, Material_of_Goods: null })),
- )
- const emptyBatchRecordList: number[] = []
- const emptyUserNotesList: number[] = []
- result.forEach((i, index) => {
- if (!i.Sample) {
- if (!i.Batch_Record) {
- emptyBatchRecordList.push(index)
- }
- }
- if (!i.User_Notes) {
- emptyUserNotesList.push(index)
- }
- })
- if (emptyBatchRecordList.length) {
- ElNotification({
- title: '请检查表单',
- message: `第 ${emptyBatchRecordList.map((i) => i + 1).join(', ')} 行的Batch Record数据`,
- duration: 5000,
- })
- return
- }
- if (emptyUserNotesList.length) {
- ElNotification({
- title: '请检查表单, 备注是必填的',
- message: `第 ${emptyUserNotesList
- .map((i) => i + 1)
- .join(', ')} 行的备注数据, 不能为空`,
- duration: 5000,
- })
- return
- }
- console.log(result, 'submit result')
- loading.value = true
- request
- .post('/sea_freight/updateSeaFreightData', {
- id: newLineTemplate.Parent_Id.id,
- Sea_Freight_array: result,
- Sales_Person: currentUserName.value,
- Sales_Person_Obj: {
- id: currentUser.value,
- name: currentUserName.value,
- },
- })
- .then((res) => {
- if (res.data.code === 1) {
- ElNotification({
- title: '保存成功',
- message: '正在刷新数据',
- duration: 3000,
- })
- getSubList(currentRow.value)
- } else {
- ElMessage.error('保存出错')
- loading.value = false
- }
- })
- .catch((e) => {
- console.log(e, 'commit error')
- loading.value = false
- })
- }
- let printDrawerVisible = ref(false)
- let currentPrintRow = ref({} as any)
- const print = (row: any) => {
- currentPrintRow.value = row
- printDrawerVisible.value = true
- }
- const exportSubTable = () => {
- const headers = [
- '箱数 Carton',
- '唛头 Marks & Nos',
- '货物名称 Description of Goods',
- '货物材质 Material goods',
- '数量 QTY',
- '单价 澳币/AUD Unit Price',
- '重量KG Weight',
- '体积m³ Cube',
- '总离岸价 澳币/AUD Total FOB',
- '负责人 Owner',
- ]
- const data: any[] = subList.value.map((i) => {
- return {
- '箱数 Carton': i.Carton || '',
- '唛头 Marks & Nos': i.Marks_Nos || '',
- '货物名称 Description of Goods': i.Description_of_Goods || '',
- '货物材质 Material goods': i.Material_of_Goods,
- '数量 QTY': i.Quantity || '',
- '单价 澳币/AUD Unit Price': i.Unit_Price || '',
- '重量KG Weight': i.Weight || '',
- '体积m³ Cube': i.Cube || '',
- '总离岸价 澳币/AUD Total FOB': i.Total_FOB || '',
- '负责人 Owner': i.Requester.name || '',
- }
- })
- if (data.length === 0) {
- throw new Error('Invalid data: Data array is empty.')
- }
- const worksheetData = []
- worksheetData.push(['发票/装箱单/INVOICE/PACKING LIST'])
- if (headers && headers.length > 0) {
- worksheetData.push(headers)
- } else {
- worksheetData.push(Object.keys(data[0]))
- }
- data.forEach((row) => {
- worksheetData.push(Object.values(row))
- })
- const wb = XLSX.utils.book_new()
- let ws = XLSX.utils.aoa_to_sheet(worksheetData)
- ws['!merges'] = [
- { s: { r: 0, c: 0 }, e: { r: 0, c: 9 } }, // 合并列作为标题
- ]
- ws['!cols'] = [
- { wpx: 80 },
- { wpx: 200 },
- { wpx: 180 },
- { wpx: 120 },
- { wpx: 90 },
- { wpx: 120 },
- { wpx: 100 },
- { wpx: 100 },
- { wpx: 120 },
- { wpx: 120 },
- ]
- XLSX.utils.book_append_sheet(wb, ws, 'Sheet1')
- XLSX.writeFile(wb, 'test.xlsx')
- }
- let qcList = ref([] as any[])
- let loading2 = ref(false)
- const search = (keyword: string) => {
- if (keyword.length < 2) return
- loading2.value = true
- zoho.CRM.API.searchRecord({
- Entity: 'QC_Record',
- Type: 'criteria',
- Query: `(Reference:in:${keyword})or(Reference:starts_with:${keyword})or(Purchase_Order.name:in:${keyword})or(Purchase_Order.name:starts_with:${keyword})`,
- delay: false,
- })
- .then((res: any) => {
- if (Array.isArray(res.data) && res.data.length) {
- qcList.value.concat(
- res.data.map((i: any) => {
- return {
- ...i,
- isSearch: true,
- }
- }),
- )
- } else {
- // qcList.value = []
- ElMessage.warning('No Data Found')
- }
- })
- .finally(() => (loading2.value = false))
- }
- const ensure = () => {
- ElMessageBox.confirm('确定要把该记录状态更新为"已确认"吗?', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning',
- }).then(() => {
- loading.value = true
- zoho.CRM.API.updateRecord({
- Entity: 'Sea_Freight_Table',
- Trigger: ['workflow'],
- APIData: {
- id: currentRow.value.id,
- Status: '已确认',
- },
- }).then((res: any) => {
- if (
- Array.isArray(res.data) &&
- res.data.length &&
- res.data[0].code === 'SUCCESS'
- ) {
- ElMessage.success('操作成功, 正在刷新数据')
- loading.value = false
- getList()
- clearSubList()
- } else {
- loading.value = false
- ElMessage.error('操作失败, 请稍后再试或者联系管理员')
- }
- })
- })
- }
- let bookingNumber = ref('')
- const updateBookingNumber = () => {
- bookingNumber.value = bookingNumber.value.trim()
- if (!bookingNumber.value || !currentRow.value.id) {
- ElMessage.error('请填写订舱号')
- return
- }
- loading.value = true
- ElMessageBox.confirm(
- `确定要把该记录的订舱号更新为"${bookingNumber.value}"吗?`,
- {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning',
- },
- ).then(() => {
- zoho.CRM.API.updateRecord({
- Entity: 'Sea_Freight_Table',
- Trigger: ['workflow'],
- APIData: {
- id: currentRow.value.id,
- Booking_Number: bookingNumber.value,
- },
- }).then((res: any) => {
- if (
- Array.isArray(res.data) &&
- res.data.length &&
- res.data[0].code === 'SUCCESS'
- ) {
- ElMessage.success('操作成功, 正在刷新数据')
- loading.value = false
- getList()
- clearSubList()
- } else {
- loading.value = false
- ElMessage.error('操作失败, 请稍后再试或者联系管理员')
- }
- })
- })
- }
- // @ts-ignore
- const zoho = window.ZOHO
- zoho.embeddedApp.on('PageLoad', function () {
- zoho.CRM.CONFIG.getCurrentUser().then(function (data: any) {
- if (Array.isArray(data.users) && data.users.length) {
- const user = data.users[0]
- // console.log(user, 'user')
- currentUser.value = user.id
- currentUserName.value = user.full_name || ''
- currentUserRawData.value = cloneDeep(user)
- getList()
- }
- })
- })
- zoho.embeddedApp.init()
- watch(currentUserRawData, () => {
- if (!currentUserRawData.value.role) return false
- let result = currentUserRawData.value.role.name.indexOf('Logistics') === -1
- if (result) {
- finalTabs.value = cloneDeep(tabs)
- finalTabs.value.push({
- label: 'Arrangement',
- value: 'Arrangement',
- })
- }
- })
- let computedWeight = computed(() => {
- return subList.value
- .reduce((t, c) => {
- t = t + Number(c.Weight)
- return t
- }, 0)
- .toFixed(2)
- })
- let computedCube = computed(() => {
- return subList.value
- .reduce((t, c) => {
- t = t + Number(c.Cube)
- return t
- }, 0)
- .toFixed(2)
- })
- let computedTotalFOB = computed(() => {
- return subList.value
- .reduce((t, c) => {
- t = t + Number(c.Total_FOB)
- return t
- }, 0)
- .toFixed(2)
- })
- // 订单轨迹地图插件
- let mapDrawerVisible = ref(false)
- const openMapDrawer = (row: any) => {
- mapDrawerVisible.value = true
- // console.log(row.Carrier, 'row.value.Carrier')
- // console.log(row.Booking_Number, 'row.value.Booking_Number')
- if ((window as any).Sgld) {
- nextTick(() => {
- ;(window as any).Sgld.createContainerTrack({
- id: 'mapDrawer',
- carrierCode: row.Carrier, // 船公司代码
- billNo: row.Booking_Number, // 提单号
- })
- })
- }
- }
- const closeMapDrawer = () => {
- mapDrawerVisible.value = false
- }
- </script>
- <style lang="scss">
- .page-cargo-consolidation {
- .el-table__body tr.current-row > td.el-table__cell {
- background-color: rgb(56, 163, 238);
- color: #fff;
- }
- }
- </style>
- <style lang="scss" scoped>
- .el-button.custom-button {
- height: 24px;
- line-height: 24px;
- background-image: linear-gradient(
- 171deg,
- rgb(28, 74, 136) 49%,
- rgb(0, 130, 193) 100%
- );
- background-color: rgb(97, 165, 245);
- color: #fff;
- font-size: 13px;
- font-family: Zoho_Puvi_Bold sans-serif;
- border-radius: 6px;
- cursor: pointer;
- &:hover,
- &:active {
- background-image: linear-gradient(
- 171deg,
- rgb(28, 74, 136) 49%,
- rgb(22, 208, 239) 100%
- );
- }
- &.fb {
- font-weight: 900;
- }
- &.small {
- height: 24px;
- line-height: 24px;
- }
- }
- </style>
|