plan-edit-dialog.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <ele-modal
  3. :visible.sync="visible"
  4. :closed="cancel"
  5. :title="`${type == 'add' ? '创建' : '编辑'}配料计划`"
  6. custom-class="ele-dialog-form"
  7. :close-on-click-modal="false"
  8. :close-on-press-escape="false"
  9. >
  10. <el-form
  11. :model="formData"
  12. ref="formRef"
  13. label-width="120px"
  14. class="ele-body"
  15. :rules="rules"
  16. >
  17. <el-row :gutter="32">
  18. <el-col :span="12">
  19. <el-form-item label="选择物料" prop="materialName">
  20. <el-input
  21. placeholder="请选择"
  22. :value="
  23. formData.materialName &&
  24. `${formData.materialName}(${formData.materialCode})`
  25. "
  26. @click.native="chooseMateriel"
  27. ></el-input>
  28. </el-form-item>
  29. </el-col>
  30. <el-col :span="12">
  31. <el-form-item label="生产版本" prop="produceVersionName">
  32. <el-input
  33. :disabled="!formData.materialName"
  34. :placeholder="!formData.materialName ? '请选择物料' : '请选择'"
  35. v-model="formData.produceVersionName"
  36. @click.native="chooseVersion"
  37. ></el-input>
  38. </el-form-item>
  39. </el-col>
  40. <el-col :span="12">
  41. <el-form-item label="牌号" prop="brandNo">
  42. <el-input v-model="formData.brandNo" disabled></el-input>
  43. </el-form-item>
  44. </el-col>
  45. <!-- <el-col :span="12">
  46. <el-form-item label="工艺路线名称" prop="brandNo">
  47. <el-input v-model="formData.aaa"></el-input>
  48. </el-form-item>
  49. </el-col> -->
  50. <el-col :span="12">
  51. <el-form-item label="要求交付日期" prop="deliveryTime">
  52. <el-date-picker
  53. style="width: 100%"
  54. v-model="formData.deliveryTime"
  55. :pickerOptions="{
  56. disabledDate: (time) =>
  57. time.getTime() <
  58. new Date(new Date().setHours(0, 0, 0, 0)).getTime()
  59. }"
  60. type="date"
  61. placeholder="选择日期"
  62. value-format="yyyy-MM-dd"
  63. >
  64. </el-date-picker>
  65. </el-form-item>
  66. </el-col>
  67. <!-- <el-col :span="12">
  68. <el-form-item label="工艺路线版本" prop="brandNo">
  69. <el-input v-model="formData.aaa"></el-input>
  70. </el-form-item>
  71. </el-col> -->
  72. <el-col :span="12">
  73. <el-form-item label="生产重量" prop="num">
  74. <!-- <el-input v-model.number="formData.num">
  75. </el-input> -->
  76. <el-row>
  77. <el-col :span="21">
  78. <el-input-number
  79. placeholder="请输入"
  80. class="w100"
  81. v-model="formData.num"
  82. :controls="false"
  83. :precision="3"
  84. :min="0"
  85. ></el-input-number>
  86. </el-col>
  87. <el-col :span="3" style="text-align: center">
  88. {{ formData.unit || 'kg' }}
  89. </el-col>
  90. </el-row>
  91. </el-form-item>
  92. </el-col>
  93. <el-col :span="12">
  94. <el-form-item label="计划备注" prop="notes">
  95. <el-input v-model="formData.notes" placeholder="请选择"></el-input>
  96. </el-form-item>
  97. </el-col>
  98. </el-row>
  99. </el-form>
  100. <div slot="footer">
  101. <el-button @click="cancel">取消</el-button>
  102. <el-button type="primary" @click="confirm">确定</el-button>
  103. </div>
  104. <!-- 选择物料 -->
  105. <ChooseMaterial
  106. ref="chooseRef"
  107. @success="handleChooseMaterial"
  108. ></ChooseMaterial>
  109. <!-- 选择生产版本 -->
  110. <ProductionVersion
  111. ref="versionRef"
  112. :productCode="formData.materialCode"
  113. @confirm="versionConfirm"
  114. ></ProductionVersion>
  115. </ele-modal>
  116. </template>
  117. <script>
  118. import ChooseMaterial from '@/components/CreatePlan/ChooseMaterial.vue';
  119. import ProductionVersion from '@/components/CreatePlan/ProductionVersion.vue';
  120. import { save, update } from '@/api/materialPlan/index';
  121. import dayjs from 'dayjs';
  122. export default {
  123. components: {
  124. ChooseMaterial,
  125. ProductionVersion
  126. },
  127. data () {
  128. return {
  129. visible: false,
  130. type: 'add',
  131. rules: {
  132. materialName: [
  133. {
  134. required: true,
  135. message: '请选择物料',
  136. trigger: ['blur', 'change']
  137. }
  138. ],
  139. produceVersionName: [
  140. {
  141. required: true,
  142. message: '请选择生产版本',
  143. trigger: ['blur', 'change']
  144. }
  145. ],
  146. deliveryTime: [
  147. {
  148. required: true,
  149. message: '请选择要求交付日期',
  150. trigger: ['blur', 'change']
  151. }
  152. ],
  153. num: [
  154. {
  155. required: true,
  156. message: '请输入生产重量',
  157. trigger: ['blur', 'change']
  158. }
  159. ]
  160. },
  161. formData: {
  162. deliveryTime: dayjs(new Date()).format('YYYY-MM-DD'),
  163. num: null,
  164. notes: '',
  165. categoryId: '',
  166. unit: '',
  167. brandNo: '',
  168. model: '',
  169. produceVersionName: '',
  170. materialCode: '',
  171. materialName: ''
  172. }
  173. };
  174. },
  175. methods: {
  176. async open (type, row = {}) {
  177. this.type = type;
  178. this.formData = Object.assign({}, this.formData, row);
  179. this.visible = true;
  180. },
  181. chooseMateriel () {
  182. this.$refs.chooseRef.open(this.formData.categoryId);
  183. },
  184. handleChooseMaterial (row) {
  185. this.formData = Object.assign({}, this.formData, {
  186. materialName: row.name,
  187. categoryId: row.id,
  188. materialCode: row.code,
  189. brandNo: row.brandNum,
  190. model: row.modelType,
  191. unit: row.measuringUnit
  192. });
  193. },
  194. confirm () {
  195. this.$refs.formRef.validate(async (value) => {
  196. if (value) {
  197. const request = this.type == 'add' ? save : update;
  198. // if (this.type == 'add') {
  199. // this.formData.produceVersionId = '1684162877351866369';
  200. // this.formData.produceVersionName = '挤压合金生产';
  201. // }
  202. await request(this.formData);
  203. this.$message.success('保存成功!');
  204. this.$emit('success');
  205. this.cancel();
  206. }
  207. });
  208. },
  209. cancel () {
  210. this.visible = false;
  211. this.formData = {};
  212. this.$refs.formRef.resetFields();
  213. },
  214. versionConfirm (cur) {
  215. console.log(cur, '2222W33000000920');
  216. this.formData.produceVersionId = cur.produceVersionId;
  217. this.formData.produceVersionName = cur.produceVersionName;
  218. },
  219. chooseVersion () {
  220. if (!this.formData.materialName) {
  221. return this.$message.error('请选择物料');
  222. }
  223. this.$refs.versionRef.open(1);
  224. }
  225. }
  226. };
  227. </script>