add.js 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  1. /*******************************************************************************
  2. * Copyright(c) 2022 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:
  5. * 编辑履历:
  6. * 作者 日期 版本 修改内容
  7. * 王英杰 2024-1-24 1.00 新建商品档案
  8. *******************************************************************************/
  9. const mixins = require('@/mixins/index.js')
  10. const app = getApp()
  11. const util = require('@/utils/util.js')
  12. const Constants = require('@/utils/Constants')
  13. import Dialog from '@/dist/dialog/dialog.js';
  14. Page({
  15. mixins: [mixins],
  16. /**
  17. * 页面的初始数据
  18. */
  19. data: {
  20. gradeCode: app.globalData.company.gradeCode, //判断版本的 ( 标准还是专业)
  21. buttonList: [{
  22. name: 'merge',
  23. title: mixins.$t("save"), //'保存'
  24. }],
  25. table: Constants.tables.goodsSku,
  26. cardList: [], //不在这定义 在 loadinit定义
  27. contentObj: {
  28. main: [{ //商品型号
  29. code: 'skuModel',
  30. type: 'textarea',
  31. title: mixins.$t("skuModel"),
  32. required: true,
  33. }, { //商品名称
  34. code: 'skuName',
  35. type: 'textarea',
  36. title: mixins.$t("skuName"),
  37. }, {
  38. code: 'skuImages',
  39. name: mixins.$t("commodityPicture"), //商品图片
  40. type: 'uploader',
  41. },
  42. ],
  43. goods: [{ //商品品牌
  44. code: 'brandId',
  45. name: 'brandName',
  46. title: mixins.$t("goodsBrand"),
  47. type: 'choose',
  48. urlKey: 'goodsBrand',
  49. required: true,
  50. },
  51. { //商品种类
  52. code: 'categoryId',
  53. name: 'catName',
  54. title: mixins.$t("goodsCategory"),
  55. type: 'choose',
  56. urlKey: 'goodsCategory',
  57. required: true,
  58. }, { //商品系列
  59. code: 'seriesId',
  60. name: 'seriesName',
  61. title: mixins.$t("goodsSeries"),
  62. type: 'choose',
  63. urlKey: 'goodsSeries',
  64. }, { //商品规格
  65. code: 'skuSpec',
  66. name: 'skuSpec',
  67. type: 'textarea',
  68. required: true,
  69. title: mixins.$t("sukSpec"),
  70. }
  71. ],
  72. unit: [{ //基本单位
  73. code: 'unitId',
  74. name: 'unitName',
  75. title: mixins.$t("unit"),
  76. type: 'choose',
  77. urlKey: 'unit',
  78. required: true,
  79. clear: false,
  80. }, { //辅助单位标识
  81. type: 'switch',
  82. title: mixins.$t("subUnitId"),
  83. code: 'flgSubUnit',
  84. }, { //包装单位
  85. code: 'subUnitId',
  86. name: 'subUnitName',
  87. title: mixins.$t("packageUnit"),
  88. type: 'choose',
  89. urlKey: 'unit',
  90. required: true,
  91. readonly: true,
  92. }, { //包装
  93. code: 'packBox',
  94. title: mixins.$t("package"),
  95. type: 'number',
  96. sign: "",
  97. digits: 0,
  98. required: true,
  99. readonly: true,
  100. },
  101. {
  102. code: 'calculationFormula',
  103. type: 'textarea',
  104. title: mixins.$t("calculationFormula"),
  105. readonly: true,
  106. }
  107. ],
  108. warehouse: [{ //期初库存标识
  109. type: 'switch',
  110. title: mixins.$t("openingInv"),
  111. code: 'flgOpeningInv',
  112. }, ],
  113. price: [{ //期初库存标识
  114. type: 'switch',
  115. title: mixins.$t("flgPrice"),
  116. code: 'flgPrice',
  117. }, { //采购价
  118. tip: mixins.$t("purchasePricetip"),
  119. code: 'pricePurchase',
  120. type: 'number',
  121. title: mixins.$t("purchasePrice"),
  122. required: true,
  123. }, { //零售价
  124. tip: mixins.$t("retailPricetip"),
  125. code: 'priceStandard',
  126. type: 'number',
  127. title: mixins.$t("retailPrice"),
  128. required: true,
  129. }, { //批发价
  130. tip: mixins.$t("wholesalePricetip"),
  131. code: 'priceWholesale',
  132. type: 'number',
  133. title: mixins.$t("wholesalePrice"),
  134. required: true,
  135. }, { //销售限价
  136. tip: mixins.$t("SaleSPriceLimittip"),
  137. code: 'priceLimited',
  138. type: 'number',
  139. title: mixins.$t("SaleSPriceLimit"),
  140. required: true,
  141. }, { //其他价
  142. tip: mixins.$t("otherPriceLimittip"),
  143. code: 'priceOther',
  144. type: 'number',
  145. title: mixins.$t("otherPriceLimit"),
  146. required: true,
  147. }, ],
  148. // warning: [{ // 预警信息
  149. // type: 'textarea',
  150. // title: mixins.$t("warningLowerLimit"),
  151. // code: 'warningLowerLimit',
  152. // },{
  153. // type: 'textarea',
  154. // title: mixins.$t("warningUpperLimit"),
  155. // code: 'warningUpperLimit',
  156. // }],
  157. other: [{
  158. code: 'remarks',
  159. type: 'textarea',
  160. title: mixins.$t("remarks"),
  161. }]
  162. },
  163. popContentBox: [],
  164. // 路由
  165. routeObjName: 'goodsSku',
  166. // 包装小数位
  167. packBoxDigits: 0,
  168. },
  169. /**
  170. * @desc : 数量改变事件
  171. * @date : 2024/2/1 15:49
  172. * @author : 王英杰
  173. */
  174. changeStep(e) {
  175. let key = e.detail.key
  176. let value = e.detail.value
  177. let dataItem = JSON.parse(this.data.dataItem)
  178. dataItem[key] = value
  179. this.setData({
  180. dataItem: JSON.stringify(dataItem)
  181. })
  182. },
  183. /**
  184. * @desc : dk-form 里 str的点击回调 的输入回调
  185. * @date : 2024/2/1 15:49
  186. * @author : 王英杰
  187. */
  188. openStr(e) {
  189. let code = e.detail.code
  190. const readonly = e.detail.readonly
  191. if (code == "packageBox" && !readonly) { //点击包装数量
  192. let formData = JSON.parse(this.data.formData)
  193. if (formData.unitId && formData.subUnitId && formData.packBox) {
  194. let dataItem = this.data.dataItem ? JSON.parse(this.data.dataItem) : {}
  195. dataItem['box'] = formData.box || 0
  196. dataItem['piece'] = formData.piece || 0
  197. dataItem.packageBox = formData.packageBox
  198. let popContentBox = [{
  199. code: 'box',
  200. type: 'step',
  201. title: formData.subUnitName,
  202. required: true
  203. },
  204. {
  205. code: 'piece',
  206. type: 'step',
  207. title: formData.unitName,
  208. required: true
  209. },
  210. ]
  211. this.setData({
  212. showPopBox: true,
  213. dataItem: JSON.stringify(dataItem),
  214. popContentBox: popContentBox
  215. })
  216. } else {
  217. util.showToast('请先输入基本单位、包装单位、包装');
  218. }
  219. }
  220. },
  221. /**
  222. * @desc : 商品确认事件--箱片的确认
  223. * @date : 2024/2/1 15:49
  224. * @author : 王英杰
  225. */
  226. editItemsBox(e) {
  227. let dataItem = JSON.parse(this.data.dataItem)
  228. let formData = JSON.parse(this.data.formData)
  229. formData['box'] = dataItem['box']
  230. formData['piece'] = dataItem['piece']
  231. formData['intoQty'] = Number(dataItem['box']) * Number(formData['packBox']) + Number(dataItem['piece'])
  232. formData.packageBox = dataItem['box'] + formData.subUnitName + dataItem['piece'] + formData.unitName
  233. this.setData({
  234. formData: JSON.stringify(formData)
  235. })
  236. },
  237. /**
  238. * @desc : dk-form 里 dk-number-input 的输入回调
  239. * @date : 2024/2/1 15:49
  240. * @author : 王英杰
  241. */
  242. changeNumberField(e) {
  243. let code = e.detail.code
  244. let formData = JSON.parse(this.data.formData)
  245. if (code == "packBox") { //包装
  246. if (formData.intoQty || formData.packageBox) {
  247. //提示
  248. Dialog.confirm({
  249. message: '修改包装将清空期初数量、包装数量',
  250. }).then(() => {
  251. formData.intoQty = null
  252. formData.packageBox = null
  253. formData.box = null
  254. formData.piece = null
  255. formData["packBox_"] = formData["packBox"]
  256. if (formData.packBox && formData.unitName && formData.subUnitName) { //选了辅助计量单位 正好 包装也有值 那么直接给出公式
  257. formData.calculationFormula = formData.packBox + formData.unitName + '= 1' + formData.subUnitName
  258. }
  259. this.setData({
  260. formData: JSON.stringify(formData)
  261. })
  262. }).catch(() => {
  263. formData["packBox"] = formData["packBox_"]
  264. this.setData({
  265. formData: JSON.stringify(formData)
  266. })
  267. });
  268. } else {
  269. if (formData.packBox && formData.unitName && formData.subUnitName) { //选了辅助计量单位 正好 包装也有值 那么直接给出公式
  270. formData.calculationFormula = formData.packBox + formData.unitName + '= 1' + formData.subUnitName
  271. }
  272. formData["packBox_"] = formData["packBox"]
  273. }
  274. }
  275. if (code == "intoQty" && formData.flgSubUnit) { //期初数量
  276. if (formData.unitId && formData.subUnitId && formData.packBox) {
  277. formData['box'] = parseInt(formData['intoQty'] / formData['packBox'])
  278. formData['piece'] = parseFloat(Number(formData['intoQty'] % formData['packBox']).toFixed(formData.decimalPlaces));
  279. formData.packageBox = formData['box'] + formData.subUnitName + formData['piece'] + formData.unitName
  280. } else {
  281. formData['intoQty'] = undefined
  282. util.showToast('请先输入基本单位、包装单位、包装');
  283. }
  284. }
  285. this.setData({
  286. formData: JSON.stringify(formData)
  287. })
  288. },
  289. /**
  290. * @desc : dk-form 里 Switch 的切换回调
  291. * @date : 2024/2/1 15:49
  292. * @author : 王英杰
  293. */
  294. onSwitchChange(e) {
  295. let code = e.detail.code
  296. let checkFlag = !e.detail.checkFlag
  297. let contentObj = this.data.contentObj
  298. let formData = JSON.stringify(this.data.formData)
  299. if (code == "flgSubUnit") { //辅助单位
  300. if (checkFlag) {
  301. let formData = JSON.parse(this.data.formData)
  302. // 当未选择基本单位时不能打开辅助单位开关
  303. if (!formData.unitId) {
  304. formData.flgSubUnit = false
  305. util.showToast('请先选择基本单位');
  306. this.setData({
  307. formData: JSON.stringify(formData)
  308. })
  309. return
  310. }
  311. contentObj.unit = [{ //基本单位
  312. code: 'unitId',
  313. name: 'unitName',
  314. title: mixins.$t("unit"),
  315. type: 'choose',
  316. urlKey: 'unit',
  317. required: true,
  318. clear: false,
  319. }, { //辅助单位标识
  320. type: 'switch',
  321. title: mixins.$t("subUnitId"),
  322. code: 'flgSubUnit',
  323. }, { //包装单位
  324. code: 'subUnitId',
  325. name: 'subUnitName',
  326. title: mixins.$t("packageUnit"),
  327. type: 'choose',
  328. urlKey: 'unit',
  329. required: checkFlag,
  330. }, { //包装
  331. code: 'packBox',
  332. title: mixins.$t("package"),
  333. type: 'number',
  334. sign: "",
  335. // todo
  336. digits: this.packBoxDigits,
  337. required: checkFlag,
  338. },
  339. {
  340. code: 'calculationFormula',
  341. type: 'textarea',
  342. title: mixins.$t("calculationFormula"),
  343. readonly: true,
  344. }
  345. ]
  346. } else {
  347. let formDataJson = JSON.parse(this.data.formData)
  348. if (formDataJson) {
  349. ['subUnitName', 'calculationFormula', 'packBox'].forEach(key => {
  350. if (formDataJson.hasOwnProperty(key)) {
  351. delete formDataJson[key];
  352. }
  353. });
  354. }
  355. this.setData({
  356. formData: JSON.stringify(formDataJson)
  357. })
  358. contentObj.unit = [{ //基本单位
  359. code: 'unitId',
  360. name: 'unitName',
  361. title: mixins.$t("unit"),
  362. type: 'choose',
  363. urlKey: 'unit',
  364. required: true,
  365. clear: false,
  366. }, { //辅助单位标识
  367. type: 'switch',
  368. title: mixins.$t("subUnitId"),
  369. code: 'flgSubUnit',
  370. }, ]
  371. }
  372. } else if (code == "flgOpeningInv") { //期初库存标识
  373. if (checkFlag) {
  374. let formData = JSON.parse(this.data.formData)
  375. //打开期初库存的时候 要先判断 需要先选择基本单位
  376. if (!formData.unitId) {
  377. formData.flgOpeningInv = false
  378. util.showToast('请先选择基本单位');
  379. this.setData({
  380. formData: JSON.stringify(formData)
  381. })
  382. return
  383. }
  384. if (formData.flgSubUnit) { //开了辅助单位
  385. contentObj.warehouse = [{ //期初库存标识
  386. type: 'switch',
  387. title: mixins.$t("openingInv"),
  388. code: 'flgOpeningInv',
  389. }, { //仓库名称
  390. code: 'whId',
  391. name: 'whName',
  392. title: mixins.$t("whName"),
  393. type: 'choose',
  394. urlKey: 'openingInventory',
  395. required: checkFlag,
  396. },
  397. { //库存批号
  398. code: 'nonStdCode',
  399. type: 'textarea',
  400. title: mixins.$t("iinventoryBatchNumber"),
  401. required: checkFlag,
  402. tip: mixins.$t('tipPop'),
  403. },
  404. { //期初数量
  405. code: 'intoQty',
  406. type: 'number',
  407. sign: "",
  408. digits: formData.decimalPlaces,
  409. title: mixins.$t("openingInventoryQty"),
  410. required: checkFlag,
  411. },
  412. {
  413. code: 'packageBox',
  414. type: 'str',
  415. title: mixins.$t("packageBox"),
  416. required: checkFlag,
  417. readonly: true,
  418. },
  419. { //期初成本价
  420. code: 'priceInto',
  421. type: 'number',
  422. title: mixins.$t("iinitialCostPrice"),
  423. required: checkFlag,
  424. },
  425. ]
  426. } else { //没开辅助单位
  427. contentObj.warehouse = [{ //期初库存标识
  428. type: 'switch',
  429. title: mixins.$t("openingInv"),
  430. code: 'flgOpeningInv',
  431. }, { //仓库名称
  432. code: 'whId',
  433. name: 'whName',
  434. title: mixins.$t("whName"),
  435. type: 'choose',
  436. urlKey: 'openingInventory',
  437. required: checkFlag,
  438. },
  439. { //库存批号
  440. code: 'nonStdCode',
  441. type: 'textarea',
  442. title: mixins.$t("iinventoryBatchNumber"),
  443. required: checkFlag,
  444. tip: mixins.$t('tipPop'),
  445. },
  446. { //期初数量
  447. code: 'intoQty',
  448. type: 'number',
  449. sign: "",
  450. digits: formData.decimalPlaces,
  451. title: mixins.$t("openingInventoryQty"),
  452. required: checkFlag,
  453. },
  454. { //期初成本价
  455. code: 'priceInto',
  456. type: 'number',
  457. title: mixins.$t("iinitialCostPrice"),
  458. required: checkFlag,
  459. },
  460. ]
  461. }
  462. } else {
  463. /**
  464. * 关闭初期按钮后删除对应的初期数据
  465. * @author 刘尧
  466. * @data 2024.06.04
  467. */
  468. let formData = JSON.parse(this.data.formData)
  469. if (formData) {
  470. ['packageBox', 'priceInto', 'intoQty', 'nonStdCode', 'whName', 'whId'].forEach(key => {
  471. if (formData.hasOwnProperty(key)) {
  472. delete formData[key];
  473. }
  474. });
  475. }
  476. this.setData({
  477. formData: JSON.stringify(formData)
  478. })
  479. contentObj.warehouse = [{ //期初库存标识
  480. type: 'switch',
  481. title: mixins.$t("openingInv"),
  482. code: 'flgOpeningInv',
  483. }, ]
  484. }
  485. } else if (code == "flgPrice") { //期初库存标识
  486. if (checkFlag) {
  487. contentObj.price = [{ //期初库存标识
  488. type: 'switch',
  489. title: mixins.$t("flgPrice"),
  490. code: 'flgPrice',
  491. }, { //采购价
  492. tip: mixins.$t("purchasePricetip"),
  493. code: 'pricePurchase',
  494. type: 'number',
  495. title: mixins.$t("purchasePrice"),
  496. required: checkFlag,
  497. }, { //零售价
  498. tip: mixins.$t("retailPricetip"),
  499. code: 'priceStandard',
  500. type: 'number',
  501. title: mixins.$t("retailPrice"),
  502. required: checkFlag,
  503. }, { //批发价
  504. tip: mixins.$t("wholesalePricetip"),
  505. code: 'priceWholesale',
  506. type: 'number',
  507. title: mixins.$t("wholesalePrice"),
  508. required: checkFlag,
  509. }, { //销售限价
  510. tip: mixins.$t("SaleSPriceLimittip"),
  511. code: 'priceLimited',
  512. type: 'number',
  513. title: mixins.$t("SaleSPriceLimit"),
  514. required: checkFlag,
  515. }, { //其他价
  516. tip: mixins.$t("otherPriceLimittip"),
  517. code: 'priceOther',
  518. type: 'number',
  519. title: mixins.$t("otherPriceLimit"),
  520. required: checkFlag,
  521. }, ]
  522. } else {
  523. contentObj.price = [{ //期初库存标识
  524. type: 'switch',
  525. title: mixins.$t("flgPrice"),
  526. code: 'flgPrice',
  527. }, ]
  528. }
  529. }
  530. this.setData({
  531. contentObj: contentObj
  532. })
  533. },
  534. onShow() {
  535. this.dialogShowChooseData();
  536. },
  537. /**
  538. * @desc : 因为chooseData 的执行顺序要高于onshow 且 chooseData无法弹 dialog 所以在onshow执行
  539. * @date : 2024/2/1 15:49
  540. * @author : 王英杰
  541. */
  542. dialogShowChooseData() {
  543. if (!this.data.handledata) {
  544. return
  545. }
  546. // todo
  547. this.setData({
  548. handledata: false
  549. })
  550. let formData = JSON.parse(this.data.formData)
  551. let data = this.data.chooseUnitData
  552. let Dialog_message = null
  553. let code = this.data.chooseDataCode
  554. if (code == "unitId") { //计量单位
  555. formData.intoQty = null
  556. formData.packBox = null
  557. formData.subUnitId = null
  558. formData.subUnitName = null
  559. formData.packageBox = null
  560. formData.box = null
  561. formData.piece = null
  562. // 当重新选择基本单位后清空公式 刘尧 2024.5.30
  563. formData.calculationFormula = null
  564. Dialog_message = '更换基础单位将清空包装单位、期初数量、包装、包装数量'
  565. }
  566. if (code == "subUnitId") { //包装单位
  567. formData.intoQty = null
  568. formData.packageBox = null
  569. formData.box = null
  570. formData.piece = null
  571. Dialog_message = '更换包装单位将清空期初数量、包装数量'
  572. }
  573. //提示
  574. Dialog.confirm({
  575. message: Dialog_message,
  576. }).then(() => {
  577. this.handleChooseDataUnit(formData, data, code)
  578. }).catch(() => {});
  579. },
  580. /**
  581. * @desc : 选择页面跳转回调事件
  582. * @date : 2024/2/1 15:49
  583. * @author : 王英杰
  584. */
  585. chooseData(e) {
  586. let formData = JSON.parse(this.data.formData)
  587. let code = e.detail.code
  588. let data = e.detail.data.data
  589. if (code == "brandId") { //商品品牌
  590. formData.brandId = data.id
  591. formData.brandName = data.name
  592. }
  593. if (code == "categoryId") { //商品种类
  594. formData.categoryId = data.id
  595. formData.catName = data.name
  596. }
  597. if (code == "unitId") { //计量单位
  598. //当期初数量有值的时候 弹提示是否清除
  599. if (formData.intoQty || formData.packBox || formData.subUnitId || formData.packageBox) { //在onshow执行 这里无法弹出dialog
  600. this.setData({
  601. chooseUnitData: data,
  602. handledata: true,
  603. chooseDataCode: code
  604. })
  605. } else {
  606. this.handleChooseDataUnit(formData, data, code)
  607. }
  608. }
  609. if (code == "subUnitId") { //辅助计量单位
  610. if (data.id == formData.unitId) {
  611. setTimeout(() => {
  612. util.showToast('包装单位不能等于基本单位');
  613. }, 1000)
  614. return
  615. }
  616. if (formData.intoQty || formData.packageBox) { //在onshow执行 这里无法弹出dialog
  617. this.setData({
  618. chooseUnitData: data,
  619. handledata: true,
  620. chooseDataCode: code
  621. })
  622. } else {
  623. this.handleChooseDataUnit(formData, data, code)
  624. }
  625. if (formData.packBox && formData.unitName && formData.subUnitName) { //选了辅助计量单位 正好 包装也有值 那么直接给出公式
  626. formData.calculationFormula = formData.packBox + formData.unitName + '= 1' + formData.subUnitName
  627. }
  628. }
  629. if (code == "seriesId") { //商品系列
  630. formData.seriesId = data.id
  631. formData.seriesName = data.name
  632. }
  633. if (code == "whId") { //仓库名称
  634. formData.whId = data.id
  635. formData.whName = data.name
  636. }
  637. this.setData({
  638. formData: JSON.stringify(formData)
  639. })
  640. },
  641. /**
  642. * @desc : 处理 选择页面回来的 基本单位
  643. * @date : 2024/2/1 15:49
  644. * @author : 王英杰
  645. */
  646. handleChooseDataUnit(formData, data, code) {
  647. if (code == "unitId") {
  648. formData.unitId = data.id
  649. formData.unitName = data.name
  650. formData.decimalPlaces = data.decimalPlaces
  651. let dataItem = this.data.dataItem ? JSON.parse(this.data.dataItem) : {}
  652. dataItem.decimalPlaces = data.decimalPlaces
  653. if (formData.packBox && formData.unitName && formData.subUnitName) { //选了辅助计量单位 正好 包装也有值 那么直接给出公式
  654. formData.calculationFormula = formData.packBox + formData.unitName + '= 1' + formData.subUnitName
  655. }
  656. let contentObj = this.data.contentObj
  657. let packBoxDigits = formData.decimalPlaces
  658. if (contentObj.warehouse.length > 0) {
  659. // 遍历 contentObj.warehouse 数组
  660. for (let i = 0; i < contentObj.warehouse.length; i++) {
  661. // 检查当前对象的 code 是否为 'intoQty'
  662. if (contentObj.warehouse[i].code === 'intoQty') { //期初数量
  663. // 如果是,则修改其 digits 属性
  664. contentObj.warehouse[i].digits = formData.decimalPlaces;
  665. contentObj.warehouse[i].readonly = false;
  666. // 找到后,可以跳出循环(如果确定只有一个匹配项)
  667. break;
  668. }
  669. }
  670. }
  671. if (contentObj.unit.length > 0) {
  672. // 遍历 contentObj.unit 数组
  673. for (let i = 0; i < contentObj.unit.length; i++) {
  674. // 检查当前对象的 code 是否为 'packBox'
  675. if (contentObj.unit[i].code === 'packBox') { //包装
  676. // 如果是,则修改其 digits 属性
  677. contentObj.unit[i].digits = formData.decimalPlaces;
  678. contentObj.unit[i].readonly = false;
  679. continue
  680. }
  681. if (contentObj.unit[i].code === 'subUnitId') { //包装单位
  682. contentObj.unit[i].readonly = false;
  683. continue
  684. }
  685. }
  686. }
  687. this.setData({
  688. packBoxDigits: packBoxDigits,
  689. contentObj: contentObj,
  690. formData: JSON.stringify(formData),
  691. dataItem: JSON.stringify(dataItem)
  692. })
  693. }
  694. if (code == "subUnitId") {
  695. formData.subUnitId = data.id
  696. formData.subUnitName = data.name
  697. this.setData({
  698. formData: JSON.stringify(formData),
  699. })
  700. }
  701. return
  702. },
  703. /**
  704. * @desc : 保存数据服务--校验
  705. * @date : 2024/2/1 15:49
  706. * @author : 王英杰
  707. */
  708. validData() {
  709. let formData = JSON.parse(this.data.formData)
  710. if (!formData.flgSubUnit) { //辅助单位标识未勾选 不存包装单位 包装
  711. delete formData.subUnitId
  712. delete formData.subUnitName
  713. delete formData.packBox
  714. }
  715. //编辑的时候 就不用删除了 因为不允许修改
  716. if ((!formData.flgOpeningInv) && this.data.formMode !== Constants.formMode.edit) { //期初库存标识未勾选 不存仓库名称 色号 起初数量 期初成本价
  717. delete formData.whId
  718. delete formData.whName
  719. delete formData.nonStdCode
  720. delete formData.priceInto
  721. }
  722. if (!formData.flgPrice) { //价格体系标识未勾选 不存采购价 零售价 批发价 销售限价 其他价
  723. delete formData.pricePurchase
  724. delete formData.priceStandard
  725. delete formData.priceWholesale
  726. delete formData.priceLimited
  727. delete formData.priceOther
  728. }
  729. this.setData({
  730. formData: JSON.stringify(formData)
  731. })
  732. return true
  733. },
  734. // 设置保存参数
  735. setParams(params) {
  736. let saveData = JSON.parse(this.data.formData)
  737. // 修改之后的 值
  738. params = Object.assign({}, params, saveData);
  739. params.serviceCategories = (params.serviceCategories && params.serviceCategories.length > 0) ? params.serviceCategories.split(',') : []
  740. params.skuImages = params.annexPaths
  741. params.orgId = app.globalData.user.orgId
  742. return params
  743. },
  744. /**
  745. * @desc : 保存数据服务
  746. * @date : 2024/2/1 15:49
  747. * @author : 王英杰
  748. */
  749. saveData() {
  750. let that = this
  751. if (this.data.formMode == Constants.formMode.edit) { //编辑接口
  752. return this.excute(this.data.service, this.data.service.update, this.data.params)
  753. } else { //新建接口
  754. let excute = this.excute(this.data.service, this.data.service.insert, this.data.params)
  755. excute.then(res => {
  756. // 增加包装;数字类型正整数,默认1
  757. let formData = {}
  758. let contentObj = this.data.contentObj
  759. formData.flgPrice = true
  760. formData.flgOpeningInv = false
  761. formData.flgSubUnit = true
  762. that.setData({
  763. formData: JSON.stringify(formData),
  764. loading: false,
  765. contentObj: {
  766. main: [{ //商品型号
  767. code: 'skuModel',
  768. type: 'textarea',
  769. title: mixins.$t("skuModel"),
  770. required: true,
  771. }, { //商品名称
  772. code: 'skuName',
  773. type: 'textarea',
  774. title: mixins.$t("skuName"),
  775. }, {
  776. code: 'skuImages',
  777. name: mixins.$t("commodityPicture"), //商品图片
  778. type: 'uploader',
  779. },
  780. ],
  781. goods: [{ //商品品牌
  782. code: 'brandId',
  783. name: 'brandName',
  784. title: mixins.$t("goodsBrand"),
  785. type: 'choose',
  786. urlKey: 'goodsBrand',
  787. required: true,
  788. },
  789. { //商品种类
  790. code: 'categoryId',
  791. name: 'catName',
  792. title: mixins.$t("goodsCategory"),
  793. type: 'choose',
  794. urlKey: 'goodsCategory',
  795. required: true,
  796. }, { //商品系列
  797. code: 'seriesId',
  798. name: 'seriesName',
  799. title: mixins.$t("goodsSeries"),
  800. type: 'choose',
  801. urlKey: 'goodsSeries',
  802. }, { //商品规格
  803. code: 'skuSpec',
  804. name: 'skuSpec',
  805. type: 'textarea',
  806. required: true,
  807. title: mixins.$t("sukSpec"),
  808. }
  809. ],
  810. unit: [{ //基本单位
  811. code: 'unitId',
  812. name: 'unitName',
  813. title: mixins.$t("unit"),
  814. type: 'choose',
  815. urlKey: 'unit',
  816. required: true,
  817. clear: false,
  818. }, { //辅助单位标识
  819. type: 'switch',
  820. title: mixins.$t("subUnitId"),
  821. code: 'flgSubUnit',
  822. }
  823. ],
  824. warehouse: [{ //期初库存标识
  825. type: 'switch',
  826. title: mixins.$t("openingInv"),
  827. code: 'flgOpeningInv',
  828. }, ],
  829. price: [{ //期初库存标识
  830. type: 'switch',
  831. title: mixins.$t("flgPrice"),
  832. code: 'flgPrice',
  833. }, { //采购价
  834. tip: mixins.$t("purchasePricetip"),
  835. code: 'pricePurchase',
  836. type: 'number',
  837. title: mixins.$t("purchasePrice"),
  838. required: true,
  839. }, { //零售价
  840. tip: mixins.$t("retailPricetip"),
  841. code: 'priceStandard',
  842. type: 'number',
  843. title: mixins.$t("retailPrice"),
  844. required: true,
  845. }, { //批发价
  846. tip: mixins.$t("wholesalePricetip"),
  847. code: 'priceWholesale',
  848. type: 'number',
  849. title: mixins.$t("wholesalePrice"),
  850. required: true,
  851. }, { //销售限价
  852. tip: mixins.$t("SaleSPriceLimittip"),
  853. code: 'priceLimited',
  854. type: 'number',
  855. title: mixins.$t("SaleSPriceLimit"),
  856. required: true,
  857. }, { //其他价
  858. tip: mixins.$t("otherPriceLimittip"),
  859. code: 'priceOther',
  860. type: 'number',
  861. title: mixins.$t("otherPriceLimit"),
  862. required: true,
  863. }, ],
  864. other: [{
  865. code: 'remarks',
  866. type: 'textarea',
  867. title: mixins.$t("remarks"),
  868. }]
  869. }
  870. })
  871. })
  872. return excute;
  873. }
  874. },
  875. /**
  876. * @desc : 处理保存后续事件
  877. * @date : 2024/2/1 15:49
  878. * @author : 姜永辉
  879. */
  880. handleSaveData() {
  881. //购物车跳转来的,新建完毕直接回到选择界面
  882. if (this.data.formType == Constants.formType.shopping) {
  883. // var pages = getCurrentPages();
  884. // var prevPage = pages[pages.length - 2]; //上一个页面
  885. // prevPage.setData({
  886. // refreshByAdd: true
  887. // })
  888. // 给父页面传递数据
  889. const eventChannel = this.getOpenerEventChannel();
  890. eventChannel.emit('refresh', {
  891. id: 1
  892. })
  893. setTimeout(() => {
  894. wx.navigateBack({
  895. delta: 1
  896. });
  897. }, 200)
  898. }
  899. //新手引导过来,需要返回
  900. if (this.data.formReturnMode == Constants.formReturnMode.beginnerGuide) {
  901. const eventChannel = this.getOpenerEventChannel();
  902. eventChannel.emit('refresh', {
  903. id: 1
  904. })
  905. setTimeout(() => {
  906. wx.navigateBack({
  907. delta: 1
  908. });
  909. }, 200)
  910. }
  911. },
  912. /**
  913. * @desc : 页面加载数据方法
  914. * @date : 2024/2/1 15:49
  915. * @author : 王英杰
  916. */
  917. loadInit() {
  918. //标准版商品档案新建、编辑、详情不展示价格体系
  919. if (this.data.gradeCode == Constants.gradeCode.STD) { //标准版
  920. this.setData({
  921. cardList: ['main', 'goods', "unit", "warehouse", 'other'],
  922. })
  923. } else {
  924. this.setData({
  925. cardList: ['main', 'goods', "unit", "warehouse", 'price', 'other'],
  926. })
  927. }
  928. if (this.data.formMode == Constants.formMode.edit) {
  929. wx.setNavigationBarTitle({
  930. title: mixins.$t('editGoodsSuk'),
  931. })
  932. } else {
  933. // 增加包装;数字类型正整数,默认1
  934. let formData = JSON.parse(this.data.formData) || {}
  935. formData.flgPrice = true
  936. formData.flgOpeningInv = false
  937. formData.flgSubUnit = false
  938. // 获取表单总信息
  939. let contentObj = this.data.contentObj
  940. // 当页面初始化的时候 将其他内容隐藏
  941. contentObj.unit = [{ //基本单位
  942. code: 'unitId',
  943. name: 'unitName',
  944. title: mixins.$t("unit"),
  945. type: 'choose',
  946. urlKey: 'unit',
  947. required: true,
  948. clear: false,
  949. }, { //辅助单位标识
  950. type: 'switch',
  951. title: mixins.$t("subUnitId"),
  952. code: 'flgSubUnit',
  953. }, ]
  954. this.setData({
  955. formData: JSON.stringify(formData),
  956. contentObj: contentObj
  957. })
  958. wx.setNavigationBarTitle({
  959. title: mixins.$t('addGoodsSuk'),
  960. })
  961. }
  962. },
  963. /**
  964. * @desc : 给表单赋值
  965. * @date : 2024/2/1 15:49
  966. * @author : 王英杰
  967. */
  968. setValuesByEdit(data) {
  969. // data.serviceCategories = (data.serviceCategories && data.serviceCategories.length > 0) ? data.serviceCategories.join(',') : undefined
  970. data.annexPaths = data.skuImages
  971. data.onlyCode = data.skuCode
  972. let contentObj = this.data.contentObj
  973. // 我们要添加的新对象是 编码 新建的时候没有 编辑的时候添加
  974. contentObj.main = [{ //唯一编码
  975. code: 'onlyCode',
  976. type: 'textarea',
  977. title: mixins.$t("onlyCode"),
  978. readonly: true
  979. }, { //商品型号
  980. code: 'skuModel',
  981. type: 'textarea',
  982. title: mixins.$t("skuModel"),
  983. required: true,
  984. }, { //商品名称
  985. code: 'skuName',
  986. type: 'textarea',
  987. title: mixins.$t("skuName"),
  988. }, {
  989. code: 'skuImages',
  990. name: mixins.$t("commodityPicture"), //商品图片
  991. type: 'uploader',
  992. },
  993. ]
  994. if (data.flgSubUnit) {
  995. if (data.inventoryCount !== 0) {
  996. contentObj.unit = [{
  997. text: '本商品有库存,不可更改单位模块;需全部出库后才可更改',
  998. type: 'text',
  999. }, { //基本单位
  1000. code: 'unitId',
  1001. name: 'unitName',
  1002. title: mixins.$t("unit"),
  1003. type: 'choose',
  1004. urlKey: 'unit',
  1005. required: true,
  1006. readonly: data.inventoryCount !== 0 //要校验库存; 库存量不为0不让更改
  1007. }, { //辅助单位标识
  1008. type: 'switch',
  1009. title: mixins.$t("subUnitId"),
  1010. code: 'flgSubUnit',
  1011. disabled: (data.inventoryCount !== 0),
  1012. }, { //包装单位
  1013. code: 'subUnitId',
  1014. name: 'subUnitName',
  1015. title: mixins.$t("packageUnit"),
  1016. type: 'choose',
  1017. urlKey: 'unit',
  1018. required: true,
  1019. readonly: data.inventoryCount !== 0 //要校验库存; 库存量不为0不让更改
  1020. }, { //包装
  1021. code: 'packBox',
  1022. title: mixins.$t("package"),
  1023. type: 'number',
  1024. sign: "",
  1025. digits: 0,
  1026. required: true,
  1027. readonly: data.inventoryCount !== 0
  1028. },
  1029. {
  1030. code: 'calculationFormula',
  1031. type: 'textarea',
  1032. title: mixins.$t("calculationFormula"),
  1033. readonly: true,
  1034. }
  1035. ]
  1036. } else { //没库存
  1037. contentObj.unit = [{ //基本单位
  1038. code: 'unitId',
  1039. name: 'unitName',
  1040. title: mixins.$t("unit"),
  1041. type: 'choose',
  1042. urlKey: 'unit',
  1043. required: true,
  1044. readonly: data.inventoryCount !== 0 //要校验库存; 库存量不为0不让更改
  1045. }, { //辅助单位标识
  1046. type: 'switch',
  1047. title: mixins.$t("subUnitId"),
  1048. code: 'flgSubUnit',
  1049. disabled: (data.inventoryCount !== 0),
  1050. }, { //包装单位
  1051. code: 'subUnitId',
  1052. name: 'subUnitName',
  1053. title: mixins.$t("packageUnit"),
  1054. type: 'choose',
  1055. urlKey: 'unit',
  1056. required: true,
  1057. readonly: data.inventoryCount !== 0 //要校验库存; 库存量不为0不让更改
  1058. }, { //包装
  1059. code: 'packBox',
  1060. title: mixins.$t("package"),
  1061. type: 'number',
  1062. sign: "",
  1063. digits: 0,
  1064. required: true,
  1065. readonly: data.inventoryCount !== 0
  1066. },
  1067. {
  1068. code: 'calculationFormula',
  1069. type: 'textarea',
  1070. title: mixins.$t("calculationFormula"),
  1071. readonly: true,
  1072. }
  1073. ]
  1074. }
  1075. } else {
  1076. contentObj.unit = [{ //基本单位
  1077. code: 'unitId',
  1078. name: 'unitName',
  1079. title: mixins.$t("unit"),
  1080. type: 'choose',
  1081. urlKey: 'unit',
  1082. required: true,
  1083. }, { //辅助单位标识
  1084. type: 'switch',
  1085. title: mixins.$t("subUnitId"),
  1086. code: 'flgSubUnit',
  1087. }, ]
  1088. }
  1089. if (data.flgOpeningInv) {
  1090. if (data.flgSubUnit) { //开了辅助单位
  1091. data.packageBox = data['box'] + data.subUnitName + data['piece'] + data.unitName
  1092. contentObj.warehouse = [{ //期初库存标识
  1093. type: 'switch',
  1094. title: mixins.$t("openingInv"),
  1095. code: 'flgOpeningInv',
  1096. disabled: true,
  1097. }, { //仓库名称
  1098. code: 'whId',
  1099. name: 'whName',
  1100. title: mixins.$t("whName"),
  1101. type: 'choose',
  1102. urlKey: 'openingInventory',
  1103. required: true,
  1104. readonly: true,
  1105. clear: false
  1106. },
  1107. { //库存批号
  1108. code: 'nonStdCode',
  1109. type: 'textarea',
  1110. title: mixins.$t("iinventoryBatchNumber"),
  1111. required: true,
  1112. readonly: true,
  1113. tip: mixins.$t('tipPop'),
  1114. },
  1115. { //期初数量
  1116. code: 'intoQty',
  1117. type: 'number',
  1118. sign: "",
  1119. digits: 0,
  1120. title: mixins.$t("openingInventoryQty"),
  1121. required: true,
  1122. readonly: true,
  1123. },
  1124. {
  1125. code: 'packageBox',
  1126. type: 'str',
  1127. title: mixins.$t("packageBox"),
  1128. required: true,
  1129. readonly: true,
  1130. },
  1131. { //期初成本价
  1132. code: 'priceInto',
  1133. type: 'number',
  1134. title: mixins.$t("iinitialCostPrice"),
  1135. required: true,
  1136. readonly: true,
  1137. },
  1138. ]
  1139. } else {
  1140. contentObj.warehouse = [{ //期初库存标识
  1141. type: 'switch',
  1142. title: mixins.$t("openingInv"),
  1143. code: 'flgOpeningInv',
  1144. disabled: true,
  1145. }, { //仓库名称
  1146. code: 'whId',
  1147. name: 'whName',
  1148. title: mixins.$t("whName"),
  1149. type: 'choose',
  1150. urlKey: 'openingInventory',
  1151. required: true,
  1152. readonly: true,
  1153. clear: false
  1154. },
  1155. { //库存批号
  1156. code: 'nonStdCode',
  1157. type: 'textarea',
  1158. title: mixins.$t("iinventoryBatchNumber"),
  1159. required: true,
  1160. readonly: true,
  1161. tip: mixins.$t('tipPop'),
  1162. },
  1163. { //期初数量
  1164. code: 'intoQty',
  1165. type: 'number',
  1166. sign: "",
  1167. digits: 0,
  1168. title: mixins.$t("openingInventoryQty"),
  1169. required: true,
  1170. readonly: true,
  1171. },
  1172. { //期初成本价
  1173. code: 'priceInto',
  1174. type: 'number',
  1175. title: mixins.$t("iinitialCostPrice"),
  1176. required: true,
  1177. readonly: true,
  1178. },
  1179. ]
  1180. }
  1181. } else {
  1182. contentObj.warehouse = [{ //期初库存标识
  1183. type: 'switch',
  1184. title: mixins.$t("openingInv"),
  1185. code: 'flgOpeningInv',
  1186. disabled: true,
  1187. }, ]
  1188. }
  1189. if (data.flgPrice) {
  1190. contentObj.price = [{ //期初库存标识
  1191. type: 'switch',
  1192. title: mixins.$t("flgPrice"),
  1193. code: 'flgPrice',
  1194. }, { //采购价
  1195. tip: mixins.$t("purchasePricetip"),
  1196. code: 'pricePurchase',
  1197. type: 'number',
  1198. title: mixins.$t("purchasePrice"),
  1199. required: true,
  1200. }, { //零售价
  1201. tip: mixins.$t("retailPricetip"),
  1202. code: 'priceStandard',
  1203. type: 'number',
  1204. title: mixins.$t("retailPrice"),
  1205. required: true,
  1206. }, { //批发价
  1207. tip: mixins.$t("wholesalePricetip"),
  1208. code: 'priceWholesale',
  1209. type: 'number',
  1210. title: mixins.$t("wholesalePrice"),
  1211. required: true,
  1212. }, { //销售限价
  1213. tip: mixins.$t("SaleSPriceLimittip"),
  1214. code: 'priceLimited',
  1215. type: 'number',
  1216. title: mixins.$t("SaleSPriceLimit"),
  1217. required: true,
  1218. }, { //其他价
  1219. tip: mixins.$t("otherPriceLimittip"),
  1220. code: 'priceOther',
  1221. type: 'number',
  1222. title: mixins.$t("otherPriceLimit"),
  1223. required: true,
  1224. }, ]
  1225. } else {
  1226. contentObj.price = [{ //期初库存标识
  1227. type: 'switch',
  1228. title: mixins.$t("flgPrice"),
  1229. code: 'flgPrice',
  1230. }, ]
  1231. }
  1232. if (data.packBox && data.unitName && data.subUnitName) { //选了辅助计量单位 正好 包装也有值 那么直接给出公式
  1233. data.calculationFormula = data.packBox + data.unitName + '= 1' + data.subUnitName
  1234. }
  1235. this.setData({
  1236. contentObj: contentObj,
  1237. formData: JSON.stringify(data),
  1238. buttonList: [{
  1239. name: 'merge',
  1240. title: mixins.$t("save"), //'保存'
  1241. }],
  1242. })
  1243. },
  1244. })