Subscribe.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <div style="width: 100%; padding: 0px 15px">
  3. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="formDom">
  4. <template #commodity>
  5. <div style="width: 100%">
  6. <el-button type="primary" plain @click="openProduct = true" style="margin-bottom: 16px" v-if="!judgeStatus()">
  7. 选择物料
  8. </el-button>
  9. <el-table :data="formData.data.subscribeDetailList" style="width: 100%; ">
  10. <el-table-column prop="productCode" label="物料编码" width="130" />
  11. <el-table-column prop="productName" label="物料名称" min-width="130" />
  12. <el-table-column label="尺寸 cm*cm*cm" width="180">
  13. <template #default="{ row, $index }">
  14. <div style="width: 100%">
  15. {{row.productLength}} * {{row.productWidth}} * {{row.productHeight}}
  16. </div>
  17. </template>
  18. </el-table-column>
  19. <el-table-column prop="productUnit" label="单位" width="100" :formatter="(row) => dictKeyValue(row.productUnit, materialUnit)" />
  20. <el-table-column label="申购数量" width="150">
  21. <template #default="{ row, $index }">
  22. <div style="width: 100%">
  23. <el-form-item :prop="'subscribeDetailList.' + $index + '.count'" :rules="rules.count" :inline-message="true"
  24. class="margin-b-0 wid100">
  25. <el-input-number onmousewheel="return false;" v-model="row.count" placeholder="请输入" style="width: 100%" :precision="0"
  26. :controls="false" :min="0" />
  27. </el-form-item>
  28. </div>
  29. </template>
  30. </el-table-column>
  31. <el-table-column label="备注">
  32. <template #default="{ row, $index }">
  33. <div style="width: 100%">
  34. <el-form-item :prop="'subscribeDetailList.' + $index + '.remark'" :rules="rules.remark" :inline-message="true"
  35. class="margin-b-0 wid100">
  36. <el-input onmousewheel="return false;" v-model="row.remark" placeholder="请输入" style="width: 100%" />
  37. </el-form-item>
  38. </div>
  39. </template>
  40. </el-table-column>
  41. <el-table-column label="操作" width="80" align="center" fixed="right" v-if="!judgeStatus()">
  42. <template #default="{ $index }">
  43. <el-button type="primary" link @click="handleRemove($index)">删除</el-button>
  44. </template>
  45. </el-table-column>
  46. </el-table>
  47. </div>
  48. </template>
  49. </byForm>
  50. <el-dialog v-if="openProduct" v-model="openProduct" title="选择物料" width="90%" append-to-body>
  51. <SelectMaterial @selectMaterial="selectMaterial"></SelectMaterial>
  52. </el-dialog>
  53. </div>
  54. </template>
  55. <script setup>
  56. import byForm from "@/components/byForm/index";
  57. import SelectMaterial from "@/components/product/SelectMaterial.vue";
  58. import { useRoute } from "vue-router";
  59. const { proxy } = getCurrentInstance();
  60. const route = useRoute();
  61. // 接收父组件的传值
  62. const props = defineProps({
  63. queryData: Object,
  64. });
  65. const openProduct = ref(false);
  66. const materialUnit = computed(
  67. () => proxy.useUserStore().allDict["material_unit"]
  68. );
  69. const formData = reactive({
  70. data: {
  71. subscribeDetailList: [],
  72. },
  73. });
  74. const formDom = ref(null);
  75. const judgeStatus = () => {
  76. if (route.query.processType == 20 || route.query.processType == 10) {
  77. return true;
  78. }
  79. if (props.queryData.recordList && props.queryData.recordList.length > 0) {
  80. let data = props.queryData.recordList.filter(
  81. (item) => item.status === 2 && item.nodeType !== 1
  82. );
  83. if (data && data.length > 0) {
  84. return true;
  85. }
  86. }
  87. return false;
  88. };
  89. const formOption = reactive({
  90. inline: true,
  91. labelWidth: 100,
  92. itemWidth: 100,
  93. disabled: false,
  94. });
  95. const formConfig = computed(() => {
  96. return [
  97. {
  98. type: "title",
  99. title: "申购信息",
  100. haveLine: false,
  101. },
  102. // {
  103. // type: "input",
  104. // prop: "deptName",
  105. // label: "申购部门",
  106. // itemWidth: 25,
  107. // disabled: true,
  108. // },
  109. {
  110. type: "input",
  111. prop: "subcribeName",
  112. label: "申购人",
  113. itemWidth: 33.33,
  114. disabled: true,
  115. },
  116. {
  117. type: "treeSelect",
  118. prop: "companyId",
  119. label: "业务公司",
  120. data: proxy.useUserStore().allDict["tree_company_data"],
  121. propsTreeLabel: "deptName",
  122. propsTreeValue: "deptId",
  123. itemWidth: 33.33,
  124. },
  125. {
  126. type: "date",
  127. prop: "subcribeTime",
  128. itemType: "date",
  129. label: "申时间",
  130. itemWidth: 33.33,
  131. disabled: false,
  132. },
  133. {
  134. type: "input",
  135. prop: "subcribeContent",
  136. itemType: "textarea",
  137. label: "申购说明",
  138. itemWidth: 100,
  139. disabled: false,
  140. },
  141. {
  142. type: "title",
  143. title: "申购明细",
  144. haveLine: true,
  145. },
  146. {
  147. type: "slot",
  148. slotName: "commodity",
  149. label: "",
  150. },
  151. ];
  152. });
  153. const rules = ref({
  154. deptName: [{ required: true, message: "请输入申购部门", trigger: "blur" }],
  155. subcribeName: [
  156. { required: true, message: "请输入申购人名称", trigger: "blur" },
  157. ],
  158. subcribeTime: [
  159. { required: true, message: "请选择申购时间", trigger: "change" },
  160. ],
  161. count: [{ required: true, message: "请输入申购数量", trigger: "blur" }],
  162. companyId: [{ required: true, message: "请选择业务公司", trigger: "change" }],
  163. });
  164. const selectMaterial = (row) => {
  165. let flag = formData.data.subscribeDetailList.some(
  166. (x) => x.productId == row.id
  167. );
  168. if (!flag) {
  169. formData.data.subscribeDetailList.push({
  170. productId: row.id,
  171. productCode: row.customCode,
  172. productName: row.name,
  173. productUnit: row.unit,
  174. productLength: row["length"],
  175. productWidth: row.width,
  176. productHeight: row.height,
  177. count: null,
  178. remark: "",
  179. });
  180. proxy.msgTip("选择成功");
  181. } else {
  182. proxy.msgTip("该物料已选择", 2);
  183. }
  184. };
  185. const handleRemove = (index) => {
  186. formData.data.subscribeDetailList.splice(index, 1);
  187. };
  188. const handleSubmit = async () => {
  189. let flag = await formDom.value.handleSubmit(() => {});
  190. if (flag) {
  191. if (
  192. formData.data.subscribeDetailList &&
  193. formData.data.subscribeDetailList.length > 0
  194. ) {
  195. return true;
  196. } else {
  197. proxy.msgTip("请添加申购明细", 2);
  198. return false;
  199. }
  200. } else {
  201. setTimeout(() => {
  202. const errorDiv = document.getElementsByClassName("is-error");
  203. errorDiv[0].scrollIntoView();
  204. }, 0);
  205. }
  206. return flag;
  207. };
  208. const getFormData = () => {
  209. return proxy.deepClone(formData.data);
  210. };
  211. // 向父组件暴露
  212. defineExpose({
  213. getFormData,
  214. handleSubmit,
  215. });
  216. const getAllData = (businessId) => {
  217. if (businessId) {
  218. proxy.post("/subscribe/detail", { id: businessId }).then((res) => {
  219. formData.data = res;
  220. });
  221. }
  222. };
  223. onMounted(() => {
  224. formOption.disabled = judgeStatus();
  225. formData.data.subcribeTime = proxy.parseTime(new Date());
  226. formData.data.deptName = proxy.useUserStore().user.dept.deptName;
  227. formData.data.deptId = proxy.useUserStore().user.dept.deptId;
  228. formData.data.subcribeName = proxy.useUserStore().user.nickName;
  229. if (route.query.businessId && route.query.processType) {
  230. getAllData(route.query.businessId);
  231. }
  232. });
  233. </script>
  234. <style lang="scss" scoped>
  235. </style>