| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712 |
- /*******************************************************************************
- * 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')
- 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,
- }, { //辅助单位标识
- type: 'switch',
- title: mixins.$t("subUnitId"),
- code: 'flgSubUnit',
- }, { //包装单位
- code: 'subUnitId',
- name: 'subUnitName',
- title: mixins.$t("packageUnit"),
- type: 'choose',
- urlKey: 'unit',
- required: true,
- }, { //包装
- code: 'packBox',
- title: mixins.$t("package"),
- type: 'number',
- sign: "",
- digits: 0,
- required: true,
- },
- {
- code: 'calculationFormula',
- type: 'textarea',
- title: mixins.$t("calculationFormula"),
- readonly:true,
- }
- ],
- warehouse: [{ //期初库存标识
- type: 'switch',
- title: mixins.$t("openingInv"),
- code: 'flgOpeningInv',
- }, { //仓库名称
- code: 'whId',
- name: 'whName',
- title: mixins.$t("whName"),
- type: 'choose',
- urlKey: 'openingInventory',
- required: true,
- },
- { //库存批号
- code: 'nonStdCode',
- type: 'textarea',
- title: mixins.$t("iinventoryBatchNumber"),
- required: true,
- },
- { //期初数量
- code: 'intoQty',
- type: 'number',
- sign: "",
- digits: 0,
- title: mixins.$t("openingInventoryQty"),
- required: true,
- },
- { //期初成本价
- code: 'priceInto',
- type: 'textarea',
- title: mixins.$t("iinitialCostPrice"),
- required: true,
- },
- ],
- 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"),
- }]
- },
- // 路由
- routeObjName: 'goodsSku',
- },
- /**
- * @desc : dk-form 里 dk-number-input 的输入回调
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- changeNumberField(e){
- console.log("changeNumberField",e);
- let code = e.detail.code
- let formData = JSON.parse(this.data.formData)
- if(code = "packBox"){//包装
- if(formData.packBox&&formData.unitName&&formData.subUnitName){ //选了辅助计量单位 正好 包装也有值 那么直接给出公式
- formData.calculationFormula = formData.packBox+ formData.unitName + '= 1'+ formData.subUnitName
- }
- }
- this.setData({
- formData:JSON.stringify(formData)
- })
- },
- /**
- * @desc : dk-form 里 Switch 的切换回调
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- onSwitchChange(e) {
- console.log("Switch", e);
- let code = e.detail.code
- let checkFlag = !e.detail.checkFlag
- let contentObj = this.data.contentObj
- if (code == "flgSubUnit") { //辅助单位
- if (checkFlag) {
- contentObj.unit = [{ //基本单位
- code: 'unitId',
- name: 'unitName',
- title: mixins.$t("unit"),
- type: 'choose',
- urlKey: 'unit',
- required: true,
- }, { //辅助单位标识
- 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: "",
- digits: 0,
- required: checkFlag,
- },
- {
- 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',
- }, ]
- }
- } else if (code == "flgOpeningInv") { //期初库存标识
- if (checkFlag) {
- 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,
- },
- { //期初数量
- code: 'intoQty',
- type: 'number',
- sign: "",
- digits: 0,
- title: mixins.$t("openingInventoryQty"),
- required: checkFlag,
- },
- { //期初成本价
- code: 'priceInto',
- type: 'textarea',
- title: mixins.$t("iinitialCostPrice"),
- required: checkFlag,
- },
- ]
- } else {
- 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
- })
- },
- /**
- * @desc : 选择页面跳转回调事件
- * @date : 2024/2/1 15:49
- * @author : 王英杰
- */
- chooseData(e) {
- console.log("t", e, this.data.formData);
- 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") { //计量单位
- formData.unitId = data.id
- formData.unitName = data.name
- if(formData.packBox&&formData.unitName&&formData.subUnitName){ //选了辅助计量单位 正好 包装也有值 那么直接给出公式
- formData.calculationFormula = formData.packBox+ formData.unitName + '= 1'+ formData.subUnitName
- }
- }
- if (code == "subUnitId") { //辅助计量单位
- formData.subUnitId = data.id
- formData.subUnitName = data.name
- 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 : 王英杰
- */
- 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() {
- console.log("参数", this.data.params);
- let that = this
- if (this.data.formMode == Constants.formMode.edit) { //编辑接口
- return this.excute(this.data.service, this.data.service.update, this.data.params)
- } else { //新建接口
- return this.excute(this.data.service, this.data.service.insert, this.data.params).then(res => {
- // 增加包装;数字类型正整数,默认1
- let formData = {}
- formData.packBox = 1
- that.setData({
- formData: JSON.stringify(formData)
- })
- })
- }
- },
- /**
- * @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
- })
- 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.packBox = 1
- formData.flgPrice = true
- formData.flgOpeningInv = true
- formData.flgSubUnit = true
- this.setData({
- formData: JSON.stringify(formData)
- })
- 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) {
- 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',
- readonly: data.inventoryCount!==0 //要校验库存; 库存量不为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,
- },
- {
- 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) {
- contentObj.warehouse = [{ //期初库存标识
- type: 'switch',
- title: mixins.$t("openingInv"),
- code: 'flgOpeningInv',
- }, { //仓库名称
- code: 'whId',
- name: 'whName',
- title: mixins.$t("whName"),
- type: 'choose',
- urlKey: 'openingInventory',
- required: true,
- readonly:true,
- },
- { //库存批号
- code: 'nonStdCode',
- type: 'textarea',
- title: mixins.$t("iinventoryBatchNumber"),
- required: true,
- readonly:true,
- },
- { //期初数量
- code: 'intoQty',
- type: 'number',
- sign: "",
- digits: 0,
- title: mixins.$t("openingInventoryQty"),
- required: true,
- readonly:true,
- },
- { //期初成本价
- code: 'priceInto',
- type: 'textarea',
- title: mixins.$t("iinitialCostPrice"),
- required: true,
- readonly:true,
- },
- ]
- } else {
- contentObj.warehouse = [{ //期初库存标识
- type: 'switch',
- title: mixins.$t("openingInv"),
- code: 'flgOpeningInv',
- }, ]
- }
- 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"), //'保存'
- }],
- })
- },
- })
|