dk-form-bill.js 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269
  1. /*******************************************************************************
  2. * Copyright(c) 2024 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:
  5. * 2.功能描述:表单-(开单)
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 周兴 2024-1-30 1.00 新建
  9. *******************************************************************************/
  10. const common = require('@/utils/common');
  11. const mixins = require('@/mixins/index.js')
  12. const util = require('@/utils/util.js')
  13. const Constants = require('@/utils/Constants');
  14. const chooseLocation = requirePlugin('chooseLocation');
  15. const config = require('@/config/config.js')
  16. import Dialog from '@/dist/dialog/dialog.js';
  17. const app = getApp();
  18. Component({
  19. /**
  20. * 组件的属性列表
  21. */
  22. properties: {
  23. // 区域
  24. cardList: {
  25. type: Array,
  26. value: [],
  27. observer: function (newVal) {
  28. if (newVal) {
  29. let filters = newVal.filter(it => it.name == 'items')
  30. if (filters && filters.length > 0) {
  31. this.setData({
  32. itemCard: {
  33. ...filters[0]
  34. }
  35. })
  36. }
  37. }
  38. }
  39. },
  40. // 内容
  41. contentObj: {
  42. type: Object,
  43. },
  44. // 点击那个日期显示哪个日期的时间戳
  45. dataTime: {
  46. type: Number,
  47. },
  48. // 开单组件类型(sale,pur)
  49. type: {
  50. type: String,
  51. },
  52. // 外部传入控制的选商品所有标识的集合
  53. controlFlags: {
  54. type: Object, // controlFlags 是一个对象
  55. value: {}, // 默认值是一个空对象
  56. },
  57. // 类型 sale; basic
  58. popType: {
  59. type: String,
  60. value: 'sale'
  61. },
  62. // 路由名称
  63. routeObjName: {
  64. type: String
  65. },
  66. titleTagCol: {
  67. type: String,
  68. value: 'titleTag'
  69. },
  70. titleCol: {
  71. type: String,
  72. value: 'title'
  73. },
  74. iconCol: {
  75. type: String,
  76. value: 'iconThumPath'
  77. },
  78. pupPriceCol: {
  79. type: String,
  80. value: 'priceCol'
  81. },
  82. // 价格列
  83. priceCol: {
  84. type: String,
  85. value: 'priceSale'
  86. },
  87. // 数量列
  88. quantityCol: {
  89. type: String,
  90. value: 'itemQuantity'
  91. },
  92. // 数量列
  93. descCol: {
  94. type: String,
  95. value: 'desc'
  96. },
  97. // pop底部描述列
  98. subCol: {
  99. type: String,
  100. value: 'desc'
  101. },
  102. // 价格标题
  103. priceTitle: {
  104. type: String,
  105. },
  106. sumStandardCol: {
  107. type: String,
  108. value: 'sumStandard'
  109. },
  110. discountStandardCol: {
  111. type: String,
  112. value: 'discountStandard'
  113. },
  114. sumQuantityCol: {
  115. type: String,
  116. value: 'sumQuantity'
  117. },
  118. sumAmountCol: {
  119. type: String,
  120. value: 'sumAmount'
  121. },
  122. swipeDisabled: {
  123. type: String,
  124. },
  125. sumAmountColFlag: {
  126. type: Boolean,
  127. value: true
  128. },
  129. isDetailFlag:{
  130. type: Boolean,
  131. value: false
  132. },
  133. // 可用收款列
  134. canUseCollectCol: {
  135. type: String,
  136. value: 'canUseCollect'
  137. },
  138. // 收款列
  139. useCollectCol: {
  140. type: String,
  141. value: 'useCollect'
  142. },
  143. // 弹框的内容
  144. popContent: {
  145. type: Array,
  146. },
  147. popupTopObj: {
  148. type: Array,
  149. },
  150. // 是否只读
  151. readonly: {
  152. type: Boolean,
  153. },
  154. titpsFlag: { //商品右上角信息
  155. type: Boolean,
  156. value: false
  157. },
  158. titpsItemColorFlagKey: {
  159. type: String,
  160. },
  161. titpsLabel: {
  162. type: String
  163. },
  164. stepperFlag: { //步进器 标识
  165. type: Boolean,
  166. },
  167. quantityMin: { //步进器 最小值
  168. type: String,
  169. },
  170. quantityMax: {
  171. type: String
  172. },
  173. showPopFlag: { //弹窗标识 true 不弹窗
  174. type: Boolean,
  175. },
  176. staff: {
  177. type: String, //主从业务员
  178. },
  179. org: {
  180. type: String, //主从业务部门
  181. },
  182. saleStaffAndOrgFlag: {
  183. type: Boolean,
  184. value: true
  185. },
  186. cardContentList: { //商品明细下的选单
  187. type: Array,
  188. },
  189. quantityRedCol: { //例 可售量显示字段 key
  190. type: String,
  191. },
  192. quantityRedColFlagKey: { // 显示隐藏整行的key 商品明细控制
  193. type: String
  194. },
  195. quantityRedTitle: { //右侧显示文字
  196. type: String,
  197. value: '可售量:'
  198. },
  199. goodsTagText: { //自定义tag
  200. type: String,
  201. value: ''
  202. },
  203. // 表名,用于上传附件
  204. table: {
  205. type: String,
  206. },
  207. // 删除时是否进行校验
  208. delValidFlag: {
  209. type: Boolean,
  210. },
  211. // 显示盈亏数量 和盈亏原因
  212. lossReasonFlag: {
  213. type: Boolean,
  214. },
  215. // 对象取值列
  216. objCol: {
  217. type: String
  218. },
  219. // 对象列名
  220. objLabel: {
  221. type: String
  222. },
  223. // 对象类型(客户customer;供应商supplier)
  224. objType: {
  225. type: String
  226. },
  227. // 对象标题
  228. objTitle: {
  229. type: String,
  230. value: 'cusName'
  231. },
  232. // 对象副标题
  233. objSubTitle: {
  234. type: String,
  235. value: 'cusPhone'
  236. },
  237. // 金额标题
  238. amountTitle: {
  239. type: String,
  240. value: '应收金额'
  241. },
  242. // 金额列
  243. amountCol: {
  244. type: String,
  245. value: 'receivableResidue'
  246. },
  247. // 对象Id列
  248. objIdCol: {
  249. type: String,
  250. value: 'cusId'
  251. },
  252. chooseText: {
  253. type: String,
  254. },
  255. goodsTagColor: { //标签颜色
  256. type: String,
  257. },
  258. // 结果集
  259. value: {
  260. type: String,
  261. observer: function (newVal) {
  262. if (newVal) {
  263. this.setData({
  264. form: JSON.parse(newVal) || {}
  265. })
  266. } else {
  267. this.setData({
  268. form: {}
  269. })
  270. // 清空明细的合计
  271. if (this.data.itemCard) {
  272. let cardList = this.data.cardList
  273. let index = cardList.findIndex(it => it.name == 'items');
  274. // 先删除掉
  275. cardList = cardList.filter(it => it.name != 'items');
  276. // 再插入
  277. cardList.splice(index, 0, {
  278. ...this.data.itemCard
  279. })
  280. // console.log('rrr1',filters);
  281. // if(filters && filters.length > 0){
  282. // filters[0] = {...this.data.itemCard}
  283. // }
  284. this.setData({
  285. cardList: cardList
  286. })
  287. }
  288. }
  289. }
  290. }
  291. },
  292. /**
  293. * 组件的初始数据
  294. */
  295. data: {
  296. // 系统版本
  297. gradeCode: null,
  298. // 是否显示pop
  299. show: false,
  300. showDate: false,
  301. showPop: false,
  302. $t: app.globalData.lang,
  303. routeUrl: app.globalData['routeUrl'],
  304. item: null,
  305. index: null,
  306. dataItem: null,
  307. dataIndex: null,
  308. card: null,
  309. itemCard: null, // 记录明细信息,清空时使用
  310. key: null,
  311. // 下拉类型
  312. dropType: null,
  313. dropCode: null,
  314. dropName: null,
  315. itemName: 'goodsList',
  316. deleteName: 'deleteList',
  317. selectCoordinationUrl: '/package-base-select/pages/select-choose-coordination/select-choose-coordination',
  318. selectGoodsUrl: null,
  319. chooseVisible: true, // 用于联动控制选商品按钮
  320. maxSize: Constants.uploadFileConfig.maxSize,
  321. imageUrl: config.image_url + '/static/img/',
  322. // popContent:
  323. // [{ 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: '赠品标识' }],
  324. form: {}
  325. },
  326. lifetimes: {
  327. attached: function () {
  328. // 获取系统版本
  329. this.setData({
  330. gradeCode: app.globalData.company.gradeCode
  331. })
  332. // 销售订单
  333. if (this.data.type == Constants.billType.sale || this.data.type == Constants.billType.saleOut ||
  334. this.data.type == Constants.billType.pur || this.data.type == Constants.billType.purInto || this.data.type == Constants.billType.saleOutReturn ||
  335. this.data.type == Constants.billType.out || this.data.type == Constants.billType.purReturn) {
  336. this.setData({
  337. selectGoodsUrl: '/package-base-select/pages/select-goods/select-goods'
  338. })
  339. }
  340. // 处理contentObj
  341. this.handleContentObj();
  342. },
  343. detached: function () {
  344. // 在组件实例被从页面节点树移除时执行
  345. // 清空地址信息
  346. chooseLocation.setLocation(null);
  347. },
  348. },
  349. pageLifetimes: {
  350. /**
  351. * @desc : 生命周期函数--监听页面显示
  352. * @author : 周兴
  353. * @date : 2024/2/19 12:16
  354. */
  355. show: function () {
  356. // 设置地址
  357. this.setAddress();
  358. // 是否弹出询问框
  359. this.checkDialog();
  360. }
  361. },
  362. /**
  363. * 组件的方法列表
  364. */
  365. methods: {
  366. /**
  367. * @desc : 改变后是否弹出询问
  368. * @author : 周兴
  369. * @date : 2024/1/26 11:46
  370. */
  371. checkDialog() {
  372. let item = this.data.item;
  373. let originalData = this.data.originalData;
  374. let form = this.data.form
  375. let itemName = this.data.itemName
  376. if (item && item.clearItemFlag && form[itemName] && form[itemName].length > 0 &&
  377. originalData && originalData.id != form[item.code]) {
  378. Dialog.confirm({
  379. message: '是否清空商品明细?',
  380. }).then(() => {
  381. form[itemName] = []
  382. originalData.id = form[item.code]
  383. originalData.name = form[item.name]
  384. this.setData({
  385. originalData: originalData,
  386. form: form,
  387. value: JSON.stringify(form)
  388. })
  389. }).catch(() => {
  390. setTimeout(() => {
  391. form[item.code] = originalData.id
  392. form[item.name] = originalData.name
  393. this.setData({
  394. form: form,
  395. value: JSON.stringify(form)
  396. })
  397. }, 500)
  398. })
  399. }
  400. },
  401. /**
  402. * @desc : 处理ContentObj数据
  403. * @author : 周兴
  404. * @date : 2024/1/26 11:46
  405. */
  406. handleContentObj(card) {
  407. let contentObj = this.data.contentObj;
  408. let cardList = this.data.cardList;
  409. let form = this.data.form;
  410. let items = form[this.data.itemName]
  411. if (cardList && cardList.length > 0 && contentObj) {
  412. if (card) {
  413. cardList = cardList.filter(it => it.name == card.name);
  414. }
  415. cardList.forEach((it, index) => {
  416. // 不是明细
  417. if (it.name != 'items') {
  418. if (it.displayNum && contentObj[it.name].length > it.displayNum) {
  419. for (let i = it.displayNum; i < contentObj[it.name].length; i++) {
  420. // 如果折叠就把超过的部分隐藏
  421. if (it.showMore) {
  422. contentObj[it.name][i].show = true;
  423. } else {
  424. contentObj[it.name][i].show = false;
  425. }
  426. }
  427. }
  428. } else {
  429. // 商品明细
  430. if (it.displayNum && items && items.length > it.displayNum) {
  431. for (let i = it.displayNum; i < items.length; i++) {
  432. // 如果折叠就把超过的部分隐藏//todo
  433. // console.log('it',it.showMore,items[i]);
  434. if (it.showMore) {
  435. items[i].show = true;
  436. } else {
  437. items[i].show = false;
  438. }
  439. }
  440. }
  441. }
  442. })
  443. this.setData({
  444. contentObj: contentObj,
  445. form: form,
  446. value: JSON.stringify(form)
  447. })
  448. }
  449. },
  450. /**
  451. * @desc : 展开收缩
  452. * @author : 周兴
  453. * @date : 2024/1/26 11:46
  454. */
  455. expand(e) {
  456. let card = e.currentTarget.dataset.card
  457. let index = e.currentTarget.dataset.index
  458. let cardList = this.data.cardList
  459. if (cardList[index]) {
  460. cardList[index].showMore = !cardList[index].showMore
  461. }
  462. this.setData({
  463. cardList: cardList
  464. })
  465. // 处理contentObj
  466. this.handleContentObj(card);
  467. },
  468. /**
  469. * @desc : 打开Pop进行修改
  470. * @author : 周兴
  471. * @date : 2024/1/26 11:46
  472. */
  473. openChoosedItemInfo(e) {
  474. if (this.data.showPopFlag) {
  475. return;
  476. }
  477. let ds = e.currentTarget.dataset;
  478. console.log('openChoosedItemInfo',e);
  479. if ( ds.item.flgSubUnit) {
  480. ds.item.calculationFormula = ds.item.packBox + ds.item.unitName + '= 1' + ds.item.subUnitName
  481. ds.item.packageBox = ds.item['box'] + ds.item.subUnitName + ds.item['piece'] + ds.item.unitName
  482. }
  483. if (this.data.type == Constants.billType.pur) { //采购订单 采购数量
  484. ds.item.sumPrice = ds.item['itemQty'] * ds.item.pricePur
  485. }
  486. if (this.data.type == Constants.billType.purInto) { //采购入库
  487. ds.item.sumPrice = ds.item['itemQty'] * ds.item.priceInto
  488. }
  489. if ( this.data.type == Constants.billType.out ) {
  490. ds.item.sumPrice = ds.item['itemQty'] * ds.item.priceOut
  491. }
  492. if (this.data.type == Constants.billType.saleOut ||
  493. this.data.type == Constants.billType.inventory) {
  494. ds.item.sumPrice = ds.item['outingQty'] * ds.item.priceOut
  495. }
  496. if (this.data.type == Constants.billType.saleOutReturn) { //销售退货的时候 打开商品的pup 就要计算箱片
  497. ds.item.sumPrice = ds.item['outingQty'] * ds.item.priceOut
  498. }
  499. this.setInitPopData()
  500. //没有skuid 是外协商品
  501. let popupTopObj_sku = null
  502. let popContent_sku = null
  503. let popContent_ = util.copyObj(this.data.popContent)
  504. if(ds.item.skuId){ //正常品走
  505. popupTopObj_sku = this.data.popupTopObj
  506. popContent_sku = popContent_
  507. }else{ //外协品走
  508. // 全-免费版-销售出库-新建、编辑、详情-外协品-抽屉不展示库存量、仓库字段
  509. popupTopObj_sku = []
  510. let index = popContent_.findIndex(element => element.code == 'whId');
  511. if (index !== -1) {
  512. // 找到了满足条件的元素,index 是它的索引
  513. popContent_sku = popContent_
  514. popContent_sku.splice(index,1)
  515. } else {
  516. popContent_sku = popContent_
  517. }
  518. }
  519. this.setData({
  520. popContent_sku:popContent_sku,
  521. popupTopObj_sku:popupTopObj_sku,
  522. dataIndex: ds.index,
  523. dataItem: JSON.stringify(ds.item),
  524. showPop: true,
  525. })
  526. this.triggerEvent("openChoosedItemInfo", {
  527. item: ds.item,
  528. index: ds.index
  529. })
  530. },
  531. /**
  532. * @desc : 再次打开箱片的弹框
  533. * @author : 周兴
  534. * @date : 2024/1/26 11:46
  535. */
  536. openPackageBox(e) {
  537. console.log("openPackageBox-", e);
  538. let dataItem = JSON.parse(this.data.dataItem)
  539. //采购入库 销售退货
  540. if (this.data.type == Constants.billType.sale ||
  541. this.data.type == Constants.billType.purReturn ||
  542. this.data.type == Constants.billType.pur ||
  543. this.data.type == Constants.billType.purInto ||
  544. this.data.type == Constants.billType.saleOutReturn ||
  545. this.data.type == Constants.billType.out ||
  546. this.data.type == Constants.billType.saleOut ||
  547. this.data.type == Constants.billType.inventory
  548. ) {
  549. this.setData({
  550. popContentBox: [{
  551. code: 'box',
  552. type: 'step',
  553. title: dataItem.subUnitName,
  554. required: true
  555. },
  556. {
  557. code: 'piece',
  558. type: 'step',
  559. title: dataItem.unitName,
  560. required: true
  561. },
  562. ],
  563. })
  564. }
  565. this.setData({
  566. showPopBox: true,
  567. })
  568. },
  569. /**
  570. * @desc : 关闭Pop后修改数据
  571. * @author : 周兴
  572. * @date : 2024/1/26 11:46
  573. */
  574. editItems(data) {
  575. let form = this.data.form;
  576. let itemName = this.data.itemName;
  577. if (form[itemName]) {
  578. form[itemName][this.data.dataIndex] = data.detail.form;
  579. }
  580. //计算金额
  581. if (this.data.type == Constants.billType.sale) {
  582. this.setGoodsAmount()
  583. }
  584. if (this.data.type == Constants.billType.saleOut) {
  585. this.setGoodsOutAmount()
  586. }
  587. if (this.data.type == Constants.billType.saleOutReturn) {
  588. this.setGoodsOutReturnAmount()
  589. }
  590. this.setData({
  591. form: form,
  592. value: JSON.stringify(form)
  593. })
  594. // 外露关闭pop后事件
  595. this.triggerEvent("editItems", {
  596. data: form
  597. })
  598. },
  599. /**
  600. * @desc : 商品确认事件--箱片的确认
  601. * @date : 2024/2/1 15:49
  602. * @author : 于继渤
  603. */
  604. editItemsBox(e) {
  605. let dataItem = JSON.parse(this.data.dataItem)
  606. if (this.data.type == Constants.billType.sale ||
  607. this.data.type == Constants.billType.pur ||
  608. this.data.type == Constants.billType.out ||
  609. this.data.type == Constants.billType.purInto ||
  610. this.data.type == Constants.billType.inventory
  611. ) {
  612. let itemQty = dataItem['box'] * dataItem['packBox'] + dataItem['piece']
  613. //如果设有做大值 判断 箱片的反算数量 大于 数量最大值
  614. if (dataItem["itemQty_max"] && itemQty > dataItem["itemQty_max"]) {
  615. //那就吧 把最大值的数量换算 箱片赋值箱片
  616. dataItem['box'] = parseInt(dataItem['itemQty'] / dataItem['packBox'])
  617. dataItem['piece'] = Number(dataItem['itemQty'] % dataItem['packBox'])
  618. dataItem.packageBox = dataItem['box'] + dataItem.subUnitName + dataItem['piece'] + dataItem.unitName
  619. this.setData({
  620. dataItem: JSON.stringify(dataItem)
  621. })
  622. util.showToast('超出最大数量');
  623. return
  624. }
  625. //数量等于 包乘以包装数 加上片数
  626. dataItem['itemQty'] = dataItem['box'] * dataItem['packBox'] + dataItem['piece']
  627. dataItem.packageBox = dataItem['box'] + dataItem.subUnitName + dataItem['piece'] + dataItem.unitName
  628. if (this.data.type == Constants.billType.pur) { // 采购订单
  629. dataItem.sumPrice = dataItem['itemQty'] * dataItem.pricePur
  630. }
  631. if (this.data.type == Constants.billType.purInto) { //采购入库
  632. dataItem.sumPrice = dataItem['itemQty'] * dataItem.priceInto
  633. }
  634. if (this.data.type == Constants.billType.out) { //销售退货
  635. dataItem.sumPrice = dataItem['itemQty'] * dataItem.priceOut
  636. }
  637. }
  638. if (this.data.type == Constants.billType.saleOutReturn) {
  639. let itemQty = (dataItem['box'] * dataItem['packBox'] + dataItem['piece'])
  640. let itemQty_min = dataItem.outingQty_min ? Math.abs(dataItem.outingQty_min) : ''; //取绝对值 (因为是负值 即最小值的绝对值 为最大值)
  641. //如果设有做大值 判断 箱片的反算数量 大于 数量最大值
  642. if (itemQty_min && itemQty > itemQty_min) {
  643. //那就吧 把最大值的数量换算 箱片赋值箱片
  644. let outingQty = Math.abs(dataItem.outingQty); //取绝对值
  645. dataItem['box'] = parseInt(outingQty / dataItem['packBox'])
  646. dataItem['piece'] = Number(outingQty % dataItem['packBox'])
  647. dataItem.packageBox = dataItem['box'] + dataItem.subUnitName + dataItem['piece'] + dataItem.unitName
  648. this.setData({
  649. dataItem: JSON.stringify(dataItem)
  650. })
  651. util.showToast('超出最大数量');
  652. return
  653. }
  654. //数量等于 包乘以包装数 加上片数
  655. dataItem['outingQty'] = -1 * (dataItem['box'] * dataItem['packBox'] + dataItem['piece'])
  656. dataItem.packageBox = dataItem['box'] + dataItem.subUnitName + dataItem['piece'] + dataItem.unitName
  657. dataItem.sumPrice = dataItem.priceOut * dataItem.itemQty
  658. }
  659. if (this.data.type == Constants.billType.saleOut || this.data.type == Constants.billType.inventory) {
  660. //数量等于 包乘以包装数 加上片数
  661. dataItem['outingQty'] = dataItem['box'] * dataItem['packBox'] + dataItem['piece']
  662. dataItem.packageBox = dataItem['box'] + dataItem.subUnitName + dataItem['piece'] + dataItem.unitName
  663. dataItem.sumPrice = dataItem['outingQty'] * dataItem.priceOut
  664. }
  665. this.setData({
  666. dataItem: JSON.stringify(dataItem)
  667. })
  668. },
  669. /**
  670. * @desc :商品明细数量加减事件
  671. * @date : 2024/2/1 15:49
  672. * @author : 于继渤
  673. */
  674. onChangeStepper(e) {
  675. this.triggerEvent("onStepper", {
  676. index: e.currentTarget.dataset.index,
  677. item: e.detail
  678. })
  679. },
  680. /**
  681. * @desc : 打开下拉/跳转选择页面
  682. * @author : 周兴
  683. * @date : 2024/1/26 11:46
  684. */
  685. open(e) {
  686. // 只读
  687. let item = e.currentTarget.dataset;
  688. if (this.data.readonly) {
  689. return;
  690. }
  691. // 明细 只读240320
  692. if (item.item.readonlyItem) {
  693. return;
  694. }
  695. let that = this
  696. if (item.item.type == 'drop') {
  697. this.setData({
  698. show: true,
  699. dropCode: item.key,
  700. dropName: item.name,
  701. dropType: item.type,
  702. index: item.index,
  703. card: item.card
  704. })
  705. } else if (item.item.type == 'mutidrop') {
  706. this.setData({
  707. mutishow: true,
  708. dropCode: item.key,
  709. dropName: item.name,
  710. dropType: item.type,
  711. index: item.index,
  712. card: item.card
  713. })
  714. } else if (item.item.type == 'choose') {
  715. if (item.item.readonlyReturn && !item.item.chooseVisible) {
  716. return
  717. }
  718. that.setData({
  719. changeObj: item.item.changeObj,
  720. })
  721. //判断是否存在此key的值
  722. if (item.item.titpsKey && !that.data.form[item.item.titpsKey]) {
  723. // 是否弹出询问框
  724. Dialog.confirm({
  725. message: item.item.titpsMessage, //提示信息
  726. }).then(() => {}).catch(() => {})
  727. return
  728. }
  729. //控制校验提示删除明细
  730. if (this.data.form[this.data.itemName] && this.data.form[this.data.itemName].length > 0 && this.data.chooseVisible && item.item.chooseVisible) {
  731. // 是否弹出询问框
  732. Dialog.confirm({
  733. message: '请先删除商品明细中的商品', //提示信息
  734. }).then(() => {}).catch(() => {})
  735. return
  736. }
  737. // 跳转链接
  738. if (item.item.urlKey) {
  739. this.setData({
  740. index: item.index,
  741. card: item.card,
  742. item: item.item,
  743. key: item.key
  744. })
  745. let route = this.data.routeUrl[this.data.routeObjName][item.item.urlKey]
  746. let url = route.url
  747. if (url) {
  748. wx.navigateTo({
  749. url: url,
  750. events: {
  751. // 回调后
  752. bindData: function (data) {
  753. //处理明细 给明细赋值 例如选仓库回调赋值
  754. if (item.flag) {
  755. let form = that.data.form
  756. form[that.data.itemName][item.index][item.item.code] = data.data.id
  757. form[that.data.itemName][item.index][item.item.name] = data.data.name
  758. that.setData({
  759. form: form
  760. })
  761. // 如果有校验信息就清除掉
  762. let card = that.data.card;
  763. let index = that.data.index;
  764. let contentObj = that.data.contentObj;
  765. if (card && contentObj[card][index]?.errMsg) {
  766. contentObj[card][index].errMsg = undefined;
  767. that.setData({
  768. contentObj: contentObj
  769. })
  770. }
  771. }
  772. // 如果需要询问,那么需要记录原始的值
  773. if (item.item.clearItemFlag) {
  774. that.setData({
  775. originalData: {
  776. id: that.data.form[item.key],
  777. name: that.data.form[item.name]
  778. }
  779. })
  780. }
  781. that.triggerEvent("chooseData", {
  782. code: item.key,
  783. data: data,
  784. index: item.index
  785. })
  786. // 如果需要联动控制选商品按钮
  787. if (item.item.controlChooseFlag) {
  788. that.setData({
  789. chooseVisible: false
  790. })
  791. }
  792. let contentObj = that.data.contentObj;
  793. if (item.card && contentObj[item.card][item.index]?.errMsg && data) {
  794. contentObj[item.card][item.index].errMsg = undefined;
  795. that.setData({
  796. contentObj: contentObj
  797. })
  798. }
  799. }
  800. },
  801. success: function (res) {
  802. let itemData = item.item
  803. if (route.primaryKey) {
  804. itemData.id = that.data.form[route.primaryKey]
  805. console.log('route', route, that.data.form[route.primaryKey])
  806. }
  807. // 通过eventChannel向被打开页面传送数据
  808. res.eventChannel.emit('params', {
  809. item: itemData,
  810. route: route
  811. })
  812. }
  813. })
  814. }
  815. }
  816. } else if (item.item.type == 'selectIcon') {
  817. // 跳转链接
  818. if (item.item.urlKey) {
  819. let url = this.data.routeUrl[this.data.routeObjName][item.item.urlKey].url
  820. // TODO
  821. // url = '/package-base6-select/pages/select-customers/select-customers'
  822. if (url) {
  823. wx.navigateTo({
  824. url: url,
  825. events: {
  826. // 回调后
  827. bindData: function (data) {
  828. that.triggerEvent("chooseData", {
  829. code: item.key,
  830. data: data
  831. })
  832. // 如果需要联动控制选商品按钮
  833. if (item.item.controlChooseFlag) {
  834. that.setData({
  835. chooseVisible: false
  836. })
  837. }
  838. }
  839. },
  840. success: function (res) {
  841. // 通过eventChannel向被打开页面传送数据
  842. res.eventChannel.emit('params', {
  843. data: item.item.urlKeyParam
  844. })
  845. }
  846. })
  847. }
  848. }
  849. }
  850. },
  851. /**
  852. * @desc : 打开选择主从业务员/业务部门组件
  853. * @author : 周兴
  854. * @date : 2024/2/20 11:46
  855. */
  856. openMulti(e) {
  857. if (this.data.readonly) {
  858. return;
  859. }
  860. console.log('openMulti', this.data.form)
  861. let type = e.currentTarget.dataset.type
  862. let _this = this
  863. // 选择主从业务员
  864. if (type == 'staff') {
  865. wx.navigateTo({
  866. url: '/package-sales/pages/choose-sale-staff/choose-sale-staff',
  867. events: {
  868. // 回调后
  869. bindData: function (data) {
  870. _this.triggerEvent("chooseData", {
  871. code: type,
  872. data: data
  873. })
  874. }
  875. },
  876. success: function (res) {
  877. // 通过eventChannel向被打开页面传送数据
  878. res.eventChannel.emit('params', {
  879. id: _this.data.form.staff.value,
  880. formMode: 'index'
  881. })
  882. }
  883. })
  884. // 选择主从业务部门
  885. } else if (type == 'org') {
  886. wx.navigateTo({
  887. url: '/package-sales/pages/choose-sale-org/choose-sale-org',
  888. events: {
  889. // 回调后
  890. bindData: function (data) {
  891. _this.triggerEvent("chooseData", {
  892. code: type,
  893. data: data
  894. })
  895. }
  896. },
  897. success: function (res) {
  898. // 通过eventChannel向被打开页面传送数据
  899. res.eventChannel.emit('params', {
  900. id: _this.data.form.org.value,
  901. formMode: 'index'
  902. })
  903. }
  904. })
  905. }
  906. },
  907. /**
  908. * @desc : 非空校验
  909. * @author : 周兴
  910. * @date : 2024/2/20 11:46
  911. */
  912. validData() {
  913. let flag = true;
  914. let cardList = this.data.cardList;
  915. if (!cardList || cardList.length == 0) {
  916. return flag;
  917. }
  918. let form = this.data.form;
  919. let contentObj = this.data.contentObj;
  920. for (let card of cardList) {
  921. if (contentObj[card.name]) {
  922. // 明细
  923. if (card.name == 'items') {
  924. if (!form[this.data.itemName] || form[this.data.itemName].length == 0) {
  925. util.showToast('商品明细不能为空')
  926. return false;
  927. }
  928. contentObj[card.name].forEach(item => {
  929. let title = this.$t(item.title ? item.title : item.code)
  930. // 如果必须输入,就要进行判断
  931. if (item.required && form[this.data.itemName] && form[this.data.itemName].length > 0) {
  932. form[this.data.itemName].forEach(t => {
  933. if (!t[item.code]) {
  934. t[item.code + '_errMsg'] = title + '不为空'
  935. flag = false;
  936. }
  937. })
  938. }
  939. })
  940. } else {
  941. contentObj[card.name].forEach(item => {
  942. let title = this.$t(item.title ? item.title : item.code)
  943. // 如果必须输入,就要进行判断
  944. if (item.required && !form[item.code]) {
  945. item.errMsg = title + '不为空'
  946. flag = false;
  947. }
  948. if (item.type == 'phone' && item.required && form[item.code]) {
  949. // 联系电话格式错误
  950. var myreg = Constants.Mobile_Phone_Number_Regular_Expression
  951. if (!myreg.test(form[item.code])) {
  952. item.errMsg = title + '格式错误'
  953. flag = false;
  954. }
  955. }
  956. })
  957. }
  958. }
  959. }
  960. this.setData({
  961. contentObj: contentObj
  962. })
  963. return flag;
  964. },
  965. /**
  966. * @desc : 展开页签
  967. * @author : 周兴
  968. * @date : 2024/2/20 11:46
  969. */
  970. expandCard(e) {
  971. let cardList = this.data.cardList
  972. let index = e.currentTarget.dataset.index
  973. if (cardList[index]) {
  974. // 收缩的时候需要展示信息
  975. let expand = cardList[index].expand
  976. cardList[index].info = undefined
  977. if (expand) {
  978. let form = this.data.form
  979. let infoCols = e.currentTarget.dataset.item.infoCols
  980. if (infoCols && infoCols.length > 0) {
  981. let info = ''
  982. infoCols.forEach(it => {
  983. if (form[it]) {
  984. info += form[it] + '/'
  985. }
  986. })
  987. if (info.length > 0) {
  988. info = info.substring(0, info.length - 1);
  989. cardList[index].info = info
  990. }
  991. }
  992. }
  993. cardList[index].expand = !expand
  994. this.setData({
  995. cardList: cardList
  996. })
  997. }
  998. },
  999. /**
  1000. * @desc : 打开日期pop
  1001. * @author : 周兴
  1002. * @date : 2024/1/26 11:46
  1003. */
  1004. openDatePop(e) {
  1005. // 只读
  1006. if (this.data.readonly) {
  1007. return;
  1008. }
  1009. let item = e.currentTarget.dataset;
  1010. this.setData({
  1011. showDate: true,
  1012. index: item.index,
  1013. key: item.key,
  1014. card: item.card
  1015. })
  1016. },
  1017. /**
  1018. * @desc : 关闭日期pop
  1019. * @author : 周兴
  1020. * @date : 2024/1/26 11:46
  1021. */
  1022. cancelDatePop() {
  1023. this.setData({
  1024. showDate: false
  1025. })
  1026. },
  1027. /**
  1028. * @desc : 选择日期
  1029. * @author : 周兴
  1030. * @date : 2024/1/26 11:46
  1031. */
  1032. chooseDate(e) {
  1033. let form = this.data.form;
  1034. let index = this.data.index;
  1035. let card = this.data.card;
  1036. let code = this.data.key;
  1037. form[code + '_time'] = e.detail
  1038. form[code] = util.toDateStr(e.detail);
  1039. let contentObj = this.data.contentObj;
  1040. if (card && contentObj[card][index]?.errMsg && e.detail) {
  1041. contentObj[card][index].errMsg = undefined;
  1042. }
  1043. this.setData({
  1044. value: JSON.stringify(form),
  1045. form: form,
  1046. contentObj: contentObj,
  1047. showDate: false
  1048. })
  1049. },
  1050. /**
  1051. * @desc : 打开选择商品明细界面
  1052. * @author : 周兴
  1053. * @date : 2024/1/26 11:46
  1054. */
  1055. openChooseItems(e) {
  1056. if (this.data.selectGoodsUrl) {
  1057. this.setData({
  1058. item: null
  1059. })
  1060. let _this = this
  1061. wx.navigateTo({
  1062. url: this.data.selectGoodsUrl,
  1063. events: {
  1064. // 回调后
  1065. bindData: function (data) {
  1066. // 设置商品明细controlChooseFlag
  1067. console.log('bindDatachoosed', data);
  1068. _this.setGoods({
  1069. data: data
  1070. });
  1071. // 选品后,是否需要控制选单只读
  1072. _this.handleChooseByItem(_this, true);
  1073. }
  1074. },
  1075. success: function (res) {
  1076. // 通过eventChannel向被打开页面传送数据
  1077. res.eventChannel.emit('params', {
  1078. choose: true,
  1079. item: e.currentTarget.dataset.type ? e.currentTarget.dataset.type : _this.data.type,
  1080. popContent: _this.data.popContent,
  1081. controlFlags: _this.data.controlFlags
  1082. })
  1083. }
  1084. })
  1085. }
  1086. },
  1087. openChooseCoordinationItems(e) {
  1088. let _this = this
  1089. wx.navigateTo({
  1090. url: this.data.selectCoordinationUrl,
  1091. events: {
  1092. // 回调后
  1093. bindData: function (data) {
  1094. // // 设置商品明细controlChooseFlag
  1095. _this.setGoods({
  1096. data: data
  1097. });
  1098. }
  1099. },
  1100. success: function (res) {
  1101. // 通过eventChannel向被打开页面传送数据
  1102. res.eventChannel.emit('params', {
  1103. // choose: true,
  1104. item: e.currentTarget.dataset.type ? e.currentTarget.dataset.type : _this.data.type,
  1105. // popContent: _this.data.popContent,
  1106. // controlFlags: _this.data.controlFlags
  1107. })
  1108. }
  1109. })
  1110. },
  1111. /**
  1112. * @desc : 选择数据
  1113. * @author : 周兴
  1114. * @date : 2024/1/26 11:46
  1115. */
  1116. chooseData(e) {
  1117. let contentObj = this.data.contentObj;
  1118. let form = this.data.form
  1119. if (e.detail.ids) {
  1120. form[this.data.dropCode + 's'] = e.detail.ids;
  1121. form[this.data.dropName + 's'] = e.detail.names;
  1122. } else {
  1123. form[this.data.dropCode] = e.detail.value;
  1124. form[this.data.dropName] = e.detail.text;
  1125. }
  1126. let card = this.data.card;
  1127. // 选择后清空校验提示信息
  1128. if (card && contentObj[card][this.data.index]?.errMsg && e.detail) {
  1129. contentObj[card][this.data.index].errMsg = undefined;
  1130. }
  1131. this.setData({
  1132. value: JSON.stringify(form),
  1133. form: form,
  1134. contentObj: contentObj
  1135. })
  1136. // 如果处理id,name还需要赋值其他,需要在页面事件中自行处理
  1137. this.triggerEvent("chooseData", {
  1138. code: this.data.dropCode,
  1139. item: e.detail.item
  1140. })
  1141. },
  1142. /**
  1143. * @desc : 修改输入框的值
  1144. * @author : 周兴
  1145. * @date : 2024/2/2 11:46
  1146. */
  1147. changeField(e) {
  1148. let ds = e.currentTarget.dataset
  1149. let key = ds.key
  1150. let item = ds.item
  1151. let form = this.data.form
  1152. if (e.detail) {
  1153. form[key] = e.detail;
  1154. } else {
  1155. delete form[key]
  1156. }
  1157. let contentObj = this.data.contentObj;
  1158. // 输入值后清空校验提示信息
  1159. if (item.errMsg && e.detail) {
  1160. contentObj[ds.card][ds.index].errMsg = undefined;
  1161. }
  1162. this.setData({
  1163. form: form,
  1164. contentObj: contentObj
  1165. })
  1166. },
  1167. /**
  1168. * @desc : 失去焦点,把值传出
  1169. * @author : 周兴
  1170. * @date : 2024/2/2 11:46
  1171. */
  1172. blurField(e) {
  1173. let ds = e.currentTarget.dataset
  1174. this.setData({
  1175. value: JSON.stringify(this.data.form)
  1176. })
  1177. this.triggerEvent("changeField", {
  1178. code: ds.key
  1179. })
  1180. },
  1181. /**
  1182. * @desc : 清空输入框的值
  1183. * @author : 周兴
  1184. * @date : 2024/2/2 11:46
  1185. */
  1186. clearField(e) {
  1187. // 只读
  1188. if (this.data.readonly) {
  1189. return;
  1190. }
  1191. let ds = e.currentTarget.dataset
  1192. let key = ds.key
  1193. let form = this.data.form
  1194. form[key] = undefined
  1195. this.setData({
  1196. value: JSON.stringify(form),
  1197. form: form
  1198. })
  1199. // 如果要清除其他值,需要调用
  1200. this.triggerEvent("clear", {
  1201. code: ds.key
  1202. })
  1203. },
  1204. /**
  1205. * @desc : 清空地址的值
  1206. * @author : 周兴
  1207. * @date : 2024/2/2 11:46
  1208. */
  1209. clearAddress(e) {
  1210. let form = this.data.form
  1211. delete form['address']
  1212. delete form['addressName'];
  1213. delete form['addressFull'];
  1214. delete form['addressGcj02'];
  1215. delete form['addressArea'];
  1216. this.setData({
  1217. value: JSON.stringify(form),
  1218. form: form
  1219. })
  1220. // 如果要清除其他值,需要调用
  1221. this.triggerEvent("clear", {
  1222. code: ds.key
  1223. })
  1224. },
  1225. /**
  1226. * @desc : 修改合计金额,反算明细商品
  1227. * @author : 周兴
  1228. * @date : 2024/5/22 11:46
  1229. */
  1230. changeAmount(e) {
  1231. let index = e.currentTarget.dataset.index
  1232. let sumAmountCol = this.data.sumAmountCol
  1233. let cardList = this.data.cardList
  1234. if (cardList && cardList[index]) {
  1235. cardList[index][sumAmountCol] = e.detail.value
  1236. }
  1237. this.setData({
  1238. cardList: cardList
  1239. })
  1240. // this.reCalcItemsAmount();
  1241. },
  1242. /**
  1243. * @desc : 修改合计金额,反算明细商品
  1244. * @author : 周兴
  1245. * @date : 2024/5/22 11:46
  1246. */
  1247. reCalcItemsAmount(amount) {
  1248. let form = this.data.form
  1249. let itemName = this.data.itemName
  1250. let itemList = form[itemName]
  1251. let type = this.data.type
  1252. if (itemList && itemList.length > 0) {
  1253. // 单条明细金额字段
  1254. let pupPriceCol = this.data.pupPriceCol;
  1255. let priceCol = this.data.priceCol;
  1256. let quantityCol = this.data.quantityCol;
  1257. let flag = false;
  1258. let sum = 0;
  1259. // 判断是否所有明细的金额都是0,金额都为0 ,按照数量金额分摊
  1260. let filters = itemList.filter(it => it[pupPriceCol])
  1261. if (!filters || filters.length == 0) {
  1262. // 所有的金额都为0
  1263. flag = true;
  1264. // 获取所有数量的汇总
  1265. sum = itemList.sum(quantityCol)
  1266. } else {
  1267. // 获取所有金额的汇总
  1268. sum = itemList.sum(pupPriceCol)
  1269. }
  1270. itemList.forEach((it, index) => {
  1271. console.log('it', it);
  1272. // 按照数量金额分
  1273. if (flag) {
  1274. it[pupPriceCol] = (it[quantityCol] / sum * amount).toFixed(2)
  1275. } else {
  1276. // 如果按照金额分,金额为0的不分
  1277. if (it[pupPriceCol]) {
  1278. it[pupPriceCol] = (it[pupPriceCol] / sum * amount).toFixed(2)
  1279. }
  1280. }
  1281. it[priceCol] = (parseFloat(it[pupPriceCol]) / it[quantityCol]).toFixed(2)
  1282. })
  1283. this.setData({
  1284. form: form
  1285. })
  1286. }
  1287. },
  1288. /**
  1289. * @desc : 清空日期的值
  1290. * @author : 周兴
  1291. * @date : 2024/2/2 11:46
  1292. */
  1293. clearDate(e) {
  1294. let ds = e.currentTarget.dataset
  1295. let key = ds.key
  1296. let form = this.data.form
  1297. form[key] = undefined
  1298. form[key + '_time'] = undefined
  1299. this.setData({
  1300. value: JSON.stringify(form),
  1301. form: form
  1302. })
  1303. },
  1304. /**
  1305. * @desc : 清空选单的值
  1306. * @author : 周兴
  1307. * @date : 2024/2/2 11:46
  1308. */
  1309. clearChoose(e) {
  1310. let ds = e.currentTarget.dataset
  1311. let key = ds.key
  1312. let name = ds.name
  1313. let item = ds.item
  1314. // 明细 只读只读240320
  1315. if (item.readonlyItem) {
  1316. return;
  1317. }
  1318. let form = this.data.form
  1319. form[key] = undefined
  1320. form[name] = undefined
  1321. this.setData({
  1322. value: JSON.stringify(form),
  1323. form: form
  1324. })
  1325. // 如果需要联动控制选商品按钮
  1326. if (item && item.controlChooseFlag) {
  1327. this.setData({
  1328. chooseVisible: true
  1329. })
  1330. }
  1331. // 如果要清除其他值,需要调用
  1332. this.triggerEvent("clear", {
  1333. code: ds.key
  1334. })
  1335. },
  1336. /**
  1337. * @desc : 修改数值输入框的值
  1338. * @author : 周兴
  1339. * @date : 2024/2/2 11:46
  1340. */
  1341. changeNumberField(e) {
  1342. let ds = e.currentTarget.dataset
  1343. let key = ds.key
  1344. let item = ds.item
  1345. let form = this.data.form
  1346. form[key] = e.detail.value
  1347. let contentObj = this.data.contentObj;
  1348. // 输入值后清空校验提示信息
  1349. if (item.errMsg && e.detail) {
  1350. contentObj[ds.card][ds.index].errMsg = undefined;
  1351. }
  1352. this.setData({
  1353. value: JSON.stringify(form),
  1354. form: form,
  1355. contentObj: contentObj
  1356. })
  1357. },
  1358. /**
  1359. * @desc : 修改数值输入框的值 离焦事件
  1360. * @author : 于继渤
  1361. * @date : 2024/2/2 11:46
  1362. */
  1363. changeNumberBlur(e) {
  1364. this.triggerEvent("changeNumberBlur", e.detail)
  1365. },
  1366. /**
  1367. * @desc : 修改电话的值
  1368. * @author : 周兴
  1369. * @date : 2024/2/2 11:46
  1370. */
  1371. changePhone(e) {
  1372. let ds = e.currentTarget.dataset;
  1373. let key = ds.key;
  1374. let index = ds.index;
  1375. let card = ds.card;
  1376. let form = this.data.form
  1377. form[key] = e.detail.detail
  1378. let contentObj = this.data.contentObj;
  1379. if (card && contentObj[card][index]?.errMsg && e.detail.detail) {
  1380. contentObj[card][index].errMsg = undefined;
  1381. }
  1382. this.setData({
  1383. value: JSON.stringify(form),
  1384. form: form,
  1385. contentObj: contentObj
  1386. })
  1387. },
  1388. /**
  1389. * @desc : 给电话赋值错误信息
  1390. * @author : 周兴
  1391. * @date : 2024/2/20 11:46
  1392. */
  1393. changePhoneblur(e) {
  1394. let ds = e.currentTarget.dataset
  1395. let errMsg = e.detail.errMsg;
  1396. let card = ds.card;
  1397. let index = ds.index;
  1398. let contentObj = this.data.contentObj;
  1399. if (errMsg && card && contentObj[card][index]) {
  1400. contentObj[card][index].errMsg = errMsg;
  1401. this.setData({
  1402. errMsg: errMsg
  1403. })
  1404. }
  1405. this.triggerEvent("changePhoneblur", ds)
  1406. },
  1407. /**
  1408. * @desc : 打开选择对象的页面
  1409. * @author : 周兴
  1410. * @date : 2024/1/26 11:46
  1411. */
  1412. openObjPop() {
  1413. let _this = this
  1414. if (_this.data.readonly) {
  1415. return
  1416. }
  1417. // 选择客户
  1418. if (this.data.objType == Constants.objType.customer) {
  1419. wx.navigateTo({
  1420. url: '/package-base-select/pages/select-customers/select-customers',
  1421. events: {
  1422. // 回调后
  1423. bindData: function (data) {
  1424. let form = _this.data.form
  1425. let objIdCol = _this.data.objIdCol;
  1426. // 赋值对象Id
  1427. if (objIdCol && data[objIdCol]) {
  1428. form[objIdCol] = data[objIdCol]
  1429. }
  1430. // 客户欠款
  1431. if (data['receivableResidue'] && data['receiptResidue']) {
  1432. data['cusDebt'] = data['receivableResidue'] - data['receiptResidue']
  1433. }
  1434. form.objInfo = data;
  1435. _this.setData({
  1436. form: form,
  1437. value: JSON.stringify(form)
  1438. })
  1439. _this.triggerEvent("chooseObjTypeData", {
  1440. data: form,
  1441. })
  1442. }
  1443. },
  1444. success: function (res) {
  1445. // 通过eventChannel向被打开页面传送数据
  1446. res.eventChannel.emit('params', {
  1447. data: 'test'
  1448. })
  1449. }
  1450. })
  1451. // 选择供应商
  1452. } else if (this.data.objType == Constants.objType.supplier) {
  1453. wx.navigateTo({
  1454. // url: '/package-base-select/pages/select-suppliers/select-suppliers',
  1455. url: '/package-base-select/pages/select-data/select-data',
  1456. events: {
  1457. // 回调后
  1458. bindData: function (data) {
  1459. let dataitem = data.data.item
  1460. let form = _this.data.form
  1461. let objIdCol = _this.data.objIdCol;
  1462. // 赋值对象Id
  1463. if (objIdCol && dataitem[objIdCol]) {
  1464. form[objIdCol] = dataitem[objIdCol]
  1465. }
  1466. form.objInfo = dataitem;
  1467. _this.setData({
  1468. form: form,
  1469. value: JSON.stringify(form)
  1470. })
  1471. _this.triggerEvent("chooseObjTypeData", {
  1472. data: form,
  1473. })
  1474. }
  1475. },
  1476. success: function (res) {
  1477. // 通过eventChannel向被打开页面传送数据
  1478. let item = {}
  1479. let route = _this.data.routeUrl[_this.data.routeObjName];
  1480. res.eventChannel.emit('params', {
  1481. item: item,
  1482. route: route['chooseSupplier']
  1483. })
  1484. }
  1485. })
  1486. }
  1487. },
  1488. /**
  1489. * @desc : 小程序地图调用
  1490. * @author : 周兴
  1491. * @date : 2024/2/18 18:16
  1492. */
  1493. onClickWxchartAddress(e) {
  1494. // 只读
  1495. if (this.data.readonly) {
  1496. return;
  1497. }
  1498. // 跳转新建地图实例
  1499. common.onClickWxchartAddress();
  1500. let item = e.currentTarget.dataset;
  1501. this.setData({
  1502. index: item.index,
  1503. card: item.card
  1504. })
  1505. },
  1506. /**
  1507. * @desc : 改变选择框内容
  1508. * @author : 周兴
  1509. * @date : 2024/1/26 11:46
  1510. */
  1511. onChange(e) {
  1512. // 只读
  1513. if (this.data.readonly) {
  1514. return;
  1515. }
  1516. let key = e.currentTarget.dataset.key
  1517. let checkFlag = e.currentTarget.dataset.value
  1518. let form = this.data.form
  1519. form[key] = !checkFlag
  1520. this.setData({
  1521. value: JSON.stringify(form),
  1522. form: form
  1523. })
  1524. },
  1525. /**
  1526. * @desc : 设置地址
  1527. * @author : 周兴
  1528. * @date : 2024/1/19
  1529. */
  1530. setAddress() {
  1531. const location = chooseLocation.getLocation();
  1532. console.log('loc', location, this.data.form);
  1533. let form = this.data.form
  1534. if (location) {
  1535. form['address'] = location;
  1536. form['addressName'] = location.name;
  1537. form['addressFull'] = form['addressFull'] ? form['addressFull'] : location.address + location.name;
  1538. form['addressGcj02'] = {
  1539. latitude: location.latitude,
  1540. longitude: location.longitude
  1541. };
  1542. form['addressArea'] = {
  1543. province: location.province,
  1544. city: location.city,
  1545. district: location.district == undefined || !location.district ? location.city : location.district
  1546. }
  1547. // 如果有校验信息就清除掉
  1548. let card = this.data.card;
  1549. let index = this.data.index;
  1550. let contentObj = this.data.contentObj;
  1551. if (card && contentObj[card][index]?.errMsg) {
  1552. contentObj[card][index].errMsg = undefined;
  1553. this.setData({
  1554. contentObj: contentObj
  1555. })
  1556. }
  1557. }
  1558. this.setData({
  1559. value: JSON.stringify(form),
  1560. form: form
  1561. })
  1562. },
  1563. /**
  1564. * @desc : 设置商品
  1565. * @author : 周兴
  1566. * @date : 2024/1/19
  1567. */
  1568. setGoods(e) {
  1569. if (e.data) {
  1570. let form = this.data.form
  1571. let goodsList = form[this.data.itemName] || []
  1572. e.data.choosedGoodsList.forEach(it => {
  1573. goodsList.push(it)
  1574. })
  1575. form[this.data.itemName] = goodsList
  1576. this.setData({
  1577. form: form,
  1578. value: JSON.stringify(form)
  1579. })
  1580. // 设置商品总单的金额信息
  1581. if (this.data.type == Constants.billType.sale) {
  1582. this.setGoodsAmount(e.data);
  1583. }
  1584. if (this.data.type == Constants.billType.saleOut) { //销售出库
  1585. this.setGoodsOutList(e.data)
  1586. }
  1587. if (this.data.type == Constants.billType.purReturn) { //采购退货
  1588. this.setReturnGoodsAmount(e.data);
  1589. }
  1590. if (this.data.type == Constants.billType.saleOutReturn) { //采购退货
  1591. this.setGoodsOutReturnList(e.data);
  1592. }
  1593. if (this.data.type == Constants.billType.pur) {
  1594. // this.setPurGoodsAmount(e.data);
  1595. }
  1596. // 设置是否进行收缩
  1597. let card = this.data.cardList.filter(it => it.name == 'items');
  1598. this.handleContentObj(card[0])
  1599. // 外露setGoods方法
  1600. this.triggerEvent("setGoods", {
  1601. data: goodsList
  1602. })
  1603. }
  1604. },
  1605. /**
  1606. * @desc : 删除商品明细
  1607. * @author : 周兴
  1608. * @date : 2024/2/22 18:16
  1609. */
  1610. onCloseDel(e) {
  1611. let deleteFlag = true;
  1612. let item = e.currentTarget.dataset.item
  1613. // 判断删除前是否需要判断
  1614. if (this.data.delValidFlag) {
  1615. // 行不允许删除
  1616. if (item.deleteFlag == false) {
  1617. deleteFlag = false;
  1618. }
  1619. }
  1620. // 不允许删除给出提示信息
  1621. if (!deleteFlag) {
  1622. util.showToast(item.message ? item.message : '不满足删除条件');
  1623. } else {
  1624. const {
  1625. instance
  1626. } = e.detail;
  1627. let index = e.currentTarget.dataset.index
  1628. // 删除明细
  1629. this.delItem(index);
  1630. let goodList = this.data.form[this.data.itemName]
  1631. if (!goodList || goodList.length == 0) {
  1632. // 还原选择组件
  1633. this.handleChooseByItem(this, false);
  1634. }
  1635. instance.close();
  1636. }
  1637. // 外露setGoods方法
  1638. this.triggerEvent("onCloseDel", {
  1639. })
  1640. },
  1641. /**
  1642. * @desc : 根据选品控制来源单
  1643. * @author : 周兴
  1644. * @date : 2024/2/22 18:16
  1645. */
  1646. handleChooseByItem(_this, readonlyReturn) {
  1647. let cardList = _this.data.cardList
  1648. let filters = cardList.filter(it => it.name == 'items');
  1649. let contentObj = _this.data.contentObj;
  1650. if (filters && filters.length > 0 && filters[0].controls && filters[0].controls.length > 0) {
  1651. filters[0].controls.forEach(it => {
  1652. let filter = contentObj[it.card].filter(t => t.code == it.code);
  1653. if (filter && filter.length > 0) {
  1654. filter[0].readonlyReturn = readonlyReturn;
  1655. }
  1656. })
  1657. _this.setData({
  1658. contentObj: contentObj
  1659. })
  1660. }
  1661. },
  1662. setFlgGift(code, flag, key) {
  1663. this.selectComponent('#dkPopup').setFlgGift(code, flag, key)
  1664. },
  1665. /**
  1666. * @desc : 删除商品明细
  1667. * @author : 周兴
  1668. * @date : 2024/2/22 18:16
  1669. */
  1670. delItem(index) {
  1671. let form = this.data.form
  1672. let goodsList = form[this.data.itemName] || []
  1673. let deleteList = form[this.data.deleteName] || []
  1674. // 把删除的数据记录下来
  1675. if (goodsList[index]) {
  1676. deleteList.push(goodsList[index])
  1677. }
  1678. goodsList.splice(index, 1)
  1679. form[this.data.itemName] = goodsList
  1680. form[this.data.deleteName] = deleteList
  1681. this.setData({
  1682. form: form,
  1683. value: JSON.stringify(form)
  1684. })
  1685. //计算
  1686. if (this.data.type == Constants.billType.sale) {
  1687. this.setGoodsAmount(goodsList);
  1688. }
  1689. if (this.data.type == Constants.billType.saleOut) {
  1690. this.setGoodsOutAmount()
  1691. }
  1692. if (this.data.type == Constants.billType.saleOutReturn) {
  1693. this.setGoodsOutReturnAmount()
  1694. }
  1695. // 外露setGoods方法
  1696. this.triggerEvent("delItem", {
  1697. data: goodsList
  1698. })
  1699. },
  1700. /**
  1701. * @desc : 设置商品明细金额相关信息 采购订单专用
  1702. * @author : 周兴
  1703. * @date : 2024/1/19
  1704. */
  1705. setPurGoodsAmount(data) {
  1706. let form = this.data.form
  1707. let cardList_ = this.data.cardList
  1708. let goodsList = form[this.data.itemName]
  1709. let sumAmountCol = this.data.sumAmountCol
  1710. goodsList.forEach(element => { //循环出商品总共价格
  1711. element.itemAmt = element.pricePurchase
  1712. element.intoingAmt = element.pricePurchase
  1713. element.intoingQty = element.itemQty
  1714. element.pricePur = element.pricePurchase
  1715. element.priceInto = element.pricePurchase
  1716. element.sumAmountCol = element.pricePurchase * element.itemQty
  1717. })
  1718. cardList_.forEach(card => { //循环出商品总共价格
  1719. if (card.name === 'items') {
  1720. card.itemAmt = goodsList ? goodsList.sum("pricePurchase") : 0
  1721. card.itemQty = goodsList ? goodsList.sum("itemQty") : 0
  1722. card.intoAmt = 0
  1723. card.intoQty = 0
  1724. card[sumAmountCol] = goodsList ? goodsList.sum("sumAmountCol") : 0
  1725. //合计金额
  1726. }
  1727. })
  1728. form[this.data.itemName] = goodsList
  1729. this.setData({
  1730. cardList: cardList_,
  1731. form: form,
  1732. value: JSON.stringify(form)
  1733. })
  1734. },
  1735. /**
  1736. * @desc : 设置商品明细金额相关信息 TODO
  1737. * @author : 周兴
  1738. * @date : 2024/1/19
  1739. */
  1740. setGoodsAmount(data) {
  1741. let cardList = this.data.cardList
  1742. let form = this.data.form
  1743. let index = cardList.findIndex(it => it.name == 'items');
  1744. if (form.goodsList && form.goodsList.length > 0) {
  1745. let sumStandard = Number(0)
  1746. let sumAmount = Number(0)
  1747. let sumQuantity = Number(0)
  1748. form.goodsList.forEach(item => {
  1749. //标价合计 = 商品标价 x 商品数量
  1750. item.priceStd = item.priceStd ? item.priceStd : (item.priceStandard ? item.priceStandard : 0) //标价
  1751. item.amtStd = Number(item.priceStd * item.itemQty) //合计标价金额
  1752. item.priceSale = item.priceSale ? item.priceSale : item.priceStandard
  1753. item.itemAmt = item.priceSale * item.itemQty //商品金额
  1754. item.priceDiscount = item.priceStd ? Number((item.priceSale / item.priceStd) * 100).toFixed(2) : 100 //售价折扣
  1755. sumQuantity += item.itemQty //数量
  1756. sumAmount += item.priceSale * item.itemQty //没有售价默认取标价
  1757. sumStandard += (item.priceStd ? item.priceStd : item.priceStandard) * item.itemQty
  1758. })
  1759. //标价合计
  1760. cardList[index].sumStandard = sumStandard
  1761. //销售折扣 (合计金额/标价合计)
  1762. cardList[index].saleDiscount = sumStandard ? Number((sumAmount / sumStandard) * 100).toFixed(2) : 100
  1763. //合计金额
  1764. cardList[index].sumAmount = sumAmount
  1765. cardList[index].sumQuantity = sumQuantity
  1766. //TODO 需要获取当前客户可用预存
  1767. cardList[index].canUseCollect = 0 //可用
  1768. cardList[index].useCollect = 0 //使用
  1769. form.sumStandard = sumStandard
  1770. form.saleDiscount = cardList[index].saleDiscount
  1771. form.sumAmount = sumAmount
  1772. form.canUseCollect = 0
  1773. form.useCollect = 0
  1774. form.sumQuantity = sumQuantity
  1775. } else {
  1776. cardList[index].sumStandard = 0
  1777. cardList[index].saleDiscount = 0
  1778. cardList[index].sumAmount = 0
  1779. cardList[index].canUseCollect = 0
  1780. cardList[index].useCollect = 0
  1781. form.sumStandard = 0
  1782. form.saleDiscount = 0
  1783. form.sumAmount = 0
  1784. form.canUseCollect = 0
  1785. form.useCollect = 0
  1786. }
  1787. this.setData({
  1788. cardList: cardList,
  1789. form: form
  1790. })
  1791. },
  1792. /**
  1793. * @desc : 设置商品明细金额相关信息 销售出库
  1794. * @author : 于继渤
  1795. * @date : 2024/1/19
  1796. */
  1797. setGoodsOutAmount() {
  1798. let cardList = this.data.cardList
  1799. let form = this.data.form
  1800. let index = cardList.findIndex(it => it.name == 'items');
  1801. if (form.goodsList && form.goodsList.length > 0) {
  1802. let sumAmount = Number(0)
  1803. let sumQuantity = Number(0)
  1804. let sumStandard = Number(0)
  1805. form.goodsList.forEach(item => {
  1806. //标价合计 = 商品标价 x 商品数量
  1807. item.priceStd = item.priceStandard //标价
  1808. item.outingAmt = item.priceOut * item.outingQty
  1809. sumQuantity += item.outingQty //数量
  1810. sumAmount += item.priceOut * item.outingQty //没有售价默认取标价
  1811. sumStandard += (item.priceStd ? item.priceStd : item.priceStandard) * item.outingQty
  1812. })
  1813. //标价合计
  1814. cardList[index].sumStandard = sumStandard
  1815. //销售折扣 (合计金额/标价合计)
  1816. cardList[index].saleDiscount = sumStandard ? Number((sumAmount / sumStandard) * 100).toFixed(2) : 100
  1817. //TODO 需要获取当前客户可用预存
  1818. cardList[index].canUseCollect = 0 //可用
  1819. cardList[index].useCollect = 0 //使用
  1820. form.sumStandard = sumStandard
  1821. form.saleDiscount = cardList[index].saleDiscount
  1822. //合计金额
  1823. cardList[index].sumAmount = sumAmount
  1824. cardList[index].sumQuantity = sumQuantity
  1825. form.sumAmount = sumAmount
  1826. form.sumQuantity = sumQuantity
  1827. form.outingAmt = sumAmount
  1828. form.outingQty = sumQuantity
  1829. }
  1830. this.setData({
  1831. cardList: cardList,
  1832. form: form
  1833. })
  1834. },
  1835. /**
  1836. * @desc : 设置商品明细金额相关信息 销售出库
  1837. * @author : 于继渤
  1838. * @date : 2024/1/19
  1839. */
  1840. setGoodsOutReturnAmount() {
  1841. let cardList = this.data.cardList
  1842. let form = this.data.form
  1843. let index = cardList.findIndex(it => it.name == 'items');
  1844. if (form.goodsList && form.goodsList.length > 0) {
  1845. let sumAmount = Number(0)
  1846. let sumQuantity = Number(0)
  1847. form.goodsList.forEach(item => {
  1848. //标价合计 = 商品标价 x 商品数量
  1849. item.priceStd = item.priceStandard //标价
  1850. item.outingQty = item.outingQty ? item.outingQty : item.itemQty * -1
  1851. item.outingAmt = item.priceOut * item.outingQty
  1852. item.priceOut = item.priceOut
  1853. sumQuantity += item.outingQty //数量
  1854. sumAmount += item.priceOut * item.outingQty //没有售价默认取标价
  1855. })
  1856. //合计金额
  1857. cardList[index].sumAmount = sumAmount
  1858. cardList[index].sumQuantity = sumQuantity
  1859. form.sumAmount = sumAmount
  1860. form.sumQuantity = sumQuantity
  1861. form.outingAmt = sumAmount
  1862. form.outingQty = sumQuantity
  1863. }
  1864. this.setData({
  1865. cardList: cardList,
  1866. form: form
  1867. })
  1868. },
  1869. /**
  1870. * @desc : 销售出库设置选品参数
  1871. * @author : 于继渤
  1872. * @date : 2024/1/19
  1873. */
  1874. setGoodsOutList(data) {
  1875. let form = this.data.form
  1876. if (form.goodsList && form.goodsList.length > 0) {
  1877. form.goodsList.forEach(item => {
  1878. item.priceOut = item.priceOut ? item.priceOut : item.priceStandard
  1879. item.outingAmt = item.priceOut * item.itemQty
  1880. item.outingQty = item.itemQty
  1881. item['outingQty_min'] = 1
  1882. delete item['priceLimited']
  1883. delete item['pricePurchase']
  1884. delete item['priceWholesale']
  1885. })
  1886. }
  1887. this.setData({
  1888. form: form
  1889. })
  1890. this.setGoodsOutAmount()
  1891. },
  1892. /**
  1893. * @desc : 数量改变事件
  1894. * @date : 2024/2/1 15:49
  1895. * @author : 于继渤
  1896. */
  1897. changeStep(e) {
  1898. let key = e.detail.key
  1899. let value = e.detail.value
  1900. let dataItem = JSON.parse(this.data.dataItem)
  1901. dataItem[key] = value
  1902. if (this.data.type == Constants.billType.sale ||
  1903. this.data.type == Constants.billType.pur ||
  1904. this.data.type == Constants.billType.purInto) {
  1905. //箱片的取值逻辑: 箱 =(数量/包装)取整,片= (数量%包装)取余数
  1906. if (key == 'itemQty') {
  1907. dataItem['itemQty'] = value
  1908. dataItem['box'] = parseInt(value / dataItem.packBox)
  1909. dataItem['piece'] = Number(value % dataItem.packBox)
  1910. dataItem.packageBox = dataItem['box'] + dataItem.subUnitName + dataItem['piece'] + dataItem.unitName
  1911. if (this.data.type == Constants.billType.pur) { //采购订单 ,单价*数量,实时变化
  1912. dataItem.sumPrice = dataItem['itemQty'] * dataItem.pricePur
  1913. }
  1914. if (this.data.type == Constants.billType.purInto) { //采购入库
  1915. dataItem.sumPrice = dataItem['itemQty'] * dataItem.priceInto
  1916. }
  1917. }
  1918. } else if (this.data.type == Constants.billType.saleOut ||
  1919. this.data.type == Constants.billType.inventory) {
  1920. //箱片的取值逻辑: 箱 =(数量/包装)取整,片= (数量%包装)取余数
  1921. if (key == 'outingQty') {
  1922. dataItem['outingQty'] = value
  1923. dataItem['box'] = parseInt(value / dataItem.packBox)
  1924. dataItem['piece'] = Number(value % dataItem.packBox)
  1925. dataItem.packageBox = dataItem['box'] + dataItem.subUnitName + dataItem['piece'] + dataItem.unitName
  1926. if (this.data.type == Constants.billType.saleOut) { //销售退货
  1927. dataItem.sumPrice = dataItem['outingQty'] * dataItem.priceOut
  1928. }
  1929. }
  1930. } else if (this.data.type == Constants.billType.saleOutReturn) {
  1931. if (key == 'outingQty') {
  1932. dataItem['outingQty'] = value
  1933. // 使用 Math.abs() 函数获取 outingQty 的绝对值
  1934. let outingQty = Math.abs(dataItem.outingQty);
  1935. dataItem['box'] = parseInt(outingQty / dataItem.packBox)
  1936. dataItem['piece'] = Number(outingQty % dataItem.packBox)
  1937. dataItem.packageBox = dataItem['box'] + dataItem.subUnitName + dataItem['piece'] + dataItem.unitName
  1938. if (this.data.type == Constants.billType.saleOutReturn) { //销售退货
  1939. dataItem.sumPrice = dataItem['outingQty'] * dataItem.priceOut
  1940. }
  1941. }
  1942. }
  1943. this.setData({
  1944. dataItem: JSON.stringify(dataItem)
  1945. })
  1946. },
  1947. /**
  1948. * @desc : 修改数值离开框的值
  1949. * @author : 周兴
  1950. * @date : 2024/2/2 11:46
  1951. */
  1952. blurNumberField(e) {
  1953. console.log("blurNumberField", e);
  1954. let dataItem = JSON.parse(this.data.dataItem)
  1955. // 采购订单
  1956. if (this.data.type == Constants.billType.pur) {
  1957. dataItem.pricePur = e.detail.value
  1958. dataItem.sumPrice = dataItem['itemQty'] * dataItem.pricePur
  1959. }
  1960. if (this.data.type == Constants.billType.purInto) { //采购入库
  1961. dataItem.priceInto = e.detail.value
  1962. dataItem.sumPrice = dataItem['itemQty'] * dataItem.priceInto
  1963. }
  1964. if (this.data.type == Constants.billType.saleOutReturn ||
  1965. this.data.type == Constants.billType.out ||
  1966. this.data.type == Constants.billType.inventory
  1967. ) { //销售退货
  1968. dataItem.priceOut = e.detail.value
  1969. dataItem.sumPrice = dataItem['itemQty'] * dataItem.priceOut
  1970. }
  1971. if (this.data.type == Constants.billType.saleOutReturn ||
  1972. this.data.type == Constants.billType.saleOut ||
  1973. this.data.type == Constants.billType.inventory) {
  1974. dataItem.priceOut = e.detail.value
  1975. dataItem.sumPrice = dataItem['outingQty'] * dataItem.priceOut
  1976. }
  1977. this.setData({
  1978. dataItem: JSON.stringify(dataItem)
  1979. })
  1980. },
  1981. /**
  1982. * @desc : 销售出库退货设置选品参数
  1983. * @author : 于继渤
  1984. * @date : 2024/1/19
  1985. */
  1986. setGoodsOutReturnList(data) {
  1987. let form = this.data.form
  1988. if (form.goodsList && form.goodsList.length > 0) {
  1989. form.goodsList.forEach(item => {
  1990. item.priceOut = item.priceOut ? item.priceOut : item.priceStandard
  1991. item.outQty = item.itemQty
  1992. item.outingQty = item.outingQty
  1993. item.outAmt = item.priceOut * item.itemQty
  1994. // item.outingAmt = item.priceOut * item.itemQty
  1995. item['outingQty_min'] = item.itemQty * -1
  1996. item['outingQty_max'] = Number(-1)
  1997. delete item['priceLimited']
  1998. delete item['pricePurchase']
  1999. delete item['priceWholesale']
  2000. })
  2001. }
  2002. this.setData({
  2003. form: form
  2004. })
  2005. this.setGoodsOutReturnAmount()
  2006. },
  2007. /**
  2008. * @desc : 显示tip
  2009. * @author : 周兴
  2010. * @date : 2024/4/25 11:46
  2011. */
  2012. showTip(e) {
  2013. let item = e.currentTarget.dataset.item
  2014. if (item.tip) {
  2015. util.showToast(item.tip);
  2016. }
  2017. },
  2018. /**
  2019. * @desc : 设置商品明细金额相关信息 TODO
  2020. * @author : 周兴
  2021. * @date : 2024/1/19
  2022. */
  2023. setReturnGoodsAmount(data) {
  2024. let cardList = this.data.cardList
  2025. let form = this.data.form
  2026. let index = cardList.findIndex(it => it.name == 'items');
  2027. if (form.goodsList && form.goodsList.length > 0) {
  2028. let sumReturnAmt = Number(0) //合计金额
  2029. let sumReturnQty = Number(0)
  2030. form.goodsList.forEach(item => {
  2031. item.priceReturn = item.priceStandard * -1
  2032. item.priceInto = item.priceStandard
  2033. item.itemAmt = Number(item.priceReturn * item.itemQty)
  2034. item.itemQtyMax = -1
  2035. if (item.itemId) { //选商品过来的 不校验 选单据校验
  2036. item.itemQtyMin = item.usableQty * -1
  2037. } else {
  2038. item.itemQtyMin = -99999999999
  2039. }
  2040. // sumReturnAmt += item.priceReturn * item.itemQty
  2041. // sumReturnQty += item.itemQty
  2042. item.itemQty = item.itemQty * -1
  2043. })
  2044. // form.sumReturnQty = sumReturnQty
  2045. // form.sumReturnAmt = sumReturnAmt
  2046. // cardList[index].sumReturnAmt = sumReturnAmt
  2047. }
  2048. console.log('form', form)
  2049. this.setData({
  2050. cardList: cardList,
  2051. form: form
  2052. })
  2053. },
  2054. /**
  2055. * @desc : 上传附件超出大小
  2056. * @author : 周兴
  2057. * @date : 2024/3/27 16:16
  2058. */
  2059. overSize(e) {
  2060. util.showToast('文件超出' + Constants.uploadFileConfig.maxSizeMB);
  2061. },
  2062. /**
  2063. * @desc : 删除图片
  2064. * @author : 周兴
  2065. * @date : 2024/4/29 18:16
  2066. */
  2067. deleteImg(e) {
  2068. let form = this.data.form;
  2069. let index = e.detail.index;
  2070. let arr = form['annexPaths']
  2071. arr.splice(index, 1);
  2072. this.setData({
  2073. form: form,
  2074. value: JSON.stringify(form)
  2075. })
  2076. },
  2077. changeCheckBox(e) {
  2078. this.triggerEvent("changeCheckBox", {
  2079. code: e.detail.code,
  2080. flag: e.detail.flag
  2081. })
  2082. },
  2083. /**
  2084. * @desc : 上传附件
  2085. * @author : 周兴
  2086. * @date : 2024/3/27 16:16
  2087. */
  2088. afterRead(e) {
  2089. // this.setData({
  2090. // uploadFileFlag:true
  2091. // })
  2092. const _this = this;
  2093. const {
  2094. file
  2095. } = e.detail;
  2096. // 配置存放的文件夹 公司code - 表名 - 年月 -- 日
  2097. let folder = app.globalData.company.cpCode + '/' + this.data.table + '/' + new Date().toYearMonth2() + '/' + new Date().toDay()
  2098. let url = config.upload_url;
  2099. url = url.replace('mdm-server', 'mdm-server' + '-' + app.globalData.company.svcCode.replace('_', '-'))
  2100. file.forEach(res => {
  2101. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  2102. wx.uploadFile({
  2103. url: url,
  2104. filePath: res.path,
  2105. name: 'file',
  2106. formData: {
  2107. 'folder': folder
  2108. },
  2109. header: {
  2110. 'Authorization': 'Bearer ' + app.globalData.token
  2111. },
  2112. success(res) {
  2113. let data = JSON.parse(res.data)
  2114. if (data.code === 200) {
  2115. _this.setData({
  2116. uploadFileFlag: false
  2117. })
  2118. let form = _this.data.form
  2119. let annexPaths = form['annexPaths'] || []
  2120. data.data.url = config.image_url + data.data.path
  2121. annexPaths.push(data.data)
  2122. form.annexPaths = annexPaths;
  2123. _this.setData({
  2124. form: form,
  2125. value: JSON.stringify(form)
  2126. })
  2127. }
  2128. },
  2129. })
  2130. })
  2131. },
  2132. customersChoose() {
  2133. this.triggerEvent("customersChoose", {})
  2134. },
  2135. /**
  2136. * @desc : 加载数据
  2137. * @date : 2024/2/1 15:49
  2138. * @author : 姜永辉
  2139. */
  2140. setInitPopData() {
  2141. //销售订单 //采购订单 库存调整
  2142. if (this.data.type == Constants.billType.sale || this.data.type == Constants.billType.pur || this.data.type == Constants.billType.out) {
  2143. this.setData({
  2144. popContentBox: [{
  2145. code: 'box',
  2146. type: 'step',
  2147. title: mixins.$t("goodsBox"),
  2148. required: true
  2149. },
  2150. {
  2151. code: 'piece',
  2152. type: 'step',
  2153. title: mixins.$t("goodsPiece"),
  2154. required: true
  2155. },
  2156. ],
  2157. })
  2158. }
  2159. //销售出库
  2160. if (this.data.type == Constants.billType.saleOut) {
  2161. this.setData({
  2162. popContentBox: [{
  2163. code: 'box',
  2164. type: 'step',
  2165. title: mixins.$t("goodsBox"),
  2166. required: true
  2167. },
  2168. {
  2169. code: 'piece',
  2170. type: 'step',
  2171. title: mixins.$t("goodsPiece"),
  2172. required: true
  2173. },
  2174. ],
  2175. })
  2176. }
  2177. //销售退货
  2178. if (this.data.type == Constants.billType.saleOutReturn) {
  2179. this.setData({
  2180. })
  2181. }
  2182. //采购退货
  2183. if (this.data.type == Constants.billType.purReturn) {
  2184. this.setData({
  2185. })
  2186. }
  2187. //采购入库 销售退货
  2188. if (this.data.type == Constants.billType.purInto || this.data.type == Constants.billType.saleOutReturn) {
  2189. this.setData({
  2190. popContentBox: [{
  2191. code: 'box',
  2192. type: 'step',
  2193. title: mixins.$t("goodsBox"),
  2194. required: true
  2195. },
  2196. {
  2197. code: 'piece',
  2198. type: 'step',
  2199. title: mixins.$t("goodsPiece"),
  2200. required: true
  2201. },
  2202. ],
  2203. })
  2204. }
  2205. },
  2206. /**
  2207. * @desc : 获取语言的方法
  2208. * @author : 周兴
  2209. * @date : 2024/1/19
  2210. */
  2211. $t(name) {
  2212. if (this.data.$t[name]) {
  2213. return this.data.$t[name];
  2214. } else {
  2215. return name;
  2216. }
  2217. },
  2218. },
  2219. })