work-order-edit.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view class="page">
  3. <uni-section title='报工单信息' type='line' :strong="true" class="bg-white"/>
  4. <view class="bg-white mb-1">
  5. <list-input title="工艺流程卡编码" :highlight="false" :subTitle="GYLCKH" :span='8' />
  6. <list-input title="当前应报工序" :highlight="false" :span='8'>
  7. <template v-if='detail.GX'>{{detail.GX}}</template>
  8. <template v-else>--</template>
  9. </list-input>
  10. <list-input title="应报工数量" :highlight="false" :span='8'>
  11. <template v-if='detail.LZSL'>{{detail.LZSL}}</template>
  12. <template v-else>--</template>
  13. </list-input>
  14. </view>
  15. <view class="bg-white mb-1">
  16. <list-input title="报工工序说明" :span="8" class="rounded">
  17. <textarea
  18. class='width-100 form-item-textarea px-2'
  19. :class="isTextAreaFocus ? 'text-left' : 'text-right form-item-textarea-blur' "
  20. v-model='produceDesc'
  21. placeholder="请输入"
  22. auto-height
  23. @focus="onFocus('textarea')"
  24. @blur="onBlur('textarea')"
  25. />
  26. </list-input>
  27. </view>
  28. <template v-for='(item,index) in list'>
  29. <list-item-delete :index='index' :showClear="showClear" @delete='onDelete(index)'>
  30. <view class="bg-white">
  31. <list-input title="生产人员员工号">
  32. <input type="text" v-model='item.workerno' placeholder="请输入" class='text-right form-item-input' />
  33. </list-input>
  34. <list-input title="生产数量">
  35. <input type="text" v-model='item.amount' placeholder="请输入" class='text-right form-item-input' />
  36. </list-input>
  37. </view>
  38. </list-item-delete>
  39. </template>
  40. <view class="my-2 mb-5 text-center">
  41. <btn-add @click="onAddWoker">添加生产人员</btn-add>
  42. </view>
  43. <btn-save @save='onSave' :disabledOk="disabledSubmit"/>
  44. </view>
  45. </template>
  46. <script>
  47. import uniSection from "@/components/uni-ui/uni-section/uni-section.vue"
  48. import listInput from "@/components/common/list-input.vue"
  49. import btnSave from "@/components/common/btn-save.vue"
  50. import btnAdd from "@/components/common/btn-add.vue"
  51. import listItemDelete from "@/components/common/list-item-delete.vue"
  52. import {formateScanData,showBackToast} from "@/common/utils/common.js"
  53. import {MAX_SCAN_NUM,MSG_MAX_SCAN,ERROR_GYLCKH_NODATA} from "@/common/utils/tipMessage.js"
  54. import {mapGetters,mapState} from "vuex"
  55. import {CORRECT_CODE} from "@/api/config.js"
  56. import {queryWorkreport,workreportSave} from "@/api/api.js"
  57. export default {
  58. components:{
  59. uniSection,
  60. listInput,
  61. btnSave,
  62. listItemDelete,
  63. btnAdd
  64. },
  65. data () {
  66. return {
  67. list:[{
  68. workerno:null,
  69. amount:null,
  70. }],
  71. detail:{}, // 明细
  72. GYLCKH:null, // 工艺流程卡编码
  73. isTextAreaFocus:false ,// 是否聚焦文本框
  74. produceDesc:"",// 报工工序说明
  75. defaultCkList:[], // 默认仓库列表
  76. }
  77. },
  78. computed:{
  79. ...mapState(['loginResponse']),
  80. ...mapGetters(['disabledSubmit']),
  81. //是否跳转到领料单
  82. goMaterial () {
  83. const detail=this.detail
  84. if (detail.XYCZ > 0 && Number(detail.xh)===1) {
  85. return true
  86. }else{
  87. return false
  88. }
  89. return false
  90. },
  91. // 是否显示清空按钮
  92. showClear () {
  93. const item=this.list[0]
  94. const x=(item.workerno || item.amount) ? true : false
  95. }
  96. },
  97. onLoad (e) {
  98. if (!e.barcode) {
  99. return uni.navigateBack({
  100. delta:1
  101. })
  102. }
  103. this.GYLCKH=e.barcode // 条形码
  104. this.initPage()
  105. },
  106. methods:{
  107. // 初始化页面
  108. async initPage () {
  109. await this._queryWorkreport()
  110. this.list[0].amount=this.detail.LZSL
  111. },
  112. // 获取默认仓库
  113. async _queryDefaultStorage () {
  114. let resdata=await queryDefaultStorage()
  115. this.defaultCkList=resdata
  116. return this.defaultCkList
  117. },
  118. // 获取明细
  119. async _queryWorkreport () {
  120. const reqdata={
  121. GYLCKH:this.GYLCKH,
  122. YGH:this.loginResponse.userid,
  123. }
  124. const res=await queryWorkreport(reqdata)
  125. if(res.code!=CORRECT_CODE){
  126. return showBackToast()
  127. }
  128. if (res.data.length===0) {
  129. return showBackToast(ERROR_GYLCKH_NODATA)
  130. }
  131. this.detail=res.data[0]
  132. return this.detail
  133. },
  134. // 聚焦
  135. onFocus (key) {
  136. switch (key) {
  137. case "textarea" :
  138. this.isTextAreaFocus=true
  139. break;
  140. }
  141. },
  142. // 失去焦点
  143. onBlur (key) {
  144. switch (key) {
  145. case "textarea" :
  146. this.isTextAreaFocus=false
  147. break;
  148. }
  149. },
  150. // 删除工作人员
  151. onDelete (index) {
  152. uni.showModal({
  153. title:'确认删除该条物品吗?',
  154. success:(res)=>{
  155. if (res.confirm) {
  156. this.list.splice(index,1)
  157. }
  158. }
  159. })
  160. },
  161. // 添加 工作人员
  162. onAddWoker () {
  163. if (this.list.length >=MAX_SCAN_NUM) {
  164. return uni.showToast({
  165. title:MSG_MAX_SCAN,
  166. icon:"none"
  167. })
  168. }
  169. this.$nextTick(()=>{
  170. this.list.push({
  171. workerno:null,
  172. amount:null,
  173. })
  174. })
  175. },
  176. onSave () {
  177. let ok=true
  178. let msg=''
  179. let _total=0
  180. let items=[]
  181. this.list.forEach(item=>{
  182. if (!item.workerno || !item.amount) {
  183. ok=false
  184. msg='生产人员员工号和生产数量为必填项'
  185. return
  186. }
  187. _total+=Number(item.amount)
  188. items.push({"YGH":item.workerno,"SL":item.amount})
  189. })
  190. if (!ok) {
  191. return uni.showToast({
  192. title:msg,
  193. icon:"none"
  194. })
  195. }
  196. if (_total!==this.detail.LZSL) {
  197. ok=false
  198. msg='生产数量总和不等于应报工数量,请检查录入的生产数量'
  199. }
  200. if (!ok) {
  201. return uni.showToast({
  202. title:msg,
  203. icon:"none",
  204. duration:2000
  205. })
  206. }
  207. uni.showModal({
  208. title:"确认保存吗?",
  209. success:async (res)=>{
  210. if (res.confirm) {
  211. this.detail.items=items
  212. this.detail.BGGXSM=this.produceDesc
  213. if (this.goMaterial) {
  214. this.detail.items=items
  215. this.detail.BGGXSM=this.produceDesc
  216. uni.navigateTo({
  217. url:`/pages/work-material-edit/work-material-edit?GYLCKH=${this.GYLCKH}&detail=${JSON.stringify(this.detail)}`
  218. })
  219. }else {
  220. await this._workreportSave(items)
  221. uni.showToast({
  222. title:"保存成功"
  223. })
  224. uni.reLaunch({
  225. url:"/pages/index/index"
  226. })
  227. }
  228. }
  229. }
  230. })
  231. },
  232. // 请求保存接口
  233. async _workreportSave (items) {
  234. const detail=this.detail
  235. const reqdata={
  236. "GYLCKH":this.GYLCKH,
  237. "DQYBGX":detail.GXH,
  238. "BGGXSM":this.produceDesc,
  239. "XYCZ":detail.XYCZ,
  240. "items":items
  241. }
  242. await workreportSave(reqdata).then(resdata=>{
  243. })
  244. return true
  245. }
  246. }
  247. }
  248. </script>
  249. <style>
  250. </style>