detail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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" style="display:flex;align-items: center;">
  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. <el-select
  80. multiple
  81. collapse-tags
  82. filterable
  83. v-model="formData.process_ids"
  84. @change="changeProvinceSelect"
  85. style="width: 300px;height:32px"
  86. @remove-tag="removeProvinceTag"
  87. >
  88. <el-option
  89. label="全选"
  90. value="全选"
  91. v-show="process_list.length > 1"
  92. @click.native="selectProvinceAll"
  93. ></el-option>
  94. <el-option
  95. v-for="item in process_list"
  96. ref="options"
  97. :key="item.id"
  98. :label="item.title"
  99. :value="item.id"
  100. >
  101. </el-option>
  102. </el-select>
  103. </span>
  104. </Col>
  105. <Col span="8">
  106. <span>部件名称:</span>
  107. <span>
  108. <Select
  109. filterable
  110. filter-by-label
  111. v-model="formData.part_id"
  112. @on-change="handlePartSelected"
  113. style="width: 200px"
  114. >
  115. <Option
  116. v-for="(item, index) in parts_list"
  117. :key="index"
  118. :label="item.title"
  119. :value="item.id"
  120. ></Option>
  121. </Select>
  122. </span>
  123. </Col>
  124. </Row>
  125. <Row
  126. type="flex"
  127. align="bottom"
  128. justify="space-between"
  129. style="padding-bottom:5px"
  130. >
  131. <Col><span>规则:</span> </Col>
  132. <Col>
  133. <Button
  134. size="small"
  135. type="primary"
  136. @click="handleSet({}, tableData.length, 1)"
  137. >新增规则</Button
  138. >
  139. </Col>
  140. </Row>
  141. <div>
  142. <Table
  143. :columns="tableColumns"
  144. border
  145. :max-height="500"
  146. :data="tableData"
  147. >
  148. <template slot="partDetailTitle" slot-scope="{ index }">
  149. <Select
  150. v-model="tableData[index].parts_detail_id"
  151. transfer
  152. @on-change="
  153. (e) => handlePartDetailSelected(tableData[index], index, e)
  154. "
  155. >
  156. <Option
  157. v-for="(item, index) in tableData[index].part_detail_list"
  158. :key="index"
  159. :label="item.spare_parts"
  160. :value="item.id"
  161. ></Option>
  162. </Select>
  163. </template>
  164. <template slot="measureSlot" slot-scope="{ index }">
  165. <Select v-model="tableData[index].basics_measure_id" transfer>
  166. <Option
  167. v-for="(item, index) in measure_list"
  168. :key="index"
  169. :label="item.title"
  170. :value="item.id"
  171. ></Option>
  172. </Select>
  173. </template>
  174. <template slot="numSlot" slot-scope="{ index }">
  175. <Input
  176. type="text"
  177. style="width:80px"
  178. v-model="tableData[index].num"
  179. />
  180. </template>
  181. <template slot="minSlot" slot-scope="{ index }">
  182. <Input
  183. type="text"
  184. style="width:80px"
  185. v-model="tableData[index].min"
  186. />
  187. </template>
  188. <template slot="maxSlot" slot-scope="{ index }">
  189. <Input
  190. type="text"
  191. style="width:80px"
  192. v-model="tableData[index].max"
  193. />
  194. </template>
  195. <template slot="materialDetailSlot" slot-scope="{ index }">
  196. <Select v-model="tableData[index].material_detail_id" transfer>
  197. <Option
  198. v-for="(item, index) in tableData[index].materialDetailList"
  199. :key="index"
  200. :label="item.materialDetailShow"
  201. :value="item.id"
  202. ></Option>
  203. </Select>
  204. </template>
  205. <template slot="setSlot" slot-scope="{ index }">
  206. <div>
  207. <a
  208. style="margin:0 5px;"
  209. @click="handleSet(tableData[index], index, 2)"
  210. >复制</a
  211. >
  212. <a
  213. style="margin:0 5px;"
  214. @click="handleSet(tableData[index], index, 3)"
  215. >删除</a
  216. >
  217. </div>
  218. </template>
  219. </Table>
  220. </div>
  221. </div>
  222. </div>
  223. </template>
  224. <script>
  225. // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  226. // 例如:import 《组件名称》 from '《组件路径》';
  227. export default {
  228. name: "",
  229. components: {},
  230. props: {},
  231. // import引入的组件需要注入到对象中才能使用
  232. data() {
  233. // 这里存放数据
  234. return {
  235. type: this.$route.query.type,
  236. id: this.$route.query.id,
  237. formData: {
  238. id: this.$route.query.id,
  239. process_id: "",
  240. part_id: "",
  241. type_title: "",
  242. process_ids: [],
  243. },
  244. urlSelectList: [],
  245. tableColumns: [
  246. {
  247. title: "零部件名称",
  248. align: "center",
  249. minWidth: 120,
  250. slot: "partDetailTitle",
  251. },
  252. {
  253. title: "物料名称",
  254. align: "center",
  255. minWidth: 100,
  256. key: "parts_detail_title",
  257. },
  258. {
  259. title: "测量字段",
  260. align: "center",
  261. minWidth: 100,
  262. slot: "measureSlot",
  263. },
  264. {
  265. title: "数量",
  266. align: "center",
  267. minWidth: 70,
  268. key: "num",
  269. slot: "numSlot",
  270. },
  271. {
  272. title: "最小数值(含)",
  273. align: "center",
  274. minWidth: 120,
  275. slot: "minSlot",
  276. },
  277. { title: "最大数值", align: "center", minWidth: 120, slot: "maxSlot" },
  278. {
  279. title: "物料规格",
  280. align: "center",
  281. minWidth: 100,
  282. key: "material_detail_id",
  283. slot: "materialDetailSlot",
  284. },
  285. { title: "操作", align: "center", minWidth: 120, slot: "setSlot" },
  286. ],
  287. tableData: [{}],
  288. basic_process_list: [], //工艺属性分类
  289. parts_list: [],
  290. type_title_list: [],
  291. process_list: [],
  292. measure_list: [],
  293. };
  294. },
  295. // 生命周期 - 创建完成(可以访问当前this实例)
  296. created() {
  297. this.axios.get("/api/basics_properties_index").then((res) => {
  298. this.basic_process_list = res.data.data;
  299. });
  300. this.axios.get("/api/parts_index").then((res) => {
  301. this.parts_list = res.data.data;
  302. });
  303. this.axios.get("/api/basics_measure_index").then((res) => {
  304. this.measure_list = res.data.data;
  305. });
  306. },
  307. // 生命周期 - 挂载完成(可以访问DOM元素)
  308. mounted() {
  309. this.id && this.initData(this.id);
  310. },
  311. methods: {
  312. back() {
  313. this.$router.go(-1);
  314. },
  315. changeProvinceSelect(val) {
  316. if (!val.includes("全选") && val.length === this.process_list.length) {
  317. this.formData.process_ids.unshift("全选");
  318. } else if (
  319. val.includes("全选") &&
  320. val.length - 1 < this.process_list.length
  321. ) {
  322. this.formData.process_ids = this.formData.process_ids.filter((item) => {
  323. return item !== "全选";
  324. });
  325. }
  326. },
  327. removeProvinceTag(val) {
  328. if (val === "全选") {
  329. this.formData.process_ids = [];
  330. }
  331. },
  332. selectProvinceAll() {
  333. if (this.formData.process_ids.length <= this.process_list.length) {
  334. this.formData.process_ids = [];
  335. this.process_list.map((item) => {
  336. this.formData.process_ids.push(item.id);
  337. });
  338. this.formData.process_ids.unshift("全选");
  339. } else {
  340. this.formData.process_ids = [];
  341. }
  342. },
  343. handleSet(row, index, type) {
  344. if (!this.formData.part_id) {
  345. return this.$Message.warning("请先选择部件");
  346. }
  347. row.part_detail_list = JSON.parse(JSON.stringify(this.part_detail_list));
  348. row.part_id = this.formData.part_id;
  349. const obj = JSON.parse(JSON.stringify(row));
  350. switch (type) {
  351. case 1:
  352. case 2:
  353. this.tableData.splice(index, 0, obj);
  354. break;
  355. case 3:
  356. this.tableData.splice(index, 1);
  357. break;
  358. }
  359. },
  360. initData(id) {
  361. this.axios
  362. .get("/api/process_part_detail", { params: { id } })
  363. .then((res) => {
  364. this.formData = res.data.detail;
  365. this.formData.process_id = this.formData.bp_id;
  366. this.tableData = res.data.list;
  367. this.handleProcessSelected(res.data.detail.process_id);
  368. this.handleGetProcessIds(
  369. res.data.detail.process_id,
  370. res.data.detail.type_title
  371. );
  372. this.handlePartSelected(this.formData.part_id, 2);
  373. });
  374. },
  375. handleProcessSelected(p_id) {
  376. p_id &&
  377. this.axios.post("/api/process_sub_title", { p_id }).then((res) => {
  378. this.type_title_list = res.data;
  379. });
  380. },
  381. handleGetProcessIds(p_id, type_title) {
  382. this.axios
  383. .get("/api/properties_index", { params: { p_id, type_title } })
  384. .then((res) => {
  385. this.process_list = res.data.data;
  386. });
  387. },
  388. handlePartSelected(id, type) {
  389. id &&
  390. this.axios.get("/api/parts_detail", { params: { id } }).then((res) => {
  391. this.part_detail_list = res.data.detail;
  392. if (type == 2) {
  393. this.tableData.map((v, k) => {
  394. v.part_detail_list = JSON.parse(
  395. JSON.stringify(this.part_detail_list)
  396. );
  397. this.handlePartDetailSelected(v, k, v.parts_detail_id);
  398. });
  399. } else {
  400. this.tableData = [];
  401. }
  402. this.tableData = JSON.parse(JSON.stringify(this.tableData));
  403. });
  404. },
  405. handlePartDetailSelected(row, index, id) {
  406. if (id) {
  407. const material_id = row.part_detail_list.filter((v) => v.id == id)[0]
  408. .material_id;
  409. this.axios
  410. .get("/api/material", { params: { id: material_id } })
  411. .then((res) => {
  412. this.tableData[index].parts_detail_title = res.data[0].title;
  413. this.tableData[index].materialDetailList = res.data[0].detail.map(
  414. (v) => {
  415. return { id: v.id, materialDetailShow: v.long + "*" + v.width };
  416. }
  417. );
  418. this.tableData.splice(index, 1, this.tableData[index]);
  419. });
  420. }
  421. },
  422. handleSaveData() {
  423. if (this.type == 1) {
  424. this.formData.id = "";
  425. }
  426. this.axios
  427. .post("/api/process_part_edit", {
  428. ...this.formData,
  429. detail: this.tableData,
  430. })
  431. .then((res) => {
  432. if (res.code == 200) {
  433. this.$Message.success(res.msg);
  434. this.back();
  435. }
  436. });
  437. },
  438. },
  439. // 监听属性 类似于data概念
  440. computed: {},
  441. // 监控data中的数据变化
  442. watch: {},
  443. beforeCreate() {}, // 生命周期 - 创建之前
  444. beforeMount() {}, // 生命周期 - 挂载之前
  445. beforeUpdate() {}, // 生命周期 - 更新之前
  446. updated() {}, // 生命周期 - 更新之后
  447. beforeDestroy() {}, // 生命周期 - 销毁之前
  448. destroyed() {}, // 生命周期 - 销毁完成
  449. activated() {}, // 如果页面有keep-alive缓存功能,这个函数会触发
  450. };
  451. </script>
  452. <style lang="scss" scoped>
  453. /deep/.el-input__inner {
  454. height: 32px;
  455. }
  456. </style>