add.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view class="bg-f9 warehouse-add">
  3. <header-bar :title="submitType === 'add' ? '添加工单' : '工单详情'"></header-bar>
  4. <view class="example">
  5. <!-- 基础用法,不包含校验规则 -->
  6. <uni-forms label-position="top" :modelValue="form" ref="form" :rules="rules" >
  7. <uni-forms-item label="工单编号" required name="unit">
  8. <uni-easyinput v-model="form.unit" placeholder="请输入" :disabled="submitType == 'edit'" />
  9. </uni-forms-item>
  10. <uni-forms-item label="产品名称" required name="classifyId">
  11. <uni-data-picker :class="submitType==='edit'?'disabled':''" v-model="form.classifyId" :map="{text:'label',value:'id'}" :localdata="treeData"
  12. popup-title="请选择产品" @change="treeChange">
  13. </uni-data-picker>
  14. </uni-forms-item>
  15. <uni-forms-item label="工单数量">
  16. <uni-easyinput v-model="form.code" :disabled="submitType == 'edit'" placeholder="请输入工单数量" />
  17. </uni-forms-item>
  18. <uni-forms-item label="完成期限" required name="type">
  19. <uni-data-select :disabled="submitType == 'edit'" v-model="form.type" :localdata="types"></uni-data-select>
  20. </uni-forms-item>
  21. <uni-forms-item label="备注" name="introduce">
  22. <uni-easyinput type="textarea" v-model="form.introduce" placeholder="请输入备注" />
  23. </uni-forms-item>
  24. </uni-forms>
  25. <button style="margin:0 20rpx" @click="submitForm">工单排程</button>
  26. <button @click="submitForm" style="background-color: red;margin:20rpx;color:#fff">停止</button>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import headerBar from '../../../components/header-bar/index.vue'
  32. import Vue from 'vue'
  33. export default {
  34. components: {
  35. headerBar
  36. },
  37. data() {
  38. return {
  39. form: {
  40. name: '',
  41. type: null,
  42. classifyId: null,
  43. code: null,
  44. unit: null,
  45. introduce: null,
  46. },
  47. types: [{
  48. text: '半成品',
  49. value: '0'
  50. }, {
  51. text: '成品',
  52. value: '1'
  53. }],
  54. rules: {
  55. // 对name字段进行必填验证
  56. name: {
  57. rules: [{
  58. required: true,
  59. errorMessage: '请输入产品名称',
  60. }, ]
  61. },
  62. // 对email字段进行必填验证
  63. type: {
  64. rules: [{
  65. required: true,
  66. errorMessage: '请选择产品类型',
  67. }, ]
  68. },
  69. unit: {
  70. rules: [{
  71. required: true,
  72. errorMessage: '请输入产品单位',
  73. }, ]
  74. },
  75. classifyId: {
  76. rules: [{
  77. required: true,
  78. errorMessage: '请选择产品分类',
  79. }, ]
  80. },
  81. },
  82. submitType: 'add',
  83. treeData: [],
  84. }
  85. },
  86. onLoad(e) {
  87. if (e.id) {
  88. this.form.id = e.id
  89. this.form.remarks = e.remarks
  90. this.form.type = e.type
  91. this.form.name = e.name
  92. this.submitType = 'edit'
  93. }
  94. this.getTree()
  95. },
  96. methods: {
  97. treeChange() {},
  98. getTree() {
  99. const v = this
  100. v.$post('/api/basics//classify/tree', {
  101. type: 1
  102. }).then(res => {
  103. if (res.code === 200) {
  104. v.treeData = res.data
  105. }
  106. })
  107. },
  108. submitForm() {
  109. const v = this
  110. this.$refs.form.validate().then(res => {
  111. uni.showLoading({
  112. title: '加载中'
  113. });
  114. v.$post('/api/syringe-management/product/' + this.submitType, v.form).then(res => {
  115. if (res.code === 200) {
  116. uni.showToast({
  117. title: this.submitType == 'add' ? '添加成功' : '修改成功',
  118. duration: 1000,
  119. icon: 'success'
  120. })
  121. }
  122. uni.hideLoading()
  123. let pages = getCurrentPages(); // 获取页面栈
  124. let prePage = pages[pages.length - 2]; //获取上一页
  125. prePage.$vm.needRefresh = true; // 需要刷新
  126. setTimeout(() => {
  127. uni.navigateBack(1)
  128. }, 1000)
  129. })
  130. }).catch(err => {
  131. console.log('表单错误信息:', err);
  132. })
  133. },
  134. },
  135. }
  136. </script>
  137. <style lang="less">
  138. .disabled{
  139. .text-color{
  140. color: #999 !important;
  141. }
  142. .uni-data-tree-input{
  143. pointer-events: none;
  144. }
  145. .uniui-clear {
  146. display: none;
  147. }
  148. }
  149. </style>