timeDialog.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :visible.sync="visible"
  5. :before-close="handleClose"
  6. :close-on-click-modal="false"
  7. :close-on-press-escape="false"
  8. append-to-body
  9. width="35%"
  10. >
  11. <el-form
  12. :model="form"
  13. ref="tableForm"
  14. class="tableForm"
  15. :rules="tableFormRules"
  16. >
  17. <el-button
  18. type="primary"
  19. size="small"
  20. style="margin-bottom: 10px"
  21. @click="handleAdd()"
  22. >新增</el-button
  23. >
  24. <span style="margin-left: 10px" v-if="!isAll"
  25. >待分配数量:<span style="color: #1890ff">{{ num }}</span></span
  26. >
  27. <el-table
  28. ref="multipleTable"
  29. :data="form.timeList"
  30. tooltip-effect="dark"
  31. style="width: 100%"
  32. stripe
  33. :header-cell-style="{ background: '#EEEEEE', border: 'none' }"
  34. >
  35. <el-table-column label="批次号" prop="batchNo">
  36. <template slot-scope="{ row, $index }">
  37. <el-form-item
  38. :prop="'timeList.' + $index + '.batchNo'"
  39. :rules="tableFormRules.batchNo"
  40. >
  41. <el-input
  42. placeholder="请输入"
  43. clearable
  44. v-model="row.batchNo"
  45. ></el-input>
  46. </el-form-item>
  47. </template>
  48. </el-table-column>
  49. <el-table-column label="数量" prop="purchaseQuantity">
  50. <template slot-scope="{ row, $index }">
  51. <el-form-item
  52. :prop="'timeList.' + $index + '.purchaseQuantity'"
  53. :rules="tableFormRules.purchaseQuantity"
  54. >
  55. <el-input
  56. placeholder="请输入"
  57. clearable
  58. type="number"
  59. v-model="row.purchaseQuantity"
  60. ></el-input>
  61. </el-form-item>
  62. </template>
  63. </el-table-column>
  64. <el-table-column label="到货时间">
  65. <template slot-scope="{ row, $index }">
  66. <el-form-item
  67. :prop="'timeList.' + $index + '.requireDeliveryTime'"
  68. :rules="tableFormRules.requireDeliveryTime"
  69. >
  70. <el-date-picker
  71. clearable
  72. v-model="row.requireDeliveryTime"
  73. value-format="timestamp"
  74. placeholder="请选择日期"
  75. :pickerOptions="{
  76. disabledDate: (time) =>
  77. time.getTime() <
  78. new Date(new Date().setHours(0, 0, 0, 0)).getTime()
  79. }"
  80. >
  81. </el-date-picker>
  82. </el-form-item> </template
  83. ></el-table-column>
  84. <el-table-column label="操作" prop="action" width="80">
  85. <template slot-scope="{ $index }">
  86. <el-link
  87. type="primary"
  88. :underline="false"
  89. @click="handleDel($index)"
  90. >删除</el-link
  91. >
  92. </template>
  93. </el-table-column>
  94. </el-table>
  95. </el-form>
  96. <div class="btns">
  97. <el-button type="primary" size="small" @click="handleOk">确认</el-button>
  98. <el-button size="small" @click="handleClose">取消</el-button>
  99. </div>
  100. </el-dialog>
  101. </template>
  102. <script>
  103. import { getCode } from '@/api/codeManagement';
  104. export default {
  105. components: {},
  106. data() {
  107. return {
  108. visible: false,
  109. title: '设置分批时间',
  110. isAll: false,
  111. current: null,
  112. form: {
  113. timeList: [
  114. {
  115. requireDeliveryTime: null,
  116. purchaseQuantity: null,
  117. batchNo: null
  118. }
  119. ]
  120. },
  121. tableFormRules: {
  122. purchaseQuantity: {
  123. required: true,
  124. message: '请输入数量',
  125. trigger: 'blur'
  126. },
  127. batchNo: {
  128. required: true,
  129. message: '请输入批次号',
  130. trigger: 'blur'
  131. },
  132. requireDeliveryTime: {
  133. required: true,
  134. message: '请选择日期',
  135. trigger: 'change'
  136. }
  137. },
  138. currentIndex: '',
  139. count: 0
  140. };
  141. },
  142. watch: {},
  143. computed: {
  144. num() {
  145. console.log(this.form.timeList, 'this.form.timeList');
  146. return (
  147. this.count -
  148. this.form.timeList.reduce((pre, cur) => {
  149. return pre + (Number(cur.purchaseQuantity) || 0);
  150. }, 0) || 0
  151. );
  152. }
  153. },
  154. methods: {
  155. open(row, index, isAll) {
  156. this.isAll = isAll;
  157. console.log(row, 'row', index);
  158. if (row) {
  159. let row1 = JSON.parse(JSON.stringify(row));
  160. this.count = row1.demandQuantity || 0;
  161. this.form.timeList = row1.timeList || [];
  162. this.form.timeList?.forEach(async (item, index) => {
  163. if (!item.batchNo) {
  164. this.$set(
  165. this.form.timeList[index],
  166. 'batchNo',
  167. await getCode('lot_number_code')
  168. );
  169. }
  170. });
  171. this.current = row1;
  172. this.currentIndex = index;
  173. }
  174. this.visible = true;
  175. },
  176. async handleAdd() {
  177. this.form.timeList.push({
  178. requireDeliveryTime: null,
  179. purchaseQuantity: null,
  180. batchNo: await getCode('lot_number_code')
  181. });
  182. },
  183. handleDel(index) {
  184. this.form.timeList.splice(index, 1);
  185. },
  186. handleOk() {
  187. this.$refs.tableForm.validate((valid) => {
  188. if (valid) {
  189. const clonedTimeList = JSON.parse(
  190. JSON.stringify(this.form.timeList)
  191. );
  192. if (!this.isAll) {
  193. if (this.num < 0) {
  194. return this.$message.warning('分配数量不能大于需求数量!');
  195. }
  196. if (this.num > 0) {
  197. return this.$message.warning('需求数量还未分配完,请检查!');
  198. }
  199. }
  200. this.$emit(
  201. 'chooseTime',
  202. this.current,
  203. clonedTimeList,
  204. this.currentIndex
  205. );
  206. this.handleClose();
  207. }
  208. });
  209. },
  210. handleClose() {
  211. this.visible = false;
  212. this.form.timeList = [
  213. {
  214. requireDeliveryTime: null,
  215. purchaseQuantity: null
  216. }
  217. ];
  218. }
  219. }
  220. };
  221. </script>
  222. <style lang="scss" scoped>
  223. .btns {
  224. margin-top: 20px;
  225. text-align: center;
  226. }
  227. .el-form-item {
  228. margin-bottom: 20px !important;
  229. }
  230. </style>