| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- import { shallowRef, reactive, computed } from 'vue'
- import { v4 } from 'uuid'
- import { useDataTable } from '@/hooks/datatable'
- import { getTableColumns } from '@/business/table'
- import { formatDecimal } from '@/filters'
- import { ClientType } from '@/constants/client'
- import { Market } from '@/constants/market'
- import { queryWarehouseInfo } from '@/services/api/warehouse'
- import { addZSGoods, queryDiamondList, queryDiamondDetails } from '@/services/api/goods'
- import { sessionData } from '@/stores'
- import {
- Category,
- getCategoryList,
- getCurrencyTypeList,
- getShapeTypeList,
- getColorTypeList,
- getCutTypeList,
- getClarityTypeList,
- getPolishTypeList,
- getSymmetryTypeList,
- getFluorescenceTypeList,
- getCurrencyTypeInfo,
- getCertTypeList,
- getCrystalTypeList,
- getStyleTypeList,
- getFancyColorType1List,
- getFancyColorType2List,
- getFancyColorType3List,
- } from '@/constants/diamond'
- // 钻石列表相关
- export function useDiamond() {
- const { UserID } = sessionData.getValue('loginInfo')
- const { dataList, total, pageIndex, pageSize, inputList, selectList, buttonList, getQueryParam } = useDataTable<Ermcp.MyWRPositionRsp>()
- const loading = shallowRef(false)
- const columns = getTableColumns('warehousingDiamond')
- selectList.value = [
- {
- label: '商品分类',
- key: 'zscategory',
- selectedValue: Category.Diamonds,
- options: getCategoryList(),
- },
- {
- label: '仓库',
- key: 'warehouseid',
- options: [],
- },
- ]
- inputList.value = [
- { label: '商品', keys: ['goodsno'] },
- ]
- const getDiamondList = () => {
- const param = getQueryParam()
- loading.value = true
- return queryDiamondList({
- data: {
- page: pageIndex.value,
- pagesize: pageSize.value,
- wruserid: UserID,
- zscategory: selectList.value[0].selectedValue as Ermcp.MyWRPositionRsp['zscategory'],
- zsallproperties: param.goodsno,
- warehouseid: param.warehouseid,
- },
- success: (res) => {
- total.value = res.total
- dataList.value = res.data
- },
- fail: () => {
- dataList.value = []
- },
- complete: () => {
- loading.value = false
- }
- })
- }
- const [reset, search] = buttonList.value
- reset.onClick = () => {
- selectList.value.forEach((e, i) => {
- if (i) {
- e.selectedValue = undefined
- }
- })
- inputList.value.forEach((e) => e.value = undefined)
- getDiamondList()
- }
- search.onClick = getDiamondList
- // 获取仓库列表
- queryWarehouseInfo({
- data: {
- userid: UserID,
- status: 1,
- isincludeexchange: true,
- },
- success: (res) => {
- const warehouse = selectList.value[1]
- res.data.forEach((e) => {
- warehouse.options.push({
- label: e.warehousename,
- value: e.autoid
- })
- })
- }
- })
- return {
- loading,
- dataList,
- total,
- pageIndex,
- pageSize,
- columns,
- inputList,
- selectList,
- buttonList,
- getDiamondList,
- }
- }
- // 钻石详情相关
- export function useDiamondDetails(goodsno: string) {
- const loading = shallowRef(false)
- const details = shallowRef<Ermcp.DiamondDetailsRsp>()
- const getDiamondDetails = () => {
- loading.value = true
- return queryDiamondDetails({
- data: {
- goodsno,
- },
- success: (res) => {
- details.value = res.data
- },
- complete: () => {
- loading.value = false
- }
- })
- }
- return {
- loading,
- details,
- getDiamondDetails
- }
- }
- // 钻石表单操作相关
- export function useDiamondForm(category: Category) {
- const { UserID, AccountIDs } = sessionData.getValue('loginInfo')
- const loading = shallowRef(false)
- const warehouseList = shallowRef<Ermcp.WarehouseInfoRsp[]>([]) // 仓库列表
- const performanceId = shallowRef<number>() // 选中的履约模板ID
- const shapeId = shallowRef<number>() // 选中的形状ID
- const formData = reactive<Partial<Proto.GZWRStandardExInfo>>({
- ZSCategory: category,
- })
- // 选中的枚举类型
- const selectedType = reactive({
- colorType: computed({
- get: () => [formData.ZSColorType1, formData.ZSColorType2],
- set: (val) => {
- formData.ZSColorType1 = val[0]
- formData.ZSColorType2 = val[1]
- }
- }),
- cutType: computed({
- get: () => [formData.ZSCutType1, formData.ZSCutType2],
- set: (val) => {
- formData.ZSCutType1 = val[0]
- formData.ZSCutType2 = val[1]
- }
- }),
- clarityType: computed({
- get: () => [formData.ZSClarityType1, formData.ZSClarityType2],
- set: (val) => {
- formData.ZSClarityType1 = val[0]
- formData.ZSClarityType2 = val[1]
- }
- }),
- polishType: computed({
- get: () => [formData.ZSPolishType1, formData.ZSPolishType2],
- set: (val) => {
- formData.ZSPolishType1 = val[0]
- formData.ZSPolishType2 = val[1]
- }
- }),
- symmetryType: computed({
- get: () => [formData.ZSSymmetryType1, formData.ZSSymmetryType2],
- set: (val) => {
- formData.ZSSymmetryType1 = val[0]
- formData.ZSSymmetryType2 = val[1]
- }
- }),
- fluorescenceType: computed({
- get: () => [formData.ZSFluorescenceType1, formData.ZSFluorescenceType2],
- set: (val) => {
- formData.ZSFluorescenceType1 = val[0]
- formData.ZSFluorescenceType2 = val[1]
- }
- }),
- })
- // 枚举类型列表
- const enums = {
- currencyTypeList: getCurrencyTypeList(),
- shapeTypeList: getShapeTypeList(),
- colorTypeList: getColorTypeList(),
- cutTypeList: getCutTypeList(),
- clarityTypeList: getClarityTypeList(),
- polishTypeList: getPolishTypeList(),
- symmetryTypeList: getSymmetryTypeList(),
- fluorescenceTypeList: getFluorescenceTypeList(),
- certTypeList: getCertTypeList(),
- crystalTypeList: getCrystalTypeList(),
- styleTypeList: getStyleTypeList(),
- fancyColorType1List: getFancyColorType1List(),
- fancyColorType2List: getFancyColorType2List(),
- fancyColorType3List: getFancyColorType3List(),
- }
- if (enums.currencyTypeList.length) {
- formData.ZSCurrencyType = enums.currencyTypeList[0].value
- }
- // 克拉单位
- const caratUnit = computed(() => {
- const { Price, Weight } = formData
- if (Price && Weight) {
- return formatDecimal(Price / Weight)
- }
- return '0.00'
- })
- // 货币信息
- const currencyInfo = computed(() => getCurrencyTypeInfo(formData.ZSCurrencyType ?? 0))
- const formSubmit = () => {
- loading.value = true
- return addZSGoods({
- data: {
- UserID,
- AccountID: AccountIDs[0],
- AddType: performanceId.value ? 2 : 1,
- MarketID: Market.GZ,
- OrderSrc: 2,
- ClientType: ClientType.Web,
- ClientSerialNo: v4(),
- GZ_WRStandardExInfo: formData,
- PerformanceTemplateID: performanceId.value,
- },
- complete: () => {
- loading.value = false
- }
- })
- }
- // 获取仓库列表
- queryWarehouseInfo({
- data: {
- userid: UserID,
- status: 1,
- isincludeexchange: true,
- },
- success: (res) => {
- warehouseList.value = res.data
- }
- })
- return {
- loading,
- formData,
- performanceId,
- shapeId,
- caratUnit,
- enums,
- selectedType,
- warehouseList,
- currencyInfo,
- formSubmit,
- }
- }
|