12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289 |
- <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
- size="small"
- @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
- v-if="['Arrangement', 'my_request'].includes(currentTab)"
- size="small"
- @click="addBulkProduct"
- >
- 提交大货集货申请
- </el-button>
- <el-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
- 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[]"
- :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"
- prop="Sales_Person"
- >
- <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 || '',
- }
- })
- // 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 = res.data
- } 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: 32px;
- line-height: 32px;
- 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>
|