in-store-add-scan.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <view class="mx3">
  3. <my-add-button @handleClick="openSpare" />
  4. <view class="main-color-bg main-bg-future"></view>
  5. <view class="p3 bg-color-white form-view">
  6. <u-form :model="form" :error-type="['message']" ref="uForm" >
  7. <view class="main-color-text f-size-32 f-weight-6">入库信息</view>
  8. <u-form-item label="仓库名称" prop="storeId" required label-width="150">
  9. <my-select
  10. :list="storeList"
  11. :value-name="'id'"
  12. :label-name="'name'"
  13. v-model="form.storeId"
  14. placeholder="请选择仓库"
  15. @selected="storeSelect"
  16. />
  17. </u-form-item>
  18. <u-form-item label="备品用途" prop="type" required label-width="150">
  19. <my-select
  20. :list="reasonList"
  21. v-model="form.type"
  22. @selected="typeSelect"
  23. placeholder="请选择备品用途" />
  24. </u-form-item>
  25. <u-form-item label="入库说明" label-width="150">
  26. <u-input type="textarea" v-model="form.remark" />
  27. </u-form-item>
  28. </u-form>
  29. </view>
  30. <view class="p3 bg-color-white form-view mt-3-imt" v-if="receiveDetailFormList && receiveDetailFormList.length>0">
  31. <!-- <view class="main-color-text f-size-32 f-weight-6">入库明细</view> -->
  32. <u-form
  33. :error-type="['message']"
  34. v-for="(item,index) in receiveDetailFormList"
  35. :key="index"
  36. :model="receiveDetailFormList[index]"
  37. :ref="item.formName"
  38. >
  39. <view class="main-color-text f-size-32 f-weight-6 d-flex j-between" @tap="del(index)">
  40. 入库明细
  41. <u-icon name="close-circle" color="red"></u-icon>
  42. </view>
  43. <u-form-item label="名称" prop="spareId" required label-width="150">
  44. <u-input
  45. v-model="item.spareName"
  46. disabled
  47. @click="handleSelect(item.formName)"
  48. placeholder="请选择"
  49. type="select"
  50. />
  51. </u-form-item>
  52. <u-form-item label="数量" prop="num" required label-width="150">
  53. <u-input type="number" v-model="item.num" />
  54. </u-form-item>
  55. </u-form>
  56. </view>
  57. <view class="mt-3">
  58. <u-button @click="submit" type="primary" shape="circle">提交</u-button>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. export default {
  64. data() {
  65. return {
  66. typeMap: {},
  67. form: {
  68. storeId: '',
  69. type: '',
  70. reason: '',
  71. storeName: null
  72. },
  73. receiveDetailFormList: [
  74. ],
  75. backSpareId: '',
  76. backSpareName: '',
  77. backFormName: '',
  78. backPrice: 0,
  79. isRefreshDetail: true,
  80. sbSpareList: [],
  81. storeList: [],
  82. reasonList: [
  83. {
  84. label: '采购入库',
  85. value: '1'
  86. }, {
  87. label: '闲置入库',
  88. value: '2'
  89. }, {
  90. label: '调拨入库',
  91. value: '3'
  92. }, {
  93. label: '发运入库',
  94. value: '4'
  95. }, {
  96. label: '盘点校准',
  97. value: '5'
  98. }
  99. ],
  100. rules: {
  101. type: [
  102. {
  103. required: true,
  104. message: '请选择入库类型',
  105. trigger: ['change']
  106. }
  107. ],
  108. storeId: [
  109. {
  110. required: true,
  111. message: '请选择仓库',
  112. trigger: ['change']
  113. }
  114. ]
  115. },
  116. detailFormRules: {
  117. spareId: [
  118. {
  119. required: true,
  120. message: '请选择备品',
  121. trigger: ['change']
  122. }
  123. ],
  124. num: [
  125. {
  126. required: true,
  127. message: '请填写数量',
  128. trigger: ['change', 'blur']
  129. }
  130. ]
  131. },
  132. id: '', // 列表 id
  133. aId: 0
  134. };
  135. },
  136. created () {
  137. this.typeMap = this.$DictCache.getLabelByValueMapByType(this.$DictCache.TYPE.IN_STORE_FORM_TYPE)
  138. },
  139. onShow() {
  140. // 获取设备与仓库
  141. this.initData();
  142. },
  143. onLoad(options) {},
  144. methods: {
  145. del(index) {
  146. console.log(this.receiveDetailFormList);
  147. this.receiveDetailFormList.splice(index, 1)
  148. console.log(this.receiveDetailFormList);
  149. },
  150. handleSelect(formName) {
  151. const spareId = '121'
  152. this.$Http.getSpareStorePage({ storeId: this.form.storeId, spareId: spareId, pageNum: 1, pageSize: 1 })
  153. .then(res => {
  154. const spareList = res.data.rows
  155. let scanSpare = ''
  156. if(spareList ==null || spareList.length == 0){
  157. // 从备件基础表里面选
  158. this.$Http.fetchSparePartInfo({ id: spareId}).then(res2 => {
  159. scanSpare = res2.data
  160. this.receiveDetailFormList.forEach(spare => {
  161. if (spare.formName === formName) {
  162. spare.spareId = scanSpare.spareId;
  163. spare.spareName = scanSpare.name;
  164. spare.price = scanSpare.price;
  165. }
  166. })
  167. })
  168. }else{
  169. scanSpare = spareList[0]
  170. this.receiveDetailFormList.forEach(spare => {
  171. if (spare.formName === formName) {
  172. spare.spareId = scanSpare.spareId;
  173. spare.spareName = scanSpare.spareName;
  174. spare.price = scanSpare.price;
  175. }
  176. })
  177. }
  178. })
  179. },
  180. // 扫码出库
  181. handleSelectScan(formName) {
  182. // #ifdef H5
  183. uni.showToast({
  184. title: "暂不支持该功能",
  185. icon: "none"
  186. });
  187. // #endif
  188. // #ifndef H5
  189. uni.scanCode({
  190. success(e) {
  191. if (e.result) {
  192. const spareId = e.result;
  193. this.$Http.getSpareStorePage({ storeId: 2, spareId: spareId, pageNum: 1, pageSize: 1 })
  194. .then(res => {
  195. const spareList = res.data.rows
  196. if(spareList ==null || spareList.length == 0){
  197. uni.showToast({
  198. title: "该仓库无此备件,请重新扫描",
  199. icon: "none",
  200. });
  201. }
  202. const scanSpare = spareList[0]
  203. this.receiveDetailFormList.forEach(spare => {
  204. if (spare.formName === formName) {
  205. spare.spareId = scanSpare.spareId;
  206. spare.spareName = scanSpare.spareName;
  207. spare.price = scanSpare.price;
  208. }
  209. })
  210. })
  211. }
  212. },
  213. });
  214. // #endif
  215. },
  216. initData() {
  217. if(this.storeList.length == 0){
  218. this.$Http.getStorePage({ filter: 2, pageNum: 1, pageSize: 1000 })
  219. .then(res => {
  220. this.storeList = res.data.rows
  221. })
  222. }
  223. },
  224. openSpare() {
  225. /* if (this.$BaseTool.Object.isBlank(this.form.type)) {
  226. uni.showToast({
  227. title: '请先选择备品用途',
  228. icon: 'none'
  229. });
  230. return
  231. } */
  232. if (this.$BaseTool.String.isBlank(this.form.storeId)) {
  233. uni.showToast({
  234. title: '请先选择仓库',
  235. icon: 'none'
  236. });
  237. return
  238. }
  239. this.aId++
  240. const detailForm = {
  241. spareId: '',
  242. num: '',
  243. spareName: '',
  244. formName: 'form' + this.aId,
  245. price: '',
  246. item: null
  247. };
  248. if (!this.isRefreshDetail) {
  249. this.receiveDetailFormList.push(detailForm)
  250. this.$nextTick(() => {
  251. this.$refs[detailForm.formName][0].setRules(this.detailFormRules);
  252. })
  253. return
  254. }
  255. if (!this.isRefreshDetail && this.sbSpareList != null && this.sbSpareList.length > 0) {
  256. return
  257. }
  258. this.$Http.getSpareStorePage({
  259. storeId: this.form.storeId,
  260. num: 0,
  261. pageNum: 1,
  262. pageSize: 10000,
  263. dataScope: {
  264. sortBy: 'desc',
  265. sortName: 'update_time'
  266. }
  267. }).then(res => {
  268. const sbSpareList = res.data.rows
  269. if (sbSpareList == null || sbSpareList.length === 0) {
  270. this.isRefreshDetail = true;
  271. uni.showToast({
  272. title: '该仓库没有备品',
  273. icon: 'none'
  274. });
  275. return
  276. }
  277. this.sbSpareList = res.data.rows
  278. this.receiveDetailFormList.push(detailForm)
  279. this.$nextTick(() => {
  280. this.$refs[detailForm.formName][0].setRules(this.detailFormRules);
  281. })
  282. this.isRefreshDetail = false;
  283. })
  284. },
  285. storeSelect(value, item) {
  286. this.form.storeName = item.name;
  287. this.isRefreshDetail = true;
  288. this.receiveDetailFormList = []
  289. },
  290. typeSelect(value, item) {
  291. this.isRefreshDetail = true;
  292. //this.receiveDetailFormList = []
  293. },
  294. spareSelect(value, item) {
  295. this.receiveDetailFormList.forEach(spare => {
  296. if (spare.spareId === item.spareId) {
  297. spare.item = item;
  298. } else {
  299. console.log(2222, spare.spareId, item.id)
  300. }
  301. })
  302. },
  303. // 提交
  304. submit() {
  305. if (this.receiveDetailFormList == null || this.receiveDetailFormList.length === 0) {
  306. uni.showToast({
  307. title: '请添加入库明细',
  308. icon: 'none'
  309. });
  310. return
  311. }
  312. const promiseList = []
  313. promiseList.push(
  314. new Promise((resolve, reject) => {
  315. this.$refs.uForm.validate().then(valid => {
  316. if (valid) {
  317. resolve(valid);
  318. } else {
  319. reject(valid);
  320. }
  321. })
  322. })
  323. );
  324. this.receiveDetailFormList.forEach(item => {
  325. promiseList.push(
  326. new Promise((resolve, reject) => {
  327. this.$refs[item.formName][0].validate(valid => {
  328. if (valid) {
  329. resolve(valid);
  330. } else {
  331. reject(valid);
  332. }
  333. })
  334. })
  335. );
  336. })
  337. Promise.all(promiseList).then(res => {
  338. // 执行
  339. const params = { ...this.form }
  340. const detailList = []
  341. this.receiveDetailFormList.forEach(item => {
  342. const space = item.item;
  343. const detail = {
  344. spareId: item.spareId,
  345. num: item.num,
  346. price: item.price,
  347. spareName: item.spareName,
  348. storeNum: item.num,
  349. totalPrice: this.$BaseTool.Number.mul(item.num, item.price)
  350. }
  351. detailList.push(detail);
  352. })
  353. params.detailList = detailList;
  354. console.log(33, params)
  355. this.$Http.addInStoreForm(params).then(res => {
  356. uni.redirectTo({
  357. url: '/pages/in-store/in-store-detail?id=' + res.data.id
  358. });
  359. })
  360. }, err => {
  361. console.log(err)
  362. })
  363. }
  364. },
  365. onReady() {
  366. console.log(4444, this.$refs.uForm)
  367. this.$refs.uForm.setRules(this.rules);
  368. }
  369. };
  370. </script>
  371. <style lang="less">
  372. page {
  373. background-color: #f4f4f4;
  374. }
  375. .mt-3-imt {
  376. margin-top: 30rpx;
  377. }
  378. </style>