add.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <view class="edit-page">
  3. <navigation title="新增锯断数据"></navigation>
  4. <view class="form-box">
  5. <u--form labelPosition="left" labelWidth="160rpx" :model="info" :rules="rules" ref="form">
  6. <view class="form">
  7. <u-form-item label="订单" prop="orderId" borderBottom>
  8. <uni-data-select v-model="info.orderId" :localdata="orderActions" placeholder="请选择订单" @change="changeOrder">
  9. </uni-data-select>
  10. </u-form-item>
  11. <u-form-item label="订单数量" prop="allLength" borderBottom>
  12. <u--input disabled disabledColor="#ffffff" border="none" v-model="orderCount"></u--input>
  13. </u-form-item>
  14. <u-form-item label="下料" prop="allLength" borderBottom>
  15. <u-number-box v-model="info.allLength" :step="0.1" :min="0.1" @change="allLengthChange"></u-number-box>
  16. </u-form-item>
  17. <u-form-item label="切割" prop="cuttingLength" borderBottom>
  18. <u-number-box v-model="info.cuttingLength" :step="0.1" :min="0.1" @change="cuttingLengthChange"></u-number-box>
  19. </u-form-item>
  20. <u-form-item label="数量">
  21. <u--input v-model="number" disabled disabledColor="#ffffff" placeholder="数量"
  22. border="none"></u--input>
  23. </u-form-item>
  24. </view>
  25. </u--form>
  26. </view>
  27. <view class="submit">
  28. <u-button @click="onSubmit" type="primary">提交</u-button>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. export default {
  34. data() {
  35. return {
  36. orderActions: [],
  37. number: 1,
  38. orderCount: '',
  39. info: {
  40. id: '',
  41. orderId: '',
  42. allLength: 1,
  43. cuttingLength: 1
  44. },
  45. rules: {
  46. orderId: {
  47. type: 'number',
  48. required: true,
  49. message: '请选择订单',
  50. trigger: ['blur', 'change']
  51. },
  52. allLength: {
  53. type: 'number',
  54. required: true,
  55. message: '请填写下料长度',
  56. trigger: ['blur', 'change']
  57. },
  58. cuttingLength: {
  59. type: 'number',
  60. required: true,
  61. message: '请填写切割长度',
  62. trigger: ['blur', 'change']
  63. },
  64. },
  65. }
  66. },
  67. onLoad(option) {
  68. if (option.id) {
  69. this.info.id = option.id
  70. this.detailInfo()
  71. }
  72. },
  73. onShow() {
  74. this.getOrderList()
  75. },
  76. methods: {
  77. changeOrder(e){
  78. console.log(e)
  79. for(let i = 0;i<this.orderActions.length;i++){
  80. if(this.orderActions[i].id == e){
  81. this.orderCount = this.orderActions[i].productionNum
  82. break
  83. }
  84. }
  85. },
  86. // 数量向下取整
  87. allLengthChange(e) {
  88. this.number = Math.floor(e.value/this.info.cuttingLength)
  89. },
  90. cuttingLengthChange(e) {
  91. this.number = Math.floor(this.info.allLength/e.value)
  92. },
  93. onSubmit() {
  94. this.$refs.form.validate().then(res => {
  95. if (this.info.id) {
  96. this.$api.updateMesCutting(this.info).then(res => {
  97. uni.showToast({
  98. title: '修改成功!',
  99. duration: 2000
  100. });
  101. setTimeout(function() {
  102. uni.navigateBack();
  103. }, 2000);
  104. }).catch(err => {})
  105. } else {
  106. this.$api.addMesCutting(this.info).then(res => {
  107. uni.showToast({
  108. title: '新增成功!',
  109. duration: 2000
  110. });
  111. setTimeout(function() {
  112. uni.navigateBack();
  113. }, 2000);
  114. }).catch(err => {})
  115. }
  116. }).catch(err => {
  117. console.log('表单错误信息:', err);
  118. })
  119. },
  120. getOrderList() {
  121. let params = {
  122. pageSize: '9999',
  123. orderStatus: '1'
  124. }
  125. this.$api.productOrderList(params).then(res => {
  126. this.orderActions = res.rows
  127. for (var i = 0; i < this.orderActions.length; i++) {
  128. this.orderActions[i].value = this.orderActions[i].id;
  129. // this.orderActions[i].count = this.orderActions[i].productionNum;
  130. this.orderActions[i].text = this.orderActions[i].orderNum + '(' + this
  131. .orderActions[i].productionName + ')';
  132. }
  133. }).catch(err => {})
  134. },
  135. detailInfo() {
  136. this.$api.getMesCutting(this.info.id).then(res => {
  137. this.info = res.data
  138. this.number = Math.floor(this.info.allLength/this.info.cuttingLength)
  139. }).catch(err => {})
  140. }
  141. }
  142. }
  143. </script>
  144. <style lang="scss" scoped>
  145. .edit-page {
  146. padding-bottom: 20rpx;
  147. .add-bg {
  148. width: 100%;
  149. height: 330rpx;
  150. }
  151. .form-box {
  152. .form {
  153. background-color: #fff;
  154. margin: 0 24rpx;
  155. padding: 10rpx 24rpx;
  156. border-radius: 12rpx;
  157. }
  158. /deep/.uni-select {
  159. border: none;
  160. padding: 0;
  161. }
  162. /deep/.u-number-box__input {
  163. width: 200rpx !important;
  164. }
  165. }
  166. .submit {
  167. margin: 34rpx;
  168. }
  169. }
  170. </style>