addEdit.vue 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :center="true"
  5. align="left"
  6. top="8vh"
  7. width="1040px"
  8. @close="closeModel"
  9. :close-on-click-modal="false"
  10. :visible.sync="showModelThis"
  11. v-loading="loading"
  12. element-loading-text="拼命加载中"
  13. element-loading-spinner="el-icon-loading"
  14. element-loading-background="rgba(0, 0, 0, 0.8)"
  15. >
  16. <el-card>
  17. <el-row :gutter="10">
  18. <el-col :span="24">
  19. <el-col :span="10" :offset="7">
  20. <div style="margin: -5px 0 10px 0">
  21. <el-steps
  22. :active="step"
  23. simple
  24. process-status="finish"
  25. finish-status="success"
  26. >
  27. <el-step
  28. v-for="(item, index) in stepList"
  29. :key="index"
  30. :title="item"
  31. />
  32. </el-steps>
  33. </div>
  34. </el-col>
  35. <el-row :gutter="10" v-if="step === 0">
  36. <el-form
  37. :model="baseForm"
  38. status-icon
  39. :rules="baseRules"
  40. ref="baseForm"
  41. label-width="110px"
  42. class="demo-ruleForm"
  43. >
  44. <el-col :span="24">
  45. <el-form-item label="商品名称" prop="good_name">
  46. <el-input
  47. placeholder="请输入商品名称"
  48. v-model="baseForm.good_name"
  49. maxlength="100"
  50. ></el-input>
  51. </el-form-item>
  52. </el-col>
  53. <el-col :span="12">
  54. <el-form-item label="供应商联系人" prop="supplier">
  55. <el-select
  56. v-model="baseForm.supplier"
  57. filterable
  58. clearable
  59. style="width: 100%"
  60. placeholder="请选择供应商联系人"
  61. >
  62. <el-option
  63. v-for="group in supplierOptions"
  64. :key="group.id"
  65. :label="group.name"
  66. :value="group.id"
  67. >
  68. <span>{{ group.name }}</span
  69. ><span class="fr">{{ group.company }}</span>
  70. </el-option>
  71. </el-select>
  72. </el-form-item>
  73. <el-form-item label="商品单位" prop="unit">
  74. <el-input
  75. placeholder="请输入单位"
  76. v-model="baseForm.unit"
  77. maxlength="10"
  78. :disabled="isDetail"
  79. ></el-input>
  80. </el-form-item>
  81. </el-col>
  82. <el-col :span="12">
  83. <el-form-item label="商品分类" prop="catid">
  84. <el-cascader
  85. v-model="baseForm.catid"
  86. style="width: 100%"
  87. filterable
  88. placeholder="请选择商品分类"
  89. clearable
  90. :options="catOptions"
  91. :props="{ expandTrigger: 'hover', checkStrictly: true }"
  92. ></el-cascader>
  93. </el-form-item>
  94. <el-form-item label="商品品牌" prop="brandid">
  95. <el-select
  96. style="width: 100%"
  97. v-model="baseForm.brandid"
  98. clearable
  99. placeholder="请选择商品品牌"
  100. >
  101. <el-option
  102. v-for="item in brandidOptions"
  103. :key="item.id"
  104. :label="item.brand_name"
  105. :value="item.id"
  106. >
  107. </el-option>
  108. </el-select>
  109. </el-form-item>
  110. </el-col>
  111. <el-col :span="24">
  112. <el-form-item
  113. label="商品主图"
  114. prop="image"
  115. class="activity-upload"
  116. >
  117. <div class="img-list-main clearfix">
  118. <div
  119. class="img-item"
  120. v-for="(item, index) in baseForm.image"
  121. :key="item + index"
  122. >
  123. <img :src="item" class="avatar" />
  124. <i class="el-icon-close" @click="closeImg(index)"></i>
  125. </div>
  126. <div
  127. class="btnupload"
  128. v-if="baseForm.image.length < 5"
  129. style="position: relative"
  130. >
  131. <i class="el-icon-plus avatar-uploader-icon"></i>
  132. <file-upload
  133. class="Upload"
  134. :accept="'.jpg,.png,.jpeg'"
  135. :multiple="true"
  136. :uploadcondition="beforeAvatarUpload"
  137. @UploadErrorEvent="UploadErrorEvent"
  138. @UploadSuccessEvent="UploadSuccessEvent"
  139. ></file-upload>
  140. </div>
  141. </div>
  142. <div class="txt-tips fl">
  143. <p>
  144. <span sty>大小:小于1M;</span><span>尺寸:100*100;</span
  145. ><span>类型:jpg.png.jpeg</span>
  146. </p>
  147. </div>
  148. </el-form-item>
  149. </el-col>
  150. </el-form>
  151. <el-col :span="24" style="text-align: right">
  152. <el-tag type="warning" class="fl" style="margin-left: 100px"
  153. >更换商品分类,会影响规格与价格,请慎重修改</el-tag
  154. >
  155. <el-button type="primary" @click="baseSubmitForm"
  156. >下一步
  157. </el-button>
  158. <el-button @click="showModelThis = false">{{
  159. isDetail ? "关 闭" : "取 消"
  160. }}</el-button>
  161. </el-col>
  162. </el-row>
  163. <el-row :gutter="10" v-else>
  164. <el-col :span="24" style="max-height: 560px; overflow-y: scroll">
  165. <el-form
  166. :model="ruleForm"
  167. status-icon
  168. ref="ruleForm"
  169. label-width="60px"
  170. class="demo-dealGoodsPool-ruleForm"
  171. >
  172. <el-form-item label="规格" required>
  173. <div class="mack-mian clearfix">
  174. <div
  175. class="mock-item-div clearfix"
  176. v-for="(item, index) in mock"
  177. :key="'specItem' + index"
  178. >
  179. <div class="mock-title clearfix">
  180. <el-input
  181. :size="size"
  182. class="fr"
  183. style="width: 250px"
  184. maxlength="40"
  185. placeholder="新增规格值,如红色"
  186. v-model="item.value"
  187. >
  188. <el-button
  189. slot="append"
  190. @click="specinfoadd(item.spec_id, item.value)"
  191. >提交</el-button
  192. >
  193. </el-input>
  194. <span class="fl">{{ item.spec_name }}</span>
  195. </div>
  196. <div v-if="item.child && item.child.length > 0">
  197. <el-checkbox-group
  198. v-model="item.change"
  199. @change="groupChange($event, index, item)"
  200. >
  201. <el-checkbox
  202. v-for="(sub, i) in item.child"
  203. :key="'sub' + i"
  204. :label="sub.id"
  205. >{{ sub.spec_value }}</el-checkbox
  206. >
  207. </el-checkbox-group>
  208. </div>
  209. <div v-else style="padding: 0 0 12px 0">
  210. <el-tag type="info">暂无规格值</el-tag>
  211. </div>
  212. </div>
  213. </div>
  214. </el-form-item>
  215. <div class="tips-error">{{ ruleForm.spec }}</div>
  216. <el-form-item label="价格" required style="padding: 0 0 12px 0">
  217. <div
  218. class="ladder-table clearfix"
  219. v-if="left && left.header && left && left.header.length > 0"
  220. >
  221. <div class="left" :style="{ width: leftS }">
  222. <div class="ladder-header" v-if="left && left.header">
  223. <ul class="header-spec clearfix">
  224. <li
  225. v-for="(h, hi) in left.header"
  226. :key="'leftHeader' + hi"
  227. >
  228. <span>{{ h.spec_name }}</span>
  229. </li>
  230. </ul>
  231. </div>
  232. <div class="ladder-body" v-if="left.specList">
  233. <ul
  234. v-for="(item, index) in left.specList"
  235. :key="'item' + index"
  236. >
  237. <li
  238. class="clearfix"
  239. v-for="(sub, subi) in item"
  240. :key="'sub' + subi"
  241. >
  242. <span>
  243. {{ sub.spec_value }}
  244. </span>
  245. </li>
  246. </ul>
  247. </div>
  248. </div>
  249. <div class="right" :style="{ paddingLeft: leftS }">
  250. <div class="ladder-header" v-if="right && right.header">
  251. <ul class="header-spec clearfix">
  252. <li
  253. v-for="(h, hi) in right.header"
  254. :key="'rightHeader' + hi"
  255. >
  256. <div class="all">
  257. <div class="title">
  258. <span> 阶梯{{ hi + 1 }}</span>
  259. <i
  260. class="el-icon-close"
  261. @click="closeImg(index)"
  262. ></i>
  263. </div>
  264. <div class="main">
  265. <span>{{ h.num }}</span>
  266. <span>{{ h.price }}</span>
  267. </div>
  268. </div>
  269. </li>
  270. </ul>
  271. </div>
  272. <div class="ladder-body" v-if="right && right.specList">
  273. <ul
  274. v-for="(h, hi) in right.specList"
  275. :key="'rightspec' + hi"
  276. >
  277. <li v-for="(s, si) in h" :key="'rightspecsi' + si">
  278. <div
  279. class="input-main"
  280. v-for="(n, ni) in s.limit"
  281. :key="'rightni' + ni"
  282. >
  283. <el-input-number
  284. style="width: 50%"
  285. v-model="n.num"
  286. :step="1"
  287. :min="0"
  288. :max="99999999"
  289. :precision="0"
  290. placeholder="起订量"
  291. step-strictly
  292. :controls="false"
  293. ></el-input-number>
  294. <el-input-number
  295. style="width: 50%"
  296. v-model="n.price"
  297. :step="0.01"
  298. :min="0"
  299. :max="99999999"
  300. :precision="2"
  301. step-strictly
  302. placeholder="成本价"
  303. :controls="false"
  304. ></el-input-number>
  305. </div>
  306. </li>
  307. </ul>
  308. </div>
  309. </div>
  310. </div>
  311. <div v-else>
  312. <el-tag type="warning">请选择规格值</el-tag>
  313. </div>
  314. </el-form-item>
  315. <div class="tips-error">{{ ruleForm.table }}</div>
  316. </el-form>
  317. </el-col>
  318. <el-col :span="24" style="text-align: right">
  319. <el-button type="primary" @click="step--" v-if="!isDetail"
  320. >上一步
  321. </el-button>
  322. <el-button type="primary" @click="submitForm" v-if="!isDetail"
  323. >保 存
  324. </el-button>
  325. <el-button @click="showModelThis = false">{{
  326. isDetail ? "关 闭" : "取 消"
  327. }}</el-button>
  328. </el-col>
  329. </el-row>
  330. </el-col>
  331. </el-row>
  332. </el-card>
  333. </el-dialog>
  334. </template>
  335. <script>
  336. import asyncRequest from "@/apis/service/goodStore/dealGoodsPool";
  337. export default {
  338. name: "dealGoodsPool",
  339. props: ["showModel", "id", "isDetail"],
  340. data() {
  341. return {
  342. leftS: "0px",
  343. size: "small",
  344. mock: [],
  345. ladderNum: 5, //阶梯数
  346. left: {
  347. header: [],
  348. middle: [],
  349. specList: [],
  350. },
  351. right: {
  352. header: [],
  353. specList: [],
  354. },
  355. headLadder: {
  356. num: "起订量≥",
  357. price: "成本价",
  358. },
  359. catOptions: [],
  360. brandidOptions: [],
  361. supplierOptions: [],
  362. oldcatid: [],
  363. stepList: ["基础信息", "规格与价格"],
  364. step: 0,
  365. loading: false,
  366. title: "添加商品",
  367. showModelThis: this.showModel,
  368. baseForm: {
  369. id: this.id,
  370. catid: [],
  371. good_name: "",
  372. unit: "",
  373. supplier: "",
  374. brandid: "",
  375. image: [],
  376. },
  377. baseRules: {
  378. supplier: [
  379. {
  380. required: true,
  381. message: "请选择供应商联系人",
  382. trigger: "change",
  383. },
  384. ],
  385. image: [
  386. {
  387. required: true,
  388. message: "请选择商品主图",
  389. trigger: "change",
  390. },
  391. ],
  392. catid: [
  393. {
  394. required: true,
  395. message: "请选择商品分类",
  396. trigger: "change",
  397. },
  398. ],
  399. brandid: [
  400. {
  401. required: true,
  402. message: "请选择商品品牌",
  403. trigger: "change",
  404. },
  405. ],
  406. good_name: [
  407. {
  408. required: true,
  409. message: "请输入商品名称",
  410. trigger: "blur",
  411. },
  412. {
  413. min: 2,
  414. max: 50,
  415. message: "长度在 2 到 50 个字符",
  416. trigger: "blur",
  417. },
  418. ],
  419. unit: [
  420. {
  421. required: true,
  422. message: "请输入商品单位",
  423. trigger: "blur",
  424. },
  425. {
  426. min: 1,
  427. max: 10,
  428. message: "长度在 1 到 10 个字符",
  429. trigger: "blur",
  430. },
  431. ],
  432. },
  433. ruleForm: {
  434. spec: "",
  435. table: "",
  436. },
  437. };
  438. },
  439. methods: {
  440. closeModel() {
  441. this.showModelThis = false;
  442. },
  443. async initForm() {
  444. this.mock = [];
  445. this.left = {
  446. header: [],
  447. middle: [],
  448. specList: [],
  449. };
  450. this.right = {
  451. header: [],
  452. specList: [],
  453. };
  454. this.step = 0;
  455. this.loading = true;
  456. // brandidOptions
  457. await this.getAllbrandid();
  458. await this.getAllCat();
  459. await this.getAllSupplier();
  460. if (this.id === "add") {
  461. this.title = "添加商品";
  462. // this.ruleForm.isAdmin = 0;
  463. await this.resetForm();
  464. } else {
  465. if (this.isDetail) {
  466. this.title = "商品详情";
  467. } else {
  468. this.title = "修改商品";
  469. }
  470. await this.resetForm();
  471. await this.initData();
  472. }
  473. this.loading = false;
  474. },
  475. async initData() {
  476. this.loading = true;
  477. let res = await asyncRequest.detail({ id: this.id });
  478. this.loading = false;
  479. if (res.code === 0) {
  480. await this.resetForm(res.data);
  481. }
  482. },
  483. async resetForm(data) {
  484. // 重置
  485. await this.$nextTick(async () => {
  486. if (this.$refs.baseForm) {
  487. this.$refs.baseForm.resetFields();
  488. this.$refs.baseForm.clearValidate();
  489. if (data) {
  490. this.baseForm = {
  491. id: this.id,
  492. catid: data.good_cat.split(","),
  493. good_name: data.good_name,
  494. unit: data.good_unit,
  495. supplier: data.supplier,
  496. brandid: data.brand_id,
  497. image: data.galley.split(","),
  498. };
  499. this.oldcatid = this.baseForm.catid;
  500. await this.specByCat(false);
  501. this.dealWithEditMock(data.attr);
  502. } else {
  503. this.baseForm = {
  504. id: this.id,
  505. catid: ["1", "2", "3"],
  506. good_name:
  507. "2018春秋新款V领修身丝绒西装女 双排扣复古极简中长款工装外套",
  508. unit: "件",
  509. supplier: "8",
  510. brandid: "3",
  511. image: [
  512. "http://cum.sit.wanyuhengtong.com/20210425/1edfa0da4eee9b24d1f35d52b6a0ec0a.jpg",
  513. "http://cum.sit.wanyuhengtong.com/20210425/cc70a4c06c83d9d8ac27ae35b118a23f.jpg",
  514. "http://cum.sit.wanyuhengtong.com/20210425/a5e05dc1c5c75030bcc95f1da1d2d9cb.jpg",
  515. "http://cum.sit.wanyuhengtong.com/20210425/9d505e7632891459a29f2fafe28d6705.jpg",
  516. "http://cum.sit.wanyuhengtong.com/20210425/714914d7545184e99e240b3affeada07.jpg",
  517. ],
  518. };
  519. }
  520. this.ruleForm = {
  521. spec: "",
  522. table: "",
  523. };
  524. }
  525. });
  526. },
  527. dealWithEditMock(attr) {
  528. console.log(this.mock);
  529. attr.forEach((v1) => {
  530. if (v1 && v1.spec && v1.spec.length > 0) {
  531. v1.spec.forEach((v2) => {
  532. this.mock.forEach((v3, i) => {
  533. if (v2.spec_id === v3.spec_id) {
  534. console.log(v2.spec_info_id);
  535. console.log(v3);
  536. let index = v3.change.findIndex((v4) => {
  537. v4 === v2.spec_info_id;
  538. });
  539. if (index === -1) {
  540. v3.change.push(v2.spec_info_id);
  541. }
  542. }
  543. this.$set(this.mock, i, v3);
  544. });
  545. });
  546. }
  547. });
  548. // console.log(attr);
  549. console.log(this.mock);
  550. this.groupChange();
  551. this.resume(attr);
  552. },
  553. resume(attr) {
  554. this.right.specList.forEach((v1) => {
  555. v1.forEach((v2) => {
  556. attr.forEach((v3) => {
  557. let is = true;
  558. v3.spec.forEach((v4) => {
  559. let index = v2.specid.findIndex((v5) => v5 === v4.spec_info_id);
  560. if (index === -1) {
  561. is = false;
  562. }
  563. });
  564. if (is) {
  565. v2.limit.forEach((v6, i) => {
  566. if (v3.limit[i]) {
  567. v6.num = v3.limit[i].begin_num;
  568. v6.price = v3.limit[i].shop_price;
  569. }
  570. });
  571. }
  572. });
  573. });
  574. });
  575. console.log(attr);
  576. console.log(this.right.specList);
  577. },
  578. async submitForm() {
  579. await this.$refs.ruleForm.validate(async (valid) => {
  580. if (valid) {
  581. let change = false;
  582. this.mock.forEach((v1) => {
  583. if (v1.change && v1.change.length > 0) {
  584. change = true;
  585. }
  586. });
  587. if (!change) {
  588. this.ruleForm.spec = "请选择规格!";
  589. return;
  590. } else {
  591. this.ruleForm.spec = "";
  592. let table = false;
  593. let hasnot = false;
  594. let stock = [];
  595. this.right.specList.forEach((v1) => {
  596. if (v1) {
  597. v1.forEach((v2) => {
  598. if (v2 && v2.limit && v2.limit.length > 0) {
  599. let list = [];
  600. v2.limit.forEach((v3) => {
  601. if (v3.num != 0 && v3.price != 0) {
  602. table = true;
  603. list.push(v3);
  604. }
  605. if (
  606. (v3.num != 0 && v3.price == 0) ||
  607. (v3.num == 0 && v3.price !== 0)
  608. ) {
  609. hasnot = true;
  610. }
  611. });
  612. if (list.length > 0) {
  613. let model = Object.assign({}, v2);
  614. model.limit = list;
  615. stock.push(model);
  616. }
  617. }
  618. });
  619. }
  620. });
  621. if (hasnot) {
  622. this.ruleForm.table =
  623. "请选择起订量与成本价需成对填写,未成对请设为零!";
  624. } else {
  625. if (!table) {
  626. this.ruleForm.table = "至少填写一堆起订量与成本价!";
  627. } else {
  628. this.ruleForm.table = "";
  629. this.loading = true;
  630. let obj = JSON.parse(JSON.stringify(this.baseForm));
  631. obj.stock = stock;
  632. obj.catid = obj.catid[obj.catid.length - 1];
  633. obj.image = obj.image.join();
  634. //split(",");
  635. console.log(obj);
  636. let res = {};
  637. if (this.id === "add") {
  638. delete obj["id"];
  639. res = await asyncRequest.add(obj);
  640. } else {
  641. res = await asyncRequest.update(obj);
  642. }
  643. this.loading = false;
  644. if (res.code === 0) {
  645. let title = this.id === "add" ? "添加成功" : "修改成功";
  646. this.$notify.success({
  647. title,
  648. message: "",
  649. });
  650. this.showModelThis = false;
  651. // 刷新
  652. this.$emit("refresh");
  653. }
  654. }
  655. }
  656. }
  657. } else {
  658. console.log("error submit!!");
  659. return false;
  660. }
  661. });
  662. },
  663. async baseSubmitForm() {
  664. await this.$refs.baseForm.validate(async (valid) => {
  665. if (valid) {
  666. await this.handleChange();
  667. }
  668. });
  669. },
  670. groupChange($event, index, item) {
  671. this.$set(this.mock, index, item);
  672. this.actionSpecList();
  673. },
  674. actionSpecList() {
  675. // this.leftS = "0px";
  676. this.left.header = [];
  677. this.left.middle = [];
  678. this.left.specList = [];
  679. console.log(this.mock);
  680. console.log(this.right.specList);
  681. this.mock.forEach((v1) => {
  682. if (
  683. v1.change &&
  684. v1.change.length > 0 &&
  685. v1.child &&
  686. v1.child.length > 0
  687. ) {
  688. this.left.header.push({
  689. spec_id: v1.spec_id,
  690. spec_name: v1.spec_name,
  691. });
  692. let arr = [];
  693. let changeList = v1.change;
  694. changeList.forEach((v2) => {
  695. let index = v1.child.findIndex((v3) => v2 === v3.id);
  696. if (index !== -1) {
  697. let x = {
  698. spec_id: v1.spec_id,
  699. spec_name: v1.spec_name,
  700. id: v1.child[index].id,
  701. spec_value: v1.child[index].spec_value,
  702. };
  703. arr.push(x);
  704. }
  705. });
  706. this.left.middle.push(arr);
  707. }
  708. });
  709. let lang = this.left.header.length;
  710. this.leftS = lang * 70 + "px";
  711. if (this.left.middle.length > 1) {
  712. this.left.specList = this.doExchange(this.left.middle);
  713. } else if (this.left.middle.length === 0) {
  714. this.left.specList = [];
  715. } else {
  716. let list1 = [];
  717. this.left.middle.forEach((v1) => {
  718. if (v1) {
  719. v1.forEach((v2) => {
  720. let list2 = [];
  721. list2.push(v2);
  722. list1.push(list2);
  723. });
  724. }
  725. });
  726. this.left.specList = list1;
  727. }
  728. this.right.header = [];
  729. for (let i = 0; i < this.ladderNum; i++) {
  730. this.right.header.push(this.headLadder);
  731. }
  732. this.right.specList = [];
  733. this.left.specList.forEach((v1) => {
  734. let arr = [];
  735. let model = {
  736. specid: [],
  737. limit: [],
  738. };
  739. v1.forEach((v2) => {
  740. model.specid.push(v2.id);
  741. });
  742. for (let i = 0; i < this.ladderNum; i++) {
  743. let bodyLadder = {
  744. num: 0,
  745. price: 0,
  746. };
  747. model.limit.push(bodyLadder);
  748. }
  749. arr.push(model);
  750. this.right.specList.push(arr);
  751. });
  752. console.log(this.right.specList);
  753. },
  754. closeLadder(index) {
  755. console.log(index);
  756. },
  757. async handleChange(type) {
  758. if (this.baseForm.catid !== this.oldcatid && this.oldcatid.length === 0) {
  759. await this.specByCat();
  760. if (this.step === 0 && !type) {
  761. this.step = 1;
  762. }
  763. } else if (
  764. this.baseForm.catid !== this.oldcatid &&
  765. this.oldcatid.length > 0
  766. ) {
  767. await this.$confirm(
  768. "分类修改会影响该商品规格与价格!",
  769. "确定要修改?",
  770. {
  771. confirmButtonText: "确定",
  772. cancelButtonText: "取消",
  773. type: "warning",
  774. }
  775. )
  776. .then(async () => {
  777. await this.specByCat();
  778. if (this.step === 0) {
  779. this.step = 1;
  780. }
  781. })
  782. .catch(() => {
  783. this.baseForm.catid = this.oldcatid;
  784. });
  785. } else {
  786. if (this.step === 0 && !type) {
  787. this.step = 1;
  788. }
  789. }
  790. },
  791. // 商品种类ID换取规格值
  792. async specByCat(type) {
  793. console.log("准备拉取!");
  794. this.mock = [];
  795. this.$set(this.mock);
  796. let list = this.baseForm.catid;
  797. let res = await asyncRequest.specByCat({ catid: list[list.length - 1] });
  798. if (res.code === 0) {
  799. this.dealWitHInitMock(res.data, type);
  800. this.oldcatid = list;
  801. } else if (res.code !== 101 && res.code !== 102) {
  802. this.baseForm.catid = this.oldcatid;
  803. }
  804. },
  805. // 规格属性值新建
  806. async specinfoadd(id, value) {
  807. console.log(id, value);
  808. let list = this.baseForm.catid;
  809. let model = {
  810. catid: list[list.length - 1],
  811. specid: id,
  812. spec_value: value,
  813. };
  814. let res = await asyncRequest.specinfoadd(model);
  815. if (res.code === 0) {
  816. await this.specByCat(true);
  817. }
  818. },
  819. dealWitHInitMock(list, type) {
  820. console.log(list, type);
  821. if (!type) {
  822. this.mock = [];
  823. console.log("12345678");
  824. console.log(this.mock);
  825. this.left.header = [];
  826. this.left.specList = [];
  827. this.right.header = [];
  828. this.right.specList = [];
  829. list.map((v1) => {
  830. v1.value = "";
  831. v1.change = [];
  832. return v1;
  833. });
  834. this.mock = list;
  835. console.log(this.mock);
  836. this.mock.forEach((v3, i) => {
  837. this.$set(this.mock, i, v3);
  838. });
  839. } else {
  840. let arr = JSON.parse(JSON.stringify(this.mock));
  841. list.map((v1) => {
  842. v1.value = "";
  843. let index = arr.findIndex((v2) => v2.spec_id === v1.spec_id);
  844. if (index !== -1) {
  845. v1.change = arr[index].change;
  846. }
  847. return v1;
  848. });
  849. this.mock = list;
  850. this.mock.forEach((v3, i) => {
  851. this.$set(this.mock, i, v3);
  852. });
  853. }
  854. },
  855. async getAllbrandid() {
  856. const res = await asyncRequest.brandAll({});
  857. if (res.code === 0 && res.data) {
  858. this.brandidOptions = res.data;
  859. }
  860. },
  861. async getAllCat() {
  862. const res = await asyncRequest.catAll({});
  863. if (res.code === 0 && res.data) {
  864. let list = res.data;
  865. list.map((v1) => {
  866. v1.value = v1.id;
  867. v1.label = v1.cat_name;
  868. if (v1.child && v1.child.length > 0) {
  869. v1.child.map((v2) => {
  870. v2.value = v2.id;
  871. v2.label = v2.cat_name;
  872. if (v2.child && v2.child.length > 0) {
  873. v2.child.map((v3) => {
  874. v3.value = v3.id;
  875. v3.label = v3.cat_name;
  876. return v3;
  877. });
  878. v2.children = v2.child;
  879. }
  880. return v2;
  881. });
  882. v1.children = v1.child;
  883. }
  884. return v1;
  885. });
  886. this.catOptions = list;
  887. }
  888. },
  889. async getAllSupplier() {
  890. const res = await asyncRequest.supplierAll({});
  891. if (res.code === 0 && res.data) {
  892. let list = res.data;
  893. this.supplierOptions = list;
  894. }
  895. },
  896. //图片上传失败
  897. UploadErrorEvent(res) {
  898. if (res !== "break") {
  899. this.$message.error("图片上传失败!");
  900. this.$refs.ruleForm.validateField("image");
  901. }
  902. },
  903. closeImg(index) {
  904. this.baseForm.image.splice(index, 1);
  905. this.$refs.baseForm.validateField("image");
  906. },
  907. //图片上传成功
  908. async UploadSuccessEvent(data) {
  909. const { url } = data;
  910. if (url === "noToken") {
  911. await this.logout();
  912. } else {
  913. this.baseForm.image.push(url);
  914. this.$message.success("图片上传成功!");
  915. this.$refs.baseForm.validateField("image");
  916. }
  917. },
  918. //判断图片规格
  919. beforeAvatarUpload(file) {
  920. console.log(file);
  921. let isJPG = false;
  922. if (
  923. file.type === "image/jpg" ||
  924. file.type === "image/png" ||
  925. file.type === "image/jpeg"
  926. ) {
  927. isJPG = true;
  928. }
  929. const isLt2M = file.size / 1024 / 1024 < 1;
  930. if (!isJPG) {
  931. this.$message.error("图片格式不正确!");
  932. }
  933. if (!isLt2M) {
  934. this.$message.error("图片大小不能超过 1MB!");
  935. }
  936. return isJPG && isLt2M;
  937. },
  938. doExchange(arr) {
  939. let len = arr.length;
  940. // 当数组大于等于2个的时候
  941. if (len >= 2) {
  942. // 第一个数组的长度
  943. let len1 = arr[0].length;
  944. // 第二个数组的长度
  945. let len2 = arr[1].length;
  946. // 2个数组产生的组合数
  947. let lenBoth = len1 * len2;
  948. // 申明一个新数组
  949. let items = new Array(lenBoth);
  950. // 申明新数组的索引
  951. let index = 0;
  952. for (let i = 0; i < len1; i++) {
  953. for (let j = 0; j < len2; j++) {
  954. if (arr[0][i] instanceof Array) {
  955. items[index] = arr[0][i].concat(arr[1][j]);
  956. } else {
  957. items[index] = [arr[0][i]].concat(arr[1][j]);
  958. }
  959. index++;
  960. }
  961. }
  962. let newArr = new Array(len - 1);
  963. for (let i = 2; i < arr.length; i++) {
  964. newArr[i - 1] = arr[i];
  965. }
  966. newArr[0] = items;
  967. return this.doExchange(newArr);
  968. } else {
  969. return arr[0];
  970. }
  971. },
  972. },
  973. watch: {
  974. showModel: function (val) {
  975. this.showModelThis = val;
  976. if (val) {
  977. this.initForm();
  978. }
  979. },
  980. showModelThis(val) {
  981. if (!val) {
  982. this.$emit("cancel");
  983. }
  984. },
  985. },
  986. };
  987. </script>
  988. <style lang="scss" scoped>
  989. .dealGoodsPool {
  990. $dealGoodsPoolBoderColor: #dfe6ec;
  991. .tips-error {
  992. color: #ff8888;
  993. font-size: 12px;
  994. height: 22px;
  995. line-height: 20px;
  996. padding-left: 60px;
  997. }
  998. .ladder-table {
  999. position: relative;
  1000. width: 100%;
  1001. border: 1px solid $dealGoodsPoolBoderColor;
  1002. .left {
  1003. position: absolute;
  1004. top: 0;
  1005. left: 0;
  1006. z-index: 3;
  1007. background: #fff;
  1008. // width: 140px;
  1009. .ladder-header {
  1010. position: relative;
  1011. width: 100%;
  1012. .header-spec {
  1013. position: relative;
  1014. // border-bottom: 1px solid $dealGoodsPoolBoderColor;
  1015. li {
  1016. float: left;
  1017. width: 70px;
  1018. height: 50px;
  1019. line-height: 50px;
  1020. overflow: hidden;
  1021. padding: 0 10px;
  1022. font-size: 12px;
  1023. color: #909399;
  1024. border-right: 1px solid $dealGoodsPoolBoderColor;
  1025. span {
  1026. height: 25px;
  1027. line-height: 25px;
  1028. min-height: 50px;
  1029. overflow: hidden;
  1030. }
  1031. }
  1032. }
  1033. }
  1034. .ladder-body {
  1035. position: relative;
  1036. width: 100%;
  1037. ul {
  1038. width: 100%;
  1039. display: flex;
  1040. li {
  1041. flex: 1;
  1042. height: 40px;
  1043. line-height: 40px;
  1044. padding: 0 10px;
  1045. // border-top: 1px solid $dealGoodsPoolBoderColor;
  1046. // border-right: 1px solid $goodsBoderColor;
  1047. span {
  1048. display: block;
  1049. height: 40px;
  1050. width: 49px;
  1051. overflow: hidden;
  1052. line-height: 40px;
  1053. color: #606266;
  1054. font-size: 12px;
  1055. text-overflow: ellipsis;
  1056. white-space: normal;
  1057. word-break: break-all;
  1058. // overflow: hidden;
  1059. // text-overflow:ellipsis;
  1060. // white-space: nowrap;
  1061. }
  1062. }
  1063. }
  1064. }
  1065. }
  1066. .right {
  1067. position: relative;
  1068. // padding-left: 140px;
  1069. width: 100%;
  1070. overflow-x: scroll;
  1071. background: #fff;
  1072. .ladder-header {
  1073. position: relative;
  1074. width: 100%;
  1075. .header-spec {
  1076. display: flex;
  1077. li {
  1078. min-width: 240px;
  1079. flex: 1;
  1080. .all {
  1081. width: 100%;
  1082. .title {
  1083. width: 100%;
  1084. height: 25px;
  1085. padding: 0 10px;
  1086. font-size: 12px;
  1087. color: #909399;
  1088. line-height: 25px;
  1089. text-align: center;
  1090. position: relative;
  1091. // border-right: 1px solid $goodsBoderColor;
  1092. // border-bottom: 1px solid $goodsBoderColor;
  1093. i {
  1094. position: absolute;
  1095. top: 2px;
  1096. right: 2px;
  1097. z-index: 2;
  1098. &:hover {
  1099. cursor: pointer;
  1100. }
  1101. }
  1102. }
  1103. .main {
  1104. width: 100%;
  1105. height: 25px;
  1106. span {
  1107. vertical-align: top;
  1108. width: 50%;
  1109. height: 25px;
  1110. line-height: 25px;
  1111. text-align: center;
  1112. padding: 0 10px;
  1113. font-size: 12px;
  1114. color: #909399;
  1115. line-height: 25px;
  1116. display: inline-block;
  1117. // border-right: 1px solid $goodsBoderColor;
  1118. // border-bottom: 1px solid $goodsBoderColor;
  1119. }
  1120. }
  1121. }
  1122. }
  1123. }
  1124. }
  1125. .ladder-body {
  1126. position: relative;
  1127. width: 100%;
  1128. ul {
  1129. width: 100%;
  1130. position: relative;
  1131. li {
  1132. width: 100%;
  1133. display: flex;
  1134. .input-main {
  1135. flex: 1;
  1136. min-width: 240px;
  1137. .el-input-number {
  1138. .el-input {
  1139. input.el-input_inner {
  1140. border-radius: 0;
  1141. }
  1142. }
  1143. }
  1144. }
  1145. }
  1146. }
  1147. }
  1148. }
  1149. }
  1150. .mack-mian {
  1151. position: relative;
  1152. width: 100%;
  1153. .mock-item-div {
  1154. width: 100%;
  1155. background: rgba(246, 247, 248, 1);
  1156. padding: 12px 12px 0 12px;
  1157. margin: 0 0 10px 0;
  1158. .mock-title {
  1159. width: 100%;
  1160. padding: 0 0 5px 0;
  1161. border-bottom: 1px solid rgba(226, 226, 226, 1);
  1162. }
  1163. }
  1164. }
  1165. }
  1166. </style>