out-store-add.vue 13 KB

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