index.vue 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481
  1. <template>
  2. <view class="app-container">
  3. <uni-nav-bar dark :fixed="true" shadow background-color="#007AFF" status-bar :title="formData.billTypeName"
  4. left-icon="left" left-text="返回" @clickLeft="handleBack"
  5. right-icon="refreshempty" @clickRight="SendNumEmpty"/>
  6. <view class="scan-header">
  7. <uni-forms-item name="remark" label="条码" :label-width="lableWidth" labelAlign="right"
  8. style="margin-bottom: 0px; padding: 0px 15px 0px 15px;" >
  9. <uni-easyinput type="text" :inputBorder="true" v-model="barCode" :focus="remarkFocus"
  10. :clearable="false" @confirm="scanSearch"></uni-easyinput>
  11. <view class="icon" @click="handleScanClick">
  12. <uni-icons type="scan" size="20"></uni-icons>
  13. </view>
  14. </uni-forms-item>
  15. </view>
  16. <view class="cprk-content">
  17. <scroll-view :scroll-top="scrollTop" :show-scrollbar="true" scroll-y="true" class="scroll-Y" @scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll">
  18. <view class="form-container">
  19. <uni-forms
  20. :rules="rules"
  21. :value="formData"
  22. ref="form"
  23. validate-trigger="submit"
  24. err-show-type="toast"
  25. >
  26. <uni-forms-item name="billTypeCode" label="单据类型" :label-width="lableWidth" labelAlign="right">
  27. <uni-data-select
  28. v-model="formData.billTypeCode"
  29. :localdata="billTypeOption"
  30. @change="ywlxChange"
  31. ></uni-data-select>
  32. </uni-forms-item>
  33. <uni-forms-item name="warehouseCode" :required="rulesStar('warehouseCode')" v-if="fieldHidden('warehouseCode')" label="仓库" :label-width="lableWidth" labelAlign="right">
  34. <uni-easyinput type="text" v-model="formData.warehouseCode" v-show="false"></uni-easyinput>
  35. <uni-easyinput type="text" :disabled="true" :styles="styleInput" :inputBorder="true"
  36. v-model="formData.warehouseName" suffixIcon="compose" @iconClick="setScan('WH')"></uni-easyinput>
  37. </uni-forms-item>
  38. <uni-forms-item name="taskInCode" :required="rulesStar('taskInCode')" v-if="fieldHidden('taskInCode')" label="任务编码" :label-width="lableWidth" labelAlign="right">
  39. <uni-easyinput type="text" :disabled="true" :styles="styleInput" :inputBorder="true"
  40. v-model="formData.taskInCode" suffixIcon="search" @iconClick="searchIconClick('task')"></uni-easyinput>
  41. </uni-forms-item>
  42. <uni-forms-item name="deptCode" :required="rulesStar('deptCode')" v-if="fieldHidden('deptCode')" label="部门" :label-width="lableWidth" labelAlign="right">
  43. <uni-easyinput type="text" :disabled="true" :styles="styleInput" :inputBorder="true" v-show="false"
  44. v-model="formData.deptCode" ></uni-easyinput>
  45. <uni-easyinput type="text" :disabled="true" :styles="styleInput" :inputBorder="true"
  46. v-model="formData.deptName" suffixIcon="search" @iconClick="searchIconClick('dept')"></uni-easyinput>
  47. </uni-forms-item>
  48. <uni-forms-item name="employeeCode" :required="rulesStar('employeeCode')" v-if="fieldHidden('employeeCode')" label="职员" :label-width="lableWidth" labelAlign="right">
  49. <uni-easyinput type="text" :disabled="true" :styles="styleInput" :inputBorder="true"
  50. v-model="formData.employeeCode" v-show="false" ></uni-easyinput>
  51. <uni-easyinput type="text" :disabled="true" :styles="styleInput" :inputBorder="true"
  52. v-model="formData.employeeName" suffixIcon="search" @iconClick="searchIconClick('empl')"></uni-easyinput>
  53. </uni-forms-item>
  54. <uni-forms-item name="supplierCode" :required="rulesStar('supplierCode')" v-if="fieldHidden('supplierCode')" label="供应商" :label-width="lableWidth" labelAlign="right">
  55. <uni-easyinput type="text" :inputBorder="true" v-model="formData.supplierCode" v-show="false" :disabled="true" :styles="styleInput"></uni-easyinput>
  56. <uni-easyinput type="text" :inputBorder="true"
  57. v-model="formData.supplierName" :disabled="true" :styles="styleInput" :suffixIcon="formData.taskInCode!=''? '' : 'search'" @iconClick="searchIconClick('supp')"></uni-easyinput>
  58. </uni-forms-item>
  59. <uni-forms-item name="extendCode01" :required="rulesStar('extendCode01')" v-if="fieldHidden('extendCode01')" label="收发类别" :label-width="lableWidth" labelAlign="right">
  60. <uni-easyinput type="text" :disabled="true" :inputBorder="true" v-show="false"
  61. v-model="formData.extendCode01" ></uni-easyinput>
  62. <uni-easyinput type="text" :disabled="true" :styles="styleInput" :inputBorder="true"
  63. v-model="formData.extendName01" suffixIcon="search" @iconClick="searchIconClick('ext01')"></uni-easyinput>
  64. </uni-forms-item>
  65. <uni-forms-item name="locationCode" :required="rulesStar('locationCode')" v-if="fieldHidden('locationCode')" label="货位" :label-width="lableWidth" labelAlign="right">
  66. <uni-easyinput type="text" v-model="formData.locationCode" v-show="false"></uni-easyinput>
  67. <uni-easyinput type="text" :disabled="true" :styles="styleInput" :inputBorder="true"
  68. v-model="formData.locationName" suffixIcon="compose" @iconClick="setScan('PT')"></uni-easyinput>
  69. </uni-forms-item>
  70. <uni-forms-item name="palletCode" :required="rulesStar('palletCode')" v-if="fieldHidden('palletCode')" label="托盘" :label-width="lableWidth" labelAlign="right">
  71. <uni-easyinput type="text" :disabled="true" :styles="styleInput" :inputBorder="true"
  72. v-model="formData.palletCode" suffixIcon="search" @iconClick="searchIconClick('pall')"></uni-easyinput>
  73. </uni-forms-item>
  74. <uni-forms-item name="packageCode" :required="rulesStar('packageCode')" v-if="fieldHidden('packageCode')" label="包装" :label-width="lableWidth" labelAlign="right">
  75. <uni-easyinput type="text" :disabled="true" :styles="styleInput" :inputBorder="true"
  76. v-model="formData.packageCode" suffixIcon="search" @iconClick="searchIconClick('pack')"></uni-easyinput>
  77. </uni-forms-item>
  78. <uni-forms-item name="labelCode" :required="rulesStar('labelCode')" v-if="fieldHidden('labelCode')" label="标签编码" :label-width="lableWidth" labelAlign="right">
  79. <uni-easyinput type="text" :disabled="true" :styles="styleInput" :inputBorder="true"
  80. v-model="formData.labelCode" suffixIcon="compose" @iconClick="setScan('L')"></uni-easyinput>
  81. </uni-forms-item>
  82. <uni-forms-item name="materialCode" :required="rulesStar('materialCode')" v-if="fieldHidden('materialCode')" label="物料" :label-width="lableWidth" labelAlign="right">
  83. <uni-easyinput type="text" v-model="formData.materialCode" v-show="false" ></uni-easyinput>
  84. <uni-easyinput type="text" :disabled="true" :styles="styleInput" :inputBorder="true"
  85. v-model="formData.materialName"></uni-easyinput>
  86. </uni-forms-item>
  87. <uni-forms-item name="batch" :required="rulesStar('batch')" v-if="fieldHidden('batch')" label="批号" :label-width="lableWidth" labelAlign="right">
  88. <uni-easyinput type="text" :disabled="true" :styles="styleInput" :inputBorder="true" v-model="formData.batch"></uni-easyinput>
  89. </uni-forms-item>
  90. <uni-forms-item name="unitCode" :required="rulesStar('unitCode')" v-if="fieldHidden('unitCode')" label="单位" :label-width="lableWidth" labelAlign="right">
  91. <uni-easyinput type="text" v-model="formData.unitCode" v-show="false"></uni-easyinput>
  92. <uni-easyinput type="text" :disabled="true" :styles="styleInput" :inputBorder="true" v-model="formData.unitName"></uni-easyinput>
  93. </uni-forms-item>
  94. <uni-forms-item name="stockQty" :required="rulesStar('stockQty')" v-if="fieldHidden('stockQty')" label="标签数量" :label-width="lableWidth" labelAlign="right">
  95. <uni-easyinput type="number" :inputBorder="true"
  96. v-model="formData.stockQty" @blur="stockQtyBlur" ></uni-easyinput>
  97. </uni-forms-item>
  98. <uni-forms-item name="rwQty" :required="rulesStar('rwQty')" v-if="fieldHidden('rwQty')" label="任务数量" :label-width="lableWidth" labelAlign="right">
  99. <uni-easyinput type="text" :disabled="true" :styles="styleInput" :inputBorder="true" v-model="formData.rwQty"></uni-easyinput>
  100. </uni-forms-item>
  101. </uni-forms>
  102. </view>
  103. </scroll-view>
  104. </view>
  105. <view class="page-bottom">
  106. <view class="p-b-btn">
  107. <uni-badge class="uni-badge-left-margin" :text="mxNum" :max-num="999" absolute="rightTop" :offset="[-3, -3]" size="small">
  108. <view class="box"><text class="box-text" @click="handleMx">明细</text></view>
  109. </uni-badge>
  110. </view>
  111. <view class="p-b-btn" @click="$noMultipleClicks(handleSave)">
  112. <text class="box-text" v-show="isShowSaveButton">暂存</text>
  113. </view>
  114. <view class="p-b-btn" @click="handleAuto">
  115. <text class="box-text">{{autoButtonTitle}}</text>
  116. </view>
  117. <view class="p-b-btn" @click="handleBack">
  118. <text class="box-text">返回</text>
  119. </view>
  120. </view>
  121. <scan-code />
  122. <!-- 明细弹窗 -->
  123. <MxPopup ref="mxPopup" @sendNum="getSendNum" :formData="formData" @sendData="getSendData"/>
  124. <!-- 任务编码弹窗 -->
  125. <RwbmPopup ref="rwbmPopup" :title="rwbmTitle" :idxFlag="rwbmFlag" :formData="formData" @sendData="getSendData" />
  126. <!-- 部门弹窗 -->
  127. <BmPopup ref="bmPopup" :title="bmTitle" :idxFlag="bmFlag" :formData="formData" @sendData="getSendData"/>
  128. <!-- 职员 -->
  129. <ZyPopup ref="zyPopup" :title="zyTitle" :idxFlag="zyFlag" :formData="formData" @sendData="getSendData"/>
  130. <!-- 收发类别 -->
  131. <SflbPopup ref="sflbPopup" :title="sflbTitle" :idxFlag="sflbFlag" :formData="formData" @sendData="getSendData"/>
  132. <!-- 供应商 -->
  133. <GysPopup ref="gysPopup" :title="gysTitle" :idxFlag="gysFlag" :formData="formData" @sendData="getSendData"/>
  134. <!-- 托盘 -->
  135. <TpPopup ref="tpPopup" :title="tpTitle" :idxFlag="tpFlag" :formData="formData" @sendData="getSendData"/>
  136. <!-- 包装 -->
  137. <BzPopup ref="bzPopup" :title="bzTitle" :idxFlag="bzFlag" :formData="formData" @sendData="getSendData"/>
  138. </view>
  139. </template>
  140. <script>
  141. import scanCode from "@/components/scan/scan.vue";
  142. import { getDicts } from "@/api/system/dict/data"; // 字典
  143. // import RadioPopup from './popup/radiopupup.vue';
  144. import RwbmPopup from './popup/commonpopup.vue' // 任务编码
  145. import BmPopup from './popup/commonpopup.vue' // 部门
  146. import ZyPopup from './popup/commonpopup.vue' // 职业
  147. import SflbPopup from './popup/commonpopup.vue' // 收发类别
  148. import GysPopup from './popup/commonpopup.vue' // 供应商
  149. import TpPopup from './popup/commonpopup.vue' // 托盘
  150. import BzPopup from './popup/commonpopup.vue' // 包装
  151. import MxPopup from './popup/mxPopup.vue'
  152. import { addStockIn, listRwbm, listWarehouse, listLocation, listLabelQueryParams, listPallet, listPackage, listExtend, getMaterial, getListFieldSetting, queryBillTypeCache } from '@/api/wms/stockIn.js'
  153. import { listFieldDefault } from '@/api/wms/report.js'
  154. import storage from '@/utils/storage'
  155. import { nanoid } from 'nanoid'; //唯一值 nanoid
  156. export default {
  157. components: {
  158. scanCode,
  159. RwbmPopup,
  160. BmPopup,
  161. MxPopup,
  162. ZyPopup,
  163. SflbPopup,
  164. GysPopup,
  165. TpPopup,
  166. BzPopup
  167. },
  168. props: {},
  169. async onLoad(option) {
  170. //下面请求如果失败改为false
  171. let isRequest = true;
  172. //字段设置
  173. try {
  174. const res = await this.retryRequest(getListFieldSetting, { billCode: "stockIn" });
  175. // 处理响应数据
  176. this.fieldSetting = res.rows;
  177. } catch (error) {
  178. isRequest = false;
  179. }
  180. //单据类型
  181. try {
  182. const res = await this.retryRequest(queryBillTypeCache, {billCode: "stockIn"});
  183. // 处理响应数据
  184. let tmpData = res.rows;
  185. this.billTypeOption = tmpData.filter(item => item.isEnableApp == 0 && item.status == 0)
  186. .map(item => ({
  187. billTypeCode: item.billTypeCode,
  188. billTypeName: item.billTypeName,
  189. value: item.billTypeCode,
  190. text: item.billTypeName,
  191. taskValue: item.taskBillTypeCode ? "'" + item.taskBillTypeCode.replace(/,/g, "','") + "'" : '',
  192. isControlTask: item.backTaskBillTypeCode ? item.isControlTask : 0,
  193. }));
  194. //触发单据类型变更
  195. this.ywlxChange(option.ywlx);
  196. } catch (error) {
  197. isRequest = false;
  198. }
  199. if(isRequest==false){
  200. uni.showModal({
  201. title: '获取单据信息失败',
  202. content: '请返回菜单重新进入',
  203. showCancel: false ,//不显示取消按钮
  204. success: function (res) {
  205. if (res.confirm) {
  206. uni.navigateBack();
  207. }
  208. }
  209. })
  210. }else{
  211. this.isRequest=true
  212. }
  213. },
  214. onUnload(){
  215. uni.removeStorageSync('stock_key');
  216. },
  217. onBackPress(options) {
  218. if (options.from === 'navigateBack') {
  219. // 来自于导航条返回按钮或者系统返回按钮的事件
  220. return false;
  221. }
  222. // 双击返回的逻辑
  223. const now = Date.now();
  224. if (this.lastBackPress && now - this.lastBackPress < 1000) {
  225. // 如果两次点击的间隔小于1000毫秒,则可以认为是双击
  226. //这时退出
  227. return false;
  228. } else {
  229. this.lastBackPress = now;
  230. uni.showToast({
  231. title: '再按一次退出',
  232. icon: 'none'
  233. });
  234. setTimeout(() => {
  235. this.lastBackPress = null;
  236. }, 1000);
  237. return true;
  238. }
  239. },
  240. data() {
  241. return {
  242. isRequest: false, //onLoad请求成功时改为true,否则不允许保存
  243. remarkFocus: false,
  244. mxNum: 0, //明细按钮数量
  245. isShowSaveButton: false, //是否显示保存按钮
  246. currentSelectBillTypeCode: '', // 当前单据类型
  247. autoButtonTitle: '自动',
  248. scrollTop: 0,
  249. old: {
  250. scrollTop: 0
  251. },
  252. billTypeOption: [], // 业务类型字典选择框数据
  253. barCode: '', //条码
  254. formData: {
  255. status: "1",
  256. // 单据类型
  257. billTypeCode: "", // 单据类型
  258. billTypeName: "", // 单据类型的名称(显示使用)
  259. taskBillTypeCode: "", //单据类型对应的任务类型
  260. isControlTask: null, //任务用,是否可超量
  261. // 任务编码
  262. taskInCode: "",// 任务编码
  263. taskInId: "",
  264. // 部门
  265. deptCode: "", //部门
  266. deptName: "", //部门名称
  267. // 职员
  268. employeeCode: "", // 职员
  269. employeeName: "", // 职员名称
  270. // 供应商
  271. supplierCode : "", //供应商
  272. supplierName: "", //供应商名称
  273. // 收发类别
  274. extendName01: "", // 收发类别
  275. extendCode01: "", // 收发类别编码
  276. //预留
  277. extendCode02: "",
  278. extendCode03: "",
  279. extendCode04: "",
  280. extendCode05: "",
  281. // 仓库
  282. warehouseCode: "", // 仓库
  283. warehouseName: "", // 仓库名称
  284. // 组id
  285. appGroupId: "",
  286. // ===== 以下 保存时转化为 wmsStockInsList=====
  287. //任务子表id
  288. taskInsId: "",
  289. // 货位
  290. locationCode: "", // 货位编码
  291. locationName: "", // 货位名称
  292. // 标签
  293. labelCode: "", // 标签编码
  294. // 物料
  295. materialCode: "", // 物料编码
  296. materialName: "", //物料名称
  297. // 批号
  298. batch: "", //批号
  299. // 托盘
  300. palletCode: "", // 托盘编码
  301. palletName: "", // 托盘名称
  302. // 包装
  303. packageCode: "", // 包装编码
  304. packageName: "", // 包装名称
  305. //单位
  306. unitCode: "", //单位编码
  307. unitName: "", //单位名称
  308. stockQty: "", // 标签数量
  309. rwQty: "",// 任务数量
  310. labelType: "", //标签类型(1一次性 2重复性)
  311. batch1: "", //批号1
  312. batch2: "", //批号2
  313. materialSpecification: "", //物料规格
  314. isLocation:"",
  315. isPackage:"",
  316. isPallet:"",
  317. },
  318. show: false,
  319. lableWidth: '80px',
  320. styleInput: {
  321. color: '#333',
  322. backgroundColor: '#fff',
  323. disableColor: '#fff',
  324. borderColor: '#e5e5e5',
  325. },
  326. fieldSetting: [], //单据字段设置
  327. // 任务编码
  328. rwbmTitle: "任务",
  329. rwbmFlag: "rwbm",
  330. // 职员
  331. zyTitle: "职员",
  332. zyFlag: "zy",
  333. // 部门
  334. bmTitle: "部门",
  335. bmFlag: "bm",
  336. // 收发类别
  337. sflbTitle: "收发类别",
  338. sflbFlag: "sflb",
  339. // 供应商
  340. gysTitle: "供应商",
  341. gysFlag: "gys",
  342. // 托盘
  343. tpTitle: "托盘",
  344. tpFlag: "tp",
  345. // 包装
  346. bzTitle: "包装",
  347. bzFlag: "bz",
  348. //配合$noMultipleClicks防止重复点击
  349. noClick:true,
  350. }
  351. },
  352. methods: {
  353. upper: function(e) {},
  354. lower: function(e) {},
  355. scroll: function(e) {
  356. this.old.scrollTop = e.detail.scrollTop
  357. },
  358. //获取单据类型等信息时,重复尝试获取
  359. //requestFunction:api函数,requestParams:参数,maxRetries:重试次数
  360. async retryRequest(requestFunction, requestParams, maxRetries = 1) {
  361. let retriesLeft = maxRetries;
  362. while (retriesLeft > 0) {
  363. try {
  364. // 调用请求函数并传入参数
  365. const response = await requestFunction(requestParams);
  366. if (response && response.code === 200) {
  367. return response; // 请求成功,返回响应
  368. } else {
  369. // 请求失败,但还有重试机会
  370. //console.warn(`请求失败,正在尝试第 ${maxRetries - retriesLeft + 1} 次重试...`);
  371. retriesLeft--;
  372. }
  373. } catch (error) {
  374. // 请求发生异常,但还有重试机会
  375. //console.error('请求发生异常,正在尝试重试...', error);
  376. retriesLeft--;
  377. }
  378. }
  379. // 所有重试都失败了,抛出错误
  380. throw new Error('获取信息失败');
  381. },
  382. //安卓扫码
  383. onShow() {
  384. let that = this;
  385. uni.$off("scancode"); // 每次进来先 移除全局自定义事件监听器
  386. uni.$on("scancode", (data) => {
  387. // 扫描PCS码
  388. if(data && data !== ''){
  389. that.barCode = data;
  390. this.getDataByRemark(that.barCode);
  391. }else{
  392. uni.showToast({
  393. title: '扫码失败!',
  394. icon:'none',
  395. duration: 2000
  396. });
  397. }
  398. });
  399. },
  400. // 条码右侧扫码按钮事件
  401. handleScanClick:function(){
  402. let that = this;
  403. uni.scanCode({
  404. success: function(res) {
  405. // {"scanType":"QR_CODE","path":"","charSet":"ISO8859_1","result":"PT|04-A-1-1","errMsg":"scanCode:ok"}
  406. if(res.errMsg == "scanCode:ok"){
  407. that.barCode = res.result;
  408. this.getDataByRemark(that.barCode);
  409. }else{
  410. uni.showToast({
  411. title: '扫码失败!',
  412. icon:'none',
  413. duration: 2000
  414. });
  415. }
  416. },
  417. fail: (err) => {
  418. //扫码失败
  419. },
  420. complete: () => {
  421. //扫码结束
  422. }
  423. });
  424. },
  425. playMusic(bool) {
  426. if(bool == true){
  427. innerAudioContext.src = '/static/mp3/cg.mp3';
  428. }else{
  429. innerAudioContext.src = '/static/mp3/sb.mp3';
  430. }
  431. innerAudioContext.play();
  432. innerAudioContext.onPlay(() => {
  433. /**开始播放是触发 */
  434. });
  435. innerAudioContext.onError((res) => {
  436. /**播放是有错误时触发 */
  437. });
  438. },
  439. // 根据扫码数据查询其他formItem数据
  440. getDataByRemark(remark){
  441. let that = this;
  442. remark = remark.replace(/^\s+|\s+$/g, '');
  443. var splitPre = remark.split("|")[0];
  444. var splitLast = remark.slice(splitPre.length+1);
  445. // 条码空 不执行
  446. if(splitLast == ""){
  447. return true;
  448. }
  449. // 扫码
  450. switch (splitPre){
  451. case "PT": // 货位 PT|04-A-1-1
  452. this.getScanHwList(splitLast);
  453. break;
  454. case "WH": // 仓库 WH|01
  455. this.getScanCkList(splitLast);
  456. break;
  457. case "RW": // 任务扫码 RW|
  458. this.getScanRwList(splitLast);
  459. break;
  460. case "L": // 标签 L|L2311060002
  461. this.getScanBqList(splitLast);
  462. break;
  463. case "P": // 托盘 P|0002
  464. this.getScanTpList(splitLast);
  465. break;
  466. case "PA": // 包装 PA|0002
  467. this.getScanBzList(splitLast);
  468. break;
  469. default:
  470. uni.showToast({
  471. title: "条码不合法",
  472. icon: "none"
  473. })
  474. break;
  475. }
  476. },
  477. // 条码框 回车
  478. scanSearch(remark){
  479. this.getDataByRemark(remark);
  480. },
  481. // 业务类型变更
  482. async ywlxChange(value) {
  483. if(value === ''){
  484. this.formData.billTypeCode = "";
  485. this.formData.billTypeName = "";
  486. this.formData.taskBillTypeCode = "";
  487. this.formData.isControlTask = "";
  488. }else {
  489. let status = this.billTypeOption.find(item => item.value == value);
  490. if(status){
  491. this.formData.billTypeCode = status.value;
  492. this.formData.billTypeName = status.text;
  493. this.formData.taskBillTypeCode = status.taskValue;
  494. this.formData.isControlTask = status.isControlTask
  495. }
  496. }
  497. // 监听业务类型变更,变更后。清空任务、供应商、收发类别、清空明细查询出的数据、清空入库单号和单号数组
  498. //清空任务
  499. this.formData.taskInCode = "";
  500. this.formData.taskInId = "";
  501. this.formData.taskInsId = "";
  502. //清空供应商
  503. this.formData.supplierCode = "";
  504. this.formData.supplierName = "";
  505. //清空收发类别
  506. this.formData.extendCode01 = "";
  507. this.formData.extendName01 = "";
  508. // 清空明细数据
  509. if (this.$refs.mxPopup) {
  510. this.$refs.mxPopup.listData = [];
  511. }
  512. // 清空入库单号和单号数组
  513. uni.removeStorageSync('stock_key');
  514. //更新唯一值
  515. this.formData.appGroupId = nanoid(19);
  516. if(value!='' && value!=null){
  517. //默认值
  518. const res = await this.retryRequest(listFieldDefault, { "billTypeCode":value, "billCode": 'stockIn' });
  519. if(res.code === 200){
  520. let fieldDefault = res.rows; //字段默认值
  521. let fieldSetting = this.fieldSetting.filter(item => item.defaults == '1'); //字段信息
  522. let form = this.formData; //新增的信息
  523. /*
  524. * 遍历字段信息,如果字段默认值和头信息中存在,则用字段中的keyCode、keyName和默认值中的settingCode、settingName赋值给from
  525. */
  526. for (let i = 0; i < fieldSetting.length; i++) {
  527. let fieldD = fieldDefault.filter(item => item.settingFlag == fieldSetting[i].field);
  528. //如果字段默认值和头信息中存在
  529. if (fieldD.length>0 && fieldSetting[i].field in form) {
  530. //仓库触发一次扫码
  531. if(fieldD[0].settingFlag=="warehouseCode" && fieldD[0].settingCode){
  532. this.getScanCkList(fieldD[0].settingCode)
  533. continue
  534. }
  535. //赋值code(实际值)
  536. if(fieldSetting[i]["keyCode"]){
  537. form[ fieldSetting[i]["keyCode"] ] = fieldD[0].settingCode;
  538. }
  539. //赋值name(显示值)
  540. if(fieldSetting[i]["keyName"]){
  541. form[ fieldSetting[i]["keyName"] ] = fieldD[0].settingName;
  542. }
  543. }
  544. }
  545. }
  546. }
  547. },
  548. getSendData(res){ //基础资料
  549. let cFlag = res.currentFlag;
  550. switch (cFlag){
  551. case "rwbm": // 任务编码
  552. this.formData.taskInCode = res.selectData.taskCode;
  553. this.formData.taskInId = res.selectData.id;
  554. // 赋值部门
  555. this.formData.deptCode = res.selectData.deptCode;
  556. this.formData.deptName = res.selectData.deptName;
  557. // 赋值职员
  558. this.formData.employeeCode = res.selectData.employeeCode;
  559. this.formData.employeeName = res.selectData.employeeName;
  560. // 赋值供应商
  561. this.formData.supplierCode = res.selectData.supplierCode;
  562. this.formData.supplierName = res.selectData.supplierName;
  563. break;
  564. case "bm": // 部门
  565. // this.formData.deptCode = res.selectData.deptCode;
  566. this.$set(this.formData,"deptCode",res.selectData.deptCode);
  567. this.$set(this.formData,"deptName",res.selectData.deptName);
  568. // this.formData.deptCode = res.selectData.deptCode;
  569. // this.formData.deptName = res.selectData.deptName;
  570. // 职员清空
  571. this.formData.employeeCode = "";
  572. this.formData.employeeName = "";
  573. break;
  574. case "zy": // 职员
  575. this.formData.employeeCode = res.selectData.employeeCode;
  576. this.formData.employeeName = res.selectData.employeeName;
  577. break;
  578. case "sflb": // 收发类别
  579. this.formData.extendName01 = res.selectData.extendName;
  580. this.formData.extendCode01 = res.selectData.extendCode;
  581. break;
  582. case "gys": // 供应商
  583. this.formData.supplierCode = res.selectData.supplierCode;
  584. this.formData.supplierName = res.selectData.supplierName;
  585. break;
  586. case "bz": // 包装
  587. this.formData.packageCode = res.selectData.packageCode;
  588. this.formData.packageName = res.selectData.packageName;
  589. if(res.selectData.warehouseCode){
  590. this.formData.warehouseCode = res.selectData.warehouseCode;
  591. this.formData.warehouseName = res.selectData.warehouseName;
  592. }
  593. if(res.selectData.locationCode){
  594. this.formData.locationCode = res.selectData.locationCode;
  595. this.formData.locationName = res.selectData.locationName;
  596. }
  597. if(res.selectData.palletCode){
  598. this.formData.palletCode = res.selectData.palletCode;
  599. this.formData.palletName = res.selectData.palletName;
  600. }
  601. break;
  602. case "tp": // 托盘
  603. this.formData.palletCode = res.selectData.palletCode;
  604. this.formData.palletName = res.selectData.palletName;
  605. if(res.selectData.warehouseCode){
  606. this.formData.warehouseCode = res.selectData.warehouseCode;
  607. this.formData.warehouseName = res.selectData.warehouseName;
  608. }
  609. if(res.selectData.locationCode){
  610. this.formData.locationCode = res.selectData.locationCode;
  611. this.formData.locationName = res.selectData.locationName;
  612. }
  613. this.formData.packageCode = '';
  614. this.formData.packageName = '';
  615. break;
  616. case "stock": // 其它单据
  617. let billType = this.billTypeOption.find(item => item.value == res.selectData.billTypeCode);
  618. this.formData = {
  619. billTypeCode: billType.value,
  620. billTypeName: billType.text,
  621. taskBillTypeCode: billType.taskValue,
  622. isControlTask: billType.isControlTask,
  623. taskInCode: res.selectData.taskInCode,
  624. taskInId: res.selectData.taskInId,
  625. deptCode: res.selectData.deptCode,
  626. deptName: res.selectData.deptName,
  627. employeeCode: res.selectData.employeeCode,
  628. employeeName: res.selectData.employeeName,
  629. supplierCode : res.selectData.supplierCode,
  630. supplierName: res.selectData.supplierName,
  631. extendName01: res.selectData.extendName01,
  632. extendCode01: res.selectData.extendCode01,
  633. warehouseCode: res.selectData.warehouseCode,
  634. warehouseName: res.selectData.warehouseName,
  635. appGroupId: res.selectData.appGroupId,
  636. // ===== 以下 保存时转化为 wmsStockInsList=====
  637. taskInsId: "",
  638. locationCode: "",
  639. locationName: "",
  640. labelCode: "",
  641. materialCode: "",
  642. materialName: "",
  643. batch: "",
  644. palletCode: "",
  645. palletName: "",
  646. packageCode: "",
  647. packageName: "",
  648. unitCode: "",
  649. unitName: "",
  650. stockQty: "",
  651. rwQty: "",
  652. labelType: "",
  653. batch1: "",
  654. batch2: "",
  655. materialSpecification: "",
  656. };
  657. break;
  658. default:
  659. break;
  660. }
  661. },
  662. searchIconClick(type){// 放大镜点击
  663. switch (type){
  664. case "task": // 任务编码
  665. this.$refs.rwbmPopup.showPopup();
  666. break;
  667. case "dept": // 部门
  668. this.$refs.bmPopup.showPopup();
  669. break;
  670. case "empl": // 职员
  671. this.$refs.zyPopup.showPopup();
  672. break;
  673. case "supp": // 供应商
  674. this.$refs.gysPopup.showPopup();
  675. break;
  676. case "ext01": // 收发类别
  677. this.$refs.sflbPopup.showPopup();
  678. break;
  679. case "pall": // 托盘
  680. this.$refs.tpPopup.showPopup();
  681. break;
  682. case "pack": // 包装
  683. this.$refs.bzPopup.showPopup();
  684. break;
  685. default:
  686. break;
  687. }
  688. },
  689. remarkGetFocus(){
  690. this.remarkFocus = false;
  691. this.$nextTick(() => {
  692. this.remarkFocus = true
  693. })
  694. },
  695. setScan(str){//赋值条码框 光标聚焦
  696. this.barCode = str + "|";
  697. this.remarkGetFocus();
  698. },
  699. stockQtyBlur(value){
  700. let stockQty = this.formData.stockQty;
  701. let rwQty = this.formData.rwQty; //任务数量
  702. if(rwQty != ""){
  703. if(stockQty > parseFloat(rwQty)){
  704. this.formData.stockQty = '';
  705. uni.showToast({
  706. title: "数量大于可入库数量 " + rwQty,
  707. icon: "none",
  708. duration: 3000
  709. })
  710. return;
  711. }
  712. }
  713. },
  714. // 下面工具栏 明细点击 事件
  715. handleMx(){
  716. this.$refs.mxPopup.showDrawer();
  717. },
  718. handleSave() {
  719. //获取信息失败时不可以保存
  720. if(this.isRequest==false){
  721. uni.showToast({
  722. title: '获取单据信息失败,请返回菜单重新进入',
  723. icon: "none"
  724. })
  725. return true;
  726. }
  727. if (this.isShowSaveButton) {
  728. uni.showToast({
  729. title: '保存中,请稍等',
  730. icon: 'none',
  731. duration:2000
  732. })
  733. }
  734. //如果唯一值空,生成唯一值
  735. if(this.formData.appGroupId=='' || this.formData.appGroupId==null){
  736. this.formData.appGroupId = nanoid(19)
  737. }
  738. let that = this;
  739. that.$refs.form.validate().then(async res => {
  740. //查询物料信息;主要获取默认入库仓库
  741. let material = "";
  742. await getMaterial(that.formData.materialCode).then(res => {
  743. material = res.data;
  744. });
  745. if(material.warehouseCodeIn && material.warehouseCodeIn != that.formData.warehouseCode){
  746. uni.vibrateLong({});
  747. uni.showModal({
  748. title: '确认删除',
  749. content: '与物料默认仓库' + material.warehouseNameIn + '不符,是否继续?',
  750. success: function (res) {
  751. if (res.confirm) {
  752. that.handleSave2();
  753. } else if (res.cancel) {
  754. //取消;不保存
  755. }
  756. }
  757. });
  758. }else{
  759. that.handleSave2();
  760. }
  761. }).catch((err) => {
  762. uni.vibrateLong({});
  763. });
  764. },
  765. handleSave2() {
  766. let that = this;
  767. let wmsStockInsArr = [];
  768. let tmpWms = {
  769. taskInsId : that.formData.taskInsId,
  770. locationCode: that.formData.locationCode, // 货位编码
  771. locationName: that.formData.locationName, // 货位名称
  772. labelCode:that.formData.labelCode, // 标签编码
  773. materialCode: that.formData.materialCode, // 物料编码
  774. materialName: that.formData.materialName, //物料名称
  775. batch: that.formData.batch, //批号
  776. palletCode: that.formData.palletCode, // 托盘编码
  777. palletName: that.formData.palletName, // 托盘名称
  778. unitCode: that.formData.unitCode, //单位编码
  779. unitName: that.formData.unitName, // 单位名称
  780. stockQty: that.formData.stockQty, // 标签数量
  781. rwQty: that.formData.rwQty, // 任务数量
  782. // labelType: that.formData.labelType, //标签类型(1一次性 2重复性)
  783. batch1: that.formData.batch1, //批号1
  784. batch2: that.formData.batch2, //批号2
  785. palletCode: that.formData.palletCode, // 托盘编码
  786. packageCode: that.formData.packageCode, // 包装编码
  787. isPackage: that.formData.isPackage,
  788. isPallet: that.formData.isPallet,
  789. };
  790. wmsStockInsArr.push(tmpWms);
  791. let params = {
  792. guid: that.getHashId,
  793. appGroupId: that.formData.appGroupId,
  794. stockType: 1,
  795. status: "1",
  796. billTypeCode: that.formData.billTypeCode, // 单据类型
  797. billTypeName: that.formData.billTypeName,// 单据类型的名称(显示使用)
  798. taskInId: that.formData.taskInId,// 任务编号
  799. deptCode: that.formData.deptCode, //部门
  800. deptName: that.formData.deptName, //部门名称
  801. employeeCode: that.formData.employeeCode, // 职员
  802. employeeName: that.formData.employeeName, // 职员名称
  803. supplierCode : that.formData.supplierCode, //供应商
  804. supplierName: that.formData.supplierName, //供应商名称
  805. extendName01: that.formData.extendName01, // 收发类别
  806. extendCode01: that.formData.extendCode01, // 收发类别编码
  807. warehouseCode: that.formData.warehouseCode, // 仓库
  808. warehouseName: that.formData.warehouseName, // 仓库名称
  809. wmsStockInsList: wmsStockInsArr,
  810. isLocation: that.formData.isLocation,
  811. }
  812. addStockIn(params).then(res => {
  813. if(res.code === 200){
  814. that.mxNum ++;
  815. // 保存单号
  816. if(res.msg !== ""){
  817. let storageData = uni.getStorageSync('stock_key');
  818. if(storageData){
  819. let stockIdList = storageData.stockIdList;
  820. stockIdList.push(res.msg);
  821. let data = {
  822. "stockId": res.msg,
  823. "stockIdList": stockIdList
  824. }
  825. uni.setStorageSync('stock_key', data);
  826. }else{
  827. let tmpList = [];
  828. tmpList.push(res.msg);
  829. let data = {
  830. "stockId": res.msg,
  831. "stockIdList": tmpList
  832. }
  833. uni.setStorageSync('stock_key', data);
  834. }
  835. }
  836. // 清空子表信息
  837. that.EmptyEntry();
  838. if (that.isShowSaveButton) {
  839. uni.showToast({
  840. title: '保存成功',
  841. icon: 'none',
  842. duration:2000
  843. })
  844. }
  845. }
  846. }).catch((err) => {
  847. uni.vibrateLong({});
  848. });
  849. },
  850. // 任务扫码请求
  851. getScanRwList(barCode){
  852. let that = this;
  853. let params = {
  854. taskType: '1', // (固定,1是入库,0是入库退)
  855. keyWord: that.keyWord,
  856. billTypeCode: that.formData.taskBillTypeCode,
  857. params: {
  858. "barCode":barCode,
  859. "limit":1,
  860. "isControlTask": that.formData.isControlTask,
  861. },
  862. }
  863. listRwbm(params).then(res => {
  864. if(res.code === 200){
  865. let data = res.rows ? res.rows[0] : {};
  866. if(data && Object.keys(data).length !== 0){
  867. // 2.带出任务编号、供应商、供应商编码、职员名称、职员编码、部门名称、部门编码
  868. // ​ 3.放大镜选择时,关键字传参 queryParams.keyword = 关键字(无值时传空),过滤数据
  869. // ​ 4.扫码时传参,queryParams.barCode = 条码(为空时扫码失败)
  870. // 赋值任务编号
  871. this.formData.taskInCode = data.taskCode;
  872. this.formData.taskInId = data.id;
  873. // 赋值部门
  874. this.formData.deptCode = data.deptCode;
  875. this.formData.deptName = data.deptName;
  876. // 赋值职员
  877. this.formData.employeeCode = data.employeeCode;
  878. this.formData.employeeName = data.employeeName;
  879. // 赋值供应商
  880. this.formData.supplierCode = data.supplierCode;
  881. this.formData.supplierName = data.supplierName;
  882. }else{
  883. uni.showToast({
  884. title: "无数据",
  885. icon: "none"
  886. })
  887. that.formData.taskInCode = "";
  888. that.formData.taskInId = "";
  889. that.formData.deptCode = "";
  890. that.formData.deptName = "";
  891. that.formData.employeeCode = "";
  892. that.formData.employeeName = "";
  893. that.formData.supplierCode = "";
  894. that.formData.supplierName = "";
  895. }
  896. }else{
  897. uni.showToast({
  898. title: "无数据",
  899. icon: 'none',
  900. duration: 3000,
  901. })
  902. }
  903. });
  904. },
  905. //仓库扫码请求
  906. getScanCkList(barCode){
  907. let that = this;
  908. let params = {
  909. status: "0", // (固定)
  910. params: {
  911. "barCode":barCode,
  912. "limit":1
  913. },
  914. }
  915. // 仓库网络请求
  916. listWarehouse(params).then(res => {
  917. if(res.code === 200){
  918. let data = res.rows ? res.rows[0] : {};
  919. if(data && Object.keys(data).length !== 0){
  920. // 赋值仓库、货位
  921. that.formData.warehouseCode = data.warehouseCode;
  922. that.formData.warehouseName = data.warehouseName;
  923. that.formData.locationCode = "";
  924. that.formData.locationName = "";
  925. // 是否显示货位
  926. let obj = {"field": "locationCode","fieldName": "货位","required": 1,"requiredCondition": null,"hidden": null,"hiddenCondition": null}
  927. obj.required = data.isLocation == "1" ? null : 1;
  928. obj.hidden = data.isLocation == "1" ? 1 : null;
  929. that.formData.isLocation = data.isLocation;
  930. that.setFieldSetting(obj);
  931. // 清空包装托盘
  932. that.formData.palletCode = '';
  933. that.formData.palletName = '';
  934. that.formData.packageCode = '';
  935. that.formData.packageName = '';
  936. // 清空信息
  937. that.EmptyEntry();
  938. }else if(this.barCode){
  939. uni.showToast({
  940. title: "无数据",
  941. icon: "none"
  942. })
  943. }
  944. }
  945. });
  946. },
  947. //收发类别扫码请求(但不是给扫码用的,在加载时调用)
  948. getScanSflbList(barCode){
  949. let that = this;
  950. let params = {
  951. extendClassCode: "01.01",
  952. params: {
  953. "keyWord":barCode,
  954. "limit":1
  955. },
  956. }
  957. // 收发类别网络请求
  958. listExtend(params).then(res => {
  959. if(res.code === 200){
  960. let data = res.rows ? res.rows[0] : {};
  961. if(data && Object.keys(data).length !== 0){
  962. // 收发类别
  963. that.formData.extendCode01 = data.extendCode;
  964. that.formData.extendName01 = data.extendName;
  965. }else if(this.barCode){
  966. uni.showToast({
  967. title: "无数据",
  968. icon: "none"
  969. })
  970. }
  971. }
  972. });
  973. },
  974. //货位扫码请求
  975. getScanHwList(barCode){
  976. let that = this;
  977. let params = {
  978. status: "0", // (固定)
  979. params: {
  980. "barCode":barCode,
  981. "limit":1
  982. },
  983. }
  984. // 货位网络请求
  985. listLocation(params).then(res => {
  986. if(res.code === 200){
  987. let data = res.rows ? res.rows[0] : {};
  988. if(data && Object.keys(data).length !== 0){
  989. if(data.warehouseCode === that.formData.warehouseCode || '' == that.formData.warehouseCode ){ // 货位能对上仓库
  990. // 赋值货位、仓库
  991. that.formData.locationCode = data.locationCode;
  992. that.formData.locationName = data.locationName;
  993. that.formData.warehouseCode = data.warehouseCode;
  994. that.formData.warehouseName = data.warehouseName;
  995. // 显示货位
  996. let obj = {"field": "locationCode","fieldName": "货位","required": 1,"requiredCondition": null,"hidden": null,"hiddenCondition": null}
  997. obj.required = 1;
  998. that.setFieldSetting(obj);
  999. that.formData.isLocation = 0
  1000. // 清空包装托盘
  1001. that.formData.palletCode = '';
  1002. that.formData.palletName = '';
  1003. that.formData.packageCode = '';
  1004. that.formData.packageName = '';
  1005. // 清空信息
  1006. that.EmptyEntry();
  1007. }else{ // 货位对不上仓库
  1008. uni.showToast({
  1009. title: "货位不属于当前仓库",
  1010. icon: "none",
  1011. duration: 3000
  1012. })
  1013. }
  1014. }else{
  1015. uni.showToast({
  1016. title: "无数据",
  1017. icon: "none"
  1018. })
  1019. }
  1020. }
  1021. });
  1022. },
  1023. // 标签扫码请求
  1024. getScanBqList(barCode){
  1025. let that = this;
  1026. let params = {
  1027. // status: "0", //固定
  1028. params: {
  1029. "barCode" : barCode,
  1030. "limit" : 1,
  1031. "billTypeCode" : that.formData.taskBillTypeCode,
  1032. "taskInId": that.formData.billTypeCode == "1" ? undefined:that.formData.taskInId //任务id
  1033. },
  1034. supplierCode: that.formData.supplierCode, //供应商
  1035. taskInCode: that.formData.taskCode, //任务编号
  1036. }
  1037. listLabelQueryParams(params).then(res => {
  1038. if(res.code === 200){
  1039. let data = res.rows ? res.rows[0] : {};
  1040. if(data && Object.keys(data).length !== 0){
  1041. // 如果 labelType=2,隐藏任务数量
  1042. let obj = {"field": "rwQty","fieldName": "任务数量","required": null,"requiredCondition": null,"hidden": null,"hiddenCondition": null}
  1043. obj.hidden = data.labelType == 2 ? 1 : null;
  1044. that.setFieldSetting(obj)
  1045. //返回数量为0,且labelType<>2,不带出数据,提示 '标签已全部入库'
  1046. let sl = (data.labelQty || 0) - (data.inStockQty || 0);// 数量
  1047. if(sl == 0 && data.labelType != 2){
  1048. uni.showToast({
  1049. title: "标签已全部入库",
  1050. icon: "none",
  1051. duration: 3000
  1052. })
  1053. return;
  1054. }
  1055. //如果数量 >0 ,且labelType<>2,数量赋值给标签数量和任务数量,标签数量可以修改
  1056. //但不能大于任务数量(就是数量只能改小,不能改大)
  1057. if(sl > 0 && data.labelType != 2){
  1058. // 赋值标签数量
  1059. that.formData.stockQty = sl;
  1060. // 赋值任务数量
  1061. that.formData.rwQty = sl;
  1062. }
  1063. // 赋值
  1064. that.formData.taskInsId = data.taskInsId; // 任务子表id
  1065. // 赋值标签
  1066. that.formData.labelCode = data.labelCode;
  1067. that.formData.labelType = data.labelType; // 标签类型(1一次性 2重复性)
  1068. // 赋值物料编码,物料名称 , 规格
  1069. that.formData.materialName = data.materialName;
  1070. that.formData.materialCode = data.materialCode;
  1071. that.formData.materialSpecification = data.materialSpecification; //规格
  1072. // 赋值批号
  1073. that.formData.batch = data.batch;
  1074. that.formData.batch1 = data.batch1;
  1075. that.formData.batch2 = data.batch2;
  1076. // 赋值单位
  1077. that.formData.unitCode = data.unitCode;
  1078. that.formData.unitName = data.unitName;
  1079. //赋值是否托、是否包装
  1080. that.formData.isPackage = data.isPackage
  1081. that.formData.isPallet = data.isPallet
  1082. // 单据类型是生产入库,且任务编号是空,且返回的数据任务编号不为空,赋值供应商和职员
  1083. if(that.formData.billTypeCode == "1" && that.formData.taskInCode == "" && data.taskCode != ""){//单据类型:1生产入库
  1084. // 赋值供应商
  1085. that.formData.supplierCode = data.supplierCode;
  1086. that.formData.supplierName = data.supplierName;
  1087. // 赋值职员
  1088. that.formData.employeeCode = data.employeeCode;
  1089. that.formData.employeeName = data.employeeName;
  1090. }
  1091. // 任务不为空且单据类型是生产入库,扫标签要覆盖部门
  1092. if(that.formData.billTypeCode == "1" && data.taskCode){//单据类型:1生产入库
  1093. // 赋值部门
  1094. that.formData.deptCode = data.deptCode;
  1095. that.formData.deptName = data.deptName;
  1096. }
  1097. // 单据类型是生产入库,任务编号和返回的编号不一致时,赋值部门和任务编号
  1098. if(that.formData.billTypeCode == "1" && that.formData.taskInCode !== data.taskCode){
  1099. //赋值部门
  1100. if(data.deptCode && data.deptName){
  1101. that.formData.deptCode = data.deptCode;
  1102. that.formData.deptName = data.deptName;
  1103. }
  1104. //赋值任务编码
  1105. that.formData.taskInCode = data.taskInCode;
  1106. //that.formData.taskInId = data.taskInId;
  1107. }
  1108. //如果不显示保存按钮则自动保存
  1109. if (!that.isShowSaveButton) {
  1110. setTimeout(() => {
  1111. that.handleSave();
  1112. },10)
  1113. }
  1114. }else{
  1115. uni.vibrateLong({});
  1116. uni.showToast({
  1117. title: "标签无效或已扫描",
  1118. icon: "none"
  1119. })
  1120. }
  1121. }
  1122. }).catch((err) => {
  1123. uni.vibrateLong({});
  1124. });
  1125. },
  1126. //托盘扫码请求
  1127. getScanTpList(barCode){
  1128. let that = this;
  1129. let params = {
  1130. status: "0", // (固定)
  1131. locationCode: this.formData.locationCode,
  1132. warehouseCode: this.formData.warehouseCode,
  1133. params: {
  1134. "barCode":barCode,
  1135. "limit":1
  1136. },
  1137. }
  1138. // 托盘网络请求
  1139. listPallet(params).then(res => {
  1140. if(res.code === 200){
  1141. let data = res.rows ? res.rows[0] : {};
  1142. if(data && Object.keys(data).length !== 0){
  1143. that.formData.palletCode = data.palletCode;
  1144. that.formData.palletName = data.palletName;
  1145. if(data.warehouseCode){
  1146. that.formData.warehouseCode = data.warehouseCode;
  1147. that.formData.warehouseName = data.warehouseName;
  1148. }
  1149. if(data.locationCode){
  1150. that.formData.locationCode = data.locationCode;
  1151. that.formData.locationName = data.locationName;
  1152. }
  1153. that.formData.packageCode = '';
  1154. that.formData.packageName = '';
  1155. }else{
  1156. uni.showToast({
  1157. title: "无数据",
  1158. icon: "none"
  1159. })
  1160. }
  1161. }
  1162. });
  1163. },
  1164. //包装扫码请求
  1165. getScanBzList(barCode){
  1166. let that = this;
  1167. let params = {
  1168. status: "0", // (固定)
  1169. locationCode: this.formData.locationCode,
  1170. warehouseCode: this.formData.warehouseCode,
  1171. palletCode: this.formData.palletCode,
  1172. params: {
  1173. "barCode":barCode,
  1174. "limit":1
  1175. },
  1176. }
  1177. // 包装网络请求
  1178. listPackage(params).then(res => {
  1179. if(res.code === 200){
  1180. let data = res.rows ? res.rows[0] : {};
  1181. if(data && Object.keys(data).length !== 0){
  1182. that.formData.packageCode = data.packageCode;
  1183. that.formData.packageName = data.packageName;
  1184. if(data.warehouseCode){
  1185. that.formData.warehouseCode = data.warehouseCode;
  1186. that.formData.warehouseName = data.warehouseName;
  1187. }
  1188. if(data.locationCode){
  1189. that.formData.locationCode = data.locationCode;
  1190. that.formData.locationName = data.locationName;
  1191. }
  1192. if(data.palletCode){
  1193. that.formData.palletCode = data.palletCode;
  1194. that.formData.palletName = data.palletName;
  1195. }
  1196. }else{
  1197. uni.showToast({
  1198. title: "无数据",
  1199. icon: "none"
  1200. })
  1201. }
  1202. }
  1203. });
  1204. },
  1205. handleAuto(){
  1206. if(this.autoButtonTitle === "自动"){ //手动
  1207. this.autoButtonTitle = "手动";
  1208. this.isShowSaveButton = true;
  1209. }else{ //自动
  1210. this.autoButtonTitle = "自动";
  1211. this.isShowSaveButton = false;
  1212. }
  1213. },
  1214. handleBack(){
  1215. uni.showModal({
  1216. title: '提示',
  1217. content: '确认返回?',
  1218. success: function (res) {
  1219. if (res.confirm) {
  1220. //用户点击确定;
  1221. uni.navigateBack();
  1222. } else if (res.cancel) {
  1223. //用户点击取消;
  1224. }
  1225. }
  1226. });
  1227. },
  1228. getSendNum(num){
  1229. this.mxNum = num;
  1230. if(num == 0){
  1231. this.formData.appGroupId=''
  1232. }
  1233. },
  1234. SendNumEmpty(){
  1235. let that = this;
  1236. if(this.mxNum>0){
  1237. uni.showModal({
  1238. title: '新单',
  1239. content: '是否要明细归零,录入新单?',
  1240. success: function (res) {
  1241. if (res.confirm) {
  1242. that.mxNum = 0;
  1243. let data = {
  1244. "stockId": "",
  1245. "stockIdList": []
  1246. }
  1247. uni.setStorageSync('stock_key', data);
  1248. //清空唯一值
  1249. that.formData.appGroupId = '';
  1250. }
  1251. }
  1252. });
  1253. }
  1254. },
  1255. //清空任务、部门、职员、供应商
  1256. EmptyTest(){
  1257. this.formData.taskInsId = "";
  1258. this.formData.taskInCode = "";
  1259. this.formData.taskInId = "";
  1260. this.formData.deptCode = "";
  1261. this.formData.deptName = "";
  1262. this.formData.employeeCode = "";
  1263. this.formData.employeeName = "";
  1264. this.formData.supplierCode = "";
  1265. this.formData.supplierName = "";
  1266. },
  1267. //清空子表信息
  1268. EmptyEntry(){
  1269. this.formData.labelCode = "";
  1270. this.formData.materialCode = "";
  1271. this.formData.materialName = "";
  1272. this.formData.batch = "";
  1273. this.formData.unitCode = "";
  1274. this.formData.unitName = "";
  1275. this.formData.stockQty = "";
  1276. this.formData.rwQty = "";
  1277. this.formData.batch1 = "";
  1278. this.formData.batch2 = "";
  1279. this.formData.materialSpecification = "";
  1280. },
  1281. rulesStar(str){ //必录
  1282. let rules=this.rules;
  1283. if(rules[str] && rules[str].rules[0] && rules[str].rules[0].required){
  1284. return true;
  1285. }else{
  1286. return false;
  1287. }
  1288. },
  1289. fieldHidden(str){ //隐藏
  1290. let rules=this.rules;
  1291. if(rules[str] && rules[str].rules[0] && rules[str].rules[0].hidden){
  1292. return !true;
  1293. }else{
  1294. return !false;
  1295. }
  1296. },
  1297. setFieldSetting(obj){ //修改字段设置
  1298. let index = this.fieldSetting.findIndex(item => item.field == obj.field);
  1299. if (index !== -1) {
  1300. // 如果找到匹配项,则使用 obj 的属性覆盖 fieldSetting 中的相应属性
  1301. Object.assign(this.fieldSetting[index], obj);
  1302. } else {
  1303. // 如果没有找到匹配项,则将 obj 添加到 fieldSetting 中
  1304. this.fieldSetting.push(obj);
  1305. }
  1306. },
  1307. },
  1308. computed: {
  1309. /*rules: {
  1310. remark: {
  1311. rules: [
  1312. { required: true, errorMessage: '请输入条码'},
  1313. { minLength: 1, maxLength: 30, errorMessage: '条码长度在 {minLength} 到 {maxLength} 个字符'},
  1314. ]
  1315. },
  1316. deptCode: {
  1317. rules: [{ required: true, errorMessage: '部门不能为空' }],
  1318. },
  1319. warehouseName:{
  1320. rules: [{ required: true, errorMessage: '仓库不能为空' }],
  1321. },
  1322. labelCode:{
  1323. rules: [{ required: true, errorMessage: '标签不能为空' }],
  1324. },
  1325. stockQty:{
  1326. rules: [{ required: true, errorMessage: '标签数量不能为空'}],
  1327. },
  1328. employeeCode:{
  1329. rules: [{ required: true, errorMessage: '职员不能为空' }],
  1330. },
  1331. extendName01:{
  1332. rules: [{ required: true, errorMessage: '收发类别不能为空'}],
  1333. },
  1334. },*/
  1335. rules() {
  1336. let form = this.formData;
  1337. let rules = {};
  1338. if(!Array.isArray(this.fieldSetting) && this.fieldSetting.length>0){
  1339. return rules;
  1340. }
  1341. //转数组
  1342. for(let i=0;i<this.fieldSetting.length;i++){
  1343. let field = this.fieldSetting[i];
  1344. rules[field.field] = {
  1345. rules: [{ required: false, errorMessage: field.fieldName + '不能为空', hidden: false }],
  1346. }
  1347. if(field.required==1 && field.field){ //判断是否必录
  1348. //判断是否必录
  1349. if(!field.requiredCondition){ //条件为空
  1350. rules[field.field].rules[0].required = true;
  1351. }else{ //有条件;form中对应属性满足正则
  1352. //先赋值true;正则不满足再赋值false
  1353. rules[field.field].rules[0].required = true;
  1354. //判断必录用正则数组
  1355. let regArr = [];
  1356. try {
  1357. if(field.requiredCondition){
  1358. let arr = JSON.parse(field.requiredCondition);
  1359. if(arr!=null){
  1360. regArr = arr.map(([key, value]) => [key, new RegExp(value)]);
  1361. }
  1362. }
  1363. }catch(err) {
  1364. console.error("err",err)
  1365. }
  1366. for(let j=0;j<regArr.length;j++){
  1367. if(regArr[j].length==2 && regArr[j][1].test( form[regArr[j][0]] )){
  1368. rules[field.field].rules[0].required = true;
  1369. }else{
  1370. rules[field.field].rules[0].required = false;
  1371. break;
  1372. }
  1373. }
  1374. }
  1375. }
  1376. if(field.hidden==1 && field.field){ //判断是否隐藏
  1377. //判断是否必录
  1378. if(!field.hiddenCondition){ //条件为空
  1379. rules[field.field].rules[0].hidden = true;
  1380. }else{ //有条件;form中对应属性满足正则
  1381. //先赋值true;正则不满足再赋值false
  1382. rules[field.field].rules[0].hidden = true;
  1383. //判断必录用正则数组
  1384. let regArr = [];
  1385. try {
  1386. if(field.hiddenCondition){
  1387. let arr = JSON.parse(field.hiddenCondition);
  1388. if(arr!=null){
  1389. regArr = arr.map(([key, value]) => [key, new RegExp(value)]);
  1390. }
  1391. }
  1392. }catch(err) {
  1393. console.error("err",err)
  1394. }
  1395. for(let j=0;j<regArr.length;j++){
  1396. if(regArr[j].length==2 && regArr[j][1].test( form[regArr[j][0]] )){
  1397. rules[field.field].rules[0].hidden = true;
  1398. }else{
  1399. rules[field.field].rules[0].hidden = false;
  1400. break;
  1401. }
  1402. }
  1403. }
  1404. }
  1405. }
  1406. return rules;
  1407. },
  1408. getHashId(){
  1409. //生成哈希值
  1410. const crypto = require('crypto');
  1411. function hashString(str) {
  1412. const hash = crypto.createHash('sha256');
  1413. hash.update(str);
  1414. return hash.digest('hex');
  1415. }
  1416. //null和undefined返回空
  1417. function IFNULL(str){
  1418. return (str==null || str==undefined) ? "" : str + "";
  1419. }
  1420. //使用头信息和nanoid来生成唯一值
  1421. let groupJson = {
  1422. appGroupId : this.formData.appGroupId,
  1423. billTypeCode : IFNULL(this.formData.billTypeCode),
  1424. taskInId : IFNULL(this.formData.taskInId),
  1425. deptCode : IFNULL(this.formData.deptCode),
  1426. employeeCode : IFNULL(this.formData.employeeCode),
  1427. supplierCode : IFNULL(this.formData.supplierCode),
  1428. warehouseCode : IFNULL(this.formData.warehouseCode),
  1429. extendCode01 : IFNULL(this.formData.extendCode01),
  1430. extendCode02 : IFNULL(this.formData.extendCode02),
  1431. extendCode03 : IFNULL(this.formData.extendCode03),
  1432. extendCode04 : IFNULL(this.formData.extendCode04),
  1433. extendCode05 : IFNULL(this.formData.extendCode05),
  1434. }
  1435. let groupStr = JSON.stringify(groupJson)
  1436. const hash = hashString(groupStr)
  1437. return hash
  1438. },
  1439. },
  1440. }
  1441. </script>
  1442. <style>
  1443. @import "@/static/scss/stock.css";
  1444. </style>