MaterialModal.vue 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451
  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">
  22. <a-tab-pane key="1" tab="基本信息" id="materialHeadModal" forceRender>
  23. <a-row class="form-row" :gutter="24">
  24. <a-col :md="6" :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 :md="6" :sm="24">
  41. <a-form-item
  42. :labelCol="labelCol"
  43. :wrapperCol="wrapperCol"
  44. label="规格"
  45. data-step="2"
  46. data-title="规格"
  47. data-intro="规格不必填,比如:10克"
  48. >
  49. <a-input placeholder="请输入规格" v-decorator.trim="['standard', validatorRules.standard]" />
  50. </a-form-item>
  51. </a-col>
  52. <a-col :md="6" :sm="24">
  53. <a-form-item
  54. :labelCol="labelCol"
  55. :wrapperCol="wrapperCol"
  56. label="型号"
  57. data-step="3"
  58. data-title="型号"
  59. data-intro="型号是比规格更小的属性,比如:RX-01"
  60. >
  61. <a-input placeholder="请输入型号" v-decorator.trim="['model', validatorRules.model]" />
  62. </a-form-item>
  63. </a-col>
  64. <a-col :md="6" :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. 比如牛奶有瓶和箱两种单位,12瓶=1箱,这就构成了多单位,多单位中有个换算比例"
  73. >
  74. <a-row class="form-row" :gutter="24">
  75. <a-col :lg="15" :md="15" :sm="24" style="padding: 0px 0px 0px 12px">
  76. <a-input
  77. placeholder="输入单位"
  78. v-if="!unitChecked"
  79. v-decorator.trim="['unit', validatorRules.unit]"
  80. @change="onlyUnitOnChange"
  81. />
  82. <a-select
  83. :value="unitList"
  84. placeholder="选择多单位"
  85. v-decorator="['unitId', validatorRules.unitId]"
  86. @change="manyUnitOnChange"
  87. showSearch
  88. optionFilterProp="children"
  89. v-if="unitChecked"
  90. :dropdownMatchSelectWidth="false"
  91. >
  92. <div slot="dropdownRender" slot-scope="menu">
  93. <v-nodes :vnodes="menu" />
  94. <a-divider style="margin: 4px 0" />
  95. <div
  96. style="padding: 4px 8px; cursor: pointer"
  97. @mousedown="(e) => e.preventDefault()"
  98. @click="addUnit"
  99. >
  100. <a-icon type="plus" /> 新增多单位
  101. </div>
  102. </div>
  103. <a-select-option v-for="(item, index) in unitList" :key="index" :value="item.id">
  104. {{ item.name }}
  105. </a-select-option>
  106. </a-select>
  107. </a-col>
  108. <a-col :lg="9" :md="9" :sm="24" style="padding: 0px; text-align: center">
  109. <a-checkbox :checked="unitChecked" @change="unitOnChange">多单位</a-checkbox>
  110. </a-col>
  111. </a-row>
  112. </a-form-item>
  113. </a-col>
  114. </a-row>
  115. <a-row class="form-row" :gutter="24">
  116. <a-col :md="6" :sm="24" v-if="!model.id">
  117. <a-form-item
  118. :labelCol="labelCol"
  119. :wrapperCol="wrapperCol"
  120. label="多属性"
  121. data-step="5"
  122. data-title="多属性"
  123. data-intro="多属性是针对的sku商品(比如服装、鞋帽行业),此处开关如果启用就可以在下方进行多sku的配置,配置具体的颜色、尺码之类的组合"
  124. >
  125. <a-tooltip title="多属性针对服装、鞋帽等行业,需要先录入单位才能激活此处输入框">
  126. <a-tag class="tag-info" v-if="!manySkuStatus">需要先录入单位才能激活</a-tag>
  127. <a-select
  128. mode="multiple"
  129. v-decorator="['manySku']"
  130. showSearch
  131. optionFilterProp="children"
  132. placeholder="请选择多属性(可多选)"
  133. @change="onManySkuChange"
  134. v-show="manySkuStatus"
  135. >
  136. <a-select-option
  137. v-for="(item, index) in materialAttributeList"
  138. :key="index"
  139. :value="item.value"
  140. :disabled="item.disabled"
  141. >
  142. {{ item.name }}
  143. </a-select-option>
  144. </a-select>
  145. </a-tooltip>
  146. </a-form-item>
  147. </a-col>
  148. <a-col :md="6" :sm="24">
  149. <a-form-item
  150. :labelCol="labelCol"
  151. :wrapperCol="wrapperCol"
  152. label="颜色"
  153. data-step="6"
  154. data-title="颜色"
  155. data-intro="请填写商品的颜色,如果是多属性商品可以不填(下面有多属性开关)"
  156. >
  157. <a-input placeholder="请输入颜色" v-decorator.trim="['color']" />
  158. </a-form-item>
  159. </a-col>
  160. <a-col :md="6" :sm="24">
  161. <a-form-item
  162. :labelCol="labelCol"
  163. :wrapperCol="wrapperCol"
  164. label="品牌"
  165. data-step="7"
  166. data-title="品牌"
  167. data-intro="请填写商品的品牌,方便区别不同品牌的商品"
  168. >
  169. <a-input placeholder="请输入品牌" v-decorator.trim="['brand']" />
  170. </a-form-item>
  171. </a-col>
  172. <a-col :md="6" :sm="24">
  173. <a-form-item
  174. :labelCol="labelCol"
  175. :wrapperCol="wrapperCol"
  176. label="助记码"
  177. data-step="8"
  178. data-title="助记码"
  179. data-intro="助记码自动生成,助记码是商品名称的首字母缩写"
  180. >
  181. <a-input placeholder="" v-decorator.trim="['mnemonic']" :readOnly="true" />
  182. </a-form-item>
  183. </a-col>
  184. </a-row>
  185. <a-row class="form-row" :gutter="24">
  186. <a-col :md="6" :sm="24">
  187. <a-form-item
  188. :labelCol="labelCol"
  189. :wrapperCol="wrapperCol"
  190. label="类别"
  191. data-step="9"
  192. data-title="类别"
  193. data-intro="类别需要在【商品类别】页面进行录入,录入之后在此处进行调用"
  194. >
  195. <a-tree-select
  196. style="width: 100%"
  197. :dropdownStyle="{ maxHeight: '200px', overflow: 'auto' }"
  198. allow-clear
  199. :treeData="categoryTree"
  200. v-decorator="['categoryId', validatorRules.categoryId]"
  201. placeholder="请选择类别"
  202. >
  203. </a-tree-select>
  204. </a-form-item>
  205. </a-col>
  206. <a-col :md="6" :sm="24">
  207. <a-form-item
  208. :labelCol="labelCol"
  209. :wrapperCol="wrapperCol"
  210. label="基础重量"
  211. data-step="10"
  212. data-title="基础重量"
  213. data-intro="请填写基本单位对应的重量,用于计算按重量分摊费用时单据中各行商品分摊的费用成本"
  214. >
  215. <a-input-number style="width: 100%" placeholder="请输入基础重量(kg)" v-decorator.trim="['weight']" />
  216. </a-form-item>
  217. </a-col>
  218. <a-col :md="6" :sm="24">
  219. <a-form-item
  220. :labelCol="labelCol"
  221. :wrapperCol="wrapperCol"
  222. label="序列号"
  223. data-step="11"
  224. data-title="序列号"
  225. data-intro="此处是商品的序列号开关,如果选择了有,则在采购入库单据需要录入该商品的序列号,在销售出库单据需要选择该商品的序列号进行出库"
  226. >
  227. <a-tooltip title="如果选择为有,则在采购入库单需要录入该商品的序列号">
  228. <a-select placeholder="有无序列号" v-decorator="['enableSerialNumber']">
  229. <a-select-option value="1">有</a-select-option>
  230. <a-select-option value="0">无</a-select-option>
  231. </a-select>
  232. </a-tooltip>
  233. </a-form-item>
  234. </a-col>
  235. <a-col :md="6" :sm="24">
  236. <a-form-item
  237. :labelCol="labelCol"
  238. :wrapperCol="wrapperCol"
  239. label="系统SKU"
  240. data-step="12"
  241. data-title="系统SKU"
  242. data-intro="系统SKU"
  243. >
  244. <a-input placeholder="提交后自动生成" disabled v-decorator="['systemSku']" />
  245. </a-form-item>
  246. </a-col>
  247. <a-col :md="6" :sm="24">
  248. <a-form-item
  249. :labelCol="labelCol"
  250. :wrapperCol="wrapperCol"
  251. label="无动销提醒周期"
  252. data-step="13"
  253. data-title="无动销提醒周期"
  254. data-intro="无动销提醒周期"
  255. >
  256. <a-tooltip title="无动销提醒周期">
  257. <a-select placeholder="无动销提醒周期" v-decorator="['movingPinReminderCycle']">
  258. <a-select-option value="7">一周</a-select-option>
  259. <a-select-option value="14">两周</a-select-option>
  260. <a-select-option value="30">一个月</a-select-option>
  261. <a-select-option value="90">一季度</a-select-option>
  262. </a-select>
  263. </a-tooltip>
  264. </a-form-item>
  265. </a-col>
  266. </a-row>
  267. <a-row class="form-row" :gutter="24">
  268. <a-col :md="12" :sm="24" v-if="manySkuSelected >= 1">
  269. <a-form-item
  270. :labelCol="{ xs: { span: 24 }, sm: { span: 4 } }"
  271. :wrapperCol="{ xs: { span: 24 }, sm: { span: 20 } }"
  272. :label="skuOneTitle"
  273. >
  274. <a-select
  275. mode="multiple"
  276. v-decorator="['skuOne']"
  277. showSearch
  278. optionFilterProp="children"
  279. placeholder="请选择(可多选)"
  280. @select="onSkuChange"
  281. @deselect="onSkuOneDeSelect"
  282. >
  283. <a-select-option v-for="(item, index) in skuOneList" :key="index" :value="item.value">
  284. {{ item.name }}
  285. </a-select-option>
  286. </a-select>
  287. </a-form-item>
  288. </a-col>
  289. <a-col :md="12" :sm="24" v-if="manySkuSelected >= 2">
  290. <a-form-item
  291. :labelCol="{ xs: { span: 24 }, sm: { span: 4 } }"
  292. :wrapperCol="{ xs: { span: 24 }, sm: { span: 20 } }"
  293. :label="skuTwoTitle"
  294. >
  295. <a-select
  296. mode="multiple"
  297. v-decorator="['skuTwo']"
  298. showSearch
  299. optionFilterProp="children"
  300. placeholder="请选择(可多选)"
  301. @select="onSkuChange"
  302. @deselect="onSkuTwoDeSelect"
  303. >
  304. <a-select-option v-for="(item, index) in skuTwoList" :key="index" :value="item.value">
  305. {{ item.name }}
  306. </a-select-option>
  307. </a-select>
  308. </a-form-item>
  309. </a-col>
  310. <a-col :md="12" :sm="24" v-if="manySkuSelected >= 3">
  311. <a-form-item
  312. :labelCol="{ xs: { span: 24 }, sm: { span: 4 } }"
  313. :wrapperCol="{ xs: { span: 24 }, sm: { span: 20 } }"
  314. :label="skuThreeTitle"
  315. >
  316. <a-select
  317. mode="multiple"
  318. v-decorator="['skuThree']"
  319. showSearch
  320. optionFilterProp="children"
  321. placeholder="请选择(可多选)"
  322. @select="onSkuChange"
  323. @deselect="onSkuThreeDeSelect"
  324. >
  325. <a-select-option v-for="(item, index) in skuThreeList" :key="index" :value="item.value">
  326. {{ item.name }}
  327. </a-select-option>
  328. </a-select>
  329. </a-form-item>
  330. </a-col>
  331. </a-row>
  332. <div style="margin-top: 8px" id="materialDetailModal">
  333. <a-table
  334. size="middle"
  335. rowKey="id"
  336. :loading="meTable.loading"
  337. :columns="meTable.columns"
  338. :dataSource="meTable.dataSource"
  339. :pagination="meTable.pagination"
  340. :scroll="meTable.scroll"
  341. bordered
  342. @change="handleMeTableChange"
  343. >
  344. <template slot="depotId" slot-scope="text, record">
  345. {{ formatDepotName(record.depotId) }}
  346. </template>
  347. </a-table>
  348. </div>
  349. <a-row class="form-row" :gutter="24">
  350. <a-col :lg="24" :md="24" :sm="24">
  351. <a-form-item :labelCol="labelCol" :wrapperCol="{ xs: { span: 24 }, sm: { span: 24 } }" label="">
  352. <a-textarea :rows="1" placeholder="请输入备注" v-decorator="['remark']" style="margin-top: 8px" />
  353. </a-form-item>
  354. </a-col>
  355. </a-row>
  356. </a-tab-pane>
  357. <a-tab-pane key="2" tab="商品条码" forceRender>
  358. <j-editable-table
  359. ref="editableProBarCodeTable"
  360. :loading="mbTable.loading"
  361. :columns="mbTable.columns"
  362. :dataSource="mbTable.dataSource"
  363. :height="300"
  364. :minWidth="1000"
  365. :maxHeight="300"
  366. :rowNumber="false"
  367. :rowSelection="true"
  368. :actionButton="true"
  369. @added="onAdded"
  370. @deleted="onDeleted"
  371. >
  372. <template #ratio="{ handleChange, value }">
  373. <a-select
  374. v-if="unitChecked"
  375. placeholder="请选择"
  376. :dropdownMatchSelectWidth="false"
  377. showSearch
  378. :value="value"
  379. @change="($event) => handleChange($event)"
  380. >
  381. <a-select-option v-for="(item, index) in barCodeUnitList" :key="index" :value="item.ratio">
  382. {{ item.name }}
  383. </a-select-option>
  384. </a-select>
  385. <a-input v-else :value="value" disabled @change="($event) => handleChange($event)"></a-input>
  386. </template>
  387. </j-editable-table>
  388. </a-tab-pane>
  389. <a-tab-pane key="3" tab="扩展信息" forceRender>
  390. <a-row v-if="mpShort.otherField1.enabled" class="form-row" :gutter="24">
  391. <a-col :lg="6" :md="6" :sm="6">
  392. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="mpShort.otherField1.name">
  393. <a-input v-decorator.trim="['otherField1']" />
  394. </a-form-item>
  395. </a-col>
  396. </a-row>
  397. <a-row v-if="mpShort.otherField2.enabled" class="form-row" :gutter="24">
  398. <a-col :lg="6" :md="6" :sm="6">
  399. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="mpShort.otherField2.name">
  400. <a-input v-decorator.trim="['otherField2']" />
  401. </a-form-item>
  402. </a-col>
  403. </a-row>
  404. <a-row v-if="mpShort.otherField3.enabled" class="form-row" :gutter="24">
  405. <a-col :lg="6" :md="6" :sm="6">
  406. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="mpShort.otherField3.name">
  407. <a-input v-decorator.trim="['otherField3']" />
  408. </a-form-item>
  409. </a-col>
  410. </a-row>
  411. </a-tab-pane>
  412. <a-tab-pane key="4" tab="库存数量" forceRender>
  413. <j-editable-table
  414. ref="editableDepotTable"
  415. :loading="depotTable.loading"
  416. :columns="depotTable.columns"
  417. :dataSource="depotTable.dataSource"
  418. :minWidth="1000"
  419. :maxHeight="300"
  420. :rowNumber="true"
  421. :rowSelection="false"
  422. :actionButton="false"
  423. >
  424. <template #buttonAfter>
  425. <!-- <a-button style="margin: 0px 0px 8px 0px" @click="batchSetStock('currentStock')">期初库存-批量</a-button> -->
  426. <a-button style="margin: 0px 0px 8px 0px" @click="batchSetStock('lowSafeStock')">最低安全库存-批量</a-button>
  427. <a-button style="margin-left: 8px" @click="batchSetStock('highSafeStock')">最高安全库存-批量</a-button>
  428. </template>
  429. </j-editable-table>
  430. <!-- 表单区域 -->
  431. <batch-set-stock-modal ref="stockModalForm" @ok="batchSetStockModalFormOk"></batch-set-stock-modal>
  432. </a-tab-pane>
  433. <a-tab-pane key="5" tab="图片信息" forceRender>
  434. <a-row class="form-row" :gutter="24" style="padding-top: 20px">
  435. <a-col :lg="18" :md="18" :sm="24">
  436. <a-form-item
  437. :labelCol="{ xs: { span: 24 }, sm: { span: 3 } }"
  438. :wrapperCol="{ xs: { span: 24 }, sm: { span: 20 } }"
  439. label="图片信息"
  440. >
  441. <j-image-upload v-model="fileList" bizPath="material" text="上传" isMultiple></j-image-upload>
  442. </a-form-item>
  443. </a-col>
  444. <a-col :lg="6" :md="6" :sm="24"></a-col>
  445. </a-row>
  446. <a-row class="form-row" :gutter="24">
  447. <a-col :lg="18" :md="18" :sm="24">
  448. <a-form-item
  449. :labelCol="{ xs: { span: 24 }, sm: { span: 3 } }"
  450. :wrapperCol="{ xs: { span: 24 }, sm: { span: 20 } }"
  451. label="上传提示"
  452. >
  453. 图片最多4张,且单张大小不超过1M
  454. </a-form-item>
  455. </a-col>
  456. <a-col :lg="6" :md="6" :sm="24"></a-col>
  457. </a-row>
  458. </a-tab-pane>
  459. </a-tabs>
  460. </a-form>
  461. </a-spin>
  462. <!-- 供应商modal -->
  463. <vendor-modal ref="vendorModalForm" @ok="vendorModalFormOk"></vendor-modal>
  464. <!-- 仓库modal -->
  465. <depot-modal ref="depotModalForm" @ok="depotModalFormOk"></depot-modal>
  466. <unit-modal ref="unitModalForm" @ok="unitModalFormOk"></unit-modal>
  467. </j-modal>
  468. </template>
  469. <script>
  470. import pick from 'lodash.pick'
  471. import BatchSetPriceModal from './BatchSetPriceModal'
  472. import BatchSetStockModal from './BatchSetStockModal'
  473. import UnitModal from '../../system/modules/UnitModal'
  474. import VendorModal from '@/views//system/modules/VendorModal'
  475. import DepotModal from '@/views//system/modules/DepotModal'
  476. import JEditableTable from '@/components/jeecg/JEditableTable'
  477. import { FormTypes, getRefPromise, VALIDATE_NO_PASSED, validateFormAndTables } from '@/utils/JEditableTableUtil'
  478. import {
  479. checkMaterial,
  480. checkMaterialBarCode,
  481. getMaterialAttributeNameList,
  482. getMaterialAttributeValueListById,
  483. getMaxBarCode,
  484. queryMaterialCategoryTreeList,
  485. changeNameToPinYin,
  486. } from '@/api/api'
  487. import { removeByVal, autoJumpNextInput, handleIntroJs } from '@/utils/util'
  488. import { getAction, httpAction } from '@/api/manage'
  489. import JImageUpload from '@/components/jeecg/JImageUpload'
  490. import JDate from '@/components/jeecg/JDate'
  491. import Vue from 'vue'
  492. import { MaterialModalMixins } from '../mixins/MaterialModalMixins'
  493. import { mixinDevice } from '@/utils/mixin.js'
  494. export default {
  495. name: 'MaterialModal',
  496. mixins: [MaterialModalMixins,mixinDevice],
  497. components: {
  498. BatchSetPriceModal,
  499. BatchSetStockModal,
  500. UnitModal,
  501. VendorModal,
  502. DepotModal,
  503. JImageUpload,
  504. JDate,
  505. JEditableTable,
  506. VNodes: {
  507. functional: true,
  508. render: (h, ctx) => ctx.props.vnodes,
  509. },
  510. },
  511. data() {
  512. return {
  513. title: '操作',
  514. width: '1300px',
  515. visible: false,
  516. modalStyle: '',
  517. categoryTree: [],
  518. unitList: [],
  519. depotList: [],
  520. fileList: [],
  521. unitStatus: false,
  522. manyUnitStatus: true,
  523. unitChecked: false,
  524. manySkuStatus: false,
  525. switchDisabled: false, //开关的启用状态
  526. barCodeSwitch: false, //生成条码开关
  527. maxBarCodeInfo: '', //最大条码
  528. meDeleteIdList: [], //删除条码信息的id数组
  529. prefixNo: 'material',
  530. materialAttributeList: [],
  531. skuOneTitle: '属性1',
  532. skuTwoTitle: '属性2',
  533. skuThreeTitle: '属性3',
  534. skuOneList: [],
  535. skuTwoList: [],
  536. skuThreeList: [],
  537. manySkuSelected: 0,
  538. model: {},
  539. showOkFlag: true,
  540. setTimeFlag: null,
  541. labelCol: {
  542. xs: { span: 24 },
  543. sm: { span: 8 },
  544. },
  545. wrapperCol: {
  546. xs: { span: 24 },
  547. sm: { span: 16 },
  548. },
  549. mpShort: {
  550. mfrs: {},
  551. otherField1: {},
  552. otherField2: {},
  553. otherField3: {},
  554. },
  555. meTable: {
  556. loading: false,
  557. dataSource: [],
  558. columns: [
  559. {
  560. title: '批次号',
  561. dataIndex: 'batchNumber',
  562. },
  563. {
  564. title: '单位',
  565. dataIndex: 'commodityUnit',
  566. },
  567. {
  568. title: '采购价',
  569. dataIndex: 'purchaseDecimal',
  570. },
  571. {
  572. title: '零售价',
  573. dataIndex: 'commodityDecimal',
  574. },
  575. {
  576. title: '销售价',
  577. dataIndex: 'wholesaleDecimal',
  578. },
  579. {
  580. title: '最低售价',
  581. dataIndex: 'lowDecimal',
  582. },
  583. {
  584. title: '生产日期',
  585. dataIndex: 'productionDate',
  586. },
  587. {
  588. title: '保质期(天)',
  589. dataIndex: 'expiryNum',
  590. },
  591. {
  592. title: '供应商',
  593. dataIndex: 'supplierId',
  594. },
  595. {
  596. title: '库存(最小单位)',
  597. dataIndex: 'inventory',
  598. },
  599. {
  600. title: '仓库名称',
  601. dataIndex: 'depotId',
  602. scopedSlots: { customRender: 'depotId' }
  603. },
  604. ],
  605. pagination: {
  606. current: 1,
  607. pageSize: 10,
  608. pageSizeOptions: ['10', '20', '30', '50', '100'],
  609. showTotal: (total, range) => {
  610. return range[0] + '-' + range[1] + ' 共' + total + '条'
  611. },
  612. showQuickJumper: true,
  613. showSizeChanger: true,
  614. total: 0,
  615. },
  616. scroll: {}
  617. },
  618. mbTable:{
  619. loading: false,
  620. dataSource: [],
  621. columns: [
  622. {
  623. title: '商品条码',
  624. key: 'barCode',
  625. width: '15%',
  626. type: FormTypes.input,
  627. placeholder: '请输入${title}',
  628. },
  629. {
  630. title: '单位',
  631. key: 'ratio',
  632. width: '15%',
  633. type: FormTypes.slot,
  634. placeholder: '请输入${title}',
  635. },
  636. ]
  637. },
  638. depotTable: {
  639. loading: false,
  640. dataSource: [],
  641. columns: [
  642. {
  643. title: '仓库',
  644. key: 'name',
  645. width: '15%',
  646. type: FormTypes.normal,
  647. },
  648. {
  649. title: '库存总数量',
  650. key: 'currentStock',
  651. width: '15%',
  652. type: FormTypes.inputNumber,
  653. defaultValue: '',
  654. disabled: true,
  655. placeholder: '请输入${title}',
  656. },
  657. {
  658. title: '最低安全库存数量',
  659. key: 'lowSafeStock',
  660. width: '15%',
  661. type: FormTypes.inputNumber,
  662. defaultValue: '',
  663. placeholder: '请输入${title}',
  664. },
  665. {
  666. title: '最高安全库存数量',
  667. key: 'highSafeStock',
  668. width: '15%',
  669. type: FormTypes.inputNumber,
  670. defaultValue: '',
  671. placeholder: '请输入${title}',
  672. },
  673. {
  674. title: '仓位货架',
  675. key: 'position',
  676. width: '9%',
  677. type: FormTypes.input,
  678. defaultValue: '',
  679. placeholder: '请输入${title}',
  680. },
  681. ],
  682. },
  683. confirmLoading: false,
  684. form: this.$form.createForm(this),
  685. validatorRules: {
  686. name: {
  687. rules: [
  688. { required: true, message: '请输入名称!' },
  689. { max: 100, message: '长度请小于100个字符', trigger: 'blur' },
  690. ],
  691. },
  692. standard: {
  693. rules: [{ max: 100, message: '长度请小于100个字符', trigger: 'blur' }],
  694. },
  695. categoryId: {
  696. rules: [{ required: true, message: '请选择类别!' }],
  697. },
  698. model: {
  699. rules: [{ max: 100, message: '长度请小于100个字符', trigger: 'blur' }],
  700. },
  701. unit: {
  702. rules: [{ required: true, message: '请输入单位!' }],
  703. },
  704. unitId: {
  705. rules: [{ required: true, message: '请选择多单位!' }],
  706. },
  707. },
  708. url: {
  709. add: '/material/add',
  710. edit: '/material/update',
  711. materialsExtendList: '/materialsExtend/getDetailList',
  712. depotWithStock: '/depot/getAllListWithStock',
  713. batchList: '/materialBatch/getDetailList',
  714. },
  715. barCodeUnitList: [],
  716. }
  717. },
  718. created() {
  719. this.loadParseMaterialProperty()
  720. let realScreenWidth = window.screen.width
  721. this.width = realScreenWidth < 1500 ? '1200px' : '1400px'
  722. this.initSelectOpts()
  723. },
  724. mounted() {
  725. document.getElementById(this.prefixNo).addEventListener('keydown', this.handleOkKey)
  726. },
  727. beforeDestroy() {
  728. document.getElementById(this.prefixNo).removeEventListener('keydown', this.handleOkKey)
  729. },
  730. methods: {
  731. formatDepotName(id){
  732. const target = this.depotList.find(item => item.value == id)
  733. return target ? target.title : ''
  734. },
  735. // 快捷键
  736. handleOkKey(e) {
  737. const key = window.event.keyCode ? window.event.keyCode : window.event.which
  738. if (key === 83 && e.ctrlKey) {
  739. //保存 CTRL+S
  740. this.handleOk()
  741. e.preventDefault()
  742. }
  743. },
  744. // 获取所有的editableTable实例
  745. getAllTable() {
  746. return Promise.all([getRefPromise(this, 'editableProBarCodeTable'),getRefPromise(this, 'editableDepotTable')])
  747. },
  748. add() {
  749. // 默认新增一条数据
  750. this.getAllTable().then((editableTables) => {
  751. editableTables[0].add()
  752. })
  753. this.edit({})
  754. this.$nextTick(() => {
  755. handleIntroJs('material', 11)
  756. })
  757. },
  758. async edit(record) {
  759. this.form.resetFields()
  760. this.model = Object.assign({}, record)
  761. this.activeKey = '1'
  762. this.manySkuSelected = 0
  763. this.barCodeSwitch = false
  764. this.manySkuStatus = false
  765. this.maxBarCodeInfo = ''
  766. this.visible = true
  767. this.meDeleteIdList = []
  768. this.modalStyle = 'top:20px;height: 95%;'
  769. if (JSON.stringify(record) === '{}') {
  770. this.fileList = []
  771. } else {
  772. setTimeout(() => {
  773. this.fileList = record.imgName
  774. }, 5)
  775. }
  776. this.$nextTick(() => {
  777. this.form.setFieldsValue(
  778. pick(
  779. this.model,
  780. 'name',
  781. 'standard',
  782. 'unit',
  783. 'unitId',
  784. 'model',
  785. 'color',
  786. 'brand',
  787. 'mnemonic',
  788. 'categoryId',
  789. 'enableSerialNumber',
  790. 'movingPinReminderCycle',
  791. 'systemSku',
  792. 'weight',
  793. 'remark',
  794. 'otherField1',
  795. 'otherField2',
  796. 'otherField3'
  797. )
  798. )
  799. autoJumpNextInput('materialHeadModal')
  800. autoJumpNextInput('materialDetailModal')
  801. })
  802. this.initMaterialAttribute()
  803. this.loadTreeData()
  804. this.loadUnitListData()
  805. // 加载子表数据
  806. if (this.model.id) {
  807. //禁用多属性开关
  808. this.switchDisabled = true
  809. // 判断是否是多单位
  810. if (this.model.unit) {
  811. this.unitChecked = false
  812. this.unitStatus = false
  813. this.manyUnitStatus = true
  814. } else {
  815. this.unitChecked = true
  816. this.unitStatus = true
  817. this.manyUnitStatus = false
  818. console.log('多单位-----', record)
  819. await this.getUnitListByID(record.unitId)
  820. }
  821. let params = { materialId: this.model.id }
  822. this.requestProMbTableData(this.url.materialsExtendList, params, this.mbTable)
  823. this.requestMeTableData()
  824. this.requestDepotTableData(this.url.depotWithStock, { mId: this.model.id }, this.depotTable)
  825. } else {
  826. this.switchDisabled = false
  827. this.requestDepotTableData(this.url.depotWithStock, { mId: 0 }, this.depotTable)
  828. }
  829. },
  830. requestMeTableData(){
  831. const params = {
  832. materialId: this.model.id,
  833. currentPage: this.meTable.pagination.current,
  834. pageSize: this.meTable.pagination.pageSize,
  835. }
  836. this.meTable.loading = true
  837. getAction(this.url.batchList, params)
  838. .then((res) => {
  839. this.meTable.dataSource = res.data.rows
  840. this.meTable.pagination.total = Number(res.data.total)
  841. })
  842. .finally(() => {
  843. this.meTable.loading = false
  844. })
  845. },
  846. /** 查询条码tab的数据 */
  847. requestProMbTableData(url, params, tab) {
  848. tab.loading = true
  849. getAction(url, params)
  850. .then((res) => {
  851. const rows = (res.data.rows || []).map(item => {
  852. if(this.unitChecked){
  853. if(item.ratio){
  854. const target = this.barCodeUnitList.find(unit => unit.ratio == item.ratio)
  855. item.commodityUnit = target?target.name : ''
  856. }
  857. }else{
  858. item.ratio = item.commodityUnit // 回显单位
  859. }
  860. return item
  861. })
  862. tab.dataSource = rows
  863. console.log('tab.dataSource-----', tab.dataSource)
  864. })
  865. .finally(() => {
  866. tab.loading = false
  867. })
  868. },
  869. /** 查询仓库tab的数据 */
  870. requestDepotTableData(url, params, tab) {
  871. tab.loading = true
  872. getAction(url, params)
  873. .then((res) => {
  874. tab.dataSource = res.data || []
  875. console.log('====================', res.data)
  876. })
  877. .finally(() => {
  878. tab.loading = false
  879. })
  880. },
  881. close() {
  882. this.$emit('close')
  883. this.visible = false
  884. this.modalStyle = ''
  885. this.unitStatus = false
  886. this.manyUnitStatus = true
  887. this.unitChecked = false
  888. this.getAllTable().then((editableTables) => {
  889. editableTables[0].initialize()
  890. editableTables[1].initialize()
  891. })
  892. },
  893. handleOk() {
  894. this.validateFields()
  895. },
  896. handleCancel() {
  897. this.close()
  898. },
  899. /** 触发表单验证 */
  900. validateFields() {
  901. this.getAllTable()
  902. .then((tables) => {
  903. console.log('tables========', tables)
  904. /** 一次性验证主表和所有的次表 */
  905. return validateFormAndTables(this.form, tables)
  906. })
  907. .then((allValues) => {
  908. console.log('allValues========',allValues)
  909. let formData = this.classifyIntoFormData(allValues)
  910. formData.sortList = []
  911. if (formData.unit === undefined) {
  912. formData.unit = ''
  913. }
  914. if (formData.unitId === undefined) {
  915. formData.unitId = ''
  916. }
  917. if (this.unitChecked) {
  918. formData.unit = ''
  919. } else {
  920. formData.unitId = ''
  921. }
  922. // 发起请求
  923. return this.requestAddOrEdit(formData)
  924. })
  925. .catch((e) => {
  926. if (e.error === VALIDATE_NO_PASSED) {
  927. // 如果有未通过表单验证的子表,就自动跳转到它所在的tab
  928. this.activeKey = e.index == null ? this.activeKey : (e.index + 1).toString()
  929. } else {
  930. console.error(e)
  931. }
  932. })
  933. },
  934. async getUnitListByID(id){
  935. await getAction('/unit/getUnitListByID', { id}).then(res => {
  936. this.barCodeUnitList = res.data || []
  937. })
  938. },
  939. /** 整理成formData */
  940. classifyIntoFormData(allValues) {
  941. const that = this
  942. let materialMain = Object.assign(this.model, allValues.formValue)
  943. console.log('materialMain------mbList------', allValues.tablesValue[0].values)
  944. return {
  945. ...materialMain, // 展开
  946. meList:[],
  947. stock: allValues.tablesValue[1].values,
  948. mbList: allValues.tablesValue[0].values.map(item => {
  949. let commodityUnit = ''
  950. // 多单位
  951. if(that.unitChecked){
  952. const target = that.barCodeUnitList.find(unit => unit.ratio == item.ratio)
  953. commodityUnit = target?target.name : ''
  954. }else{
  955. commodityUnit = item.ratio
  956. item.ratio = null
  957. }
  958. return {
  959. barCode: item.barCode,
  960. ratio: item.ratio,
  961. commodityUnit: commodityUnit,
  962. id: item.id.length > 19 ? null : item.id, // 后端接收不了大于19位id
  963. }
  964. }),
  965. }
  966. },
  967. /** 发起新增或修改的请求 */
  968. requestAddOrEdit(formData) {
  969. console.log('formData------------', formData)
  970. if (formData.mbList.length === 0) {
  971. this.$message.warning('抱歉,请输入条码信息!')
  972. return
  973. }
  974. for (const item of formData.mbList){
  975. if(item.barCode === ''){
  976. this.$message.warning('抱歉,请输入条码信息!')
  977. return
  978. }
  979. if(item.ratio === ''){
  980. this.$message.warning('抱歉,条码信息中列表单位不能为空!')
  981. return
  982. }
  983. }
  984. if (formData.enableSerialNumber === '1' && formData.enableBatchNumber === '1') {
  985. this.$message.warning('抱歉,序列号和批号只能选择一项!')
  986. return
  987. }
  988. //校验商品是否存在,通过校验商品的名称、型号、规格、颜色、单位、制造商等
  989. let param = {
  990. id: this.model.id ? this.model.id : 0,
  991. name: this.model.name,
  992. model: this.parseParam(this.model.model),
  993. color: this.parseParam(this.model.color),
  994. standard: this.parseParam(this.model.standard),
  995. mfrs: this.parseParam(this.model.mfrs),
  996. otherField1: this.parseParam(this.model.otherField1),
  997. otherField2: this.parseParam(this.model.otherField2),
  998. otherField3: this.parseParam(this.model.otherField3),
  999. unit: this.parseParam(this.model.unit),
  1000. unitId: this.parseParam(this.model.unitId),
  1001. }
  1002. checkMaterial(param).then((res) => {
  1003. if (res && res.code === 200) {
  1004. if (res.data.status) {
  1005. this.$message.warning('抱歉,该商品已存在!')
  1006. return
  1007. } else {
  1008. //进一步校验单位
  1009. let basicUnit = '',
  1010. otherUnit = '',
  1011. otherUnitTwo = '',
  1012. otherUnitThree = ''
  1013. if (formData.unitId) {
  1014. let unitArr = this.unitList
  1015. for (let i = 0; i < unitArr.length; i++) {
  1016. if (unitArr[i].id == formData.unitId) {
  1017. basicUnit = unitArr[i].basicUnit
  1018. otherUnit = unitArr[i].otherUnit
  1019. if (unitArr[i].otherUnitTwo) {
  1020. otherUnitTwo = unitArr[i].otherUnitTwo
  1021. }
  1022. if (unitArr[i].otherUnitThree) {
  1023. otherUnitThree = unitArr[i].otherUnitThree
  1024. }
  1025. }
  1026. }
  1027. }
  1028. //对最低和最高安全库存进行校验
  1029. for (let i = 0; i < formData.stock.length; i++) {
  1030. let depotStockObj = formData.stock[i]
  1031. if (formData.enableSerialNumber === '1' && depotStockObj.initStock && depotStockObj.initStock - 0) {
  1032. this.$message.warning('抱歉,序列号商品不能录入期初库存,建议进行入库单据录入!')
  1033. return
  1034. }
  1035. if (formData.enableBatchNumber === '1' && depotStockObj.initStock && depotStockObj.initStock - 0) {
  1036. this.$message.warning('抱歉,批号商品不能录入期初库存,建议进行入库单据录入!')
  1037. return
  1038. }
  1039. if (depotStockObj.lowSafeStock && depotStockObj.highSafeStock) {
  1040. if (depotStockObj.lowSafeStock - 0 > depotStockObj.highSafeStock - 0) {
  1041. this.$message.warning('抱歉,' + depotStockObj.name + '的最低安全库存大于最高安全库存!')
  1042. return
  1043. }
  1044. }
  1045. }
  1046. //图片校验
  1047. if (this.fileList && this.fileList.length > 0) {
  1048. formData.imgName = this.fileList
  1049. let fileArr = this.fileList.split(',')
  1050. if (fileArr.length > 4) {
  1051. this.$message.warning('抱歉,商品图片不能超过4张!')
  1052. return
  1053. }
  1054. } else {
  1055. formData.imgName = ''
  1056. }
  1057. formData.meDeleteIdList = this.meDeleteIdList
  1058. //接口调用
  1059. let url = this.url.add,
  1060. method = 'post'
  1061. if (this.model.id) {
  1062. url = this.url.edit
  1063. method = 'put'
  1064. }
  1065. const that = this
  1066. this.confirmLoading = true
  1067. httpAction(url, formData, method)
  1068. .then((res) => {
  1069. if (res.code === 200) {
  1070. that.$emit('ok')
  1071. that.confirmLoading = false
  1072. that.close()
  1073. } else {
  1074. that.$message.warning(res.data.message)
  1075. that.confirmLoading = false
  1076. }
  1077. })
  1078. .finally(() => {})
  1079. }
  1080. }
  1081. })
  1082. },
  1083. parseParam(param) {
  1084. return param ? param : ''
  1085. },
  1086. validateBarCode(type, value, row, column, callback, target) {
  1087. let params = {
  1088. barCode: value,
  1089. id: row.id.length >= 20 ? 0 : row.id,
  1090. }
  1091. checkMaterialBarCode(params).then((res) => {
  1092. if (res && res.code === 200) {
  1093. if (!res.data.status) {
  1094. callback(true)
  1095. } else {
  1096. callback(false, '该条码已经存在')
  1097. }
  1098. } else {
  1099. callback(false, res.data)
  1100. }
  1101. })
  1102. },
  1103. loadTreeData() {
  1104. let that = this
  1105. let params = {}
  1106. params.id = ''
  1107. queryMaterialCategoryTreeList(params).then((res) => {
  1108. if (res) {
  1109. that.categoryTree = []
  1110. for (let i = 0; i < res.length; i++) {
  1111. let temp = res[i]
  1112. that.categoryTree.push(temp)
  1113. }
  1114. }
  1115. })
  1116. },
  1117. loadUnitListData() {
  1118. let that = this
  1119. let params = {}
  1120. params.currentPage = 1
  1121. params.pageSize = 100
  1122. getAction('/unit/getAllList', params).then((res) => {
  1123. if (res) {
  1124. that.unitList = res.data
  1125. }
  1126. })
  1127. },
  1128. onManySkuChange(value) {
  1129. this.manySkuSelected = value.length
  1130. //控制多属性下拉框中选择项的状态
  1131. if (value.length < 3) {
  1132. this.materialAttributeList.forEach((item, index, array) => {
  1133. array.indexOf(item.value) === -1 ? Vue.set(array[index], 'disabled', false) : ''
  1134. })
  1135. } else {
  1136. this.materialAttributeList.forEach((item, index, array) => {
  1137. value.indexOf(item.value) === -1 ? Vue.set(array[index], 'disabled', true) : ''
  1138. })
  1139. }
  1140. //更新属性1和属性2和属性3的下拉框
  1141. if (value.length <= 3) {
  1142. let skuOneId = value[0]
  1143. let skuTwoId = value[1]
  1144. let skuThreeId = value[2]
  1145. this.materialAttributeList.forEach((item) => {
  1146. if (item.value === skuOneId) {
  1147. this.skuOneTitle = item.name
  1148. }
  1149. if (item.value === skuTwoId) {
  1150. this.skuTwoTitle = item.name
  1151. }
  1152. if (item.value === skuThreeId) {
  1153. this.skuThreeTitle = item.name
  1154. }
  1155. })
  1156. if (skuOneId) {
  1157. getMaterialAttributeValueListById({ id: skuOneId }).then((res) => {
  1158. this.skuOneList = res ? res : []
  1159. })
  1160. }
  1161. if (skuTwoId) {
  1162. getMaterialAttributeValueListById({ id: skuTwoId }).then((res) => {
  1163. this.skuTwoList = res ? res : []
  1164. })
  1165. }
  1166. if (skuThreeId) {
  1167. getMaterialAttributeValueListById({ id: skuThreeId }).then((res) => {
  1168. this.skuThreeList = res ? res : []
  1169. })
  1170. }
  1171. }
  1172. this.barCodeSwitch = false
  1173. this.meTable.dataSource = []
  1174. },
  1175. onSkuChange() {
  1176. let skuOneData = this.form.getFieldValue('skuOne')
  1177. let skuTwoData = this.form.getFieldValue('skuTwo')
  1178. let skuThreeData = this.form.getFieldValue('skuThree')
  1179. this.autoSkuList(skuOneData, skuTwoData, skuThreeData)
  1180. },
  1181. onSkuOneDeSelect(value) {
  1182. let skuOneData = this.form.getFieldValue('skuOne')
  1183. let skuTwoData = this.form.getFieldValue('skuTwo')
  1184. let skuThreeData = this.form.getFieldValue('skuThree')
  1185. removeByVal(skuOneData, value)
  1186. this.autoSkuList(skuOneData, skuTwoData, skuThreeData)
  1187. },
  1188. onSkuTwoDeSelect(value) {
  1189. let skuOneData = this.form.getFieldValue('skuOne')
  1190. let skuTwoData = this.form.getFieldValue('skuTwo')
  1191. let skuThreeData = this.form.getFieldValue('skuThree')
  1192. removeByVal(skuTwoData, value)
  1193. this.autoSkuList(skuOneData, skuTwoData, skuThreeData)
  1194. },
  1195. onSkuThreeDeSelect(value) {
  1196. let skuOneData = this.form.getFieldValue('skuOne')
  1197. let skuTwoData = this.form.getFieldValue('skuTwo')
  1198. let skuThreeData = this.form.getFieldValue('skuThree')
  1199. removeByVal(skuThreeData, value)
  1200. this.autoSkuList(skuOneData, skuTwoData, skuThreeData)
  1201. },
  1202. autoSkuList(skuOneData, skuTwoData, skuThreeData) {
  1203. let unit = this.form.getFieldValue('unit')
  1204. if (unit) {
  1205. //计算多属性已经选择了几个
  1206. let skuArr = []
  1207. if (this.getNumByField('skuOne')) {
  1208. skuArr.push(skuOneData)
  1209. }
  1210. if (this.getNumByField('skuTwo')) {
  1211. skuArr.push(skuTwoData)
  1212. }
  1213. if (this.getNumByField('skuThree')) {
  1214. skuArr.push(skuThreeData)
  1215. }
  1216. let skuArrOne = skuArr[0]
  1217. let skuArrTwo = skuArr[1]
  1218. let skuArrThree = skuArr[2]
  1219. let count = this.getNumByField('skuOne') + this.getNumByField('skuTwo') + this.getNumByField('skuThree')
  1220. let barCodeSku = []
  1221. if (count === 1) {
  1222. let skuArrOnly = []
  1223. if (this.getNumByField('skuOne')) {
  1224. skuArrOnly = skuOneData
  1225. } else if (this.getNumByField('skuTwo')) {
  1226. skuArrOnly = skuTwoData
  1227. } else if (this.getNumByField('skuThree')) {
  1228. skuArrOnly = skuThreeData
  1229. }
  1230. for (let i = 0; i < skuArrOnly.length; i++) {
  1231. barCodeSku.push(skuArrOnly[i])
  1232. }
  1233. } else if (count === 2) {
  1234. for (let i = 0; i < skuArrOne.length; i++) {
  1235. for (let j = 0; j < skuArrTwo.length; j++) {
  1236. barCodeSku.push(skuArrOne[i] + '/' + skuArrTwo[j])
  1237. }
  1238. }
  1239. } else if (count === 3) {
  1240. for (let i = 0; i < skuArrOne.length; i++) {
  1241. for (let j = 0; j < skuArrTwo.length; j++) {
  1242. for (let k = 0; k < skuArrThree.length; k++) {
  1243. barCodeSku.push(skuArrOne[i] + '/' + skuArrTwo[j] + '/' + skuArrThree[k])
  1244. }
  1245. }
  1246. }
  1247. }
  1248. let meTableData = []
  1249. getMaxBarCode({}).then((res) => {
  1250. if (res && res.code === 200) {
  1251. let maxBarCode = res.data.barCode - 0
  1252. for (let i = 0; i < barCodeSku.length; i++) {
  1253. let currentBarCode = maxBarCode + i + 1
  1254. meTableData.push({ barCode: currentBarCode, commodityUnit: unit, sku: barCodeSku[i] })
  1255. }
  1256. this.meTable.dataSource = meTableData
  1257. }
  1258. })
  1259. } else {
  1260. this.$message.warning('请填写单位(注意不要勾选多单位)')
  1261. this.barCodeSwitch = false
  1262. }
  1263. },
  1264. getNumByField(field) {
  1265. let num = 0
  1266. if (this.form.getFieldValue(field)) {
  1267. if (this.form.getFieldValue(field).length > 0) {
  1268. num = 1
  1269. }
  1270. }
  1271. return num
  1272. },
  1273. onAdded(event) {
  1274. const { row, target } = event
  1275. // 不勾选多单位
  1276. if(!this.unitChecked){
  1277. let formUnit = this.form.getFieldValue('unit')||''
  1278. target.setValues([{rowKey:row.id, values:{barCode: '', commodityUnit: formUnit}}])
  1279. }
  1280. console.log('onAdded', event)
  1281. },
  1282. onDeleted(value) {
  1283. // this.meDeleteIdList = value
  1284. console.log('onDeleted', value)
  1285. },
  1286. // batchSetPrice(type) {
  1287. // if (this.manySkuSelected > 0 || this.model.id) {
  1288. // this.$refs.priceModalForm.add(type)
  1289. // this.$refs.priceModalForm.disableSubmit = false
  1290. // } else {
  1291. // this.$message.warning('抱歉,只有开启多属性才能进行批量操作!')
  1292. // }
  1293. // },
  1294. batchSetStock(type) {
  1295. this.$refs.stockModalForm.add(type)
  1296. this.$refs.stockModalForm.disableSubmit = false
  1297. },
  1298. batchSetStockModalFormOk(stock, batchType) {
  1299. let arr = this.depotTable.dataSource
  1300. let depotTableData = []
  1301. for (let i = 0; i < arr.length; i++) {
  1302. let depotInfo = {
  1303. name: arr[i].name,
  1304. currentStock: arr[i].currentStock,
  1305. lowSafeStock: arr[i].lowSafeStock,
  1306. highSafeStock: arr[i].highSafeStock,
  1307. }
  1308. if (batchType === 'currentStock') {
  1309. depotInfo.currentStock = stock - 0
  1310. } else if (batchType === 'lowSafeStock') {
  1311. depotInfo.lowSafeStock = stock - 0
  1312. } else if (batchType === 'highSafeStock') {
  1313. depotInfo.highSafeStock = stock - 0
  1314. }
  1315. if (arr[i].id) {
  1316. depotInfo.id = arr[i].id
  1317. }
  1318. depotTableData.push(depotInfo)
  1319. }
  1320. this.depotTable.dataSource = depotTableData
  1321. },
  1322. initMaterialAttribute() {
  1323. getMaterialAttributeNameList().then((res) => {
  1324. if (res) {
  1325. this.materialAttributeList = res
  1326. }
  1327. })
  1328. },
  1329. loadParseMaterialProperty() {
  1330. let mpList = Vue.ls.get('materialPropertyList')
  1331. for (let i = 0; i < mpList.length; i++) {
  1332. if (mpList[i].nativeName === '制造商') {
  1333. this.mpShort.mfrs.name = mpList[i].anotherName
  1334. this.mpShort.mfrs.enabled = mpList[i].enabled
  1335. }
  1336. if (mpList[i].nativeName === '自定义1') {
  1337. this.mpShort.otherField1.name = mpList[i].anotherName
  1338. this.mpShort.otherField1.enabled = mpList[i].enabled
  1339. }
  1340. if (mpList[i].nativeName === '自定义2') {
  1341. this.mpShort.otherField2.name = mpList[i].anotherName
  1342. this.mpShort.otherField2.enabled = mpList[i].enabled
  1343. }
  1344. if (mpList[i].nativeName === '自定义3') {
  1345. this.mpShort.otherField3.name = mpList[i].anotherName
  1346. this.mpShort.otherField3.enabled = mpList[i].enabled
  1347. }
  1348. }
  1349. },
  1350. handleNameChange(e) {
  1351. let that = this
  1352. if (e.target.value) {
  1353. if (this.setTimeFlag != null) {
  1354. clearTimeout(this.setTimeFlag)
  1355. }
  1356. this.setTimeFlag = setTimeout(() => {
  1357. changeNameToPinYin({ name: e.target.value }).then((res) => {
  1358. if (res && res.code === 200) {
  1359. that.form.setFieldsValue({ mnemonic: res.data })
  1360. } else {
  1361. that.$message.warning(res.data)
  1362. }
  1363. })
  1364. }, 500)
  1365. } else {
  1366. that.form.setFieldsValue({ mnemonic: '' })
  1367. }
  1368. },
  1369. onlyUnitOnChange(e) {
  1370. if (e.target.value) {
  1371. //单位有填写了之后则显示多属性的文本框
  1372. this.manySkuStatus = true
  1373. } else {
  1374. this.manySkuStatus = false
  1375. }
  1376. console.log('onlyUnitOnChange=======',e.target.value)
  1377. this.$refs.editableProBarCodeTable.getValues((error, values) => {
  1378. let mArr = values
  1379. for (let i = 0; i < mArr.length; i++) {
  1380. let mInfo = mArr[i]
  1381. mInfo.commodityUnit = e.target.value
  1382. mInfo.ratio = e.target.value
  1383. }
  1384. this.mbTable.dataSource = mArr
  1385. })
  1386. },
  1387. manyUnitOnChange(value) {
  1388. console.log('manyUnitOnChange', value)
  1389. this.getUnitListByID(value)
  1390. },
  1391. unitOnChange(e) {
  1392. let isChecked = e.target.checked
  1393. if (isChecked) {
  1394. this.unitStatus = true
  1395. this.manyUnitStatus = false
  1396. this.unitChecked = true
  1397. } else {
  1398. this.unitStatus = false
  1399. this.manyUnitStatus = true
  1400. this.unitChecked = false
  1401. }
  1402. this.barCodeUnitList = []
  1403. this.$refs.editableProBarCodeTable.getValues((error, values) => {
  1404. let mArr = values
  1405. for (let i = 0; i < mArr.length; i++) {
  1406. let mInfo = mArr[i]
  1407. mInfo.commodityUnit = undefined
  1408. mInfo.ratio = undefined
  1409. }
  1410. this.mbTable.dataSource = mArr
  1411. })
  1412. },
  1413. addUnit() {
  1414. this.$refs.unitModalForm.add()
  1415. this.$refs.unitModalForm.title = '新增多单位'
  1416. this.$refs.unitModalForm.disableSubmit = false
  1417. },
  1418. unitModalFormOk() {
  1419. this.loadUnitListData()
  1420. },
  1421. handleMeTableChange(pagination) {
  1422. if (pagination && pagination.current) {
  1423. this.meTable.pagination = pagination
  1424. }
  1425. this.requestMeTableData()
  1426. },
  1427. },
  1428. }
  1429. </script>
  1430. <style lang="less" scoped>
  1431. .input-table {
  1432. max-width: 100%;
  1433. min-width: 1200px;
  1434. }
  1435. .tag-info {
  1436. font-size: 14px;
  1437. height: 32px;
  1438. line-height: 32px;
  1439. width: 100%;
  1440. padding: 0px 11px;
  1441. color: #bbb;
  1442. background-color: #ffffff;
  1443. }
  1444. /deep/ .ant-table td { white-space: nowrap; }
  1445. </style>