detail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <div>
  3. <Toptitle
  4. :title="
  5. type == 1 ? '复制' : type == 2 ? '编辑' : type == 3 ? '查看' : '新增'
  6. "
  7. >
  8. <Button type="primary" style="margin-right:5px" ghost @click="back()"
  9. >取消</Button
  10. >
  11. <Button type="primary" v-show="type != 3" @click="handleSaveData"
  12. >保存</Button
  13. >
  14. </Toptitle>
  15. <div>
  16. <Row type="flex" justify="space-between" style="padding:10px 0">
  17. <Col span="4">
  18. <span>ID:</span>
  19. <span>
  20. <Input
  21. type="text"
  22. disabled
  23. style="width:80px"
  24. v-model="formData.id"
  25. placeholder="自动生成"
  26. />
  27. </span>
  28. </Col>
  29. <Col span="12">
  30. <span>工艺属性分类:</span>
  31. <span>
  32. <Select
  33. filterable
  34. filter-by-label
  35. v-model="formData.process_id"
  36. style="width: 100px;margin-right:5px"
  37. @on-change="handleProcessSelected"
  38. >
  39. <Option
  40. v-for="(item, index) in basic_process_list"
  41. :key="index"
  42. :label="item.title"
  43. :value="item.id"
  44. ></Option>
  45. </Select>
  46. </span>
  47. <span>
  48. <Select
  49. filterable
  50. filter-by-label
  51. @on-change="(e) => handleGetProcessIds(formData.process_id, e)"
  52. v-model="formData.type_title"
  53. style="width: 100px;margin-right:5px"
  54. >
  55. <Option
  56. v-for="(item, index) in type_title_list"
  57. :key="index"
  58. :label="item"
  59. :value="item"
  60. ></Option>
  61. </Select>
  62. </span>
  63. <span>
  64. <Select
  65. filterable
  66. filter-by-label
  67. multiple
  68. :max-tag-count="2"
  69. v-model="formData.process_ids"
  70. style="width: 300px"
  71. >
  72. <Option
  73. v-for="(item, index) in process_list"
  74. :key="index"
  75. :label="item.title"
  76. :value="item.id"
  77. ></Option>
  78. </Select>
  79. </span>
  80. </Col>
  81. <Col span="8">
  82. <span>部件名称:</span>
  83. <span>
  84. <Select
  85. filterable
  86. filter-by-label
  87. v-model="formData.part_id"
  88. @on-change="handlePartSelected"
  89. style="width: 200px"
  90. >
  91. <Option
  92. v-for="(item, index) in parts_list"
  93. :key="index"
  94. :label="item.title"
  95. :value="item.id"
  96. ></Option>
  97. </Select>
  98. </span>
  99. </Col>
  100. </Row>
  101. <Row
  102. type="flex"
  103. align="bottom"
  104. justify="space-between"
  105. style="padding-bottom:5px"
  106. >
  107. <Col><span>规则:</span> </Col>
  108. <Col>
  109. <Button
  110. size="small"
  111. type="primary"
  112. @click="handleSet({}, tableData.length, 1)"
  113. >新增规则</Button
  114. >
  115. </Col>
  116. </Row>
  117. <div>
  118. <Table
  119. :columns="tableColumns"
  120. border
  121. :max-height="500"
  122. :data="tableData"
  123. >
  124. <template slot="partDetailTitle" slot-scope="{ index }">
  125. <Select
  126. v-model="tableData[index].parts_detail_id"
  127. transfer
  128. @on-change="
  129. (e) => handlePartDetailSelected(tableData[index], index, e)
  130. "
  131. >
  132. <Option
  133. v-for="(item, index) in tableData[index].part_detail_list"
  134. :key="index"
  135. :label="item.spare_parts"
  136. :value="item.id"
  137. ></Option>
  138. </Select>
  139. </template>
  140. <template slot="measureSlot" slot-scope="{ index }">
  141. <Select v-model="tableData[index].basics_measure_id" transfer>
  142. <Option
  143. v-for="(item, index) in measure_list"
  144. :key="index"
  145. :label="item.title"
  146. :value="item.id"
  147. ></Option>
  148. </Select>
  149. </template>
  150. <template slot="numSlot" slot-scope="{ index }">
  151. <Input
  152. type="text"
  153. style="width:80px"
  154. v-model="tableData[index].num"
  155. />
  156. </template>
  157. <template slot="minSlot" slot-scope="{ index }">
  158. <Input
  159. type="text"
  160. style="width:80px"
  161. v-model="tableData[index].min"
  162. />
  163. </template>
  164. <template slot="maxSlot" slot-scope="{ index }">
  165. <Input
  166. type="text"
  167. style="width:80px"
  168. v-model="tableData[index].max"
  169. />
  170. </template>
  171. <template slot="materialDetailSlot" slot-scope="{ index }">
  172. <Select v-model="tableData[index].material_detail_id" transfer>
  173. <Option
  174. v-for="(item, index) in tableData[index].materialDetailList"
  175. :key="index"
  176. :label="item.materialDetailShow"
  177. :value="item.id"
  178. ></Option>
  179. </Select>
  180. </template>
  181. <template slot="setSlot" slot-scope="{ index }">
  182. <div>
  183. <a
  184. style="margin:0 5px;"
  185. @click="handleSet(tableData[index], index, 2)"
  186. >复制</a
  187. >
  188. <a
  189. style="margin:0 5px;"
  190. @click="handleSet(tableData[index], index, 3)"
  191. >删除</a
  192. >
  193. </div>
  194. </template>
  195. </Table>
  196. </div>
  197. </div>
  198. </div>
  199. </template>
  200. <script>
  201. // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  202. // 例如:import 《组件名称》 from '《组件路径》';
  203. export default {
  204. name: "",
  205. components: {},
  206. props: {},
  207. // import引入的组件需要注入到对象中才能使用
  208. data() {
  209. // 这里存放数据
  210. return {
  211. type: this.$route.query.type,
  212. id: this.$route.query.id,
  213. formData: {
  214. id: this.$route.query.id,
  215. process_id: "",
  216. part_id: "",
  217. type_title: "",
  218. process_ids: [],
  219. },
  220. urlSelectList: [],
  221. tableColumns: [
  222. {
  223. title: "零部件名称",
  224. align: "center",
  225. minWidth: 120,
  226. slot: "partDetailTitle",
  227. },
  228. {
  229. title: "物料名称",
  230. align: "center",
  231. minWidth: 100,
  232. key: "parts_detail_title",
  233. },
  234. {
  235. title: "测量字段",
  236. align: "center",
  237. minWidth: 100,
  238. slot: "measureSlot",
  239. },
  240. {
  241. title: "数量",
  242. align: "center",
  243. minWidth: 70,
  244. key: "num",
  245. slot: "numSlot",
  246. },
  247. {
  248. title: "最小数值(含)",
  249. align: "center",
  250. minWidth: 120,
  251. slot: "minSlot",
  252. },
  253. { title: "最大数值", align: "center", minWidth: 120, slot: "maxSlot" },
  254. {
  255. title: "物料规格",
  256. align: "center",
  257. minWidth: 100,
  258. key: "material_detail_id",
  259. slot: "materialDetailSlot",
  260. },
  261. { title: "操作", align: "center", minWidth: 120, slot: "setSlot" },
  262. ],
  263. tableData: [{}],
  264. basic_process_list: [], //工艺属性分类
  265. parts_list: [],
  266. type_title_list: [],
  267. process_list: [],
  268. measure_list: [],
  269. };
  270. },
  271. // 生命周期 - 创建完成(可以访问当前this实例)
  272. created() {
  273. this.axios.get("/api/basics_properties_index").then((res) => {
  274. this.basic_process_list = res.data.data;
  275. });
  276. this.axios.get("/api/parts_index").then((res) => {
  277. this.parts_list = res.data.data;
  278. });
  279. this.axios.get("/api/basics_measure_index").then((res) => {
  280. this.measure_list = res.data.data;
  281. });
  282. },
  283. // 生命周期 - 挂载完成(可以访问DOM元素)
  284. mounted() {
  285. this.id && this.initData(this.id);
  286. },
  287. methods: {
  288. back() {
  289. this.$router.go(-1);
  290. },
  291. handleSet(row, index, type) {
  292. if (!this.formData.part_id) {
  293. return this.$Message.warning("请先选择部件");
  294. }
  295. row.part_detail_list = JSON.parse(JSON.stringify(this.part_detail_list));
  296. row.part_id = this.formData.part_id;
  297. const obj = JSON.parse(JSON.stringify(row));
  298. switch (type) {
  299. case 1:
  300. case 2:
  301. this.tableData.splice(index, 0, obj);
  302. break;
  303. case 3:
  304. this.tableData.splice(index, 1);
  305. break;
  306. }
  307. },
  308. initData(id) {
  309. this.axios
  310. .get("/api/process_part_detail", { params: { id } })
  311. .then((res) => {
  312. this.formData = res.data.detail;
  313. this.formData.process_id = this.formData.bp_id;
  314. this.tableData = res.data.list;
  315. this.handleProcessSelected(res.data.detail.process_id);
  316. this.handleGetProcessIds(
  317. res.data.detail.process_id,
  318. res.data.detail.type_title
  319. );
  320. this.handlePartSelected(this.formData.part_id, 2);
  321. });
  322. },
  323. handleProcessSelected(p_id) {
  324. p_id &&
  325. this.axios.post("/api/process_sub_title", { p_id }).then((res) => {
  326. this.type_title_list = res.data;
  327. });
  328. },
  329. handleGetProcessIds(p_id, type_title) {
  330. this.axios
  331. .get("/api/properties_index", { params: { p_id, type_title } })
  332. .then((res) => {
  333. this.process_list = res.data.data;
  334. });
  335. },
  336. handlePartSelected(id, type) {
  337. id &&
  338. this.axios.get("/api/parts_detail", { params: { id } }).then((res) => {
  339. this.part_detail_list = res.data.detail;
  340. if (type == 2) {
  341. this.tableData.map((v, k) => {
  342. v.part_detail_list = JSON.parse(
  343. JSON.stringify(this.part_detail_list)
  344. );
  345. this.handlePartDetailSelected(v, k, v.parts_detail_id);
  346. });
  347. } else {
  348. this.tableData = [];
  349. }
  350. this.tableData = JSON.parse(JSON.stringify(this.tableData));
  351. });
  352. },
  353. handlePartDetailSelected(row, index, id) {
  354. if (id) {
  355. const material_id = row.part_detail_list.filter((v) => v.id == id)[0]
  356. .material_id;
  357. this.axios
  358. .get("/api/material", { params: { id: material_id } })
  359. .then((res) => {
  360. this.tableData[index].parts_detail_title = res.data[0].title;
  361. this.tableData[index].materialDetailList = res.data[0].detail.map(
  362. (v) => {
  363. return { id: v.id, materialDetailShow: v.long + "*" + v.width };
  364. }
  365. );
  366. this.tableData.splice(index, 1, this.tableData[index]);
  367. });
  368. }
  369. },
  370. handleSaveData() {
  371. if (this.type == 1) {
  372. this.formData.id = "";
  373. }
  374. this.axios
  375. .post("/api/process_part_edit", {
  376. ...this.formData,
  377. detail: this.tableData,
  378. })
  379. .then((res) => {
  380. if (res.code == 200) {
  381. this.$Message.success(res.msg);
  382. this.back();
  383. }
  384. });
  385. },
  386. },
  387. // 监听属性 类似于data概念
  388. computed: {},
  389. // 监控data中的数据变化
  390. watch: {},
  391. beforeCreate() {}, // 生命周期 - 创建之前
  392. beforeMount() {}, // 生命周期 - 挂载之前
  393. beforeUpdate() {}, // 生命周期 - 更新之前
  394. updated() {}, // 生命周期 - 更新之后
  395. beforeDestroy() {}, // 生命周期 - 销毁之前
  396. destroyed() {}, // 生命周期 - 销毁完成
  397. activated() {}, // 如果页面有keep-alive缓存功能,这个函数会触发
  398. };
  399. </script>
  400. <style lang="scss" scoped></style>