MaterialModal.vue 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019
  1. <template>
  2. <j-modal
  3. :title="title"
  4. :width="width"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. v-bind:prefixNo="prefixNo"
  8. fullscreen
  9. switchHelp
  10. switchFullscreen
  11. @cancel="handleCancel"
  12. :id="prefixNo"
  13. :style="modalStyle"
  14. >
  15. <template slot="footer">
  16. <a-button key="back" @click="handleCancel">取消</a-button>
  17. <a-button type="primary" v-if="showOkFlag" :loading="confirmLoading" @click="handleOk">保存(Ctrl+S)</a-button>
  18. </template>
  19. <a-spin :spinning="confirmLoading">
  20. <a-form :form="form">
  21. <a-tabs default-active-key="1" size="small" v-model="activeKey">
  22. <a-tab-pane key="1" tab="基本信息" id="materialHeadModal" forceRender>
  23. <a-row class="form-row" :gutter="24" type="flex">
  24. <a-col :xl="6" :lg="8" :md="12" :sm="24">
  25. <a-form-item
  26. :labelCol="labelCol"
  27. :wrapperCol="wrapperCol"
  28. label="名称"
  29. data-step="1"
  30. data-title="名称"
  31. data-intro="名称必填,可以重复"
  32. >
  33. <a-input
  34. placeholder="请输入名称"
  35. v-decorator.trim="['name', validatorRules.name]"
  36. @change="handleNameChange"
  37. />
  38. </a-form-item>
  39. </a-col>
  40. <a-col :xl="6" :lg="8" :md="12" :sm="24">
  41. <a-form-item
  42. :labelCol="labelCol"
  43. :wrapperCol="wrapperCol"
  44. label="品牌"
  45. data-step="2"
  46. data-title="品牌"
  47. data-intro="请填写商品的品牌,方便区别不同品牌的商品"
  48. >
  49. <a-input placeholder="请输入品牌" v-decorator.trim="['brand']" />
  50. </a-form-item>
  51. </a-col>
  52. <a-col :xl="6" :lg="8" :md="12" :sm="24">
  53. <a-form-item
  54. :labelCol="labelCol"
  55. :wrapperCol="wrapperCol"
  56. label="助记码"
  57. data-step="3"
  58. data-title="助记码"
  59. data-intro="助记码自动生成,助记码是商品名称的首字母缩写"
  60. >
  61. <a-input placeholder="" v-decorator.trim="['mnemonic']" :readOnly="true" />
  62. </a-form-item>
  63. </a-col>
  64. <a-col :xl="6" :lg="8" :md="12" :sm="24">
  65. <a-form-item
  66. :labelCol="labelCol"
  67. :wrapperCol="wrapperCol"
  68. label="类别"
  69. data-step="4"
  70. data-title="类别"
  71. data-intro="类别需要在【商品类别】页面进行录入,录入之后在此处进行调用"
  72. >
  73. <a-tree-select
  74. style="width: 100%"
  75. :dropdownStyle="{ maxHeight: '200px', overflow: 'auto' }"
  76. allow-clear
  77. :treeData="categoryTree"
  78. v-decorator="['categoryId', validatorRules.categoryId]"
  79. placeholder="请选择类别"
  80. >
  81. </a-tree-select>
  82. </a-form-item>
  83. </a-col>
  84. <a-col :xl="6" :lg="8" :md="12" :sm="24">
  85. <a-form-item
  86. :labelCol="labelCol"
  87. :wrapperCol="wrapperCol"
  88. label="序列号"
  89. data-step="5"
  90. data-title="序列号"
  91. data-intro="此处是商品的序列号开关,如果选择了有,则在采购入库单据需要录入该商品的序列号,在销售出库单据需要选择该商品的序列号进行出库"
  92. >
  93. <a-tooltip title="如果选择为有,则在采购入库单需要录入该商品的序列号">
  94. <a-select placeholder="有无序列号" v-decorator="['enableSerialNumber']">
  95. <a-select-option value="1">有</a-select-option>
  96. <a-select-option value="0">无</a-select-option>
  97. </a-select>
  98. </a-tooltip>
  99. </a-form-item>
  100. </a-col>
  101. <a-col :xl="6" :lg="8" :md="12" :sm="24">
  102. <a-form-item
  103. :labelCol="labelCol"
  104. :wrapperCol="wrapperCol"
  105. label="系统SPU"
  106. data-step="6"
  107. data-title="系统SPU"
  108. data-intro="系统SPU"
  109. >
  110. <a-input placeholder="提交后自动生成" disabled v-decorator="['systemSpu']" />
  111. </a-form-item>
  112. </a-col>
  113. <a-col :xl="6" :lg="8" :md="12" :sm="24">
  114. <a-form-item
  115. :labelCol="{
  116. xs: { span: 24 },
  117. sm: { span: 10 },
  118. }"
  119. :wrapperCol="{
  120. xs: { span: 24 },
  121. sm: { span: 14 },
  122. }"
  123. label="无动销提醒周期"
  124. data-step="7"
  125. data-title="无动销提醒周期"
  126. data-intro="无动销提醒周期"
  127. >
  128. <a-tooltip title="无动销提醒周期">
  129. <a-select placeholder="无动销提醒周期" v-decorator="['movingPinReminderCycle']">
  130. <a-select-option value="7">一周</a-select-option>
  131. <a-select-option value="14">两周</a-select-option>
  132. <a-select-option value="30">一个月</a-select-option>
  133. <a-select-option value="90">一季度</a-select-option>
  134. </a-select>
  135. </a-tooltip>
  136. </a-form-item>
  137. </a-col>
  138. <a-col :xl="6" :lg="8" :md="12" :sm="24">
  139. <a-form-item
  140. :labelCol="labelCol"
  141. :wrapperCol="wrapperCol"
  142. label="保质期(天)"
  143. data-step="8"
  144. data-title="保质期(天)"
  145. data-intro="保质期(天)"
  146. >
  147. <a-input-number :min="0" v-decorator="['expiryNum']" style="width: 100%;" placeholder="请输入保质期(天)" />
  148. </a-form-item>
  149. </a-col>
  150. <a-col :xl="6" :lg="8" :md="12" :sm="24">
  151. <a-form-item
  152. :labelCol="labelCol"
  153. :wrapperCol="wrapperCol"
  154. label="默认采购价"
  155. data-step="9"
  156. data-title="默认采购价"
  157. data-intro="默认采购价"
  158. >
  159. <a-input @blur="$refs.meTable.$forceUpdate()" v-decorator="['defaultPurchaseDecimal',validatorRules.defaultPurchaseDecimal]" style="width: 100%" placeholder="请输入默认采购价" />
  160. </a-form-item>
  161. </a-col>
  162. <a-col :xl="6" :lg="8" :md="12" :sm="24">
  163. <a-form-item
  164. :labelCol="labelCol"
  165. :wrapperCol="wrapperCol"
  166. label="默认销售价"
  167. data-step="10"
  168. data-title="默认销售价"
  169. data-intro="默认销售价"
  170. >
  171. <a-input @blur="$refs.meTable.$forceUpdate()" v-decorator="['defaultWholesaleDecimal',validatorRules.defaultWholesaleDecimal]" style="width: 100%;" placeholder="请输入默认销售价" />
  172. </a-form-item>
  173. </a-col>
  174. </a-row>
  175. <div style="margin-top: 8px" id="materialDetailModal">
  176. <a-table
  177. ref="meTable"
  178. size="middle"
  179. rowKey="id"
  180. :loading="meTable.loading"
  181. :columns="meTable.columns"
  182. :dataSource="meTable.dataSource"
  183. :pagination="meTable.pagination"
  184. :scroll="meTable.scroll"
  185. bordered
  186. @change="handleMeTableChange"
  187. >
  188. <template slot="supplierId" slot-scope="text, record">
  189. {{ formatSupplierName(record.supplierId) }}
  190. </template>
  191. <template slot="depotId" slot-scope="text, record">
  192. {{ formatDepotName(record.depotId) }}
  193. </template>
  194. <template slot="purchaseDecimal" slot-scope="text, record">
  195. {{ record.purchaseDecimal }}
  196. <a-tooltip slot="suffix" title="采购价和默认采购价不一致">
  197. <a-icon type="info-circle" style="color: #f5222d" v-show="record.purchaseDecimal!=form.getFieldValue('defaultPurchaseDecimal')" />
  198. </a-tooltip>
  199. </template>
  200. <template slot="wholesaleDecimal" slot-scope="text, record">
  201. {{ record.wholesaleDecimal }}
  202. <a-tooltip slot="suffix" title="销售价和默认销售价不一致">
  203. <a-icon type="info-circle" style="color: #f5222d" v-show="record.wholesaleDecimal!=form.getFieldValue('defaultWholesaleDecimal')" />
  204. </a-tooltip>
  205. </template>
  206. </a-table>
  207. </div>
  208. <a-row class="form-row" :gutter="24" type="flex">
  209. <a-col :lg="24" :md="24" :sm="24">
  210. <a-form-item :labelCol="labelCol" :wrapperCol="{ xs: { span: 24 }, sm: { span: 24 } }" label="">
  211. <a-textarea :rows="1" placeholder="请输入备注" v-decorator="['remark']" style="margin-top: 8px" />
  212. </a-form-item>
  213. </a-col>
  214. </a-row>
  215. </a-tab-pane>
  216. <a-tab-pane key="2" tab="商品SKU" forceRender>
  217. <j-editable-table
  218. ref="editableProBarCodeTable"
  219. :loading="mbTable.loading"
  220. :columns="mbTable.columns"
  221. :dataSource="mbTable.dataSource"
  222. :height="300"
  223. minWidth="100%"
  224. :maxHeight="300"
  225. :rowNumber="false"
  226. :rowSelection="true"
  227. :actionButton="true"
  228. @added="handleMbTableAdded"
  229. >
  230. <template #commodityUnit="{value,index,allValues,rowId}">
  231. <div style="display: flex;align-items: center;">
  232. <a-input disabled :value="value" placeholder="自动带出">
  233. </a-input>
  234. <span class="sp-btn" @click="editMaterialUnitModal({value,index,allValues,rowId})">+管理</span>
  235. </div>
  236. </template>
  237. <template #upcList="{value,rowId}">
  238. <div style="display: flex;align-items: center;">
  239. <a-input disabled :value="value[0]&&value[0].upc?value[0].upc:''" placeholder="自动带出">
  240. </a-input>
  241. <span class="sp-btn" @click="editMaterialUpcModal({value,rowId})">+管理</span>
  242. </div>
  243. </template>
  244. <template #enabled="{value,handleChange}">
  245. <a-switch :checked="value" @change="(v) => handleChange(v)" checkedChildren="启用" unCheckedChildren="禁用" />
  246. </template>
  247. </j-editable-table>
  248. </a-tab-pane>
  249. <a-tab-pane key="3" tab="扩展信息" forceRender>
  250. <a-row v-if="mpShort.otherField1.enabled" class="form-row" :gutter="24">
  251. <a-col :lg="6" :md="6" :sm="6">
  252. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="mpShort.otherField1.name">
  253. <a-input v-decorator.trim="['otherField1']" />
  254. </a-form-item>
  255. </a-col>
  256. </a-row>
  257. <a-row v-if="mpShort.otherField2.enabled" class="form-row" :gutter="24">
  258. <a-col :lg="6" :md="6" :sm="6">
  259. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="mpShort.otherField2.name">
  260. <a-input v-decorator.trim="['otherField2']" />
  261. </a-form-item>
  262. </a-col>
  263. </a-row>
  264. <a-row v-if="mpShort.otherField3.enabled" class="form-row" :gutter="24">
  265. <a-col :lg="6" :md="6" :sm="6">
  266. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="mpShort.otherField3.name">
  267. <a-input v-decorator.trim="['otherField3']" />
  268. </a-form-item>
  269. </a-col>
  270. </a-row>
  271. </a-tab-pane>
  272. <a-tab-pane key="4" tab="库存数量" forceRender>
  273. <j-editable-table
  274. ref="editableDepotTable"
  275. :loading="depotTable.loading"
  276. :columns="depotTable.columns"
  277. :dataSource="depotTable.dataSource"
  278. minWidth="100%"
  279. :maxHeight="300"
  280. :rowNumber="true"
  281. :rowSelection="false"
  282. :actionButton="false"
  283. >
  284. <template #buttonAfter>
  285. <a-button style="margin: 0px 0px 8px 0px" @click="batchSetStock('lowSafeStock')">最低安全库存-批量</a-button>
  286. <a-button style="margin-left: 8px" @click="batchSetStock('highSafeStock')">最高安全库存-批量</a-button>
  287. </template>
  288. </j-editable-table>
  289. <!-- 表单区域 -->
  290. <batch-set-stock-modal ref="stockModalForm" @ok="batchSetStockModalFormOk"></batch-set-stock-modal>
  291. </a-tab-pane>
  292. <a-tab-pane key="5" tab="图片信息" forceRender>
  293. <a-row class="form-row" :gutter="24" style="padding-top: 20px">
  294. <a-col :lg="18" :md="18" :sm="24">
  295. <a-form-item
  296. :labelCol="{ xs: { span: 24 }, sm: { span: 3 } }"
  297. :wrapperCol="{ xs: { span: 24 }, sm: { span: 20 } }"
  298. label="图片信息"
  299. >
  300. <j-image-upload v-model="fileList" bizPath="material" text="上传" isMultiple></j-image-upload>
  301. </a-form-item>
  302. </a-col>
  303. <a-col :md="6" :sm="24"></a-col>
  304. </a-row>
  305. <a-row class="form-row" :gutter="24">
  306. <a-col :lg="18" :md="18" :sm="24">
  307. <a-form-item
  308. :labelCol="{ xs: { span: 24 }, sm: { span: 3 } }"
  309. :wrapperCol="{ xs: { span: 24 }, sm: { span: 20 } }"
  310. label="上传提示"
  311. >
  312. 图片最多4张,且单张大小不超过1M
  313. </a-form-item>
  314. </a-col>
  315. <a-col :md="6" :sm="24"></a-col>
  316. </a-row>
  317. </a-tab-pane>
  318. </a-tabs>
  319. </a-form>
  320. </a-spin>
  321. <!-- 货品单位管理 -->
  322. <material-unit-modal ref="materialUnitModal" @ok="unitOk"></material-unit-modal>
  323. <material-upc-modal ref="materialUpcModal" @ok="upcOk"></material-upc-modal>
  324. </j-modal>
  325. </template>
  326. <script>
  327. import pick from 'lodash.pick'
  328. import BatchSetPriceModal from './BatchSetPriceModal'
  329. import BatchSetStockModal from './BatchSetStockModal'
  330. import MaterialUnitModal from './MaterialUnitModal'
  331. import MaterialUpcModal from './MaterialUpcModal'
  332. import JEditableTable from '@/components/jeecg/JEditableTable'
  333. import { FormTypes, getRefPromise, VALIDATE_NO_PASSED, validateFormAndTables } from '@/utils/JEditableTableUtil'
  334. import {
  335. queryMaterialCategoryTreeList,
  336. changeNameToPinYin,
  337. } from '@/api/api'
  338. import { autoJumpNextInput, handleIntroJs } from '@/utils/util'
  339. import { getAction, httpAction } from '@/api/manage'
  340. import JImageUpload from '@/components/jeecg/JImageUpload'
  341. import JDate from '@/components/jeecg/JDate'
  342. import Vue from 'vue'
  343. import { MaterialModalMixins } from '../mixins/MaterialModalMixins'
  344. import { mixinDevice } from '@/utils/mixin.js'
  345. export default {
  346. name: 'MaterialModal',
  347. mixins: [MaterialModalMixins,mixinDevice],
  348. components: {
  349. BatchSetPriceModal,
  350. BatchSetStockModal,
  351. MaterialUnitModal,
  352. MaterialUpcModal,
  353. JImageUpload,
  354. JDate,
  355. JEditableTable,
  356. VNodes: {
  357. functional: true,
  358. render: (h, ctx) => ctx.props.vnodes,
  359. },
  360. },
  361. data() {
  362. return {
  363. title: '操作',
  364. width: '1300px',
  365. visible: false,
  366. activeKey: '1',
  367. modalStyle: '',
  368. categoryTree: [],
  369. unitList: [],
  370. depotList: [],
  371. fileList: [],
  372. meDeleteIdList: [], //删除条码信息的id数组
  373. prefixNo: 'material',
  374. model: {},
  375. showOkFlag: true,
  376. setTimeFlag: null,
  377. labelCol: {
  378. xs: { span: 24 },
  379. sm: { span: 8 },
  380. },
  381. wrapperCol: {
  382. xs: { span: 24 },
  383. sm: { span: 16 },
  384. },
  385. mpShort: {
  386. mfrs: {},
  387. otherField1: {},
  388. otherField2: {},
  389. otherField3: {},
  390. },
  391. meTable: {
  392. loading: false,
  393. dataSource: [],
  394. columns: [
  395. {
  396. title: '批次号',
  397. dataIndex: 'batchNumber',
  398. },
  399. {
  400. title: 'SKU',
  401. dataIndex: 'sku',
  402. },
  403. {
  404. title: '单位',
  405. dataIndex: 'commodityUnit',
  406. },
  407. {
  408. title: '采购价',
  409. dataIndex: 'purchaseDecimal',
  410. scopedSlots: { customRender: 'purchaseDecimal' }
  411. },
  412. {
  413. title: '销售价',
  414. dataIndex: 'wholesaleDecimal',
  415. scopedSlots: { customRender: 'wholesaleDecimal' }
  416. },
  417. {
  418. title: '生产日期',
  419. dataIndex: 'productionDate',
  420. },
  421. {
  422. title: '供应商',
  423. dataIndex: 'supplierId',
  424. scopedSlots: { customRender: 'supplierId' }
  425. },
  426. {
  427. title: '库存(最小单位)',
  428. dataIndex: 'inventory',
  429. },
  430. {
  431. title: '仓库名称',
  432. dataIndex: 'depotId',
  433. scopedSlots: { customRender: 'depotId' }
  434. },
  435. {
  436. title: '库位',
  437. dataIndex: 'position',
  438. },
  439. ],
  440. pagination: {
  441. current: 1,
  442. pageSize: 10,
  443. pageSizeOptions: ['10', '20', '30', '50', '100'],
  444. showTotal: (total, range) => {
  445. return range[0] + '-' + range[1] + ' 共' + total + '条'
  446. },
  447. showQuickJumper: true,
  448. showSizeChanger: true,
  449. total: 0,
  450. },
  451. scroll: {}
  452. },
  453. mbTable:{
  454. loading: false,
  455. dataSource: [],
  456. columns: [
  457. {
  458. title: 'SKU',
  459. key: 'sku',
  460. width: '250px',
  461. disabled: true,
  462. type: FormTypes.input,
  463. placeholder: '自动生成',
  464. },
  465. {
  466. title: '单位',
  467. key: 'commodityUnit',
  468. width: '140px',
  469. type: FormTypes.slot,
  470. disabled: true,
  471. placeholder: '请输入${title}',
  472. validateRules: [{ required: true, message: '单位不能为空' }],
  473. },
  474. {
  475. title: '规格',
  476. key: 'standard',
  477. width: '100px',
  478. type: FormTypes.input,
  479. placeholder: '请输入${title}',
  480. validateRules: [{ required: true, message: '规格不能为空' }],
  481. },
  482. {
  483. title: '颜色',
  484. key: 'color',
  485. width: '100px',
  486. type: FormTypes.input,
  487. placeholder: '请输入${title}',
  488. },
  489. {
  490. title: '重量(kg)',
  491. key: 'weight',
  492. width: '100px',
  493. type: FormTypes.inputNumber,
  494. placeholder: '请输入重量',
  495. },
  496. {
  497. title: '型号',
  498. key: 'model',
  499. width: '100px',
  500. type: FormTypes.input,
  501. placeholder: '请输入${title}',
  502. },
  503. {
  504. title: 'UPC',
  505. key: 'upcList',
  506. width: '180px',
  507. type: FormTypes.slot,
  508. placeholder: '请输入${title}',
  509. },
  510. {
  511. title: '是否启用',
  512. key: 'enabled',
  513. width: '100px',
  514. type: FormTypes.slot,
  515. placeholder: '请输入${title}',
  516. },
  517. {
  518. title: '单位集合',
  519. key: 'unitList',
  520. width: '100px',
  521. type: FormTypes.hidden,
  522. },
  523. ]
  524. },
  525. depotTable: {
  526. loading: false,
  527. dataSource: [],
  528. columns: [
  529. {
  530. title: '仓库',
  531. key: 'name',
  532. width: '15%',
  533. type: FormTypes.normal,
  534. },
  535. {
  536. title: '期初库存',
  537. key: 'number',
  538. width: '15%',
  539. type: FormTypes.inputNumber,
  540. defaultValue: '',
  541. placeholder: '请输入${title}',
  542. },
  543. {
  544. title: '库存总数量',
  545. key: 'currentStock',
  546. width: '15%',
  547. type: FormTypes.inputNumber,
  548. defaultValue: '',
  549. disabled: true,
  550. placeholder: '请输入${title}',
  551. },
  552. {
  553. title: '最低安全库存数量',
  554. key: 'lowSafeStock',
  555. width: '15%',
  556. type: FormTypes.inputNumber,
  557. defaultValue: '',
  558. placeholder: '请输入${title}',
  559. },
  560. {
  561. title: '最高安全库存数量',
  562. key: 'highSafeStock',
  563. width: '15%',
  564. type: FormTypes.inputNumber,
  565. defaultValue: '',
  566. placeholder: '请输入${title}',
  567. },
  568. {
  569. title: '仓位货架',
  570. key: 'position',
  571. width: '9%',
  572. type: FormTypes.input,
  573. defaultValue: '',
  574. placeholder: '请输入${title}',
  575. },
  576. ],
  577. },
  578. confirmLoading: false,
  579. form: this.$form.createForm(this),
  580. validatorRules: {
  581. name: {
  582. rules: [
  583. { required: true, message: '请输入名称!' },
  584. { max: 100, message: '长度请小于100个字符', trigger: 'blur' },
  585. ],
  586. },
  587. categoryId: {
  588. rules: [{ required: true, message: '请选择类别!' }],
  589. },
  590. defaultWholesaleDecimal: {
  591. rules: [{ required: true, message: '请输入默认销售价!' },{ pattern: /^(?:0|[1-9]\d*)(?:\.\d{1,4})?$/, message: '金额格式不正确!' }],
  592. },
  593. defaultPurchaseDecimal: {
  594. rules: [{ required: true, message: '请输入默认采购价!' },{ pattern: /^(?:0|[1-9]\d*)(?:\.\d{1,4})?$/, message: '金额格式不正确!' }],
  595. },
  596. },
  597. url: {
  598. add: '/material/add',
  599. edit: '/material/update',
  600. materialsExtendList: '/materialsExtend/getDetailList',
  601. depotWithStock: '/depot/getAllListWithStock',
  602. batchList: '/materialBatch/getDetailList',
  603. },
  604. }
  605. },
  606. created() {
  607. this.loadParseMaterialProperty()
  608. let realScreenWidth = window.screen.width
  609. this.width = realScreenWidth < 1500 ? '1200px' : '1400px'
  610. this.initSelectOpts()
  611. },
  612. mounted() {
  613. document.getElementById(this.prefixNo).addEventListener('keydown', this.handleOkKey)
  614. },
  615. beforeDestroy() {
  616. document.getElementById(this.prefixNo).removeEventListener('keydown', this.handleOkKey)
  617. },
  618. methods: {
  619. // 快捷键
  620. handleOkKey(e) {
  621. const key = window.event.keyCode ? window.event.keyCode : window.event.which
  622. if (key === 83 && e.ctrlKey) {
  623. //保存 CTRL+S
  624. this.handleOk()
  625. e.preventDefault()
  626. }
  627. },
  628. // 获取所有的editableTable实例
  629. getAllTable() {
  630. return Promise.all([getRefPromise(this, 'editableProBarCodeTable'),getRefPromise(this, 'editableDepotTable')])
  631. },
  632. handleMbTableAdded(e){
  633. const { row, target } = e
  634. target.setValues([{ rowKey: row.id, values: { enabled: true } }])
  635. },
  636. add() {
  637. // 默认新增一条数据
  638. this.getAllTable().then((editableTables) => {
  639. editableTables[0].add()
  640. })
  641. this.edit({})
  642. this.$nextTick(() => {
  643. handleIntroJs('material', 11)
  644. })
  645. },
  646. async edit(record) {
  647. this.form.resetFields()
  648. this.model = Object.assign({}, record)
  649. this.activeKey = '1'
  650. this.visible = true
  651. this.meDeleteIdList = []
  652. this.modalStyle = 'top:0;height: 95%;'
  653. if (JSON.stringify(record) === '{}') {
  654. this.fileList = []
  655. } else {
  656. setTimeout(() => {
  657. this.fileList = record.imgName
  658. }, 5)
  659. }
  660. this.$nextTick(() => {
  661. this.form.setFieldsValue(
  662. pick(
  663. this.model,
  664. 'name',
  665. 'brand',
  666. 'mnemonic',
  667. 'categoryId',
  668. 'enableSerialNumber',
  669. 'movingPinReminderCycle',
  670. 'expiryNum',
  671. 'defaultPurchaseDecimal',
  672. 'defaultWholesaleDecimal',
  673. 'systemSpu',
  674. 'remark',
  675. 'otherField1',
  676. 'otherField2',
  677. 'otherField3'
  678. )
  679. )
  680. autoJumpNextInput('materialHeadModal')
  681. })
  682. this.loadTreeData()
  683. this.loadUnitListData()
  684. // 加载子表数据
  685. if (this.model.id) {
  686. let params = { materialId: this.model.id }
  687. this.requestProMbTableData(this.url.materialsExtendList, params, this.mbTable)
  688. this.requestMeTableData()
  689. this.requestDepotTableData(this.url.depotWithStock, { mId: this.model.id }, this.depotTable)
  690. } else {
  691. this.requestDepotTableData(this.url.depotWithStock, { mId: 0 }, this.depotTable)
  692. }
  693. },
  694. requestMeTableData(){
  695. const params = {
  696. materialId: this.model.id,
  697. currentPage: this.meTable.pagination.current,
  698. pageSize: this.meTable.pagination.pageSize,
  699. }
  700. this.meTable.loading = true
  701. getAction(this.url.batchList, params)
  702. .then((res) => {
  703. this.meTable.dataSource = res.data.rows
  704. this.meTable.pagination.total = Number(res.data.total)
  705. })
  706. .finally(() => {
  707. this.meTable.loading = false
  708. })
  709. },
  710. /** 查询条码tab的数据 */
  711. requestProMbTableData(url, params, tab) {
  712. tab.loading = true
  713. getAction(url, params)
  714. .then((res) => {
  715. tab.dataSource = res.data
  716. console.log('tab.dataSource-----', tab.dataSource)
  717. })
  718. .finally(() => {
  719. tab.loading = false
  720. })
  721. },
  722. /** 查询仓库tab的数据 */
  723. requestDepotTableData(url, params, tab) {
  724. tab.loading = true
  725. getAction(url, params)
  726. .then((res) => {
  727. tab.dataSource = (res.data || []).map(item => {
  728. item.number = item.initStock
  729. return item
  730. })
  731. console.log('====================', res.data)
  732. })
  733. .finally(() => {
  734. tab.loading = false
  735. })
  736. },
  737. close() {
  738. this.$emit('close')
  739. this.visible = false
  740. this.modalStyle = ''
  741. this.meTable.dataSource = []
  742. this.meTable.pagination.current = 1
  743. this.getAllTable().then((editableTables) => {
  744. editableTables[0].initialize()
  745. editableTables[1].initialize()
  746. })
  747. },
  748. handleOk() {
  749. this.validateFields()
  750. },
  751. handleCancel() {
  752. this.close()
  753. },
  754. /** 触发表单验证 */
  755. validateFields() {
  756. this.getAllTable()
  757. .then((tables) => {
  758. console.log('tables========', tables)
  759. /** 一次性验证主表和所有的次表 */
  760. return validateFormAndTables(this.form, tables)
  761. })
  762. .then((allValues) => {
  763. console.log('allValues========',allValues)
  764. let formData = this.classifyIntoFormData(allValues)
  765. // 发起请求
  766. return this.requestAddOrEdit(formData)
  767. })
  768. .catch((e) => {
  769. this.$message.warning('请完善必填项!')
  770. if (e.error === VALIDATE_NO_PASSED) {
  771. // 如果有未通过表单验证的子表,就自动跳转到它所在的tab
  772. this.activeKey = e.index == null ? this.activeKey : (e.index + 2).toString()
  773. } else {
  774. console.error(e)
  775. }
  776. })
  777. },
  778. /** 整理成formData */
  779. classifyIntoFormData(allValues) {
  780. let materialMain = Object.assign(this.model, allValues.formValue)
  781. console.log('allValues.tablesValue[0].values',allValues.tablesValue[0].values)
  782. return {
  783. ...materialMain, // 展开
  784. stock: allValues.tablesValue[1].values,
  785. meList: allValues.tablesValue[0].values.map(item => {
  786. return {
  787. ...item,
  788. upcList: item.upcList?item.upcList:[],
  789. id: item.id.length > 19 ? null : item.id, // 后端接收不了大于19位id
  790. }
  791. }),
  792. }
  793. },
  794. /** 发起新增或修改的请求 */
  795. requestAddOrEdit(formData) {
  796. console.log('formData------------', formData)
  797. if (formData.meList.length === 0) {
  798. this.$message.warning('抱歉,必须填一条SKU信息!')
  799. return
  800. }
  801. //对最低和最高安全库存进行校验
  802. for (let i = 0; i < formData.stock.length; i++) {
  803. let depotStockObj = formData.stock[i]
  804. if (formData.enableSerialNumber === '1' && depotStockObj.initStock && depotStockObj.initStock - 0) {
  805. this.$message.warning('抱歉,序列号商品不能录入期初库存,建议进行入库单据录入!')
  806. return
  807. }
  808. if (formData.enableBatchNumber === '1' && depotStockObj.initStock && depotStockObj.initStock - 0) {
  809. this.$message.warning('抱歉,批号商品不能录入期初库存,建议进行入库单据录入!')
  810. return
  811. }
  812. if (depotStockObj.lowSafeStock && depotStockObj.highSafeStock) {
  813. if (depotStockObj.lowSafeStock - 0 > depotStockObj.highSafeStock - 0) {
  814. this.$message.warning('抱歉,' + depotStockObj.name + '的最低安全库存大于最高安全库存!')
  815. return
  816. }
  817. }
  818. }
  819. //图片校验
  820. if (this.fileList && this.fileList.length > 0) {
  821. formData.imgName = this.fileList
  822. let fileArr = this.fileList.split(',')
  823. if (fileArr.length > 4) {
  824. this.$message.warning('抱歉,商品图片不能超过4张!')
  825. return
  826. }
  827. } else {
  828. formData.imgName = ''
  829. }
  830. formData.meDeleteIdList = this.meDeleteIdList
  831. //接口调用
  832. let url = this.url.add,
  833. method = 'post'
  834. if (this.model.id) {
  835. url = this.url.edit
  836. method = 'put'
  837. }
  838. const that = this
  839. this.confirmLoading = true
  840. httpAction(url, formData, method)
  841. .then((res) => {
  842. if (res.code === 200) {
  843. that.$emit('ok')
  844. that.confirmLoading = false
  845. that.close()
  846. } else {
  847. that.$message.warning(res.data.message)
  848. that.confirmLoading = false
  849. }
  850. })
  851. .finally(() => {})
  852. },
  853. loadTreeData() {
  854. let that = this
  855. let params = {}
  856. params.id = ''
  857. queryMaterialCategoryTreeList(params).then((res) => {
  858. if (res) {
  859. that.categoryTree = []
  860. for (let i = 0; i < res.length; i++) {
  861. let temp = res[i]
  862. that.categoryTree.push(temp)
  863. }
  864. }
  865. })
  866. },
  867. loadUnitListData() {
  868. let that = this
  869. let params = {}
  870. getAction('/unit/getAllList', params).then((res) => {
  871. if (res) {
  872. that.unitList = res.data
  873. }
  874. })
  875. },
  876. batchSetStock(type) {
  877. this.$refs.stockModalForm.add(type)
  878. this.$refs.stockModalForm.disableSubmit = false
  879. },
  880. batchSetStockModalFormOk(stock, batchType) {
  881. let arr = this.depotTable.dataSource
  882. let depotTableData = []
  883. for (let i = 0; i < arr.length; i++) {
  884. let depotInfo = {
  885. name: arr[i].name,
  886. currentStock: arr[i].currentStock,
  887. lowSafeStock: arr[i].lowSafeStock,
  888. highSafeStock: arr[i].highSafeStock,
  889. }
  890. if (batchType === 'currentStock') {
  891. depotInfo.currentStock = stock - 0
  892. } else if (batchType === 'lowSafeStock') {
  893. depotInfo.lowSafeStock = stock - 0
  894. } else if (batchType === 'highSafeStock') {
  895. depotInfo.highSafeStock = stock - 0
  896. }
  897. if (arr[i].id) {
  898. depotInfo.id = arr[i].id
  899. }
  900. depotTableData.push(depotInfo)
  901. }
  902. this.depotTable.dataSource = depotTableData
  903. },
  904. loadParseMaterialProperty() {
  905. let mpList = Vue.ls.get('materialPropertyList')
  906. for (let i = 0; i < mpList.length; i++) {
  907. if (mpList[i].nativeName === '制造商') {
  908. this.mpShort.mfrs.name = mpList[i].anotherName
  909. this.mpShort.mfrs.enabled = mpList[i].enabled
  910. }
  911. if (mpList[i].nativeName === '自定义1') {
  912. this.mpShort.otherField1.name = mpList[i].anotherName
  913. this.mpShort.otherField1.enabled = mpList[i].enabled
  914. }
  915. if (mpList[i].nativeName === '自定义2') {
  916. this.mpShort.otherField2.name = mpList[i].anotherName
  917. this.mpShort.otherField2.enabled = mpList[i].enabled
  918. }
  919. if (mpList[i].nativeName === '自定义3') {
  920. this.mpShort.otherField3.name = mpList[i].anotherName
  921. this.mpShort.otherField3.enabled = mpList[i].enabled
  922. }
  923. }
  924. },
  925. handleNameChange(e) {
  926. let that = this
  927. if (e.target.value) {
  928. if (this.setTimeFlag != null) {
  929. clearTimeout(this.setTimeFlag)
  930. }
  931. this.setTimeFlag = setTimeout(() => {
  932. changeNameToPinYin({ name: e.target.value }).then((res) => {
  933. if (res && res.code === 200) {
  934. that.form.setFieldsValue({ mnemonic: res.data })
  935. } else {
  936. that.$message.warning(res.data)
  937. }
  938. })
  939. }, 500)
  940. } else {
  941. that.form.setFieldsValue({ mnemonic: '' })
  942. }
  943. },
  944. handleMeTableChange(pagination) {
  945. if (pagination && pagination.current) {
  946. this.meTable.pagination = pagination
  947. }
  948. this.requestMeTableData()
  949. },
  950. editMaterialUnitModal({value,index,allValues,rowId}){
  951. console.log('allValues====',allValues)
  952. console.log('value====',value)
  953. const obj = allValues.inputValues[index]
  954. let unitList = [
  955. {
  956. name: value,
  957. ratio: 1,
  958. }
  959. ]
  960. if(obj.unitList&& obj.unitList.length > 0){
  961. unitList = obj.unitList
  962. }
  963. this.$refs.materialUnitModal.edit({
  964. unitList,
  965. rowId: rowId,
  966. })
  967. this.$refs.materialUnitModal.unitOpts = this.unitList
  968. },
  969. editMaterialUpcModal({value,rowId}) {
  970. let upcList = [
  971. {
  972. upc: ''
  973. }
  974. ]
  975. if (value&&value.length > 0) {
  976. upcList = value
  977. }
  978. this.$refs.materialUpcModal.edit({
  979. upcList: upcList,
  980. rowId: rowId,
  981. })
  982. },
  983. upcOk({upcList,rowId}) {
  984. const target = this.$refs.editableProBarCodeTable
  985. target.setValues([{ rowKey: rowId, values: { upcList: upcList } }])
  986. },
  987. unitOk({unitList,rowId}) {
  988. const target = this.$refs.editableProBarCodeTable
  989. target.setValues([{ rowKey: rowId, values: { commodityUnit: unitList[0].name, unitList: unitList } }])
  990. },
  991. },
  992. }
  993. </script>
  994. <style lang="less" scoped>
  995. .input-table {
  996. max-width: 100%;
  997. min-width: 1200px;
  998. }
  999. .tag-info {
  1000. font-size: 14px;
  1001. height: 32px;
  1002. line-height: 32px;
  1003. width: 100%;
  1004. padding: 0px 11px;
  1005. color: #bbb;
  1006. background-color: #ffffff;
  1007. }
  1008. /deep/ .ant-table td { white-space: nowrap; }
  1009. .sp-btn{
  1010. display: inline-block;
  1011. white-space: nowrap;
  1012. box-sizing: border-box;
  1013. padding: 0 5px;
  1014. font-size: 12px;
  1015. cursor: pointer;
  1016. color: #1890FF;
  1017. }
  1018. </style>