RecordEdit.vue 9.0 KB

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