CreateBound.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <uni-drawer ref="drawer" mode="left" :mask-click="false" width="85%" :maskClick='true'>
  3. <scroll-view class="scroll-view" scroll-y="true">
  4. <uni-section :title="'新增物资:' + (type==='in'?'入库':'出库')" type="line"></uni-section>
  5. <view class="form-wrap" >
  6. <uni-forms ref="form" label-position="top" :rules="rules" :model="form">
  7. <view class="inbound" v-if="type==='in'">
  8. <uni-forms-item label="入库人员" name="accountId" required>
  9. <uni-data-select v-model="form.accountId" :localdata="userList" placeholder="请选择入库人员" :clear="false"></uni-data-select>
  10. </uni-forms-item>
  11. <uni-forms-item label="入库类型" name="inboundType" required>
  12. <uni-data-select v-model="form.inboundType" :localdata="inboundTypeList" placeholder="请选择入库类型" :clear="false"></uni-data-select>
  13. </uni-forms-item>
  14. <uni-forms-item label="物资种类" name="goodsCatId" required>
  15. <uni-data-select v-model="form.goodsCatId" :localdata="goodsCats" placeholder="请选择物资种类" :clear="false"></uni-data-select>
  16. </uni-forms-item>
  17. <uni-forms-item label="物资数量" label-position="left" required>
  18. <uni-easyinput v-model="form.qty" placeholder="请输入物资数量" :clearable="false" />
  19. </uni-forms-item>
  20. <uni-forms-item label="物资编号" >
  21. <uni-easyinput v-model="form.goodsNo" placeholder="请输入物资编号" :clearable="false" />
  22. </uni-forms-item>
  23. <uni-forms-item label="存放位置" name="inboundLocation">
  24. <uni-easyinput v-model="form.inboundLocation" placeholder="请输入存放位置" :clearable="false" />
  25. </uni-forms-item>
  26. <uni-forms-item label="物资名称" >
  27. <uni-easyinput v-model="form.goodsTitle" ></uni-easyinput>
  28. </uni-forms-item>
  29. <uni-forms-item label="生产日期">
  30. <uni-datetime-picker type="date" v-model="form.goodsPdDate" />
  31. </uni-forms-item>
  32. <uni-forms-item label="过期时间">
  33. <uni-datetime-picker type="date" v-model="form.goodsExpDate"/>
  34. </uni-forms-item>
  35. <uni-forms-item label="物资说明">
  36. <uni-easyinput type="textarea" :maxlength="1000" v-model="form.goodsDesc" placeholder="请输入物资说明" autoHeight ></uni-easyinput>
  37. <view class="word-limit">{{form.goodsDesc.length||0}}/1000</view>
  38. </uni-forms-item>
  39. </view>
  40. <view class="outbound" v-if="type==='out'">
  41. <uni-card margin="10px 0">
  42. <uni-list>
  43. <uni-list-item title="物资种类" >
  44. <template v-slot:footer><uni-tag :text="form.goodsCatTitle" type="success"></uni-tag></template>
  45. </uni-list-item>
  46. <uni-list-item title="库存数量" >
  47. <template v-slot:footer><uni-tag :text="`${form.qty}`" type="primary"></uni-tag></template>
  48. </uni-list-item>
  49. </uni-list>
  50. </uni-card>
  51. <uni-forms-item label="出库类型" name="outboundType" v-if="type==='out'" required>
  52. <uni-data-select v-model="form.outboundType" :localdata="outboundTypeList" placeholder="请选择出库类型" :clear="false"></uni-data-select>
  53. </uni-forms-item>
  54. <uni-forms-item label="出库人员" name="accountId" required>
  55. <uni-data-select v-model="form.accountId" :localdata="userList" placeholder="请选择出库人员" :clear="false"></uni-data-select>
  56. </uni-forms-item>
  57. <uni-forms-item label="物资名称" label-position="left" required>
  58. <uni-easyinput v-model="form.goodsTitle" placeholder="请输物资名称" :clearable="false" />
  59. </uni-forms-item>
  60. <uni-forms-item label="出库数量" label-position="left" required>
  61. <uni-easyinput v-model="form.qty" placeholder="请输出库数量" :clearable="false" />
  62. </uni-forms-item>
  63. <uni-forms-item label="出库地点">
  64. <uni-easyinput type="textarea" :maxlength="100"
  65. v-model="form.outboundLocation" autoHeight
  66. placeholder="请输入出库地点"></uni-easyinput>
  67. <view class="word-limit">{{form.outboundLocation.length||0}}/100</view>
  68. </uni-forms-item>
  69. </view>
  70. <uni-forms-item label="备注">
  71. <uni-easyinput type="textarea" :maxlength="500"
  72. v-model="form.remark" autoHeight
  73. placeholder="请输入备注"></uni-easyinput>
  74. <view class="word-limit">{{form.remark.length||0}}/500</view>
  75. </uni-forms-item>
  76. </uni-forms>
  77. <view class="handle-container">
  78. <button class="save" type="primary" @click="onSubmit">保存</button>
  79. <button class="cancel" type="default" @click="close">取消</button>
  80. </view>
  81. </view>
  82. </scroll-view>
  83. </uni-drawer>
  84. </template>
  85. <script>
  86. import goodsApi from '@/api/goods.js'
  87. import { parseTime } from '@/libs'
  88. export default{
  89. name:"CreateBound",
  90. computed:{
  91. ocId(){
  92. let accountInfo=uni.getStorageSync('accountInfo')
  93. if(!accountInfo)return undefined
  94. return accountInfo.ocId
  95. },
  96. goodsCats(){
  97. let goodsCats=this.cats
  98. if(!goodsCats)return []
  99. return goodsCats.map(item=>{
  100. return{
  101. value:item.goodsCatId,
  102. text:item.goodsCatTitle
  103. }
  104. })
  105. },
  106. userList(){
  107. let groupUser=uni.getStorageSync('groupUser')
  108. let userList=[]
  109. groupUser.map((item,index)=>{
  110. userList.push({...item,value:`root-${index+1}`,text:item.name,disable:true})
  111. if(Array.isArray(item.children)&&item.children.length>0){
  112. userList=userList.concat(item.children.map(item=>{return{...item,value:item.accountId,text:item.accountName}}))
  113. }
  114. })
  115. return userList
  116. }
  117. },
  118. props:{
  119. cats:{
  120. type:Array,
  121. default:()=>[]
  122. }
  123. },
  124. data(){
  125. return{
  126. type:undefined,
  127. rules:{
  128. accountId:{
  129. rules:[
  130. {
  131. required: true,
  132. errorMessage:this.type==='in'?'入库人员':'出库人员'
  133. }
  134. ],
  135. validateTrigger:'submit'
  136. },
  137. intboundType:{
  138. rules:[
  139. {
  140. required: true,
  141. errorMessage:"请选择入库类型"
  142. }
  143. ],
  144. validateTrigger:'submit'
  145. },
  146. outboundType:{
  147. rules:[
  148. {
  149. required: true,
  150. errorMessage:"请选择出库类型"
  151. }
  152. ],
  153. validateTrigger:'submit'
  154. },
  155. goodsCatId:{
  156. rules:[
  157. {
  158. required: true,
  159. errorMessage: '请选择物资种类',
  160. }
  161. ],
  162. validateTrigger:'submit'
  163. },
  164. },
  165. inboundTypeList:[
  166. { value: 1, text: '正常入库' },
  167. { value: 2, text: '报溢' },
  168. ],
  169. outboundTypeList:[
  170. { value: 1, text: '正常出库' },
  171. { value: 2, text: '报损' },
  172. { value: 3, text: '过期' },
  173. ],
  174. form:{
  175. groupId: undefined,
  176. groupName: undefined,
  177. inboundId: 0,
  178. inboundType: 1,
  179. inboundTime: '',
  180. inboundLocation: '',
  181. accountId: "",
  182. accountName:"",
  183. goodsType: "",
  184. goodsCatId: 1,
  185. goodsCatTitle: '',
  186. qty: 1,
  187. goodsNo: '',
  188. goodsTitle: '',
  189. goodsPdDate: '',
  190. goodsExpDate: '',
  191. goodsDesc: '',
  192. remark: '',
  193. //out
  194. outboundId: 0,
  195. outboundType: 1,
  196. outboundTime: '',
  197. outboundLocation: ''
  198. }
  199. }
  200. },
  201. methods:{
  202. resetForm(){
  203. this.form={
  204. groupId: undefined,
  205. groupName: undefined,
  206. inboundId: 0,
  207. inboundType: 1,
  208. inboundTime: '',
  209. inboundLocation: '',
  210. accountId: "",
  211. accountName:"",
  212. goodsType: "",
  213. goodsCatId: 1,
  214. goodsCatTitle: '',
  215. qty: 1,
  216. goodsNo: '',
  217. goodsTitle: '',
  218. goodsPdDate: '',
  219. goodsExpDate: '',
  220. goodsDesc: '',
  221. remark: '',
  222. //out
  223. outboundId: 0,
  224. outboundType: 1,
  225. outboundTime: '',
  226. outboundLocation: ''
  227. }
  228. },
  229. onSubmit(){
  230. this.$refs.form.validate().then(res=>{
  231. let submitFx=this.type==='in'?goodsApi.createInbound:goodsApi.createOutbound
  232. let user=this.userList.find(item=>this.form.accountId===item.accountId)
  233. let goodsCat=this.goodsCats.find(item=>this.form.goodsCatId===item.value)
  234. let params={
  235. accountId: user.accountId,
  236. accountName: user.accountName,
  237. positionId: user.positionId,
  238. positionName: user.positionName,
  239. ocId:this.ocId,
  240. goodsType: this.form.goodsType,
  241. goodsCatId: goodsCat.value,
  242. goodsCatTitle:goodsCat.text,
  243. qty: this.form.qty,
  244. remark: this.form.remark
  245. }
  246. if(this.type==='in'){
  247. params={...params,
  248. goodsNo:this.form.goodsNo,
  249. goodsTitle: this.form.goodsTitle,
  250. goodsPdDate:this.form.goodsPdDate,
  251. goodsExpDate: this.form.goodsExpDate,
  252. goodsDesc: this.form.goodsDesc,
  253. inboundId: this.form.inboundId,
  254. inboundType: this.form.inboundType,
  255. inboundTime: this.form.inboundTime,
  256. inboundLocation: this.form.inboundLocation,
  257. }
  258. }else{
  259. params={...params,
  260. outboundId: this.form.outboundId,
  261. outboundType: this.form.outboundType,
  262. outboundTime: this.form.outboundTime,
  263. outboundLocation: this.form.outboundLocation,
  264. }
  265. }
  266. submitFx(params).then(()=>{
  267. uni.showToast({
  268. icon:"none",
  269. title:"成功!!"
  270. })
  271. this.$emit('success',this.type==='in'?1:2)
  272. this.close();
  273. })
  274. }).catch(err =>{
  275. uni.showToast({
  276. icon:"none",
  277. title:"请检查填写信息!"
  278. })
  279. })
  280. },
  281. show({type,item}){
  282. this.resetForm()
  283. this.form={...this.form,...item}
  284. this.type=type
  285. this.$refs.drawer.open()
  286. },
  287. close(){
  288. this.$refs.drawer.close()
  289. }
  290. }
  291. }
  292. </script>
  293. <style lang="scss" scoped>
  294. .scroll-view {
  295. height: 100%;
  296. padding: 20rpx;
  297. box-sizing: border-box;
  298. .form-wrap{
  299. padding:40rpx 20rpx;
  300. .handle-container{
  301. display: flex;
  302. justify-content: center;
  303. align-items: center;
  304. button{
  305. width: 160rpx;
  306. padding: 20rpx 16rpx;
  307. line-height: 1;
  308. font-size: 28rpx;
  309. &.save{
  310. background-color: #007aff;
  311. }
  312. }
  313. }
  314. .word-limit{
  315. text-align: right;
  316. padding: 10rpx 0;
  317. color: #999;
  318. font-size: 26rpx;
  319. }
  320. }
  321. }
  322. </style>