| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269 |
- /*******************************************************************************
- * Copyright(c) 2024 dongke All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:
- * 2.功能描述:表单-(开单)
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 周兴 2024-1-30 1.00 新建
- *******************************************************************************/
- const common = require('@/utils/common');
- const mixins = require('@/mixins/index.js')
- const util = require('@/utils/util.js')
- const Constants = require('@/utils/Constants');
- const chooseLocation = requirePlugin('chooseLocation');
- const config = require('@/config/config.js')
- import Dialog from '@/dist/dialog/dialog.js';
- const app = getApp();
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- // 区域
- cardList: {
- type: Array,
- value: [],
- observer: function (newVal) {
- if (newVal) {
- let filters = newVal.filter(it => it.name == 'items')
- if (filters && filters.length > 0) {
- this.setData({
- itemCard: {
- ...filters[0]
- }
- })
- }
- }
- }
- },
- // 内容
- contentObj: {
- type: Object,
- },
- // 点击那个日期显示哪个日期的时间戳
- dataTime: {
- type: Number,
- },
- // 开单组件类型(sale,pur)
- type: {
- type: String,
- },
- // 外部传入控制的选商品所有标识的集合
- controlFlags: {
- type: Object, // controlFlags 是一个对象
- value: {}, // 默认值是一个空对象
- },
- // 类型 sale; basic
- popType: {
- type: String,
- value: 'sale'
- },
- // 路由名称
- routeObjName: {
- type: String
- },
- titleTagCol: {
- type: String,
- value: 'titleTag'
- },
- titleCol: {
- type: String,
- value: 'title'
- },
- iconCol: {
- type: String,
- value: 'iconThumPath'
- },
- pupPriceCol: {
- type: String,
- value: 'priceCol'
- },
- // 价格列
- priceCol: {
- type: String,
- value: 'priceSale'
- },
- // 数量列
- quantityCol: {
- type: String,
- value: 'itemQuantity'
- },
- // 数量列
- descCol: {
- type: String,
- value: 'desc'
- },
- // pop底部描述列
- subCol: {
- type: String,
- value: 'desc'
- },
- // 价格标题
- priceTitle: {
- type: String,
- },
- sumStandardCol: {
- type: String,
- value: 'sumStandard'
- },
- discountStandardCol: {
- type: String,
- value: 'discountStandard'
- },
- sumQuantityCol: {
- type: String,
- value: 'sumQuantity'
- },
- sumAmountCol: {
- type: String,
- value: 'sumAmount'
- },
- swipeDisabled: {
- type: String,
- },
- sumAmountColFlag: {
- type: Boolean,
- value: true
- },
- isDetailFlag:{
- type: Boolean,
- value: false
- },
- // 可用收款列
- canUseCollectCol: {
- type: String,
- value: 'canUseCollect'
- },
- // 收款列
- useCollectCol: {
- type: String,
- value: 'useCollect'
- },
- // 弹框的内容
- popContent: {
- type: Array,
- },
- popupTopObj: {
- type: Array,
- },
- // 是否只读
- readonly: {
- type: Boolean,
- },
- titpsFlag: { //商品右上角信息
- type: Boolean,
- value: false
- },
- titpsItemColorFlagKey: {
- type: String,
- },
- titpsLabel: {
- type: String
- },
- stepperFlag: { //步进器 标识
- type: Boolean,
- },
- quantityMin: { //步进器 最小值
- type: String,
- },
- quantityMax: {
- type: String
- },
- showPopFlag: { //弹窗标识 true 不弹窗
- type: Boolean,
- },
- staff: {
- type: String, //主从业务员
- },
- org: {
- type: String, //主从业务部门
- },
- saleStaffAndOrgFlag: {
- type: Boolean,
- value: true
- },
- cardContentList: { //商品明细下的选单
- type: Array,
- },
- quantityRedCol: { //例 可售量显示字段 key
- type: String,
- },
- quantityRedColFlagKey: { // 显示隐藏整行的key 商品明细控制
- type: String
- },
- quantityRedTitle: { //右侧显示文字
- type: String,
- value: '可售量:'
- },
- goodsTagText: { //自定义tag
- type: String,
- value: ''
- },
- // 表名,用于上传附件
- table: {
- type: String,
- },
- // 删除时是否进行校验
- delValidFlag: {
- type: Boolean,
- },
- // 显示盈亏数量 和盈亏原因
- lossReasonFlag: {
- type: Boolean,
- },
- // 对象取值列
- objCol: {
- type: String
- },
- // 对象列名
- objLabel: {
- type: String
- },
- // 对象类型(客户customer;供应商supplier)
- objType: {
- type: String
- },
- // 对象标题
- objTitle: {
- type: String,
- value: 'cusName'
- },
- // 对象副标题
- objSubTitle: {
- type: String,
- value: 'cusPhone'
- },
- // 金额标题
- amountTitle: {
- type: String,
- value: '应收金额'
- },
- // 金额列
- amountCol: {
- type: String,
- value: 'receivableResidue'
- },
- // 对象Id列
- objIdCol: {
- type: String,
- value: 'cusId'
- },
- chooseText: {
- type: String,
- },
- goodsTagColor: { //标签颜色
- type: String,
- },
- // 结果集
- value: {
- type: String,
- observer: function (newVal) {
- if (newVal) {
- this.setData({
- form: JSON.parse(newVal) || {}
- })
- } else {
- this.setData({
- form: {}
- })
- // 清空明细的合计
- if (this.data.itemCard) {
- let cardList = this.data.cardList
- let index = cardList.findIndex(it => it.name == 'items');
- // 先删除掉
- cardList = cardList.filter(it => it.name != 'items');
- // 再插入
- cardList.splice(index, 0, {
- ...this.data.itemCard
- })
- // console.log('rrr1',filters);
- // if(filters && filters.length > 0){
- // filters[0] = {...this.data.itemCard}
- // }
- this.setData({
- cardList: cardList
- })
- }
- }
- }
- }
- },
- /**
- * 组件的初始数据
- */
- data: {
- // 系统版本
- gradeCode: null,
- // 是否显示pop
- show: false,
- showDate: false,
- showPop: false,
- $t: app.globalData.lang,
- routeUrl: app.globalData['routeUrl'],
- item: null,
- index: null,
- dataItem: null,
- dataIndex: null,
- card: null,
- itemCard: null, // 记录明细信息,清空时使用
- key: null,
- // 下拉类型
- dropType: null,
- dropCode: null,
- dropName: null,
- itemName: 'goodsList',
- deleteName: 'deleteList',
- selectCoordinationUrl: '/package-base-select/pages/select-choose-coordination/select-choose-coordination',
- selectGoodsUrl: null,
- chooseVisible: true, // 用于联动控制选商品按钮
- maxSize: Constants.uploadFileConfig.maxSize,
- imageUrl: config.image_url + '/static/img/',
- // popContent:
- // [{ code: 'quantity', type: 'step', title: '数量', required: true }, { code: 'pricePromotion', type: 'number', title: '销售价格', required: true }, { code: 'warehouseId', name: 'warehouseName', type: 'drop', required: true, dropType: 'warehouse' , required: true}, { code: 'color', type: 'str', title: '批次号' , required: true}, { code: 'giftFlag', type: 'checkbox', title: '赠品标识' }],
- form: {}
- },
- lifetimes: {
- attached: function () {
- // 获取系统版本
- this.setData({
- gradeCode: app.globalData.company.gradeCode
- })
- // 销售订单
- if (this.data.type == Constants.billType.sale || this.data.type == Constants.billType.saleOut ||
- this.data.type == Constants.billType.pur || this.data.type == Constants.billType.purInto || this.data.type == Constants.billType.saleOutReturn ||
- this.data.type == Constants.billType.out || this.data.type == Constants.billType.purReturn) {
- this.setData({
- selectGoodsUrl: '/package-base-select/pages/select-goods/select-goods'
- })
- }
- // 处理contentObj
- this.handleContentObj();
- },
- detached: function () {
- // 在组件实例被从页面节点树移除时执行
- // 清空地址信息
- chooseLocation.setLocation(null);
- },
- },
- pageLifetimes: {
- /**
- * @desc : 生命周期函数--监听页面显示
- * @author : 周兴
- * @date : 2024/2/19 12:16
- */
- show: function () {
- // 设置地址
- this.setAddress();
- // 是否弹出询问框
- this.checkDialog();
- }
- },
- /**
- * 组件的方法列表
- */
- methods: {
- /**
- * @desc : 改变后是否弹出询问
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- checkDialog() {
- let item = this.data.item;
- let originalData = this.data.originalData;
- let form = this.data.form
- let itemName = this.data.itemName
- if (item && item.clearItemFlag && form[itemName] && form[itemName].length > 0 &&
- originalData && originalData.id != form[item.code]) {
- Dialog.confirm({
- message: '是否清空商品明细?',
- }).then(() => {
- form[itemName] = []
- originalData.id = form[item.code]
- originalData.name = form[item.name]
- this.setData({
- originalData: originalData,
- form: form,
- value: JSON.stringify(form)
- })
- }).catch(() => {
- setTimeout(() => {
- form[item.code] = originalData.id
- form[item.name] = originalData.name
- this.setData({
- form: form,
- value: JSON.stringify(form)
- })
- }, 500)
- })
- }
- },
- /**
- * @desc : 处理ContentObj数据
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- handleContentObj(card) {
- let contentObj = this.data.contentObj;
- let cardList = this.data.cardList;
- let form = this.data.form;
- let items = form[this.data.itemName]
- if (cardList && cardList.length > 0 && contentObj) {
- if (card) {
- cardList = cardList.filter(it => it.name == card.name);
- }
- cardList.forEach((it, index) => {
- // 不是明细
- if (it.name != 'items') {
- if (it.displayNum && contentObj[it.name].length > it.displayNum) {
- for (let i = it.displayNum; i < contentObj[it.name].length; i++) {
- // 如果折叠就把超过的部分隐藏
- if (it.showMore) {
- contentObj[it.name][i].show = true;
- } else {
- contentObj[it.name][i].show = false;
- }
- }
- }
- } else {
- // 商品明细
- if (it.displayNum && items && items.length > it.displayNum) {
- for (let i = it.displayNum; i < items.length; i++) {
- // 如果折叠就把超过的部分隐藏//todo
- // console.log('it',it.showMore,items[i]);
- if (it.showMore) {
- items[i].show = true;
- } else {
- items[i].show = false;
- }
- }
- }
- }
- })
- this.setData({
- contentObj: contentObj,
- form: form,
- value: JSON.stringify(form)
- })
- }
- },
- /**
- * @desc : 展开收缩
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- expand(e) {
- let card = e.currentTarget.dataset.card
- let index = e.currentTarget.dataset.index
- let cardList = this.data.cardList
- if (cardList[index]) {
- cardList[index].showMore = !cardList[index].showMore
- }
- this.setData({
- cardList: cardList
- })
- // 处理contentObj
- this.handleContentObj(card);
- },
- /**
- * @desc : 打开Pop进行修改
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- openChoosedItemInfo(e) {
- if (this.data.showPopFlag) {
- return;
- }
- let ds = e.currentTarget.dataset;
- console.log('openChoosedItemInfo',e);
- if ( ds.item.flgSubUnit) {
- ds.item.calculationFormula = ds.item.packBox + ds.item.unitName + '= 1' + ds.item.subUnitName
- ds.item.packageBox = ds.item['box'] + ds.item.subUnitName + ds.item['piece'] + ds.item.unitName
- }
- if (this.data.type == Constants.billType.pur) { //采购订单 采购数量
- ds.item.sumPrice = ds.item['itemQty'] * ds.item.pricePur
- }
- if (this.data.type == Constants.billType.purInto) { //采购入库
- ds.item.sumPrice = ds.item['itemQty'] * ds.item.priceInto
- }
- if ( this.data.type == Constants.billType.out ) {
- ds.item.sumPrice = ds.item['itemQty'] * ds.item.priceOut
- }
-
- if (this.data.type == Constants.billType.saleOut ||
- this.data.type == Constants.billType.inventory) {
- ds.item.sumPrice = ds.item['outingQty'] * ds.item.priceOut
- }
- if (this.data.type == Constants.billType.saleOutReturn) { //销售退货的时候 打开商品的pup 就要计算箱片
- ds.item.sumPrice = ds.item['outingQty'] * ds.item.priceOut
- }
- this.setInitPopData()
- //没有skuid 是外协商品
- let popupTopObj_sku = null
- let popContent_sku = null
- let popContent_ = util.copyObj(this.data.popContent)
- if(ds.item.skuId){ //正常品走
- popupTopObj_sku = this.data.popupTopObj
- popContent_sku = popContent_
- }else{ //外协品走
- // 全-免费版-销售出库-新建、编辑、详情-外协品-抽屉不展示库存量、仓库字段
- popupTopObj_sku = []
- let index = popContent_.findIndex(element => element.code == 'whId');
- if (index !== -1) {
- // 找到了满足条件的元素,index 是它的索引
- popContent_sku = popContent_
- popContent_sku.splice(index,1)
- } else {
- popContent_sku = popContent_
- }
- }
- this.setData({
- popContent_sku:popContent_sku,
- popupTopObj_sku:popupTopObj_sku,
- dataIndex: ds.index,
- dataItem: JSON.stringify(ds.item),
- showPop: true,
- })
- this.triggerEvent("openChoosedItemInfo", {
- item: ds.item,
- index: ds.index
- })
- },
- /**
- * @desc : 再次打开箱片的弹框
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- openPackageBox(e) {
- console.log("openPackageBox-", e);
- let dataItem = JSON.parse(this.data.dataItem)
- //采购入库 销售退货
- if (this.data.type == Constants.billType.sale ||
- this.data.type == Constants.billType.purReturn ||
- this.data.type == Constants.billType.pur ||
- this.data.type == Constants.billType.purInto ||
- this.data.type == Constants.billType.saleOutReturn ||
- this.data.type == Constants.billType.out ||
- this.data.type == Constants.billType.saleOut ||
- this.data.type == Constants.billType.inventory
- ) {
- this.setData({
- popContentBox: [{
- code: 'box',
- type: 'step',
- title: dataItem.subUnitName,
- required: true
- },
- {
- code: 'piece',
- type: 'step',
- title: dataItem.unitName,
- required: true
- },
- ],
- })
- }
- this.setData({
- showPopBox: true,
- })
- },
- /**
- * @desc : 关闭Pop后修改数据
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- editItems(data) {
- let form = this.data.form;
- let itemName = this.data.itemName;
- if (form[itemName]) {
- form[itemName][this.data.dataIndex] = data.detail.form;
- }
- //计算金额
- if (this.data.type == Constants.billType.sale) {
- this.setGoodsAmount()
- }
- if (this.data.type == Constants.billType.saleOut) {
- this.setGoodsOutAmount()
- }
- if (this.data.type == Constants.billType.saleOutReturn) {
- this.setGoodsOutReturnAmount()
- }
- this.setData({
- form: form,
- value: JSON.stringify(form)
- })
- // 外露关闭pop后事件
- this.triggerEvent("editItems", {
- data: form
- })
- },
- /**
- * @desc : 商品确认事件--箱片的确认
- * @date : 2024/2/1 15:49
- * @author : 于继渤
- */
- editItemsBox(e) {
- let dataItem = JSON.parse(this.data.dataItem)
- if (this.data.type == Constants.billType.sale ||
- this.data.type == Constants.billType.pur ||
- this.data.type == Constants.billType.out ||
- this.data.type == Constants.billType.purInto ||
- this.data.type == Constants.billType.inventory
- ) {
- let itemQty = dataItem['box'] * dataItem['packBox'] + dataItem['piece']
- //如果设有做大值 判断 箱片的反算数量 大于 数量最大值
- if (dataItem["itemQty_max"] && itemQty > dataItem["itemQty_max"]) {
- //那就吧 把最大值的数量换算 箱片赋值箱片
- dataItem['box'] = parseInt(dataItem['itemQty'] / dataItem['packBox'])
- dataItem['piece'] = Number(dataItem['itemQty'] % dataItem['packBox'])
- dataItem.packageBox = dataItem['box'] + dataItem.subUnitName + dataItem['piece'] + dataItem.unitName
- this.setData({
- dataItem: JSON.stringify(dataItem)
- })
- util.showToast('超出最大数量');
- return
- }
- //数量等于 包乘以包装数 加上片数
- dataItem['itemQty'] = dataItem['box'] * dataItem['packBox'] + dataItem['piece']
- dataItem.packageBox = dataItem['box'] + dataItem.subUnitName + dataItem['piece'] + dataItem.unitName
- if (this.data.type == Constants.billType.pur) { // 采购订单
- dataItem.sumPrice = dataItem['itemQty'] * dataItem.pricePur
- }
- if (this.data.type == Constants.billType.purInto) { //采购入库
- dataItem.sumPrice = dataItem['itemQty'] * dataItem.priceInto
- }
- if (this.data.type == Constants.billType.out) { //销售退货
- dataItem.sumPrice = dataItem['itemQty'] * dataItem.priceOut
- }
- }
- if (this.data.type == Constants.billType.saleOutReturn) {
- let itemQty = (dataItem['box'] * dataItem['packBox'] + dataItem['piece'])
- let itemQty_min = dataItem.outingQty_min ? Math.abs(dataItem.outingQty_min) : ''; //取绝对值 (因为是负值 即最小值的绝对值 为最大值)
- //如果设有做大值 判断 箱片的反算数量 大于 数量最大值
- if (itemQty_min && itemQty > itemQty_min) {
- //那就吧 把最大值的数量换算 箱片赋值箱片
- let outingQty = Math.abs(dataItem.outingQty); //取绝对值
- dataItem['box'] = parseInt(outingQty / dataItem['packBox'])
- dataItem['piece'] = Number(outingQty % dataItem['packBox'])
- dataItem.packageBox = dataItem['box'] + dataItem.subUnitName + dataItem['piece'] + dataItem.unitName
- this.setData({
- dataItem: JSON.stringify(dataItem)
- })
- util.showToast('超出最大数量');
- return
- }
- //数量等于 包乘以包装数 加上片数
- dataItem['outingQty'] = -1 * (dataItem['box'] * dataItem['packBox'] + dataItem['piece'])
- dataItem.packageBox = dataItem['box'] + dataItem.subUnitName + dataItem['piece'] + dataItem.unitName
- dataItem.sumPrice = dataItem.priceOut * dataItem.itemQty
- }
- if (this.data.type == Constants.billType.saleOut || this.data.type == Constants.billType.inventory) {
- //数量等于 包乘以包装数 加上片数
- dataItem['outingQty'] = dataItem['box'] * dataItem['packBox'] + dataItem['piece']
- dataItem.packageBox = dataItem['box'] + dataItem.subUnitName + dataItem['piece'] + dataItem.unitName
- dataItem.sumPrice = dataItem['outingQty'] * dataItem.priceOut
- }
- this.setData({
- dataItem: JSON.stringify(dataItem)
- })
- },
- /**
- * @desc :商品明细数量加减事件
- * @date : 2024/2/1 15:49
- * @author : 于继渤
- */
- onChangeStepper(e) {
- this.triggerEvent("onStepper", {
- index: e.currentTarget.dataset.index,
- item: e.detail
- })
- },
- /**
- * @desc : 打开下拉/跳转选择页面
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- open(e) {
- // 只读
- let item = e.currentTarget.dataset;
- if (this.data.readonly) {
- return;
- }
- // 明细 只读240320
- if (item.item.readonlyItem) {
- return;
- }
- let that = this
- if (item.item.type == 'drop') {
- this.setData({
- show: true,
- dropCode: item.key,
- dropName: item.name,
- dropType: item.type,
- index: item.index,
- card: item.card
- })
- } else if (item.item.type == 'mutidrop') {
- this.setData({
- mutishow: true,
- dropCode: item.key,
- dropName: item.name,
- dropType: item.type,
- index: item.index,
- card: item.card
- })
- } else if (item.item.type == 'choose') {
- if (item.item.readonlyReturn && !item.item.chooseVisible) {
- return
- }
- that.setData({
- changeObj: item.item.changeObj,
- })
- //判断是否存在此key的值
- if (item.item.titpsKey && !that.data.form[item.item.titpsKey]) {
- // 是否弹出询问框
- Dialog.confirm({
- message: item.item.titpsMessage, //提示信息
- }).then(() => {}).catch(() => {})
- return
- }
- //控制校验提示删除明细
- if (this.data.form[this.data.itemName] && this.data.form[this.data.itemName].length > 0 && this.data.chooseVisible && item.item.chooseVisible) {
- // 是否弹出询问框
- Dialog.confirm({
- message: '请先删除商品明细中的商品', //提示信息
- }).then(() => {}).catch(() => {})
- return
- }
- // 跳转链接
- if (item.item.urlKey) {
- this.setData({
- index: item.index,
- card: item.card,
- item: item.item,
- key: item.key
- })
- let route = this.data.routeUrl[this.data.routeObjName][item.item.urlKey]
- let url = route.url
- if (url) {
- wx.navigateTo({
- url: url,
- events: {
- // 回调后
- bindData: function (data) {
- //处理明细 给明细赋值 例如选仓库回调赋值
- if (item.flag) {
- let form = that.data.form
- form[that.data.itemName][item.index][item.item.code] = data.data.id
- form[that.data.itemName][item.index][item.item.name] = data.data.name
- that.setData({
- form: form
- })
- // 如果有校验信息就清除掉
- let card = that.data.card;
- let index = that.data.index;
- let contentObj = that.data.contentObj;
- if (card && contentObj[card][index]?.errMsg) {
- contentObj[card][index].errMsg = undefined;
- that.setData({
- contentObj: contentObj
- })
- }
- }
- // 如果需要询问,那么需要记录原始的值
- if (item.item.clearItemFlag) {
- that.setData({
- originalData: {
- id: that.data.form[item.key],
- name: that.data.form[item.name]
- }
- })
- }
- that.triggerEvent("chooseData", {
- code: item.key,
- data: data,
- index: item.index
- })
- // 如果需要联动控制选商品按钮
- if (item.item.controlChooseFlag) {
- that.setData({
- chooseVisible: false
- })
- }
- let contentObj = that.data.contentObj;
- if (item.card && contentObj[item.card][item.index]?.errMsg && data) {
- contentObj[item.card][item.index].errMsg = undefined;
- that.setData({
- contentObj: contentObj
- })
- }
- }
- },
- success: function (res) {
- let itemData = item.item
- if (route.primaryKey) {
- itemData.id = that.data.form[route.primaryKey]
- console.log('route', route, that.data.form[route.primaryKey])
- }
- // 通过eventChannel向被打开页面传送数据
- res.eventChannel.emit('params', {
- item: itemData,
- route: route
- })
- }
- })
- }
- }
- } else if (item.item.type == 'selectIcon') {
- // 跳转链接
- if (item.item.urlKey) {
- let url = this.data.routeUrl[this.data.routeObjName][item.item.urlKey].url
- // TODO
- // url = '/package-base6-select/pages/select-customers/select-customers'
- if (url) {
- wx.navigateTo({
- url: url,
- events: {
- // 回调后
- bindData: function (data) {
- that.triggerEvent("chooseData", {
- code: item.key,
- data: data
- })
- // 如果需要联动控制选商品按钮
- if (item.item.controlChooseFlag) {
- that.setData({
- chooseVisible: false
- })
- }
- }
- },
- success: function (res) {
- // 通过eventChannel向被打开页面传送数据
- res.eventChannel.emit('params', {
- data: item.item.urlKeyParam
- })
- }
- })
- }
- }
- }
- },
- /**
- * @desc : 打开选择主从业务员/业务部门组件
- * @author : 周兴
- * @date : 2024/2/20 11:46
- */
- openMulti(e) {
- if (this.data.readonly) {
- return;
- }
- console.log('openMulti', this.data.form)
- let type = e.currentTarget.dataset.type
- let _this = this
- // 选择主从业务员
- if (type == 'staff') {
- wx.navigateTo({
- url: '/package-sales/pages/choose-sale-staff/choose-sale-staff',
- events: {
- // 回调后
- bindData: function (data) {
- _this.triggerEvent("chooseData", {
- code: type,
- data: data
- })
- }
- },
- success: function (res) {
- // 通过eventChannel向被打开页面传送数据
- res.eventChannel.emit('params', {
- id: _this.data.form.staff.value,
- formMode: 'index'
- })
- }
- })
- // 选择主从业务部门
- } else if (type == 'org') {
- wx.navigateTo({
- url: '/package-sales/pages/choose-sale-org/choose-sale-org',
- events: {
- // 回调后
- bindData: function (data) {
- _this.triggerEvent("chooseData", {
- code: type,
- data: data
- })
- }
- },
- success: function (res) {
- // 通过eventChannel向被打开页面传送数据
- res.eventChannel.emit('params', {
- id: _this.data.form.org.value,
- formMode: 'index'
- })
- }
- })
- }
- },
- /**
- * @desc : 非空校验
- * @author : 周兴
- * @date : 2024/2/20 11:46
- */
- validData() {
- let flag = true;
- let cardList = this.data.cardList;
- if (!cardList || cardList.length == 0) {
- return flag;
- }
- let form = this.data.form;
- let contentObj = this.data.contentObj;
- for (let card of cardList) {
- if (contentObj[card.name]) {
- // 明细
- if (card.name == 'items') {
- if (!form[this.data.itemName] || form[this.data.itemName].length == 0) {
- util.showToast('商品明细不能为空')
- return false;
- }
- contentObj[card.name].forEach(item => {
- let title = this.$t(item.title ? item.title : item.code)
- // 如果必须输入,就要进行判断
- if (item.required && form[this.data.itemName] && form[this.data.itemName].length > 0) {
- form[this.data.itemName].forEach(t => {
- if (!t[item.code]) {
- t[item.code + '_errMsg'] = title + '不为空'
- flag = false;
- }
-
- })
- }
- })
- } else {
- contentObj[card.name].forEach(item => {
- let title = this.$t(item.title ? item.title : item.code)
- // 如果必须输入,就要进行判断
- if (item.required && !form[item.code]) {
- item.errMsg = title + '不为空'
- flag = false;
- }
-
- if (item.type == 'phone' && item.required && form[item.code]) {
- // 联系电话格式错误
- var myreg = Constants.Mobile_Phone_Number_Regular_Expression
- if (!myreg.test(form[item.code])) {
- item.errMsg = title + '格式错误'
- flag = false;
- }
- }
- })
- }
- }
- }
- this.setData({
- contentObj: contentObj
- })
- return flag;
- },
- /**
- * @desc : 展开页签
- * @author : 周兴
- * @date : 2024/2/20 11:46
- */
- expandCard(e) {
- let cardList = this.data.cardList
- let index = e.currentTarget.dataset.index
- if (cardList[index]) {
- // 收缩的时候需要展示信息
- let expand = cardList[index].expand
- cardList[index].info = undefined
- if (expand) {
- let form = this.data.form
- let infoCols = e.currentTarget.dataset.item.infoCols
- if (infoCols && infoCols.length > 0) {
- let info = ''
- infoCols.forEach(it => {
- if (form[it]) {
- info += form[it] + '/'
- }
- })
- if (info.length > 0) {
- info = info.substring(0, info.length - 1);
- cardList[index].info = info
- }
- }
- }
- cardList[index].expand = !expand
- this.setData({
- cardList: cardList
- })
- }
- },
- /**
- * @desc : 打开日期pop
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- openDatePop(e) {
- // 只读
- if (this.data.readonly) {
- return;
- }
- let item = e.currentTarget.dataset;
- this.setData({
- showDate: true,
- index: item.index,
- key: item.key,
- card: item.card
- })
- },
- /**
- * @desc : 关闭日期pop
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- cancelDatePop() {
- this.setData({
- showDate: false
- })
- },
- /**
- * @desc : 选择日期
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- chooseDate(e) {
- let form = this.data.form;
- let index = this.data.index;
- let card = this.data.card;
- let code = this.data.key;
- form[code + '_time'] = e.detail
- form[code] = util.toDateStr(e.detail);
- let contentObj = this.data.contentObj;
- if (card && contentObj[card][index]?.errMsg && e.detail) {
- contentObj[card][index].errMsg = undefined;
- }
- this.setData({
- value: JSON.stringify(form),
- form: form,
- contentObj: contentObj,
- showDate: false
- })
- },
- /**
- * @desc : 打开选择商品明细界面
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- openChooseItems(e) {
- if (this.data.selectGoodsUrl) {
- this.setData({
- item: null
- })
- let _this = this
- wx.navigateTo({
- url: this.data.selectGoodsUrl,
- events: {
- // 回调后
- bindData: function (data) {
- // 设置商品明细controlChooseFlag
- console.log('bindDatachoosed', data);
- _this.setGoods({
- data: data
- });
- // 选品后,是否需要控制选单只读
- _this.handleChooseByItem(_this, true);
- }
- },
- success: function (res) {
- // 通过eventChannel向被打开页面传送数据
- res.eventChannel.emit('params', {
- choose: true,
- item: e.currentTarget.dataset.type ? e.currentTarget.dataset.type : _this.data.type,
- popContent: _this.data.popContent,
- controlFlags: _this.data.controlFlags
- })
- }
- })
- }
- },
- openChooseCoordinationItems(e) {
- let _this = this
- wx.navigateTo({
- url: this.data.selectCoordinationUrl,
- events: {
- // 回调后
- bindData: function (data) {
- // // 设置商品明细controlChooseFlag
- _this.setGoods({
- data: data
- });
- }
- },
- success: function (res) {
- // 通过eventChannel向被打开页面传送数据
- res.eventChannel.emit('params', {
- // choose: true,
- item: e.currentTarget.dataset.type ? e.currentTarget.dataset.type : _this.data.type,
- // popContent: _this.data.popContent,
- // controlFlags: _this.data.controlFlags
- })
- }
- })
- },
- /**
- * @desc : 选择数据
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- chooseData(e) {
- let contentObj = this.data.contentObj;
- let form = this.data.form
- if (e.detail.ids) {
- form[this.data.dropCode + 's'] = e.detail.ids;
- form[this.data.dropName + 's'] = e.detail.names;
- } else {
- form[this.data.dropCode] = e.detail.value;
- form[this.data.dropName] = e.detail.text;
- }
- let card = this.data.card;
- // 选择后清空校验提示信息
- if (card && contentObj[card][this.data.index]?.errMsg && e.detail) {
- contentObj[card][this.data.index].errMsg = undefined;
- }
- this.setData({
- value: JSON.stringify(form),
- form: form,
- contentObj: contentObj
- })
- // 如果处理id,name还需要赋值其他,需要在页面事件中自行处理
- this.triggerEvent("chooseData", {
- code: this.data.dropCode,
- item: e.detail.item
- })
- },
- /**
- * @desc : 修改输入框的值
- * @author : 周兴
- * @date : 2024/2/2 11:46
- */
- changeField(e) {
- let ds = e.currentTarget.dataset
- let key = ds.key
- let item = ds.item
- let form = this.data.form
- if (e.detail) {
- form[key] = e.detail;
- } else {
- delete form[key]
- }
- let contentObj = this.data.contentObj;
- // 输入值后清空校验提示信息
- if (item.errMsg && e.detail) {
- contentObj[ds.card][ds.index].errMsg = undefined;
- }
- this.setData({
- form: form,
- contentObj: contentObj
- })
- },
- /**
- * @desc : 失去焦点,把值传出
- * @author : 周兴
- * @date : 2024/2/2 11:46
- */
- blurField(e) {
- let ds = e.currentTarget.dataset
- this.setData({
- value: JSON.stringify(this.data.form)
- })
- this.triggerEvent("changeField", {
- code: ds.key
- })
- },
- /**
- * @desc : 清空输入框的值
- * @author : 周兴
- * @date : 2024/2/2 11:46
- */
- clearField(e) {
- // 只读
- if (this.data.readonly) {
- return;
- }
- let ds = e.currentTarget.dataset
- let key = ds.key
- let form = this.data.form
- form[key] = undefined
- this.setData({
- value: JSON.stringify(form),
- form: form
- })
- // 如果要清除其他值,需要调用
- this.triggerEvent("clear", {
- code: ds.key
- })
- },
- /**
- * @desc : 清空地址的值
- * @author : 周兴
- * @date : 2024/2/2 11:46
- */
- clearAddress(e) {
- let form = this.data.form
- delete form['address']
- delete form['addressName'];
- delete form['addressFull'];
- delete form['addressGcj02'];
- delete form['addressArea'];
- this.setData({
- value: JSON.stringify(form),
- form: form
- })
- // 如果要清除其他值,需要调用
- this.triggerEvent("clear", {
- code: ds.key
- })
- },
- /**
- * @desc : 修改合计金额,反算明细商品
- * @author : 周兴
- * @date : 2024/5/22 11:46
- */
- changeAmount(e) {
- let index = e.currentTarget.dataset.index
- let sumAmountCol = this.data.sumAmountCol
- let cardList = this.data.cardList
- if (cardList && cardList[index]) {
- cardList[index][sumAmountCol] = e.detail.value
- }
- this.setData({
- cardList: cardList
- })
- // this.reCalcItemsAmount();
- },
- /**
- * @desc : 修改合计金额,反算明细商品
- * @author : 周兴
- * @date : 2024/5/22 11:46
- */
- reCalcItemsAmount(amount) {
- let form = this.data.form
- let itemName = this.data.itemName
- let itemList = form[itemName]
- let type = this.data.type
- if (itemList && itemList.length > 0) {
- // 单条明细金额字段
- let pupPriceCol = this.data.pupPriceCol;
- let priceCol = this.data.priceCol;
- let quantityCol = this.data.quantityCol;
- let flag = false;
- let sum = 0;
- // 判断是否所有明细的金额都是0,金额都为0 ,按照数量金额分摊
- let filters = itemList.filter(it => it[pupPriceCol])
- if (!filters || filters.length == 0) {
- // 所有的金额都为0
- flag = true;
- // 获取所有数量的汇总
- sum = itemList.sum(quantityCol)
- } else {
- // 获取所有金额的汇总
- sum = itemList.sum(pupPriceCol)
- }
- itemList.forEach((it, index) => {
- console.log('it', it);
- // 按照数量金额分
- if (flag) {
- it[pupPriceCol] = (it[quantityCol] / sum * amount).toFixed(2)
- } else {
- // 如果按照金额分,金额为0的不分
- if (it[pupPriceCol]) {
- it[pupPriceCol] = (it[pupPriceCol] / sum * amount).toFixed(2)
- }
- }
- it[priceCol] = (parseFloat(it[pupPriceCol]) / it[quantityCol]).toFixed(2)
- })
- this.setData({
- form: form
- })
- }
- },
- /**
- * @desc : 清空日期的值
- * @author : 周兴
- * @date : 2024/2/2 11:46
- */
- clearDate(e) {
- let ds = e.currentTarget.dataset
- let key = ds.key
- let form = this.data.form
- form[key] = undefined
- form[key + '_time'] = undefined
- this.setData({
- value: JSON.stringify(form),
- form: form
- })
- },
- /**
- * @desc : 清空选单的值
- * @author : 周兴
- * @date : 2024/2/2 11:46
- */
- clearChoose(e) {
- let ds = e.currentTarget.dataset
- let key = ds.key
- let name = ds.name
- let item = ds.item
- // 明细 只读只读240320
- if (item.readonlyItem) {
- return;
- }
- let form = this.data.form
- form[key] = undefined
- form[name] = undefined
- this.setData({
- value: JSON.stringify(form),
- form: form
- })
- // 如果需要联动控制选商品按钮
- if (item && item.controlChooseFlag) {
- this.setData({
- chooseVisible: true
- })
- }
- // 如果要清除其他值,需要调用
- this.triggerEvent("clear", {
- code: ds.key
- })
- },
- /**
- * @desc : 修改数值输入框的值
- * @author : 周兴
- * @date : 2024/2/2 11:46
- */
- changeNumberField(e) {
- let ds = e.currentTarget.dataset
- let key = ds.key
- let item = ds.item
- let form = this.data.form
- form[key] = e.detail.value
- let contentObj = this.data.contentObj;
- // 输入值后清空校验提示信息
- if (item.errMsg && e.detail) {
- contentObj[ds.card][ds.index].errMsg = undefined;
- }
- this.setData({
- value: JSON.stringify(form),
- form: form,
- contentObj: contentObj
- })
- },
- /**
- * @desc : 修改数值输入框的值 离焦事件
- * @author : 于继渤
- * @date : 2024/2/2 11:46
- */
- changeNumberBlur(e) {
- this.triggerEvent("changeNumberBlur", e.detail)
- },
- /**
- * @desc : 修改电话的值
- * @author : 周兴
- * @date : 2024/2/2 11:46
- */
- changePhone(e) {
- let ds = e.currentTarget.dataset;
- let key = ds.key;
- let index = ds.index;
- let card = ds.card;
- let form = this.data.form
- form[key] = e.detail.detail
- let contentObj = this.data.contentObj;
- if (card && contentObj[card][index]?.errMsg && e.detail.detail) {
- contentObj[card][index].errMsg = undefined;
- }
- this.setData({
- value: JSON.stringify(form),
- form: form,
- contentObj: contentObj
- })
- },
- /**
- * @desc : 给电话赋值错误信息
- * @author : 周兴
- * @date : 2024/2/20 11:46
- */
- changePhoneblur(e) {
- let ds = e.currentTarget.dataset
- let errMsg = e.detail.errMsg;
- let card = ds.card;
- let index = ds.index;
- let contentObj = this.data.contentObj;
- if (errMsg && card && contentObj[card][index]) {
- contentObj[card][index].errMsg = errMsg;
- this.setData({
- errMsg: errMsg
- })
- }
- this.triggerEvent("changePhoneblur", ds)
- },
- /**
- * @desc : 打开选择对象的页面
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- openObjPop() {
- let _this = this
- if (_this.data.readonly) {
- return
- }
- // 选择客户
- if (this.data.objType == Constants.objType.customer) {
- wx.navigateTo({
- url: '/package-base-select/pages/select-customers/select-customers',
- events: {
- // 回调后
- bindData: function (data) {
- let form = _this.data.form
- let objIdCol = _this.data.objIdCol;
- // 赋值对象Id
- if (objIdCol && data[objIdCol]) {
- form[objIdCol] = data[objIdCol]
- }
- // 客户欠款
- if (data['receivableResidue'] && data['receiptResidue']) {
- data['cusDebt'] = data['receivableResidue'] - data['receiptResidue']
- }
- form.objInfo = data;
- _this.setData({
- form: form,
- value: JSON.stringify(form)
- })
- _this.triggerEvent("chooseObjTypeData", {
- data: form,
- })
- }
- },
- success: function (res) {
- // 通过eventChannel向被打开页面传送数据
- res.eventChannel.emit('params', {
- data: 'test'
- })
- }
- })
- // 选择供应商
- } else if (this.data.objType == Constants.objType.supplier) {
- wx.navigateTo({
- // url: '/package-base-select/pages/select-suppliers/select-suppliers',
- url: '/package-base-select/pages/select-data/select-data',
- events: {
- // 回调后
- bindData: function (data) {
- let dataitem = data.data.item
- let form = _this.data.form
- let objIdCol = _this.data.objIdCol;
- // 赋值对象Id
- if (objIdCol && dataitem[objIdCol]) {
- form[objIdCol] = dataitem[objIdCol]
- }
- form.objInfo = dataitem;
- _this.setData({
- form: form,
- value: JSON.stringify(form)
- })
- _this.triggerEvent("chooseObjTypeData", {
- data: form,
- })
- }
- },
- success: function (res) {
- // 通过eventChannel向被打开页面传送数据
- let item = {}
- let route = _this.data.routeUrl[_this.data.routeObjName];
- res.eventChannel.emit('params', {
- item: item,
- route: route['chooseSupplier']
- })
- }
- })
- }
- },
- /**
- * @desc : 小程序地图调用
- * @author : 周兴
- * @date : 2024/2/18 18:16
- */
- onClickWxchartAddress(e) {
- // 只读
- if (this.data.readonly) {
- return;
- }
- // 跳转新建地图实例
- common.onClickWxchartAddress();
- let item = e.currentTarget.dataset;
- this.setData({
- index: item.index,
- card: item.card
- })
- },
- /**
- * @desc : 改变选择框内容
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- onChange(e) {
- // 只读
- if (this.data.readonly) {
- return;
- }
- let key = e.currentTarget.dataset.key
- let checkFlag = e.currentTarget.dataset.value
- let form = this.data.form
- form[key] = !checkFlag
- this.setData({
- value: JSON.stringify(form),
- form: form
- })
- },
- /**
- * @desc : 设置地址
- * @author : 周兴
- * @date : 2024/1/19
- */
- setAddress() {
- const location = chooseLocation.getLocation();
- console.log('loc', location, this.data.form);
- let form = this.data.form
- if (location) {
- form['address'] = location;
- form['addressName'] = location.name;
- form['addressFull'] = form['addressFull'] ? form['addressFull'] : location.address + location.name;
- form['addressGcj02'] = {
- latitude: location.latitude,
- longitude: location.longitude
- };
- form['addressArea'] = {
- province: location.province,
- city: location.city,
- district: location.district == undefined || !location.district ? location.city : location.district
- }
- // 如果有校验信息就清除掉
- let card = this.data.card;
- let index = this.data.index;
- let contentObj = this.data.contentObj;
- if (card && contentObj[card][index]?.errMsg) {
- contentObj[card][index].errMsg = undefined;
- this.setData({
- contentObj: contentObj
- })
- }
- }
- this.setData({
- value: JSON.stringify(form),
- form: form
- })
- },
- /**
- * @desc : 设置商品
- * @author : 周兴
- * @date : 2024/1/19
- */
- setGoods(e) {
- if (e.data) {
- let form = this.data.form
- let goodsList = form[this.data.itemName] || []
- e.data.choosedGoodsList.forEach(it => {
- goodsList.push(it)
- })
- form[this.data.itemName] = goodsList
- this.setData({
- form: form,
- value: JSON.stringify(form)
- })
- // 设置商品总单的金额信息
- if (this.data.type == Constants.billType.sale) {
- this.setGoodsAmount(e.data);
- }
- if (this.data.type == Constants.billType.saleOut) { //销售出库
- this.setGoodsOutList(e.data)
- }
- if (this.data.type == Constants.billType.purReturn) { //采购退货
- this.setReturnGoodsAmount(e.data);
- }
- if (this.data.type == Constants.billType.saleOutReturn) { //采购退货
- this.setGoodsOutReturnList(e.data);
- }
- if (this.data.type == Constants.billType.pur) {
- // this.setPurGoodsAmount(e.data);
- }
- // 设置是否进行收缩
- let card = this.data.cardList.filter(it => it.name == 'items');
- this.handleContentObj(card[0])
- // 外露setGoods方法
- this.triggerEvent("setGoods", {
- data: goodsList
- })
- }
- },
- /**
- * @desc : 删除商品明细
- * @author : 周兴
- * @date : 2024/2/22 18:16
- */
- onCloseDel(e) {
- let deleteFlag = true;
- let item = e.currentTarget.dataset.item
- // 判断删除前是否需要判断
- if (this.data.delValidFlag) {
- // 行不允许删除
- if (item.deleteFlag == false) {
- deleteFlag = false;
- }
- }
- // 不允许删除给出提示信息
- if (!deleteFlag) {
- util.showToast(item.message ? item.message : '不满足删除条件');
- } else {
- const {
- instance
- } = e.detail;
- let index = e.currentTarget.dataset.index
- // 删除明细
- this.delItem(index);
- let goodList = this.data.form[this.data.itemName]
- if (!goodList || goodList.length == 0) {
- // 还原选择组件
- this.handleChooseByItem(this, false);
- }
- instance.close();
- }
- // 外露setGoods方法
- this.triggerEvent("onCloseDel", {
- })
- },
- /**
- * @desc : 根据选品控制来源单
- * @author : 周兴
- * @date : 2024/2/22 18:16
- */
- handleChooseByItem(_this, readonlyReturn) {
- let cardList = _this.data.cardList
- let filters = cardList.filter(it => it.name == 'items');
- let contentObj = _this.data.contentObj;
- if (filters && filters.length > 0 && filters[0].controls && filters[0].controls.length > 0) {
- filters[0].controls.forEach(it => {
- let filter = contentObj[it.card].filter(t => t.code == it.code);
- if (filter && filter.length > 0) {
- filter[0].readonlyReturn = readonlyReturn;
- }
- })
- _this.setData({
- contentObj: contentObj
- })
- }
- },
- setFlgGift(code, flag, key) {
- this.selectComponent('#dkPopup').setFlgGift(code, flag, key)
- },
- /**
- * @desc : 删除商品明细
- * @author : 周兴
- * @date : 2024/2/22 18:16
- */
- delItem(index) {
- let form = this.data.form
- let goodsList = form[this.data.itemName] || []
- let deleteList = form[this.data.deleteName] || []
- // 把删除的数据记录下来
- if (goodsList[index]) {
- deleteList.push(goodsList[index])
- }
- goodsList.splice(index, 1)
- form[this.data.itemName] = goodsList
- form[this.data.deleteName] = deleteList
- this.setData({
- form: form,
- value: JSON.stringify(form)
- })
- //计算
- if (this.data.type == Constants.billType.sale) {
- this.setGoodsAmount(goodsList);
- }
- if (this.data.type == Constants.billType.saleOut) {
- this.setGoodsOutAmount()
- }
- if (this.data.type == Constants.billType.saleOutReturn) {
- this.setGoodsOutReturnAmount()
- }
- // 外露setGoods方法
- this.triggerEvent("delItem", {
- data: goodsList
- })
- },
- /**
- * @desc : 设置商品明细金额相关信息 采购订单专用
- * @author : 周兴
- * @date : 2024/1/19
- */
- setPurGoodsAmount(data) {
- let form = this.data.form
- let cardList_ = this.data.cardList
- let goodsList = form[this.data.itemName]
- let sumAmountCol = this.data.sumAmountCol
- goodsList.forEach(element => { //循环出商品总共价格
- element.itemAmt = element.pricePurchase
- element.intoingAmt = element.pricePurchase
- element.intoingQty = element.itemQty
- element.pricePur = element.pricePurchase
- element.priceInto = element.pricePurchase
- element.sumAmountCol = element.pricePurchase * element.itemQty
- })
- cardList_.forEach(card => { //循环出商品总共价格
- if (card.name === 'items') {
- card.itemAmt = goodsList ? goodsList.sum("pricePurchase") : 0
- card.itemQty = goodsList ? goodsList.sum("itemQty") : 0
- card.intoAmt = 0
- card.intoQty = 0
- card[sumAmountCol] = goodsList ? goodsList.sum("sumAmountCol") : 0
- //合计金额
- }
- })
- form[this.data.itemName] = goodsList
- this.setData({
- cardList: cardList_,
- form: form,
- value: JSON.stringify(form)
- })
- },
- /**
- * @desc : 设置商品明细金额相关信息 TODO
- * @author : 周兴
- * @date : 2024/1/19
- */
- setGoodsAmount(data) {
- let cardList = this.data.cardList
- let form = this.data.form
- let index = cardList.findIndex(it => it.name == 'items');
- if (form.goodsList && form.goodsList.length > 0) {
- let sumStandard = Number(0)
- let sumAmount = Number(0)
- let sumQuantity = Number(0)
- form.goodsList.forEach(item => {
- //标价合计 = 商品标价 x 商品数量
- item.priceStd = item.priceStd ? item.priceStd : (item.priceStandard ? item.priceStandard : 0) //标价
- item.amtStd = Number(item.priceStd * item.itemQty) //合计标价金额
- item.priceSale = item.priceSale ? item.priceSale : item.priceStandard
- item.itemAmt = item.priceSale * item.itemQty //商品金额
- item.priceDiscount = item.priceStd ? Number((item.priceSale / item.priceStd) * 100).toFixed(2) : 100 //售价折扣
- sumQuantity += item.itemQty //数量
- sumAmount += item.priceSale * item.itemQty //没有售价默认取标价
- sumStandard += (item.priceStd ? item.priceStd : item.priceStandard) * item.itemQty
- })
- //标价合计
- cardList[index].sumStandard = sumStandard
- //销售折扣 (合计金额/标价合计)
- cardList[index].saleDiscount = sumStandard ? Number((sumAmount / sumStandard) * 100).toFixed(2) : 100
- //合计金额
- cardList[index].sumAmount = sumAmount
- cardList[index].sumQuantity = sumQuantity
- //TODO 需要获取当前客户可用预存
- cardList[index].canUseCollect = 0 //可用
- cardList[index].useCollect = 0 //使用
- form.sumStandard = sumStandard
- form.saleDiscount = cardList[index].saleDiscount
- form.sumAmount = sumAmount
- form.canUseCollect = 0
- form.useCollect = 0
- form.sumQuantity = sumQuantity
- } else {
- cardList[index].sumStandard = 0
- cardList[index].saleDiscount = 0
- cardList[index].sumAmount = 0
- cardList[index].canUseCollect = 0
- cardList[index].useCollect = 0
- form.sumStandard = 0
- form.saleDiscount = 0
- form.sumAmount = 0
- form.canUseCollect = 0
- form.useCollect = 0
- }
- this.setData({
- cardList: cardList,
- form: form
- })
- },
- /**
- * @desc : 设置商品明细金额相关信息 销售出库
- * @author : 于继渤
- * @date : 2024/1/19
- */
- setGoodsOutAmount() {
- let cardList = this.data.cardList
- let form = this.data.form
- let index = cardList.findIndex(it => it.name == 'items');
- if (form.goodsList && form.goodsList.length > 0) {
- let sumAmount = Number(0)
- let sumQuantity = Number(0)
- let sumStandard = Number(0)
- form.goodsList.forEach(item => {
- //标价合计 = 商品标价 x 商品数量
- item.priceStd = item.priceStandard //标价
- item.outingAmt = item.priceOut * item.outingQty
- sumQuantity += item.outingQty //数量
- sumAmount += item.priceOut * item.outingQty //没有售价默认取标价
- sumStandard += (item.priceStd ? item.priceStd : item.priceStandard) * item.outingQty
- })
- //标价合计
- cardList[index].sumStandard = sumStandard
- //销售折扣 (合计金额/标价合计)
- cardList[index].saleDiscount = sumStandard ? Number((sumAmount / sumStandard) * 100).toFixed(2) : 100
- //TODO 需要获取当前客户可用预存
- cardList[index].canUseCollect = 0 //可用
- cardList[index].useCollect = 0 //使用
- form.sumStandard = sumStandard
- form.saleDiscount = cardList[index].saleDiscount
- //合计金额
- cardList[index].sumAmount = sumAmount
- cardList[index].sumQuantity = sumQuantity
- form.sumAmount = sumAmount
- form.sumQuantity = sumQuantity
- form.outingAmt = sumAmount
- form.outingQty = sumQuantity
- }
- this.setData({
- cardList: cardList,
- form: form
- })
- },
- /**
- * @desc : 设置商品明细金额相关信息 销售出库
- * @author : 于继渤
- * @date : 2024/1/19
- */
- setGoodsOutReturnAmount() {
- let cardList = this.data.cardList
- let form = this.data.form
- let index = cardList.findIndex(it => it.name == 'items');
- if (form.goodsList && form.goodsList.length > 0) {
- let sumAmount = Number(0)
- let sumQuantity = Number(0)
- form.goodsList.forEach(item => {
- //标价合计 = 商品标价 x 商品数量
- item.priceStd = item.priceStandard //标价
- item.outingQty = item.outingQty ? item.outingQty : item.itemQty * -1
- item.outingAmt = item.priceOut * item.outingQty
- item.priceOut = item.priceOut
- sumQuantity += item.outingQty //数量
- sumAmount += item.priceOut * item.outingQty //没有售价默认取标价
- })
- //合计金额
- cardList[index].sumAmount = sumAmount
- cardList[index].sumQuantity = sumQuantity
- form.sumAmount = sumAmount
- form.sumQuantity = sumQuantity
- form.outingAmt = sumAmount
- form.outingQty = sumQuantity
- }
- this.setData({
- cardList: cardList,
- form: form
- })
- },
- /**
- * @desc : 销售出库设置选品参数
- * @author : 于继渤
- * @date : 2024/1/19
- */
- setGoodsOutList(data) {
- let form = this.data.form
- if (form.goodsList && form.goodsList.length > 0) {
- form.goodsList.forEach(item => {
- item.priceOut = item.priceOut ? item.priceOut : item.priceStandard
- item.outingAmt = item.priceOut * item.itemQty
- item.outingQty = item.itemQty
- item['outingQty_min'] = 1
- delete item['priceLimited']
- delete item['pricePurchase']
- delete item['priceWholesale']
- })
- }
- this.setData({
- form: form
- })
- this.setGoodsOutAmount()
- },
- /**
- * @desc : 数量改变事件
- * @date : 2024/2/1 15:49
- * @author : 于继渤
- */
- changeStep(e) {
- let key = e.detail.key
- let value = e.detail.value
- let dataItem = JSON.parse(this.data.dataItem)
- dataItem[key] = value
- if (this.data.type == Constants.billType.sale ||
- this.data.type == Constants.billType.pur ||
- this.data.type == Constants.billType.purInto) {
- //箱片的取值逻辑: 箱 =(数量/包装)取整,片= (数量%包装)取余数
- if (key == 'itemQty') {
- dataItem['itemQty'] = value
- dataItem['box'] = parseInt(value / dataItem.packBox)
- dataItem['piece'] = Number(value % dataItem.packBox)
- dataItem.packageBox = dataItem['box'] + dataItem.subUnitName + dataItem['piece'] + dataItem.unitName
- if (this.data.type == Constants.billType.pur) { //采购订单 ,单价*数量,实时变化
- dataItem.sumPrice = dataItem['itemQty'] * dataItem.pricePur
- }
- if (this.data.type == Constants.billType.purInto) { //采购入库
- dataItem.sumPrice = dataItem['itemQty'] * dataItem.priceInto
- }
- }
- } else if (this.data.type == Constants.billType.saleOut ||
- this.data.type == Constants.billType.inventory) {
- //箱片的取值逻辑: 箱 =(数量/包装)取整,片= (数量%包装)取余数
- if (key == 'outingQty') {
- dataItem['outingQty'] = value
- dataItem['box'] = parseInt(value / dataItem.packBox)
- dataItem['piece'] = Number(value % dataItem.packBox)
- dataItem.packageBox = dataItem['box'] + dataItem.subUnitName + dataItem['piece'] + dataItem.unitName
- if (this.data.type == Constants.billType.saleOut) { //销售退货
- dataItem.sumPrice = dataItem['outingQty'] * dataItem.priceOut
- }
- }
- } else if (this.data.type == Constants.billType.saleOutReturn) {
- if (key == 'outingQty') {
- dataItem['outingQty'] = value
- // 使用 Math.abs() 函数获取 outingQty 的绝对值
- let outingQty = Math.abs(dataItem.outingQty);
- dataItem['box'] = parseInt(outingQty / dataItem.packBox)
- dataItem['piece'] = Number(outingQty % dataItem.packBox)
- dataItem.packageBox = dataItem['box'] + dataItem.subUnitName + dataItem['piece'] + dataItem.unitName
- if (this.data.type == Constants.billType.saleOutReturn) { //销售退货
- dataItem.sumPrice = dataItem['outingQty'] * dataItem.priceOut
- }
- }
- }
- this.setData({
- dataItem: JSON.stringify(dataItem)
- })
- },
- /**
- * @desc : 修改数值离开框的值
- * @author : 周兴
- * @date : 2024/2/2 11:46
- */
- blurNumberField(e) {
- console.log("blurNumberField", e);
- let dataItem = JSON.parse(this.data.dataItem)
- // 采购订单
- if (this.data.type == Constants.billType.pur) {
- dataItem.pricePur = e.detail.value
- dataItem.sumPrice = dataItem['itemQty'] * dataItem.pricePur
- }
- if (this.data.type == Constants.billType.purInto) { //采购入库
- dataItem.priceInto = e.detail.value
- dataItem.sumPrice = dataItem['itemQty'] * dataItem.priceInto
- }
- if (this.data.type == Constants.billType.saleOutReturn ||
- this.data.type == Constants.billType.out ||
- this.data.type == Constants.billType.inventory
- ) { //销售退货
- dataItem.priceOut = e.detail.value
- dataItem.sumPrice = dataItem['itemQty'] * dataItem.priceOut
- }
- if (this.data.type == Constants.billType.saleOutReturn ||
- this.data.type == Constants.billType.saleOut ||
- this.data.type == Constants.billType.inventory) {
- dataItem.priceOut = e.detail.value
- dataItem.sumPrice = dataItem['outingQty'] * dataItem.priceOut
- }
- this.setData({
- dataItem: JSON.stringify(dataItem)
- })
- },
- /**
- * @desc : 销售出库退货设置选品参数
- * @author : 于继渤
- * @date : 2024/1/19
- */
- setGoodsOutReturnList(data) {
- let form = this.data.form
- if (form.goodsList && form.goodsList.length > 0) {
- form.goodsList.forEach(item => {
- item.priceOut = item.priceOut ? item.priceOut : item.priceStandard
- item.outQty = item.itemQty
- item.outingQty = item.outingQty
- item.outAmt = item.priceOut * item.itemQty
- // item.outingAmt = item.priceOut * item.itemQty
- item['outingQty_min'] = item.itemQty * -1
- item['outingQty_max'] = Number(-1)
- delete item['priceLimited']
- delete item['pricePurchase']
- delete item['priceWholesale']
- })
- }
- this.setData({
- form: form
- })
- this.setGoodsOutReturnAmount()
- },
- /**
- * @desc : 显示tip
- * @author : 周兴
- * @date : 2024/4/25 11:46
- */
- showTip(e) {
- let item = e.currentTarget.dataset.item
- if (item.tip) {
- util.showToast(item.tip);
- }
- },
- /**
- * @desc : 设置商品明细金额相关信息 TODO
- * @author : 周兴
- * @date : 2024/1/19
- */
- setReturnGoodsAmount(data) {
- let cardList = this.data.cardList
- let form = this.data.form
- let index = cardList.findIndex(it => it.name == 'items');
- if (form.goodsList && form.goodsList.length > 0) {
- let sumReturnAmt = Number(0) //合计金额
- let sumReturnQty = Number(0)
- form.goodsList.forEach(item => {
- item.priceReturn = item.priceStandard * -1
- item.priceInto = item.priceStandard
- item.itemAmt = Number(item.priceReturn * item.itemQty)
- item.itemQtyMax = -1
- if (item.itemId) { //选商品过来的 不校验 选单据校验
- item.itemQtyMin = item.usableQty * -1
- } else {
- item.itemQtyMin = -99999999999
- }
- // sumReturnAmt += item.priceReturn * item.itemQty
- // sumReturnQty += item.itemQty
- item.itemQty = item.itemQty * -1
- })
- // form.sumReturnQty = sumReturnQty
- // form.sumReturnAmt = sumReturnAmt
- // cardList[index].sumReturnAmt = sumReturnAmt
- }
- console.log('form', form)
- this.setData({
- cardList: cardList,
- form: form
- })
- },
- /**
- * @desc : 上传附件超出大小
- * @author : 周兴
- * @date : 2024/3/27 16:16
- */
- overSize(e) {
- util.showToast('文件超出' + Constants.uploadFileConfig.maxSizeMB);
- },
- /**
- * @desc : 删除图片
- * @author : 周兴
- * @date : 2024/4/29 18:16
- */
- deleteImg(e) {
- let form = this.data.form;
- let index = e.detail.index;
- let arr = form['annexPaths']
- arr.splice(index, 1);
- this.setData({
- form: form,
- value: JSON.stringify(form)
- })
- },
- changeCheckBox(e) {
- this.triggerEvent("changeCheckBox", {
- code: e.detail.code,
- flag: e.detail.flag
- })
- },
- /**
- * @desc : 上传附件
- * @author : 周兴
- * @date : 2024/3/27 16:16
- */
- afterRead(e) {
- // this.setData({
- // uploadFileFlag:true
- // })
- const _this = this;
- const {
- file
- } = e.detail;
- // 配置存放的文件夹 公司code - 表名 - 年月 -- 日
- let folder = app.globalData.company.cpCode + '/' + this.data.table + '/' + new Date().toYearMonth2() + '/' + new Date().toDay()
- let url = config.upload_url;
- url = url.replace('mdm-server', 'mdm-server' + '-' + app.globalData.company.svcCode.replace('_', '-'))
- file.forEach(res => {
- // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
- wx.uploadFile({
- url: url,
- filePath: res.path,
- name: 'file',
- formData: {
- 'folder': folder
- },
- header: {
- 'Authorization': 'Bearer ' + app.globalData.token
- },
- success(res) {
- let data = JSON.parse(res.data)
- if (data.code === 200) {
- _this.setData({
- uploadFileFlag: false
- })
- let form = _this.data.form
- let annexPaths = form['annexPaths'] || []
- data.data.url = config.image_url + data.data.path
- annexPaths.push(data.data)
- form.annexPaths = annexPaths;
- _this.setData({
- form: form,
- value: JSON.stringify(form)
- })
- }
- },
- })
- })
- },
- customersChoose() {
- this.triggerEvent("customersChoose", {})
- },
- /**
- * @desc : 加载数据
- * @date : 2024/2/1 15:49
- * @author : 姜永辉
- */
- setInitPopData() {
- //销售订单 //采购订单 库存调整
- if (this.data.type == Constants.billType.sale || this.data.type == Constants.billType.pur || this.data.type == Constants.billType.out) {
- this.setData({
- popContentBox: [{
- code: 'box',
- type: 'step',
- title: mixins.$t("goodsBox"),
- required: true
- },
- {
- code: 'piece',
- type: 'step',
- title: mixins.$t("goodsPiece"),
- required: true
- },
- ],
- })
- }
- //销售出库
- if (this.data.type == Constants.billType.saleOut) {
- this.setData({
- popContentBox: [{
- code: 'box',
- type: 'step',
- title: mixins.$t("goodsBox"),
- required: true
- },
- {
- code: 'piece',
- type: 'step',
- title: mixins.$t("goodsPiece"),
- required: true
- },
- ],
- })
- }
- //销售退货
- if (this.data.type == Constants.billType.saleOutReturn) {
- this.setData({
- })
- }
- //采购退货
- if (this.data.type == Constants.billType.purReturn) {
- this.setData({
- })
- }
- //采购入库 销售退货
- if (this.data.type == Constants.billType.purInto || this.data.type == Constants.billType.saleOutReturn) {
- this.setData({
- popContentBox: [{
- code: 'box',
- type: 'step',
- title: mixins.$t("goodsBox"),
- required: true
- },
- {
- code: 'piece',
- type: 'step',
- title: mixins.$t("goodsPiece"),
- required: true
- },
- ],
- })
- }
- },
- /**
- * @desc : 获取语言的方法
- * @author : 周兴
- * @date : 2024/1/19
- */
- $t(name) {
- if (this.data.$t[name]) {
- return this.data.$t[name];
- } else {
- return name;
- }
- },
- },
- })
|