| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280 |
- /*******************************************************************************
- * Copyright(c) 2022 dongke All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 王英杰 2024-1-24 1.00 新建商品档案
- *******************************************************************************/
- const mixins = require('@/mixins/index.js')
- const app = getApp()
- const util = require('@/utils/util.js')
- const Constants = require('@/utils/Constants')
- import Dialog from '@/dist/dialog/dialog.js';
- Page({
- mixins: [mixins],
- /**
- * 页面的初始数据
- */
- data: {
- gradeCode: app.globalData.company.gradeCode, //判断版本的 ( 标准还是专业)
- buttonList: [{
- name: 'merge',
- title: mixins.$t("save"), //'保存'
- }],
- table: Constants.tables.goodsSku,
- cardList: [], //不在这定义 在 loadinit定义
- contentObj: {
- main: [{ //商品型号
- code: 'skuModel',
- type: 'textarea',
- title: mixins.$t("skuModel"),
- required: true,
- }, { //商品名称
- code: 'skuName',
- type: 'textarea',
- title: mixins.$t("skuName"),
- }, {
- code: 'skuImages',
- name: mixins.$t("commodityPicture"), //商品图片
- type: 'uploader',
- },
- ],
- goods: [{ //商品品牌
- code: 'brandId',
- name: 'brandName',
- title: mixins.$t("goodsBrand"),
- type: 'choose',
- urlKey: 'goodsBrand',
- required: true,
- },
- { //商品种类
- code: 'categoryId',
- name: 'catName',
- title: mixins.$t("goodsCategory"),
- type: 'choose',
- urlKey: 'goodsCategory',
- required: true,
- }, { //商品系列
- code: 'seriesId',
- name: 'seriesName',
- title: mixins.$t("goodsSeries"),
- type: 'choose',
- urlKey: 'goodsSeries',
- }, { //商品规格
- code: 'skuSpec',
- name: 'skuSpec',
- type: 'textarea',
- required: true,
- title: mixins.$t("sukSpec"),
- }
- ],
- unit: [{ //基本单位
- code: 'unitId',
- name: 'unitName',
- title: mixins.$t("unit"),
- type: 'choose',
- urlKey: 'unit',
- required: true,
- clear: false,
- }, { //辅助单位标识
- type: 'switch',
- title: mixins.$t("subUnitId"),
- code: 'flgSubUnit',
- }, { //包装单位
- code: 'subUnitId',
- name: 'subUnitName',
- title: mixins.$t("packageUnit"),
- type: 'choose',
- urlKey: 'unit',
- required: true,
- readonly: true,
- }, { //包装
- code: 'packBox',
- title: mixins.$t("package"),
- type: 'number',
- sign: "",
- digits: 0,
- required: true,
- readonly: true,
- },
- {
- code: 'calculationFormula',
- type: 'textarea',
- title: mixins.$t("calculationFormula"),
- readonly: true,
- }
- ],
- warehouse: [{ //期初库存标识
- type: 'switch',
- title: mixins.$t("openingInv"),
- code: 'flgOpeningInv',
- }, ],
- price: [{ //期初库存标识
- type: 'switch',
- title: mixins.$t("flgPrice"),
- code: 'flgPrice',
- }, { //采购价
- tip: mixins.$t("purchasePricetip"),
- code: 'pricePurchase',
- type: 'number',
- title: mixins.$t("purchasePrice"),
- required: true,
- }, { //零售价
- tip: mixins.$t("retailPricetip"),
- code: 'priceStandard',
- type: 'number',
- title: mixins.$t("retailPrice"),
- required: true,
- }, { //批发价
- tip: mixins.$t("wholesalePricetip"),
- code: 'priceWholesale',
- type: 'number',
- title: mixins.$t("wholesalePrice"),
- required: true,
- }, { //销售限价
- tip: mixins.$t("SaleSPriceLimittip"),
- code: 'priceLimited',
- type: 'number',
- title: mixins.$t("SaleSPriceLimit"),
- required: true,
- }, { //其他价
- tip: mixins.$t("otherPriceLimittip"),
- code: 'priceOther',
- type: 'number',
- title: mixins.$t("otherPriceLimit"),
- required: true,
- }, ],
- // warning: [{ // 预警信息
- // type: 'textarea',
- // title: mixins.$t("warningLowerLimit"),
- // code: 'warningLowerLimit',
- // },{
- // type: 'textarea',
- // title: mixins.$t("warningUpperLimit"),
- // code: 'warningUpperLimit',
- // }],
- other: [{
- code: 'remarks',
- type: 'textarea',
- title: mixins.$t("remarks"),
- }]
- },
- popContentBox: [],
- // 路由
- routeObjName: 'goodsSku',
- // 包装小数位
- packBoxDigits: 0,
- },
- /**
- * @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
- this.setData({
- dataItem: JSON.stringify(dataItem)
- })
- },
- /**
- * @desc : dk-form 里 str的点击回调 的输入回调
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- openStr(e) {
- let code = e.detail.code
- const readonly = e.detail.readonly
- if (code == "packageBox" && !readonly) { //点击包装数量
- let formData = JSON.parse(this.data.formData)
- if (formData.unitId && formData.subUnitId && formData.packBox) {
- let dataItem = this.data.dataItem ? JSON.parse(this.data.dataItem) : {}
- dataItem['box'] = formData.box || 0
- dataItem['piece'] = formData.piece || 0
- dataItem.packageBox = formData.packageBox
- let popContentBox = [{
- code: 'box',
- type: 'step',
- title: formData.subUnitName,
- required: true
- },
- {
- code: 'piece',
- type: 'step',
- title: formData.unitName,
- required: true
- },
- ]
- this.setData({
- showPopBox: true,
- dataItem: JSON.stringify(dataItem),
- popContentBox: popContentBox
- })
- } else {
- util.showToast('请先输入基本单位、包装单位、包装');
- }
- }
- },
- /**
- * @desc : 商品确认事件--箱片的确认
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- editItemsBox(e) {
- let dataItem = JSON.parse(this.data.dataItem)
- let formData = JSON.parse(this.data.formData)
- formData['box'] = dataItem['box']
- formData['piece'] = dataItem['piece']
- formData['intoQty'] = Number(dataItem['box']) * Number(formData['packBox']) + Number(dataItem['piece'])
- formData.packageBox = dataItem['box'] + formData.subUnitName + dataItem['piece'] + formData.unitName
- this.setData({
- formData: JSON.stringify(formData)
- })
- },
- /**
- * @desc : dk-form 里 dk-number-input 的输入回调
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- changeNumberField(e) {
- let code = e.detail.code
- let formData = JSON.parse(this.data.formData)
- if (code == "packBox") { //包装
- if (formData.intoQty || formData.packageBox) {
- //提示
- Dialog.confirm({
- message: '修改包装将清空期初数量、包装数量',
- }).then(() => {
- formData.intoQty = null
- formData.packageBox = null
- formData.box = null
- formData.piece = null
- formData["packBox_"] = formData["packBox"]
- if (formData.packBox && formData.unitName && formData.subUnitName) { //选了辅助计量单位 正好 包装也有值 那么直接给出公式
- formData.calculationFormula = formData.packBox + formData.unitName + '= 1' + formData.subUnitName
- }
- this.setData({
- formData: JSON.stringify(formData)
- })
- }).catch(() => {
- formData["packBox"] = formData["packBox_"]
- this.setData({
- formData: JSON.stringify(formData)
- })
- });
- } else {
- if (formData.packBox && formData.unitName && formData.subUnitName) { //选了辅助计量单位 正好 包装也有值 那么直接给出公式
- formData.calculationFormula = formData.packBox + formData.unitName + '= 1' + formData.subUnitName
- }
- formData["packBox_"] = formData["packBox"]
- }
- }
- if (code == "intoQty" && formData.flgSubUnit) { //期初数量
- if (formData.unitId && formData.subUnitId && formData.packBox) {
- formData['box'] = parseInt(formData['intoQty'] / formData['packBox'])
- formData['piece'] = parseFloat(Number(formData['intoQty'] % formData['packBox']).toFixed(formData.decimalPlaces));
- formData.packageBox = formData['box'] + formData.subUnitName + formData['piece'] + formData.unitName
- } else {
- formData['intoQty'] = undefined
- util.showToast('请先输入基本单位、包装单位、包装');
- }
- }
- this.setData({
- formData: JSON.stringify(formData)
- })
- },
- /**
- * @desc : dk-form 里 Switch 的切换回调
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- onSwitchChange(e) {
- let code = e.detail.code
- let checkFlag = !e.detail.checkFlag
- let contentObj = this.data.contentObj
- let formData = JSON.stringify(this.data.formData)
- if (code == "flgSubUnit") { //辅助单位
- if (checkFlag) {
- let formData = JSON.parse(this.data.formData)
- // 当未选择基本单位时不能打开辅助单位开关
- if (!formData.unitId) {
- formData.flgSubUnit = false
- util.showToast('请先选择基本单位');
- this.setData({
- formData: JSON.stringify(formData)
- })
- return
- }
- contentObj.unit = [{ //基本单位
- code: 'unitId',
- name: 'unitName',
- title: mixins.$t("unit"),
- type: 'choose',
- urlKey: 'unit',
- required: true,
- clear: false,
- }, { //辅助单位标识
- type: 'switch',
- title: mixins.$t("subUnitId"),
- code: 'flgSubUnit',
- }, { //包装单位
- code: 'subUnitId',
- name: 'subUnitName',
- title: mixins.$t("packageUnit"),
- type: 'choose',
- urlKey: 'unit',
- required: checkFlag,
- }, { //包装
- code: 'packBox',
- title: mixins.$t("package"),
- type: 'number',
- sign: "",
- // todo
- digits: this.packBoxDigits,
- required: checkFlag,
- },
- {
- code: 'calculationFormula',
- type: 'textarea',
- title: mixins.$t("calculationFormula"),
- readonly: true,
- }
- ]
- } else {
- let formDataJson = JSON.parse(this.data.formData)
- if (formDataJson) {
- ['subUnitName', 'calculationFormula', 'packBox'].forEach(key => {
- if (formDataJson.hasOwnProperty(key)) {
- delete formDataJson[key];
- }
- });
- }
- this.setData({
- formData: JSON.stringify(formDataJson)
- })
- contentObj.unit = [{ //基本单位
- code: 'unitId',
- name: 'unitName',
- title: mixins.$t("unit"),
- type: 'choose',
- urlKey: 'unit',
- required: true,
- clear: false,
- }, { //辅助单位标识
- type: 'switch',
- title: mixins.$t("subUnitId"),
- code: 'flgSubUnit',
- }, ]
- }
- } else if (code == "flgOpeningInv") { //期初库存标识
- if (checkFlag) {
- let formData = JSON.parse(this.data.formData)
- //打开期初库存的时候 要先判断 需要先选择基本单位
- if (!formData.unitId) {
- formData.flgOpeningInv = false
- util.showToast('请先选择基本单位');
- this.setData({
- formData: JSON.stringify(formData)
- })
- return
- }
- if (formData.flgSubUnit) { //开了辅助单位
- contentObj.warehouse = [{ //期初库存标识
- type: 'switch',
- title: mixins.$t("openingInv"),
- code: 'flgOpeningInv',
- }, { //仓库名称
- code: 'whId',
- name: 'whName',
- title: mixins.$t("whName"),
- type: 'choose',
- urlKey: 'openingInventory',
- required: checkFlag,
- },
- { //库存批号
- code: 'nonStdCode',
- type: 'textarea',
- title: mixins.$t("iinventoryBatchNumber"),
- required: checkFlag,
- tip: mixins.$t('tipPop'),
- },
- { //期初数量
- code: 'intoQty',
- type: 'number',
- sign: "",
- digits: formData.decimalPlaces,
- title: mixins.$t("openingInventoryQty"),
- required: checkFlag,
- },
- {
- code: 'packageBox',
- type: 'str',
- title: mixins.$t("packageBox"),
- required: checkFlag,
- readonly: true,
- },
- { //期初成本价
- code: 'priceInto',
- type: 'number',
- title: mixins.$t("iinitialCostPrice"),
- required: checkFlag,
- },
- ]
- } else { //没开辅助单位
- contentObj.warehouse = [{ //期初库存标识
- type: 'switch',
- title: mixins.$t("openingInv"),
- code: 'flgOpeningInv',
- }, { //仓库名称
- code: 'whId',
- name: 'whName',
- title: mixins.$t("whName"),
- type: 'choose',
- urlKey: 'openingInventory',
- required: checkFlag,
- },
- { //库存批号
- code: 'nonStdCode',
- type: 'textarea',
- title: mixins.$t("iinventoryBatchNumber"),
- required: checkFlag,
- tip: mixins.$t('tipPop'),
- },
- { //期初数量
- code: 'intoQty',
- type: 'number',
- sign: "",
- digits: formData.decimalPlaces,
- title: mixins.$t("openingInventoryQty"),
- required: checkFlag,
- },
- { //期初成本价
- code: 'priceInto',
- type: 'number',
- title: mixins.$t("iinitialCostPrice"),
- required: checkFlag,
- },
- ]
- }
- } else {
- /**
- * 关闭初期按钮后删除对应的初期数据
- * @author 刘尧
- * @data 2024.06.04
- */
- let formData = JSON.parse(this.data.formData)
- if (formData) {
- ['packageBox', 'priceInto', 'intoQty', 'nonStdCode', 'whName', 'whId'].forEach(key => {
- if (formData.hasOwnProperty(key)) {
- delete formData[key];
- }
- });
- }
- this.setData({
- formData: JSON.stringify(formData)
- })
- contentObj.warehouse = [{ //期初库存标识
- type: 'switch',
- title: mixins.$t("openingInv"),
- code: 'flgOpeningInv',
- }, ]
- }
- } else if (code == "flgPrice") { //期初库存标识
- if (checkFlag) {
- contentObj.price = [{ //期初库存标识
- type: 'switch',
- title: mixins.$t("flgPrice"),
- code: 'flgPrice',
- }, { //采购价
- tip: mixins.$t("purchasePricetip"),
- code: 'pricePurchase',
- type: 'number',
- title: mixins.$t("purchasePrice"),
- required: checkFlag,
- }, { //零售价
- tip: mixins.$t("retailPricetip"),
- code: 'priceStandard',
- type: 'number',
- title: mixins.$t("retailPrice"),
- required: checkFlag,
- }, { //批发价
- tip: mixins.$t("wholesalePricetip"),
- code: 'priceWholesale',
- type: 'number',
- title: mixins.$t("wholesalePrice"),
- required: checkFlag,
- }, { //销售限价
- tip: mixins.$t("SaleSPriceLimittip"),
- code: 'priceLimited',
- type: 'number',
- title: mixins.$t("SaleSPriceLimit"),
- required: checkFlag,
- }, { //其他价
- tip: mixins.$t("otherPriceLimittip"),
- code: 'priceOther',
- type: 'number',
- title: mixins.$t("otherPriceLimit"),
- required: checkFlag,
- }, ]
- } else {
- contentObj.price = [{ //期初库存标识
- type: 'switch',
- title: mixins.$t("flgPrice"),
- code: 'flgPrice',
- }, ]
- }
- }
- this.setData({
- contentObj: contentObj
- })
- },
- onShow() {
- this.dialogShowChooseData();
- },
- /**
- * @desc : 因为chooseData 的执行顺序要高于onshow 且 chooseData无法弹 dialog 所以在onshow执行
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- dialogShowChooseData() {
- if (!this.data.handledata) {
- return
- }
- // todo
- this.setData({
- handledata: false
- })
- let formData = JSON.parse(this.data.formData)
- let data = this.data.chooseUnitData
- let Dialog_message = null
- let code = this.data.chooseDataCode
- if (code == "unitId") { //计量单位
- formData.intoQty = null
- formData.packBox = null
- formData.subUnitId = null
- formData.subUnitName = null
- formData.packageBox = null
- formData.box = null
- formData.piece = null
- // 当重新选择基本单位后清空公式 刘尧 2024.5.30
- formData.calculationFormula = null
- Dialog_message = '更换基础单位将清空包装单位、期初数量、包装、包装数量'
- }
- if (code == "subUnitId") { //包装单位
- formData.intoQty = null
- formData.packageBox = null
- formData.box = null
- formData.piece = null
- Dialog_message = '更换包装单位将清空期初数量、包装数量'
- }
-
- //提示
- Dialog.confirm({
- message: Dialog_message,
- }).then(() => {
- this.handleChooseDataUnit(formData, data, code)
- }).catch(() => {});
- },
- /**
- * @desc : 选择页面跳转回调事件
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- chooseData(e) {
- let formData = JSON.parse(this.data.formData)
- let code = e.detail.code
- let data = e.detail.data.data
- if (code == "brandId") { //商品品牌
- formData.brandId = data.id
- formData.brandName = data.name
- }
- if (code == "categoryId") { //商品种类
- formData.categoryId = data.id
- formData.catName = data.name
- }
- if (code == "unitId") { //计量单位
- //当期初数量有值的时候 弹提示是否清除
- if (formData.intoQty || formData.packBox || formData.subUnitId || formData.packageBox) { //在onshow执行 这里无法弹出dialog
- this.setData({
- chooseUnitData: data,
- handledata: true,
- chooseDataCode: code
- })
- } else {
- this.handleChooseDataUnit(formData, data, code)
- }
- }
- if (code == "subUnitId") { //辅助计量单位
- if (data.id == formData.unitId) {
- setTimeout(() => {
- util.showToast('包装单位不能等于基本单位');
- }, 1000)
- return
- }
- if (formData.intoQty || formData.packageBox) { //在onshow执行 这里无法弹出dialog
- this.setData({
- chooseUnitData: data,
- handledata: true,
- chooseDataCode: code
- })
- } else {
- this.handleChooseDataUnit(formData, data, code)
- }
- if (formData.packBox && formData.unitName && formData.subUnitName) { //选了辅助计量单位 正好 包装也有值 那么直接给出公式
- formData.calculationFormula = formData.packBox + formData.unitName + '= 1' + formData.subUnitName
- }
- }
- if (code == "seriesId") { //商品系列
- formData.seriesId = data.id
- formData.seriesName = data.name
- }
- if (code == "whId") { //仓库名称
- formData.whId = data.id
- formData.whName = data.name
- }
- this.setData({
- formData: JSON.stringify(formData)
- })
- },
- /**
- * @desc : 处理 选择页面回来的 基本单位
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- handleChooseDataUnit(formData, data, code) {
- if (code == "unitId") {
- formData.unitId = data.id
- formData.unitName = data.name
- formData.decimalPlaces = data.decimalPlaces
- let dataItem = this.data.dataItem ? JSON.parse(this.data.dataItem) : {}
- dataItem.decimalPlaces = data.decimalPlaces
- if (formData.packBox && formData.unitName && formData.subUnitName) { //选了辅助计量单位 正好 包装也有值 那么直接给出公式
- formData.calculationFormula = formData.packBox + formData.unitName + '= 1' + formData.subUnitName
- }
- let contentObj = this.data.contentObj
- let packBoxDigits = formData.decimalPlaces
- if (contentObj.warehouse.length > 0) {
- // 遍历 contentObj.warehouse 数组
- for (let i = 0; i < contentObj.warehouse.length; i++) {
- // 检查当前对象的 code 是否为 'intoQty'
- if (contentObj.warehouse[i].code === 'intoQty') { //期初数量
- // 如果是,则修改其 digits 属性
- contentObj.warehouse[i].digits = formData.decimalPlaces;
- contentObj.warehouse[i].readonly = false;
- // 找到后,可以跳出循环(如果确定只有一个匹配项)
- break;
- }
- }
- }
- if (contentObj.unit.length > 0) {
- // 遍历 contentObj.unit 数组
- for (let i = 0; i < contentObj.unit.length; i++) {
- // 检查当前对象的 code 是否为 'packBox'
- if (contentObj.unit[i].code === 'packBox') { //包装
- // 如果是,则修改其 digits 属性
- contentObj.unit[i].digits = formData.decimalPlaces;
- contentObj.unit[i].readonly = false;
- continue
- }
- if (contentObj.unit[i].code === 'subUnitId') { //包装单位
- contentObj.unit[i].readonly = false;
- continue
- }
- }
- }
- this.setData({
- packBoxDigits: packBoxDigits,
- contentObj: contentObj,
- formData: JSON.stringify(formData),
- dataItem: JSON.stringify(dataItem)
- })
- }
- if (code == "subUnitId") {
- formData.subUnitId = data.id
- formData.subUnitName = data.name
- this.setData({
- formData: JSON.stringify(formData),
- })
- }
- return
- },
- /**
- * @desc : 保存数据服务--校验
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- validData() {
- let formData = JSON.parse(this.data.formData)
- if (!formData.flgSubUnit) { //辅助单位标识未勾选 不存包装单位 包装
- delete formData.subUnitId
- delete formData.subUnitName
- delete formData.packBox
- }
- //编辑的时候 就不用删除了 因为不允许修改
- if ((!formData.flgOpeningInv) && this.data.formMode !== Constants.formMode.edit) { //期初库存标识未勾选 不存仓库名称 色号 起初数量 期初成本价
- delete formData.whId
- delete formData.whName
- delete formData.nonStdCode
- delete formData.priceInto
- }
- if (!formData.flgPrice) { //价格体系标识未勾选 不存采购价 零售价 批发价 销售限价 其他价
- delete formData.pricePurchase
- delete formData.priceStandard
- delete formData.priceWholesale
- delete formData.priceLimited
- delete formData.priceOther
- }
- this.setData({
- formData: JSON.stringify(formData)
- })
- return true
- },
- // 设置保存参数
- setParams(params) {
- let saveData = JSON.parse(this.data.formData)
- // 修改之后的 值
- params = Object.assign({}, params, saveData);
- params.serviceCategories = (params.serviceCategories && params.serviceCategories.length > 0) ? params.serviceCategories.split(',') : []
- params.skuImages = params.annexPaths
- params.orgId = app.globalData.user.orgId
- return params
- },
- /**
- * @desc : 保存数据服务
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- saveData() {
- let that = this
- if (this.data.formMode == Constants.formMode.edit) { //编辑接口
- return this.excute(this.data.service, this.data.service.update, this.data.params)
- } else { //新建接口
- let excute = this.excute(this.data.service, this.data.service.insert, this.data.params)
- excute.then(res => {
- // 增加包装;数字类型正整数,默认1
- let formData = {}
- let contentObj = this.data.contentObj
- formData.flgPrice = true
- formData.flgOpeningInv = false
- formData.flgSubUnit = true
- that.setData({
- formData: JSON.stringify(formData),
- loading: false,
- contentObj: {
- main: [{ //商品型号
- code: 'skuModel',
- type: 'textarea',
- title: mixins.$t("skuModel"),
- required: true,
- }, { //商品名称
- code: 'skuName',
- type: 'textarea',
- title: mixins.$t("skuName"),
- }, {
- code: 'skuImages',
- name: mixins.$t("commodityPicture"), //商品图片
- type: 'uploader',
- },
- ],
- goods: [{ //商品品牌
- code: 'brandId',
- name: 'brandName',
- title: mixins.$t("goodsBrand"),
- type: 'choose',
- urlKey: 'goodsBrand',
- required: true,
- },
- { //商品种类
- code: 'categoryId',
- name: 'catName',
- title: mixins.$t("goodsCategory"),
- type: 'choose',
- urlKey: 'goodsCategory',
- required: true,
- }, { //商品系列
- code: 'seriesId',
- name: 'seriesName',
- title: mixins.$t("goodsSeries"),
- type: 'choose',
- urlKey: 'goodsSeries',
- }, { //商品规格
- code: 'skuSpec',
- name: 'skuSpec',
- type: 'textarea',
- required: true,
- title: mixins.$t("sukSpec"),
- }
- ],
- unit: [{ //基本单位
- code: 'unitId',
- name: 'unitName',
- title: mixins.$t("unit"),
- type: 'choose',
- urlKey: 'unit',
- required: true,
- clear: false,
- }, { //辅助单位标识
- type: 'switch',
- title: mixins.$t("subUnitId"),
- code: 'flgSubUnit',
- }
- ],
- warehouse: [{ //期初库存标识
- type: 'switch',
- title: mixins.$t("openingInv"),
- code: 'flgOpeningInv',
- }, ],
- price: [{ //期初库存标识
- type: 'switch',
- title: mixins.$t("flgPrice"),
- code: 'flgPrice',
- }, { //采购价
- tip: mixins.$t("purchasePricetip"),
- code: 'pricePurchase',
- type: 'number',
- title: mixins.$t("purchasePrice"),
- required: true,
- }, { //零售价
- tip: mixins.$t("retailPricetip"),
- code: 'priceStandard',
- type: 'number',
- title: mixins.$t("retailPrice"),
- required: true,
- }, { //批发价
- tip: mixins.$t("wholesalePricetip"),
- code: 'priceWholesale',
- type: 'number',
- title: mixins.$t("wholesalePrice"),
- required: true,
- }, { //销售限价
- tip: mixins.$t("SaleSPriceLimittip"),
- code: 'priceLimited',
- type: 'number',
- title: mixins.$t("SaleSPriceLimit"),
- required: true,
- }, { //其他价
- tip: mixins.$t("otherPriceLimittip"),
- code: 'priceOther',
- type: 'number',
- title: mixins.$t("otherPriceLimit"),
- required: true,
- }, ],
- other: [{
- code: 'remarks',
- type: 'textarea',
- title: mixins.$t("remarks"),
- }]
- }
- })
- })
- return excute;
- }
- },
- /**
- * @desc : 处理保存后续事件
- * @date : 2024/2/1 15:49
- * @author : 姜永辉
- */
- handleSaveData() {
- //购物车跳转来的,新建完毕直接回到选择界面
- if (this.data.formType == Constants.formType.shopping) {
- // var pages = getCurrentPages();
- // var prevPage = pages[pages.length - 2]; //上一个页面
- // prevPage.setData({
- // refreshByAdd: true
- // })
- // 给父页面传递数据
- const eventChannel = this.getOpenerEventChannel();
- eventChannel.emit('refresh', {
- id: 1
- })
- setTimeout(() => {
- wx.navigateBack({
- delta: 1
- });
- }, 200)
- }
- //新手引导过来,需要返回
- if (this.data.formReturnMode == Constants.formReturnMode.beginnerGuide) {
- const eventChannel = this.getOpenerEventChannel();
- eventChannel.emit('refresh', {
- id: 1
- })
- setTimeout(() => {
- wx.navigateBack({
- delta: 1
- });
- }, 200)
- }
- },
- /**
- * @desc : 页面加载数据方法
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- loadInit() {
- //标准版商品档案新建、编辑、详情不展示价格体系
- if (this.data.gradeCode == Constants.gradeCode.STD) { //标准版
- this.setData({
- cardList: ['main', 'goods', "unit", "warehouse", 'other'],
- })
- } else {
- this.setData({
- cardList: ['main', 'goods', "unit", "warehouse", 'price', 'other'],
- })
- }
- if (this.data.formMode == Constants.formMode.edit) {
- wx.setNavigationBarTitle({
- title: mixins.$t('editGoodsSuk'),
- })
- } else {
- // 增加包装;数字类型正整数,默认1
- let formData = JSON.parse(this.data.formData) || {}
- formData.flgPrice = true
- formData.flgOpeningInv = false
- formData.flgSubUnit = false
- // 获取表单总信息
- let contentObj = this.data.contentObj
- // 当页面初始化的时候 将其他内容隐藏
- contentObj.unit = [{ //基本单位
- code: 'unitId',
- name: 'unitName',
- title: mixins.$t("unit"),
- type: 'choose',
- urlKey: 'unit',
- required: true,
- clear: false,
- }, { //辅助单位标识
- type: 'switch',
- title: mixins.$t("subUnitId"),
- code: 'flgSubUnit',
- }, ]
- this.setData({
- formData: JSON.stringify(formData),
- contentObj: contentObj
- })
- wx.setNavigationBarTitle({
- title: mixins.$t('addGoodsSuk'),
- })
- }
- },
- /**
- * @desc : 给表单赋值
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- setValuesByEdit(data) {
- // data.serviceCategories = (data.serviceCategories && data.serviceCategories.length > 0) ? data.serviceCategories.join(',') : undefined
- data.annexPaths = data.skuImages
- data.onlyCode = data.skuCode
-
- let contentObj = this.data.contentObj
- // 我们要添加的新对象是 编码 新建的时候没有 编辑的时候添加
- contentObj.main = [{ //唯一编码
- code: 'onlyCode',
- type: 'textarea',
- title: mixins.$t("onlyCode"),
- readonly: true
- }, { //商品型号
- code: 'skuModel',
- type: 'textarea',
- title: mixins.$t("skuModel"),
- required: true,
- }, { //商品名称
- code: 'skuName',
- type: 'textarea',
- title: mixins.$t("skuName"),
- }, {
- code: 'skuImages',
- name: mixins.$t("commodityPicture"), //商品图片
- type: 'uploader',
- },
- ]
- if (data.flgSubUnit) {
- if (data.inventoryCount !== 0) {
- contentObj.unit = [{
- text: '本商品有库存,不可更改单位模块;需全部出库后才可更改',
- type: 'text',
- }, { //基本单位
- code: 'unitId',
- name: 'unitName',
- title: mixins.$t("unit"),
- type: 'choose',
- urlKey: 'unit',
- required: true,
- readonly: data.inventoryCount !== 0 //要校验库存; 库存量不为0不让更改
- }, { //辅助单位标识
- type: 'switch',
- title: mixins.$t("subUnitId"),
- code: 'flgSubUnit',
- disabled: (data.inventoryCount !== 0),
- }, { //包装单位
- code: 'subUnitId',
- name: 'subUnitName',
- title: mixins.$t("packageUnit"),
- type: 'choose',
- urlKey: 'unit',
- required: true,
- readonly: data.inventoryCount !== 0 //要校验库存; 库存量不为0不让更改
- }, { //包装
- code: 'packBox',
- title: mixins.$t("package"),
- type: 'number',
- sign: "",
- digits: 0,
- required: true,
- readonly: data.inventoryCount !== 0
- },
- {
- code: 'calculationFormula',
- type: 'textarea',
- title: mixins.$t("calculationFormula"),
- readonly: true,
- }
- ]
- } else { //没库存
- contentObj.unit = [{ //基本单位
- code: 'unitId',
- name: 'unitName',
- title: mixins.$t("unit"),
- type: 'choose',
- urlKey: 'unit',
- required: true,
- readonly: data.inventoryCount !== 0 //要校验库存; 库存量不为0不让更改
- }, { //辅助单位标识
- type: 'switch',
- title: mixins.$t("subUnitId"),
- code: 'flgSubUnit',
- disabled: (data.inventoryCount !== 0),
- }, { //包装单位
- code: 'subUnitId',
- name: 'subUnitName',
- title: mixins.$t("packageUnit"),
- type: 'choose',
- urlKey: 'unit',
- required: true,
- readonly: data.inventoryCount !== 0 //要校验库存; 库存量不为0不让更改
- }, { //包装
- code: 'packBox',
- title: mixins.$t("package"),
- type: 'number',
- sign: "",
- digits: 0,
- required: true,
- readonly: data.inventoryCount !== 0
- },
- {
- code: 'calculationFormula',
- type: 'textarea',
- title: mixins.$t("calculationFormula"),
- readonly: true,
- }
- ]
- }
- } else {
- contentObj.unit = [{ //基本单位
- code: 'unitId',
- name: 'unitName',
- title: mixins.$t("unit"),
- type: 'choose',
- urlKey: 'unit',
- required: true,
- }, { //辅助单位标识
- type: 'switch',
- title: mixins.$t("subUnitId"),
- code: 'flgSubUnit',
- }, ]
- }
- if (data.flgOpeningInv) {
- if (data.flgSubUnit) { //开了辅助单位
- data.packageBox = data['box'] + data.subUnitName + data['piece'] + data.unitName
- contentObj.warehouse = [{ //期初库存标识
- type: 'switch',
- title: mixins.$t("openingInv"),
- code: 'flgOpeningInv',
- disabled: true,
- }, { //仓库名称
- code: 'whId',
- name: 'whName',
- title: mixins.$t("whName"),
- type: 'choose',
- urlKey: 'openingInventory',
- required: true,
- readonly: true,
- clear: false
- },
- { //库存批号
- code: 'nonStdCode',
- type: 'textarea',
- title: mixins.$t("iinventoryBatchNumber"),
- required: true,
- readonly: true,
- tip: mixins.$t('tipPop'),
- },
- { //期初数量
- code: 'intoQty',
- type: 'number',
- sign: "",
- digits: 0,
- title: mixins.$t("openingInventoryQty"),
- required: true,
- readonly: true,
- },
- {
- code: 'packageBox',
- type: 'str',
- title: mixins.$t("packageBox"),
- required: true,
- readonly: true,
- },
- { //期初成本价
- code: 'priceInto',
- type: 'number',
- title: mixins.$t("iinitialCostPrice"),
- required: true,
- readonly: true,
- },
- ]
- } else {
- contentObj.warehouse = [{ //期初库存标识
- type: 'switch',
- title: mixins.$t("openingInv"),
- code: 'flgOpeningInv',
- disabled: true,
- }, { //仓库名称
- code: 'whId',
- name: 'whName',
- title: mixins.$t("whName"),
- type: 'choose',
- urlKey: 'openingInventory',
- required: true,
- readonly: true,
- clear: false
- },
- { //库存批号
- code: 'nonStdCode',
- type: 'textarea',
- title: mixins.$t("iinventoryBatchNumber"),
- required: true,
- readonly: true,
- tip: mixins.$t('tipPop'),
- },
- { //期初数量
- code: 'intoQty',
- type: 'number',
- sign: "",
- digits: 0,
- title: mixins.$t("openingInventoryQty"),
- required: true,
- readonly: true,
- },
- { //期初成本价
- code: 'priceInto',
- type: 'number',
- title: mixins.$t("iinitialCostPrice"),
- required: true,
- readonly: true,
- },
- ]
- }
- } else {
- contentObj.warehouse = [{ //期初库存标识
- type: 'switch',
- title: mixins.$t("openingInv"),
- code: 'flgOpeningInv',
- disabled: true,
- }, ]
- }
- if (data.flgPrice) {
- contentObj.price = [{ //期初库存标识
- type: 'switch',
- title: mixins.$t("flgPrice"),
- code: 'flgPrice',
- }, { //采购价
- tip: mixins.$t("purchasePricetip"),
- code: 'pricePurchase',
- type: 'number',
- title: mixins.$t("purchasePrice"),
- required: true,
- }, { //零售价
- tip: mixins.$t("retailPricetip"),
- code: 'priceStandard',
- type: 'number',
- title: mixins.$t("retailPrice"),
- required: true,
- }, { //批发价
- tip: mixins.$t("wholesalePricetip"),
- code: 'priceWholesale',
- type: 'number',
- title: mixins.$t("wholesalePrice"),
- required: true,
- }, { //销售限价
- tip: mixins.$t("SaleSPriceLimittip"),
- code: 'priceLimited',
- type: 'number',
- title: mixins.$t("SaleSPriceLimit"),
- required: true,
- }, { //其他价
- tip: mixins.$t("otherPriceLimittip"),
- code: 'priceOther',
- type: 'number',
- title: mixins.$t("otherPriceLimit"),
- required: true,
- }, ]
- } else {
- contentObj.price = [{ //期初库存标识
- type: 'switch',
- title: mixins.$t("flgPrice"),
- code: 'flgPrice',
- }, ]
- }
- if (data.packBox && data.unitName && data.subUnitName) { //选了辅助计量单位 正好 包装也有值 那么直接给出公式
- data.calculationFormula = data.packBox + data.unitName + '= 1' + data.subUnitName
- }
- this.setData({
- contentObj: contentObj,
- formData: JSON.stringify(data),
- buttonList: [{
- name: 'merge',
- title: mixins.$t("save"), //'保存'
- }],
- })
- },
- })
|