out-store-add-scan.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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.OUT_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. if(spareList ==null || spareList.length == 0){
  156. uni.showToast({
  157. title: "该仓库无此备件,请重新扫描",
  158. icon: "none",
  159. });
  160. }
  161. const scanSpare = spareList[0]
  162. this.receiveDetailFormList.forEach(spare => {
  163. if (spare.formName === formName) {
  164. spare.spareId = scanSpare.spareId;
  165. spare.spareName = scanSpare.spareName;
  166. spare.price = scanSpare.price;
  167. }
  168. })
  169. })
  170. },
  171. // 扫码出库
  172. handleSelectScan(formName) {
  173. // #ifdef H5
  174. uni.showToast({
  175. title: "暂不支持该功能",
  176. icon: "none"
  177. });
  178. // #endif
  179. // #ifndef H5
  180. uni.scanCode({
  181. success(e) {
  182. if (e.result) {
  183. const spareId = e.result;
  184. this.$Http.getSpareStorePage({ storeId: 2, spareId: spareId, pageNum: 1, pageSize: 1 })
  185. .then(res => {
  186. const spareList = res.data.rows
  187. if(spareList ==null || spareList.length == 0){
  188. uni.showToast({
  189. title: "该仓库无此备件,请重新扫描",
  190. icon: "none",
  191. });
  192. }
  193. const scanSpare = spareList[0]
  194. this.receiveDetailFormList.forEach(spare => {
  195. if (spare.formName === formName) {
  196. spare.spareId = scanSpare.spareId;
  197. spare.spareName = scanSpare.spareName;
  198. spare.price = scanSpare.price;
  199. }
  200. })
  201. })
  202. }
  203. },
  204. });
  205. // #endif
  206. },
  207. initData() {
  208. if(this.storeList.length == 0){
  209. this.$Http.getStorePage({ filter: 2, pageNum: 1, pageSize: 1000 })
  210. .then(res => {
  211. this.storeList = res.data.rows
  212. })
  213. }
  214. },
  215. openSpare() {
  216. /* if (this.$BaseTool.Object.isBlank(this.form.type)) {
  217. uni.showToast({
  218. title: '请先选择备品用途',
  219. icon: 'none'
  220. });
  221. return
  222. } */
  223. if (this.$BaseTool.String.isBlank(this.form.storeId)) {
  224. uni.showToast({
  225. title: '请先选择仓库',
  226. icon: 'none'
  227. });
  228. return
  229. }
  230. this.aId++
  231. const detailForm = {
  232. spareId: '',
  233. num: '',
  234. spareName: '',
  235. formName: 'form' + this.aId,
  236. price: '',
  237. item: null
  238. };
  239. if (!this.isRefreshDetail) {
  240. this.receiveDetailFormList.push(detailForm)
  241. this.$nextTick(() => {
  242. this.$refs[detailForm.formName][0].setRules(this.detailFormRules);
  243. })
  244. return
  245. }
  246. if (!this.isRefreshDetail && this.sbSpareList != null && this.sbSpareList.length > 0) {
  247. return
  248. }
  249. this.$Http.getSpareStorePage({
  250. storeId: this.form.storeId,
  251. num: 0,
  252. pageNum: 1,
  253. pageSize: 10000,
  254. dataScope: {
  255. sortBy: 'desc',
  256. sortName: 'update_time'
  257. }
  258. }).then(res => {
  259. const sbSpareList = res.data.rows
  260. if (sbSpareList == null || sbSpareList.length === 0) {
  261. this.isRefreshDetail = true;
  262. uni.showToast({
  263. title: '该仓库没有备品',
  264. icon: 'none'
  265. });
  266. return
  267. }
  268. this.sbSpareList = res.data.rows
  269. this.receiveDetailFormList.push(detailForm)
  270. this.$nextTick(() => {
  271. this.$refs[detailForm.formName][0].setRules(this.detailFormRules);
  272. })
  273. this.isRefreshDetail = false;
  274. })
  275. },
  276. storeSelect(value, item) {
  277. this.form.storeName = item.name;
  278. this.isRefreshDetail = true;
  279. this.receiveDetailFormList = []
  280. },
  281. typeSelect(value, item) {
  282. this.isRefreshDetail = true;
  283. //this.receiveDetailFormList = []
  284. },
  285. // 提交
  286. submit() {
  287. if (this.receiveDetailFormList == null || this.receiveDetailFormList.length === 0) {
  288. uni.showToast({
  289. title: '请添加出库明细',
  290. icon: 'none'
  291. });
  292. return
  293. }
  294. const promiseList = []
  295. promiseList.push(
  296. new Promise((resolve, reject) => {
  297. this.$refs.uForm.validate().then(valid => {
  298. if (valid) {
  299. resolve(valid);
  300. } else {
  301. reject(valid);
  302. }
  303. })
  304. })
  305. );
  306. this.receiveDetailFormList.forEach(item => {
  307. promiseList.push(
  308. new Promise((resolve, reject) => {
  309. this.$refs[item.formName][0].validate(valid => {
  310. if (valid) {
  311. resolve(valid);
  312. } else {
  313. reject(valid);
  314. }
  315. })
  316. })
  317. );
  318. })
  319. Promise.all(promiseList).then(res => {
  320. // 执行
  321. const params = { ...this.form }
  322. const detailList = []
  323. this.receiveDetailFormList.forEach(item => {
  324. const space = item.item;
  325. const detail = {
  326. spareId: item.spareId,
  327. num: item.num,
  328. price: item.price,
  329. spareName: item.spareName,
  330. storeNum: item.num,
  331. totalPrice: this.$BaseTool.Number.mul(item.num, item.price)
  332. }
  333. detailList.push(detail);
  334. })
  335. params.detailList = detailList;
  336. console.log(33, params)
  337. this.$Http.addOutStoreForm(params).then(res => {
  338. uni.redirectTo({
  339. url: '/pages/out-store/out-store-detail?id=' + res.data.id
  340. });
  341. })
  342. }, err => {
  343. console.log(err)
  344. })
  345. }
  346. },
  347. onReady() {
  348. console.log(4444, this.$refs.uForm)
  349. this.$refs.uForm.setRules(this.rules);
  350. }
  351. };
  352. </script>
  353. <style lang="less">
  354. page {
  355. background-color: #f4f4f4;
  356. }
  357. .mt-3-imt {
  358. margin-top: 30rpx;
  359. }
  360. </style>