index.vue 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  1. <template>
  2. <div>
  3. <FullPage
  4. :title="$route.query.title"
  5. :list="list"
  6. @init="init"
  7. :loading="loading"
  8. @searchData="init"
  9. @changePage="changePage"
  10. @changeSize="changeSize"
  11. :tableColums="tableColums"
  12. :tableData="tableData"
  13. :pageIndex="pageIndex"
  14. :total="total"
  15. >
  16. <div slot="titleButton" style="display:flex;">
  17. <Upload
  18. v-if="persimissionData['批量导入'] || persimissionData.all"
  19. name="your_file"
  20. :show-upload-list="false"
  21. :headers="headers"
  22. :on-error="uploadError"
  23. :on-success="uploadSuccess"
  24. :action="$store.state.ip + '/api/product_import'"
  25. >
  26. <Button type="success" ghost icon="md-exit" style="margin-right:10px;"
  27. >批量导入</Button
  28. >
  29. </Upload>
  30. <Button
  31. v-if="persimissionData['批量导出'] || persimissionData.all"
  32. @click="exportData"
  33. type="warning"
  34. ghost
  35. icon="md-return-left"
  36. style="margin-right:10px;"
  37. >批量导出</Button
  38. >
  39. <!-- v-if="persimissionData['批改替换项'] || persimissionData.all" -->
  40. <Button
  41. type="primary"
  42. ghost
  43. @click="replaceItem"
  44. style="margin-right:10px;"
  45. >批改替换项</Button
  46. >
  47. <Button
  48. v-if="persimissionData['新增产品'] || persimissionData.all"
  49. type="primary"
  50. ghost
  51. icon="md-add"
  52. @click="goPage(1)"
  53. >新增产品</Button
  54. >
  55. </div>
  56. <div slot="navButton"></div>
  57. <template slot="set" slot-scope="{ row }">
  58. <div class="table-set">
  59. <svg
  60. style="font-size:20px"
  61. color="#3764FF"
  62. @click="goPage(4, row)"
  63. class="icon icon-nav"
  64. aria-hidden="true"
  65. >
  66. <use xlink:href="#iconcopy-01"></use>
  67. </svg>
  68. <svg
  69. v-if="persimissionData['编辑'] || persimissionData.all"
  70. style="font-size:20px"
  71. color="#3764FF"
  72. @click="goPage(2, row)"
  73. class="icon icon-nav"
  74. aria-hidden="true"
  75. >
  76. <use xlink:href="#iconbianji"></use>
  77. </svg>
  78. <svg
  79. style="font-size:20px"
  80. color="green"
  81. @click="goPage(3, row)"
  82. class="icon icon-nav"
  83. aria-hidden="true"
  84. >
  85. <use xlink:href="#iconxiangqing"></use>
  86. </svg>
  87. <svg
  88. v-if="persimissionData['删除'] || persimissionData.all"
  89. @click="delItems(row)"
  90. class="icon icon-nav"
  91. style="font-size:20px"
  92. color="red"
  93. aria-hidden="true"
  94. >
  95. <use xlink:href="#iconshanchu"></use>
  96. </svg>
  97. </div>
  98. </template>
  99. </FullPage>
  100. <Modal
  101. v-model="showModal"
  102. :title="'批改替换项:' + $route.query.title"
  103. width="1300"
  104. >
  105. <div class="show_modal_content">
  106. <div class="show_modal_content_left">
  107. <div class="show_modal_content_left_item">
  108. <div class="show_modal_content_left_item_title">
  109. <Button
  110. type="primary"
  111. style="cursor:default;border-radius:0"
  112. :ghost="!isSelectAll"
  113. @click="handleProductAllClick(tableData)"
  114. >产品名称</Button
  115. >
  116. </div>
  117. <div class="show_modal_content_left_item_detail_warp">
  118. <div
  119. class="show_modal_content_left_item_detail"
  120. v-for="product in tableData"
  121. :key="product.id"
  122. >
  123. <Button
  124. type="primary"
  125. :ghost="!product.isSelect"
  126. style="border-radius:10px"
  127. @click="handleProductClick(product, 2)"
  128. >{{ product.title }}</Button
  129. >
  130. </div>
  131. </div>
  132. </div>
  133. <div class="show_modal_content_left_item">
  134. <div class="show_modal_content_left_item_title">
  135. <Button
  136. type="primary"
  137. style="cursor:default;border-radius:0"
  138. ghost
  139. >部件名称</Button
  140. >
  141. </div>
  142. <div v-if="productPartList.length < 1">
  143. <Button type="primary" ghost style="border-radius:10px"
  144. >无</Button
  145. >
  146. <Button type="primary" ghost style="border-radius:10px;margin-left:10px" @click="add" v-if="add_show"
  147. ><Icon type="md-add" :size='20'/></Button
  148. >
  149. </div>
  150. <div v-else class="show_modal_content_left_item_detail_warp" >
  151. <div
  152. class="show_modal_content_left_item_detail"
  153. v-for="part in productPartList"
  154. :key="part.id"
  155. id="content_left_item"
  156. >
  157. <svg t="1638267575516" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3395" width="200" height="200" style="position: relative;left: 6px;top: -10px;" @click="edit(part,3)"><path d="M1005.037624 158.992107 899.701554 264.044722 759.214916 123.967406 864.587825 18.915815c19.389606-19.335371 50.835805-19.335371 70.225411 0l70.224388 70.047356C1024.42723 108.297518 1024.42723 139.656737 1005.037624 158.992107zM267.31879 614.19145l140.484591 140.091642-187.231265 46.62183L267.31879 614.19145zM864.587825 299.04998l-421.387259 420.210457L302.75179 579.203588l421.352467-420.211481L864.587825 299.04998zM113.70518 181.723831l0 728.575594 728.57764 0L842.28282 363.868241l109.289102-72.858378 0 692.146916c0 27.535123-8.895601 36.429701-36.432771 36.429701L54.296115 1019.58648c-27.535123 0-49.875944-22.305005-49.875944-49.841152L4.420171 108.866477c0-27.535123 8.858762-36.429701 36.428677-36.429701l692.14794 0L623.709733 181.723831 113.70518 181.723831z" p-id="3396" fill="#707070"></path></svg>
  158. <!-- <Icon type="md-create" style="position: relative;left: 10px;top: -8px;" color='black' :size='10'/> -->
  159. <Button
  160. type="primary"
  161. :ghost="!part.isSelect"
  162. style="border-radius:10px"
  163. @click="handlePartClick(part, 3)"
  164. >{{ part.title }}</Button
  165. >
  166. <svg t="1638267935515" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5634" width="200" height="200" style="position: relative;left: -8px;top: -10px;" @click="del(part)"><path d="M585.412525 512.594747L973.601616 124.418586c19.600808-19.600808 19.600808-51.898182 0-71.49899l-2.120404-2.120404c-19.600808-19.600808-51.898182-19.600808-71.49899 0L511.793131 439.518384 123.61697 50.799192c-19.600808-19.600808-51.898182-19.600808-71.49899 0l-2.120404 2.120404c-20.11798 19.600808-20.11798 51.898182 0 71.49899l388.189091 388.189091L49.997576 900.783838c-19.587879 19.600808-19.587879 51.898182 0 71.49899l2.120404 2.120404c19.600808 19.600808 51.898182 19.600808 71.49899 0L511.793131 586.214141l388.189091 388.176162c19.600808 19.600808 51.898182 19.600808 71.49899 0l2.120404-2.120404c19.600808-19.600808 19.600808-51.898182 0-71.49899L585.412525 512.594747z m0 0" p-id="5635" fill="#707070"></path></svg>
  167. <!-- <Icon type="md-close" style="position: relative;left: -10px;top: -8px;" color='black' :size='20'/> -->
  168. </div>
  169. <Button type="primary" ghost style="border-radius:10px;margin-left:10px" @click="add"
  170. ><Icon type="md-add" :size='20'/></Button
  171. >
  172. </div>
  173. </div>
  174. </div>
  175. <div class="show_modal_content_right">
  176. <div style="margin-top:20px">
  177. <span style="padding-right:10px"
  178. >默认部件:{{ defaultPart.title }}</span
  179. >
  180. <span style="margin-right:10px"
  181. >高:<Input v-model="defaultPart.formula_l" style="width:50px" disabled
  182. /></span>
  183. <span style="margin-right:10px"
  184. >宽:<Input v-model="defaultPart.formula_w" style="width:50px" disabled
  185. /></span>
  186. <span style="margin-right:10px"
  187. >厚:<Input v-model="defaultPart.formula_h" style="width:50px" disabled
  188. /></span>
  189. <span>是否为空: <vxe-switch v-model="defaultPart.is_null" disabled></vxe-switch> </span>
  190. </div>
  191. <div class="show_modal_content_right_top">
  192. <Button type="primary" @click="handleAddChangeable"
  193. >新增替换部件</Button
  194. >
  195. </div>
  196. <div class="show_modal_content_right_body">
  197. <Table
  198. border
  199. max-height="500"
  200. :columns="changeableColumns"
  201. :data="changeableTableData"
  202. ></Table>
  203. </div>
  204. </div>
  205. </div>
  206. <div slot="footer">
  207. <Button
  208. type="primary"
  209. style="margin-right:10px;"
  210. @click="showModal = false"
  211. >取消</Button
  212. >
  213. <Button
  214. type="primary"
  215. style="margin-right:10px;"
  216. @click="handleChangeableConfirm"
  217. >确定</Button
  218. >
  219. </div>
  220. </Modal>
  221. <Modal
  222. v-model="showKey"
  223. :width="1250"
  224. :mask-closable="false"
  225. :closable="false"
  226. >
  227. <div>
  228. <KeyBoard
  229. :rightData="measureList"
  230. @cancel="cancelKey"
  231. @success="successKey"
  232. class="key-co"
  233. />
  234. </div>
  235. <div slot="footer"></div>
  236. </Modal>
  237. <Modal
  238. v-model="edit_showModel"
  239. title="批量修改部件"
  240. width="400"
  241. :draggable='true'
  242. @on-ok='edit_part'
  243. >
  244. <Form>
  245. <FormItem >
  246. <span>默认部件:</span>
  247. <Select v-model="formData.part_id" style="width:140px" filterable clearable>
  248. <Option v-for="item in partsList" :key="item.id" :value="item.id">
  249. {{item.title}}
  250. </Option>
  251. </Select>
  252. </FormItem>
  253. <FormItem >
  254. <span>高:</span><Input type="number" style='width:60px;margin-right:20px' v-model="formData.formula_l"/>
  255. <span>宽:</span><Input type="number" style='width:60px;margin-right:20px' v-model="formData.formula_w"/>
  256. <span>厚:</span><Input type="number" style='width:60px' v-model="formData.formula_h"/>
  257. </FormItem>
  258. <FormItem>
  259. <span>是否为空: <vxe-switch v-model="formData.is_null"></vxe-switch> </span>
  260. </FormItem>
  261. </Form>
  262. </Modal>
  263. <Modal title="批量删除部件"
  264. width="400"
  265. v-model="del_showModel"
  266. @on-ok='del_part'
  267. >
  268. <div style="text-align:center">是否确定删除该部件?</div>
  269. </Modal>
  270. <Modal
  271. v-model="add_showModel"
  272. title="批量增加部件"
  273. width="400"
  274. :draggable='true'
  275. @on-ok='add_part'
  276. >
  277. <Form :model='addData' >
  278. <FormItem >
  279. <span>默认部件:</span>
  280. <Select v-model="addData.part_id" style="width:140px" filterable clearable>
  281. <Option v-for="item in partsList" :key="item.id" :value="item.id">
  282. {{item.title}}
  283. </Option>
  284. </Select>
  285. </FormItem>
  286. <FormItem >
  287. <span>高:</span><Input type="number" style='width:60px;margin-right:20px' v-model="addData.formula_l"/>
  288. <span>宽:</span><Input type="number" style='width:60px;margin-right:20px' v-model="addData.formula_w"/>
  289. <span>厚:</span><Input type="number" style='width:60px' v-model="addData.formula_h"/>
  290. </FormItem>
  291. <FormItem>
  292. <span>是否为空: <vxe-switch v-model="addData.is_null"></vxe-switch> </span>
  293. </FormItem>
  294. </Form>
  295. </Modal>
  296. </div>
  297. </template>
  298. <script>
  299. import { mapState } from "vuex";
  300. import KeyBoard from "../../components/keyboard/index";
  301. export default {
  302. components: { KeyBoard },
  303. data() {
  304. return {
  305. select_id:[],
  306. add_show:false,
  307. title:'',
  308. part_id:null,
  309. add_showModel:false,
  310. edit_showModel:false,
  311. del_showModel:false,
  312. formData:{
  313. part_id:'',
  314. formula_l:'',
  315. formula_w:'',
  316. formula_h:'',
  317. is_null:'',
  318. },
  319. addData:{
  320. part_id:'',
  321. formula_l:'',
  322. formula_w:'',
  323. formula_h:'',
  324. is_null:'',
  325. },
  326. list: [
  327. {
  328. title: "产品名称",
  329. name: "Input",
  330. value: "",
  331. serverName: "title",
  332. placeholder: "请输入产品名称",
  333. },
  334. {
  335. title: "产品型号",
  336. name: "Input",
  337. value: "",
  338. serverName: "model",
  339. placeholder: "请输入产品型号",
  340. },
  341. {
  342. title: "图号",
  343. name: "Input",
  344. value: "",
  345. serverName: "url_number",
  346. placeholder: "请输入图号",
  347. },
  348. ],
  349. tableColums: [
  350. {
  351. title: "序号",
  352. type: "index",
  353. align: "center",
  354. key: "",
  355. resizable: true,
  356. width: 70,
  357. },
  358. { title: "分类名称", align: "center", key: "type_name", resizable: true,width:190 },
  359. { title: "产品名称", align: "center", key: "title" , resizable: true,width:190},
  360. { title: "计量单位", align: "center", key: "unit" , resizable: true,width:190},
  361. { title: "型号", align: "center", key: "model", resizable: true,width:190 },
  362. { title: "图号", align: "center", key: "url_number", resizable: true,width:190 },
  363. {
  364. title: "产品图片",
  365. align: "center",
  366. key: "company",
  367. resizable: true,width:190,
  368. render: (h, params) => {
  369. const { row } = params;
  370. return h("img", {
  371. attrs: {
  372. src: params.row.img_url?this.$store.state.ip + params.row.img_url:'',
  373. style:
  374. "max-width:50px;max-height:50px;position:relative;top:3px;",
  375. },
  376. on: {
  377. click: (e) => {
  378. this.axios("/api/orders_img", {
  379. params: { id: row.id, type: 0 },
  380. }).then((res) => {
  381. console.log(
  382. "this.$store.state.ip :>> ",
  383. this.$store.state.ip
  384. );
  385. if (res.code == 200) {
  386. row.imgs = res.data;
  387. this.$previewImg({
  388. list: res.data,
  389. baseUrl: this.$store.state.ip,
  390. baseImgField: "img_url",
  391. baseTitleField: "",
  392. });
  393. }
  394. });
  395. // if(row.imgs&&row.imgs.length>0){//优化处理考虑到图纸我就暂时不处理了
  396. // this.$previewImg({
  397. // list:row.imgs,
  398. // baseUrl:this.$store.state.ip,
  399. // baseImgField:'img_url',
  400. // baseTitleField:''
  401. // })
  402. // }else{
  403. // this.axios('/api/orders_img',{params:{id:row.id,type:0}}).then(res=>{
  404. // if(res.code == 200){
  405. // row.imgs = res.data
  406. // this.$previewImg({
  407. // list:row.imgs,
  408. // baseUrl:this.$store.state.ip,
  409. // baseImgField:'img_url',
  410. // baseTitleField:''
  411. // })
  412. // }
  413. // })
  414. // }
  415. },
  416. },
  417. });
  418. },
  419. },
  420. {
  421. title: "图纸",
  422. align: "center",
  423. key: "url",
  424. resizable: true,width:190,
  425. render: (h, params) => {
  426. const { row } = params;
  427. return h("img", {
  428. attrs: {
  429. src: params.row.url?this.$store.state.ip + params.row.url:'',
  430. style:
  431. "max-width:50px;max-height:50px;position:relative;top:3px;",
  432. },
  433. on: {
  434. click: (e) => {
  435. this.axios("/api/orders_img", {
  436. params: { id: row.id, type: 1 },
  437. }).then((res) => {
  438. if (res.code == 200) {
  439. row.imgs = res.data;
  440. this.$previewImg({
  441. list: row.imgs,
  442. baseUrl: this.$store.state.ip,
  443. baseImgField: "img_url",
  444. baseTitleField: "",
  445. });
  446. }
  447. });
  448. },
  449. },
  450. });
  451. },
  452. },
  453. { title: "操作", align: "center", slot: "set", minWidth: 150 },
  454. ],
  455. tableData: [],
  456. pageIndex: 1,
  457. total: 0,
  458. pageSize: 10,
  459. proxyObj: {
  460. page_index: 1,
  461. page_size: 10,
  462. },
  463. loading: false,
  464. headers: { Authorization: localStorage.getItem("token") },
  465. showModal: false,
  466. productPartList: [],
  467. currentProductList: [],
  468. changeableColumns: [
  469. {
  470. title: "替换部件",
  471. align: "center",
  472. key: "part_id",
  473. render: (h, params) => {
  474. const { index } = params;
  475. const currencyRow = this.changeableTableData[index];
  476. return h(
  477. "Select",
  478. {
  479. props: {
  480. value: currencyRow.part_id,
  481. size: "small",
  482. transfer: true,
  483. clearable: true,
  484. filterable: true,
  485. },
  486. on: {
  487. "on-change": (e) => {
  488. currencyRow.part_id = e;
  489. },
  490. },
  491. },
  492. [
  493. this.partsList.map((item) => {
  494. return h("Option", {
  495. props: { label: item.title, value: item.id },
  496. });
  497. }),
  498. ]
  499. );
  500. },
  501. },
  502. {
  503. title: "高",
  504. align: "center",
  505. key: "formula_l",
  506. width: "100px",
  507. render: (h, params) => {
  508. const { index } = params;
  509. const currencyRow = this.changeableTableData[index];
  510. return h("Input", {
  511. props: {
  512. placeholder: "请输入高",
  513. value: currencyRow.formula_l,
  514. disabled: this.isChecked,
  515. },
  516. on: {
  517. "on-focus": () => {
  518. this.openKey(index, "formula_l", currencyRow);
  519. },
  520. },
  521. });
  522. },
  523. },
  524. {
  525. title: "宽",
  526. align: "center",
  527. key: "formula_w",
  528. width: "100px",
  529. render: (h, params) => {
  530. const { index } = params;
  531. const currencyRow = this.changeableTableData[index];
  532. return h("Input", {
  533. props: {
  534. placeholder: "请输入宽",
  535. value: currencyRow.formula_w,
  536. },
  537. on: {
  538. "on-focus": () => {
  539. this.openKey(index, "formula_w", currencyRow);
  540. },
  541. },
  542. });
  543. },
  544. },
  545. {
  546. title: "厚",
  547. align: "center",
  548. key: "formula_h",
  549. width: "100px",
  550. render: (h, params) => {
  551. const { index } = params;
  552. const currencyRow = this.changeableTableData[index];
  553. return h("Input", {
  554. props: {
  555. placeholder: "请输入厚",
  556. value: currencyRow.formula_h,
  557. },
  558. on: {
  559. "on-focus": () => {
  560. this.openKey(index, "formula_h", currencyRow);
  561. },
  562. },
  563. });
  564. },
  565. },
  566. {
  567. title: "操作",
  568. align: "center",
  569. key: "set",
  570. width: "100px",
  571. render: (h, params) => {
  572. const { index } = params;
  573. // const currencyRow = this.changeableTableData[index];
  574. return h(
  575. "a",
  576. {
  577. on: {
  578. click: () => {
  579. this.changeableTableData.splice(index, 1);
  580. },
  581. },
  582. },
  583. "删除"
  584. );
  585. },
  586. },
  587. ],
  588. changeableTableData: [],
  589. partsList: [],
  590. showKey: false,
  591. measureList: [],
  592. currencyChoose: {},
  593. attrindex: null,
  594. attrName: "",
  595. isSelectAll: false,
  596. defaultPart: {
  597. title: "",
  598. formula_l: "",
  599. formula_w: "",
  600. formula_h: "",
  601. is_null: "",
  602. },
  603. };
  604. },
  605. beforeRouteLeave(to, from, next) {
  606. if (to.path == "/cms/product/edit") {
  607. this.$route.meta.keepAlive = true;
  608. } else {
  609. this.$route.meta.keepAlive = false;
  610. }
  611. next();
  612. },
  613. beforeRouteEnter(to, from, next) {
  614. next((vm) => {
  615. vm.getData(vm.proxyObj);
  616. vm.productPartList =[];
  617. vm.defaultPart = [];
  618. vm.changeableTableData = []
  619. })
  620. },
  621. created() {
  622. // 获取部件列表
  623. this.axios("/api/parts_index").then((res) => {
  624. this.partsList = res.data.data;
  625. });
  626. // 获取产品分类测量字段
  627. this.axios("/api/basics_product_list", {
  628. params: { id: this.$route.query.id },
  629. }).then((res) => {
  630. if (res.code == 200) {
  631. const { data } = res;
  632. const result = data.filter((rows) => rows.id == this.$route.query.id);
  633. this.measureList = result[0].measure;
  634. }
  635. });
  636. },
  637. mounted() {
  638. this.proxyObj.type_id = this.$route.query.id;
  639. this.getData(this.proxyObj);
  640. },
  641. computed: {
  642. ...mapState(["persimissionData"]),
  643. },
  644. watch: {
  645. "$route.query.title": {
  646. handler() {
  647. this.proxyObj.type_id = this.$route.query.id;
  648. this.list.forEach((element) => {
  649. element.value = "";
  650. });
  651. this.proxyObj.model = "";
  652. this.proxyObj.title = "";
  653. this.getData(this.proxyObj);
  654. },
  655. },
  656. },
  657. methods: {
  658. add_part(){
  659. const temp_product = this.tableData.filter((item) => item.isSelect);
  660. const product_id = temp_product.map((item) => item.id);
  661. let part_list_id = [];
  662. this.productPartList.forEach(m=>{
  663. part_list_id.push(m.id)
  664. })
  665. this.addData.is_null = this.addData.is_null?1:0;
  666. this.axios.post('/api/support_product_parts_add',{product_id:product_id,...this.addData,part_list:part_list_id}).then(res=>{
  667. if(res.code == 200){
  668. this.$Message.success(res.msg);
  669. this.axios.post("/api/support_product_get_part", {
  670. type:2,
  671. basic_product_id: [this.$route.query.id],
  672. product_id,
  673. part_id: []
  674. })
  675. .then((res) => {
  676. console.log(res);
  677. this.productPartList = res.data;
  678. this.productPartList.map((item) => {
  679. (item.isSelect = false)
  680. if(item.id == this.addData.part_id){
  681. item.isSelect = true;
  682. this.axios.post("/api/support_product_get_part", {
  683. type:3,
  684. basic_product_id: [this.$route.query.id],
  685. product_id,
  686. part_id:[this.addData.part_id],
  687. })
  688. .then((res) => {
  689. console.log(res);
  690. this.changeableTableData = res.data.list;
  691. this.defaultPart = res.data.head;
  692. this.defaultPart.is_null = (res.data.head.is_null == 0||!res.data.head.is_null)?false:true
  693. this.partsList.forEach(m=>{
  694. if(m.id == this.addData.part_id){
  695. this.defaultPart.title = m.title
  696. }
  697. })
  698. });
  699. this.$forceUpdate();
  700. }
  701. });
  702. });
  703. this.$forceUpdate();
  704. }
  705. })
  706. },
  707. replaceItem(){
  708. this.showModal = true;
  709. },
  710. edit_part(){
  711. const temp_product = this.tableData.filter((item) => item.isSelect);
  712. const product_id = temp_product.map((item) => item.id);
  713. const temp_part = this.productPartList.filter((item) => item.isSelect);
  714. const part_list = this.productPartList.filter((item) => !item.isSelect);
  715. let part_list_id = [];
  716. part_list.forEach(m=>{
  717. part_list_id.push(m.id)
  718. })
  719. const part_id = temp_part.map((item) => item.id);
  720. this.formData.is_null = this.formData.is_null?1:0;
  721. let parts_id = Number(part_id.toString()) ;
  722. this.axios.post('/api/support_product_parts_edit',{
  723. product_id:product_id,
  724. part_id:parts_id,
  725. children:{...this.formData},
  726. part_list:part_list_id
  727. }).then(res=>{
  728. if(res.code == 200){
  729. this.$Message.success(res.msg);
  730. this.axios
  731. .post("/api/support_product_get_part", {
  732. type:2,
  733. basic_product_id: [this.$route.query.id],
  734. product_id,
  735. part_id: [],
  736. })
  737. .then((res) => {
  738. console.log(res);
  739. this.productPartList = res.data;
  740. this.productPartList.map((item) =>{
  741. (item.isSelect = false);
  742. if(item.id == this.formData.part_id){
  743. item.isSelect = true;
  744. this.title = item.title
  745. }});
  746. });
  747. this.axios
  748. .post("/api/support_product_get_part", {
  749. type:3,
  750. basic_product_id: [this.$route.query.id],
  751. product_id:product_id,
  752. part_id:[this.formData.part_id],
  753. })
  754. .then((res) => {
  755. console.log(res);
  756. this.changeableTableData = res.data.list;
  757. if(res.data.head instanceof Array){
  758. res.data.head.is_null = false;
  759. }else{
  760. res.data.head.is_null = res.data.head.is_null == 0?false:true;
  761. }
  762. this.defaultPart = res.data.head;
  763. console.log(this.defaultPart)
  764. this.defaultPart.title =this.title;
  765. });
  766. this.$forceUpdate();
  767. }
  768. })
  769. },
  770. add(){
  771. this.addData = {
  772. part_id:'',
  773. formula_l:'',
  774. formula_w:'',
  775. formula_h:'',
  776. is_null:'',
  777. }
  778. this.add_showModel = true;
  779. },
  780. del(part){
  781. this.del_showModel = true;
  782. this.part_id = part.id;
  783. },
  784. del_part(){
  785. const temp_product = this.tableData.filter((item) => item.isSelect);
  786. const product_id = temp_product.map((item) => item.id);
  787. const temp_part = this.productPartList.filter((item) => item.isSelect);
  788. const part_id = temp_part.map((item) => item.id);
  789. this.axios.post('/api/support_product_parts_del',{product_id:product_id,part_id:this.part_id}).then(res=>{
  790. if(res.code == 200){
  791. this.$Message.success(res.msg);
  792. this.changeableTableData = [];
  793. this.defaultPart = [];
  794. this.axios
  795. .post("/api/support_product_get_part", {
  796. type:2,
  797. basic_product_id: [this.$route.query.id],
  798. product_id:product_id,
  799. part_id: [],
  800. })
  801. .then((res) => {
  802. this.productPartList = res.data;
  803. this.productPartList.map((item) => {
  804. (item.isSelect = false);
  805. if(item.id == part_id){
  806. item.isSelect =true;
  807. }
  808. });
  809. });
  810. this.$forceUpdate();
  811. }
  812. })
  813. },
  814. init(row) {
  815. this.pageIndex = 1;
  816. row.page_index = this.pageIndex;
  817. row.page_size = this.pageSize;
  818. row.type_id = this.$route.query.id; //产品管理因为无法使用id 所以用type_id替代
  819. this.proxyObj = row;
  820. this.getData(row);
  821. },
  822. getData(row) {
  823. this.loading = true;
  824. this.axios("/api/product", { params: row }).then((res) => {
  825. this.loading = false;
  826. this.tableData = res.data.data;
  827. this.total = res.data.total;
  828. this.tableData.map((item) => (item.isSelect = false));
  829. });
  830. },
  831. delItems(row) {
  832. this.confirmDelete({
  833. content: "确认删除么?",
  834. then: () => {
  835. this.axios
  836. .post("/api/product", { id: row.id, state: 0 })
  837. .then((res) => {
  838. if (res.code == 200) {
  839. this.$Message.success(res.msg);
  840. this.getData(this.proxyObj);
  841. }
  842. });
  843. },
  844. });
  845. },
  846. handleProductAllClick(product) {
  847. this.isSelectAll = !this.isSelectAll;
  848. // let flag
  849. product.map((item) => {
  850. item.isSelect = this.isSelectAll;
  851. });
  852. this.add_show = false;
  853. let ids = product.map((item) => item.id);
  854. this.isSelectAll &&
  855. this.axios
  856. .post("/api/support_product_get_part", {
  857. type: 2,
  858. basic_product_id: [this.$route.query.id],
  859. product_id: ids,
  860. part_id: [],
  861. })
  862. .then((res) => {
  863. console.log(res);
  864. this.productPartList = res.data;
  865. this.productPartList.map((item) => (item.isSelect = false));
  866. this.add_show = true
  867. });
  868. },
  869. handleProductClick(product, type) {
  870. product.isSelect = !product.isSelect;
  871. this.currentProductList = product;
  872. const temp_product = this.tableData.filter((item) => item.isSelect);
  873. const product_id = temp_product.map((item) => item.id);
  874. this.select_id = product_id;
  875. // 判断是否全选,全选标题选中
  876. let flag = true;
  877. this.tableData.map((item) => {
  878. if (!item.isSelect) {
  879. flag = false;
  880. }
  881. });
  882. this.isSelectAll = flag;
  883. this.axios
  884. .post("/api/support_product_get_part", {
  885. type,
  886. basic_product_id: [this.$route.query.id],
  887. product_id,
  888. part_id: [],
  889. })
  890. .then((res) => {
  891. console.log(res);
  892. this.productPartList = res.data;
  893. this.productPartList.map((item) => (item.isSelect = false));
  894. });
  895. this.$forceUpdate();
  896. },
  897. handlePartClick(part, type) {
  898. // 部件单选
  899. this.productPartList.map((item) => (item.isSelect = false));
  900. part.isSelect = !part.isSelect;
  901. const temp_product = this.tableData.filter((item) => item.isSelect);
  902. const product_id = temp_product.map((item) => item.id);
  903. const temp_part = this.productPartList.filter((item) => item.isSelect);
  904. const part_id = temp_part.map((item) => item.id);
  905. this.axios
  906. .post("/api/support_product_get_part", {
  907. type,
  908. basic_product_id: [this.$route.query.id],
  909. product_id,
  910. part_id,
  911. })
  912. .then((res) => {
  913. console.log(res);
  914. this.changeableTableData = res.data.list;
  915. this.defaultPart = res.data.head;
  916. this.formData = res.data.head;
  917. this.formData.is_null = res.data.head.is_null == 0?false:true;
  918. this.defaultPart.title = part.title;
  919. this.formData.part_id = part.id;
  920. });
  921. this.$forceUpdate();
  922. },
  923. handleAddChangeable() {
  924. const temp = this.productPartList.filter((item) => item.isSelect);
  925. if (temp.length > 0) {
  926. this.changeableTableData.push({
  927. id: "",
  928. formula_h: "",
  929. formula_l: "",
  930. formula_w: "",
  931. });
  932. } else {
  933. this.$Message.warning("请选择部件名称");
  934. }
  935. },
  936. handleChangeableConfirm() {
  937. const temp_product = this.tableData.filter((item) => item.isSelect);
  938. const product_id = temp_product.map((item) => item.id);
  939. const temp_part = this.productPartList.filter((item) => item.isSelect);
  940. const part_id = temp_part.map((item) => item.id);
  941. console.log(product_id)
  942. if(part_id.length == 0){
  943. return this.$Message.warning('请选择部件')
  944. }
  945. this.axios
  946. .post("/api/support_product_batch", {
  947. type: 3,
  948. basic_product_id: [this.$route.query.id],
  949. product_id,
  950. part_id,
  951. change: this.changeableTableData,
  952. head: this.defaultPart,
  953. })
  954. .then((res) => {
  955. if (res.code == 200) {
  956. this.$Message.success(res.msg);
  957. this.tableData.map((item) => (item.isSelect = false));
  958. this.productPartList = [];
  959. this.changeableTableData = [];
  960. this.defaultPart = {
  961. title: "",
  962. formula_l: "",
  963. formula_w: "",
  964. formula_h: "",
  965. is_null: "",
  966. },
  967. this.showModal = false;
  968. }
  969. });
  970. },
  971. openKey(row, attr, cur) {
  972. this.showKey = true;
  973. this.attrindex = row;
  974. this.attrName = attr;
  975. this.currencyChoose = cur;
  976. },
  977. successKey(str) {
  978. // this.info.part[this.attrindex][this.attrName] = str;
  979. this.currencyChoose[this.attrName] = str;
  980. this.showKey = false;
  981. },
  982. cancelKey() {
  983. this.showKey = false;
  984. },
  985. changePage(e) {
  986. this.pageIndex = e;
  987. this.proxyObj.page_index = this.pageIndex;
  988. // const sortList = this.sortList.filter((item) => item.sort);
  989. // this.proxyObj.sortList = sortList;
  990. this.getData(this.proxyObj);
  991. },
  992. changeSize(e) {
  993. this.pageSize = e;
  994. this.proxyObj.page_size = this.pageSize;
  995. // const sortList = this.sortList.filter((item) => item.sort);
  996. // this.proxyObj.sortList = sortList;
  997. this.getData(this.proxyObj);
  998. },
  999. edit(val,type){
  1000. this.productPartList.forEach(v=>{
  1001. v.isSelect = false;
  1002. })
  1003. val.isSelect = !val.isSelect;
  1004. const temp_product = this.tableData.filter((item) => item.isSelect);
  1005. const product_id = temp_product.map((item) => item.id);
  1006. this.axios
  1007. .post("/api/support_product_get_part", {
  1008. type,
  1009. basic_product_id: [this.$route.query.id],
  1010. product_id,
  1011. part_id:[val.id],
  1012. })
  1013. .then((res) => {
  1014. this.formData = res.data.head;
  1015. this.formData.part_id = val.id;
  1016. this.changeableTableData = res.data.list;
  1017. this.defaultPart = JSON.parse(JSON.stringify(res.data.head)) ;
  1018. this.defaultPart.title = val.title;
  1019. if(res.data.head instanceof Array){
  1020. this.formData.is_null = false;
  1021. this.formData.formula_l = '';
  1022. this.formData.formula_w = '';
  1023. this.formData.formula_h = '';
  1024. this.defaultPart.is_null = false;
  1025. }else{
  1026. this.formData.is_null=res.data.head.is_null == 0?false:true;
  1027. this.defaultPart.is_null = this.defaultPart.is_null == 0?false:true;
  1028. }
  1029. });
  1030. this.$forceUpdate();
  1031. this.edit_showModel = true;
  1032. },
  1033. goPage(n, row) {
  1034. //n = 1 新增 2 编辑 3 查看
  1035. let id = row ? row.id : "";
  1036. this.$router.push({
  1037. path: "/cms/product/edit",
  1038. query: {
  1039. type: n,
  1040. id: id,
  1041. back_id: this.$route.query.id,
  1042. title: this.$route.query.title,
  1043. },
  1044. });
  1045. },
  1046. async exportData() {
  1047. const res = await this.axios("/api/product_export", {
  1048. params: { ...this.proxyObj },
  1049. });
  1050. if (res.code == 200) {
  1051. let url = `${this.$store.state.ip}/api/storage/${res.data.file}`;
  1052. location.href = url;
  1053. }
  1054. },
  1055. uploadSuccess(res) {
  1056. if (res.code == 200) {
  1057. this.$Message.success(res.msg || "上传成功");
  1058. } else {
  1059. this.$Message.warning(res.msg || "上传失败");
  1060. }
  1061. this.getData(this.proxyObj);
  1062. },
  1063. uploadError(err) {
  1064. this.$Message.error(err.msg || "上传失败");
  1065. },
  1066. },
  1067. };
  1068. </script>
  1069. <style lang="scss" scoped>
  1070. .show_modal_content {
  1071. display: flex;
  1072. .show_modal_content_left {
  1073. width: 50%;
  1074. min-height: 500px;
  1075. overflow: hidden;
  1076. overflow-y: auto;
  1077. border-right: 1px solid #e8eaec;
  1078. padding-top: 20px;
  1079. .show_modal_content_left_item {
  1080. width: 100%;
  1081. display: flex;
  1082. .show_modal_content_left_item_title,
  1083. .show_modal_content_left_item_detail {
  1084. margin-bottom: 10px;
  1085. margin-right: 20px;
  1086. }
  1087. .show_modal_content_left_item_detail_warp {
  1088. display: flex;
  1089. justify-content: flex-start;
  1090. align-items: flex-start;
  1091. flex-wrap: wrap;
  1092. }
  1093. }
  1094. }
  1095. .show_modal_content_right {
  1096. width: 50%;
  1097. padding-left: 20px;
  1098. .show_modal_content_right_top {
  1099. display: flex;
  1100. justify-content: flex-end;
  1101. margin-top: 30px;
  1102. margin-bottom: 10px;
  1103. }
  1104. }
  1105. }
  1106. </style>