goods.js 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'toastr'], function ($, undefined, Backend, Table, Form, Toastr) {
  2. var Controller = {
  3. index: function () {
  4. function debounce(handle, delay) {
  5. let time = null;
  6. return function () {
  7. let self = this,
  8. arg = arguments;
  9. clearTimeout(time);
  10. time = setTimeout(function () {
  11. handle.apply(self, arg);
  12. }, delay)
  13. }
  14. }
  15. var goodsIndex = new Vue({
  16. el: "#goodsIndex",
  17. data() {
  18. return {
  19. goodsData: [],
  20. multipleSelection: [],
  21. chooseType: 0,
  22. activityType: 'all',
  23. activeStatus: 'all',
  24. searchKey: '',
  25. priceFrist: '',
  26. priceLast: '',
  27. sort: 'id',
  28. order: 'desc',
  29. offset: 0,
  30. limit: 10,
  31. totalPage: 0,
  32. currentPage: 1,
  33. rowDel: false,
  34. allDel: false,
  35. upStatus: true,
  36. allAjax: true,
  37. tableAjax: false
  38. }
  39. },
  40. created() {
  41. this.getData();
  42. },
  43. methods: {
  44. getData() {
  45. let that = this;
  46. if (!that.allAjax) {
  47. that.tableAjax = true;
  48. }
  49. let dataAc = {
  50. search: that.searchKey,
  51. status: that.activeStatus,
  52. activity_type: that.activityType,
  53. min_price: that.priceFrist,
  54. max_price: that.priceLast,
  55. offset: that.offset,
  56. limit: that.limit,
  57. sort: that.sort,
  58. order: that.order,
  59. };
  60. if (that.activityType == 'score') {
  61. dataAc = {
  62. search: that.searchKey,
  63. status: that.activeStatus,
  64. app_type: that.activityType,
  65. min_price: that.priceFrist,
  66. max_price: that.priceLast,
  67. offset: that.offset,
  68. limit: that.limit,
  69. sort: that.sort,
  70. order: that.order,
  71. };
  72. }
  73. Fast.api.ajax({
  74. url: 'shopro/goods/goods/index',
  75. loading: false,
  76. type: 'GET',
  77. data: dataAc
  78. }, function (ret, res) {
  79. that.goodsData = res.data.rows;
  80. that.goodsData.forEach(i => {
  81. i.showFlag = false;
  82. i.rowDel = false;
  83. });
  84. that.totalPage = res.data.total;
  85. that.allAjax = false;
  86. that.tableAjax = false;
  87. return false;
  88. }, function (ret, res) {
  89. that.allAjax = false;
  90. that.tableAjax = false;
  91. })
  92. },
  93. tabOpt(tab, event) {
  94. this.activeStatus = tab.name
  95. },
  96. goodsOpt(type, id) {
  97. let that = this;
  98. switch (type) {
  99. case 'create':
  100. Fast.api.open('shopro/goods/goods/add', '新增商品', {
  101. callback() {
  102. that.getData();
  103. }
  104. })
  105. break;
  106. case 'edit':
  107. Fast.api.open('shopro/goods/goods/edit/ids/' + id + "?id=" + id + "&type=edit", '编辑商品', {
  108. callback() {
  109. that.getData();
  110. }
  111. })
  112. break;
  113. case 'down':
  114. let idArr = []
  115. if (that.multipleSelection.length > 0) {
  116. that.multipleSelection.forEach(i => {
  117. idArr.push(i.id)
  118. })
  119. let idss = idArr.join(',')
  120. that.editStatus(idss, 'down')
  121. }
  122. break;
  123. case 'up':
  124. let idArrup = []
  125. if (that.multipleSelection.length > 0) {
  126. that.multipleSelection.forEach(i => {
  127. idArrup.push(i.id)
  128. })
  129. let idup = idArrup.join(',')
  130. that.editStatus(idup, 'up')
  131. }
  132. break;
  133. case 'del':
  134. let ids;
  135. if (id) {
  136. ids = id;
  137. } else {
  138. let idArr = []
  139. if (that.multipleSelection.length > 0) {
  140. that.multipleSelection.forEach(i => {
  141. idArr.push(i.id)
  142. })
  143. ids = idArr.join(',')
  144. }
  145. }
  146. if (ids) {
  147. that.$confirm('此操作将删除商品, 是否继续?', '提示', {
  148. confirmButtonText: '确定',
  149. cancelButtonText: '取消',
  150. type: 'warning'
  151. }).then(() => {
  152. Fast.api.ajax({
  153. url: 'shopro/goods/goods/del/ids/' + ids,
  154. loading: true,
  155. type: 'POST',
  156. }, function (ret, res) {
  157. that.getData();
  158. return false;
  159. })
  160. }).catch(() => {
  161. that.$message({
  162. type: 'info',
  163. message: '已取消删除'
  164. });
  165. });
  166. }
  167. break;
  168. case 'copy':
  169. Fast.api.open('shopro/goods/goods/edit/ids/' + id + "?id=" + id + "&type=copy", '商品详情', {
  170. callback() {
  171. that.getData();
  172. }
  173. })
  174. break;
  175. case 'filter':
  176. that.offset = 0;
  177. that.limit = 10;
  178. that.currentPage = 1;
  179. that.getData();
  180. break;
  181. case 'clear':
  182. that.activityType = 'all';
  183. that.priceFrist = "";
  184. that.priceLast = "";
  185. break;
  186. case 'recycle':
  187. Fast.api.open('shopro/goods/goods/recyclebin', '查看回收站')
  188. break;
  189. default:
  190. Fast.api.open('shopro/goods/goods/edit/ids/' + type.id + "?id=" + type.id + "&type=edit", '编辑商品', {
  191. callback() {
  192. that.getData();
  193. }
  194. })
  195. break;
  196. }
  197. },
  198. hideup() {
  199. for (key in this.selectedRowId) {
  200. this.selectedRowId[key] = false;
  201. }
  202. },
  203. sortOrder(sort, order) {
  204. this.sort = sort;
  205. this.order = order;
  206. this.getData();
  207. },
  208. handleSelectionChange(val) {
  209. this.multipleSelection = val;
  210. },
  211. handleSizeChange(val) {
  212. this.offset = 0
  213. this.limit = val;
  214. this.currentPage = 1;
  215. this.getData()
  216. },
  217. handleCurrentChange(val) {
  218. this.currentPage = val;
  219. this.offset = (val - 1) * this.limit;
  220. this.getData()
  221. },
  222. editStatus(id, type) {
  223. let that = this;
  224. Fast.api.ajax({
  225. url: `shopro/goods/goods/setStatus/ids/${id}/status/${type}`,
  226. loading: true,
  227. }, function (ret, res) {
  228. that.getData();
  229. return false;
  230. })
  231. },
  232. chooseOpt(type) {
  233. this.activityType = type
  234. },
  235. isShoose() {
  236. this.chooseType == 0 ? 1 : 0;
  237. if (this.chooseType == 0) {
  238. this.activityType = 'all';
  239. this.priceFrist = "";
  240. this.priceLast = "";
  241. }
  242. },
  243. tableRowClassName({
  244. rowIndex
  245. }) {
  246. if (rowIndex % 2 == 1) {
  247. return 'bg-color';
  248. }
  249. return '';
  250. },
  251. tableCellClassName({
  252. columnIndex
  253. }) {
  254. if (columnIndex == 2) {
  255. return 'cell-left';
  256. }
  257. return '';
  258. },
  259. debounceFilter: debounce(function () {
  260. this.getData()
  261. }, 1000),
  262. },
  263. watch: {
  264. activeStatus(newVal, oldVal) {
  265. if (newVal != oldVal) {
  266. this.offset = 0;
  267. this.limit = 10;
  268. this.currentPage = 1;
  269. this.getData();
  270. }
  271. },
  272. searchKey(newVal, oldVal) {
  273. if (newVal != oldVal) {
  274. this.offset = 0;
  275. this.limit = 10;
  276. this.currentPage = 1;
  277. this.debounceFilter();
  278. }
  279. },
  280. },
  281. })
  282. },
  283. recyclebin: function () {
  284. // 初始化表格参数配置
  285. Table.api.init({
  286. extend: {
  287. 'dragsort_url': ''
  288. }
  289. });
  290. var table = $("#table");
  291. // 初始化表格
  292. table.bootstrapTable({
  293. url: 'shopro/goods/goods/recyclebin' + location.search,
  294. pk: 'id',
  295. sortName: 'deletetime',
  296. columns: [
  297. [{
  298. checkbox: true
  299. },
  300. {
  301. field: 'id',
  302. title: __('Id')
  303. },
  304. {
  305. field: 'title',
  306. title: __('Title'),
  307. align: 'left'
  308. },
  309. {
  310. field: 'deletetime',
  311. title: __('Deletetime'),
  312. operate: 'RANGE',
  313. addclass: 'datetimerange',
  314. formatter: Table.api.formatter.datetime
  315. },
  316. {
  317. field: 'operate',
  318. width: '130px',
  319. title: __('Operate'),
  320. table: table,
  321. events: Table.api.events.operate,
  322. buttons: [{
  323. name: 'Restore',
  324. text: __('Restore'),
  325. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  326. icon: 'fa fa-rotate-left',
  327. url: 'shopro/goods/goods/restore',
  328. refresh: true
  329. },
  330. {
  331. name: 'Destroy',
  332. text: __('Destroy'),
  333. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  334. icon: 'fa fa-times',
  335. url: 'shopro/goods/goods/destroy',
  336. refresh: true
  337. }
  338. ],
  339. formatter: Table.api.formatter.operate
  340. }
  341. ]
  342. ]
  343. });
  344. // 为表格绑定事件
  345. Table.api.bindevent(table);
  346. },
  347. add: function () {
  348. Controller.initAddEdit(null, null, [], []);
  349. },
  350. edit: function () {
  351. let id, type
  352. window.location.search.replace("?", '').split('&').forEach(i => {
  353. if (i.split('=')[0] == 'id') {
  354. id = i.split('=')[1]
  355. }
  356. if (i.split('=')[0] == 'type') {
  357. type = i.split('=')[1]
  358. }
  359. })
  360. Controller.initAddEdit(id, type, Config.skuList, Config.skuPrice);
  361. },
  362. select: function () {
  363. function debounce(handle, delay) {
  364. let time = null;
  365. return function () {
  366. let self = this,
  367. arg = arguments;
  368. clearTimeout(time);
  369. time = setTimeout(function () {
  370. handle.apply(self, arg);
  371. }, delay)
  372. }
  373. }
  374. var goodsSelect = new Vue({
  375. el: "#goodsSelect",
  376. data() {
  377. return {
  378. categoryData: [],
  379. searchWhere: '',
  380. goodsList: [],
  381. totalPage: 0,
  382. offset: 0,
  383. currentPage: 1,
  384. multiple: new URLSearchParams(location.search).get('multiple'),
  385. category_id: null,
  386. selectedIds: []
  387. }
  388. },
  389. mounted() {
  390. if (new URLSearchParams(location.search).get('ids')) {
  391. this.selectedIds = new URLSearchParams(location.search).get('ids').split(',')
  392. }
  393. this.getList();
  394. this.categoryData = Config.category
  395. },
  396. methods: {
  397. getList(id) {
  398. let that = this;
  399. let url = "shopro/goods/goods/select?status=up,hidden";
  400. if (id) {
  401. url = 'shopro/goods/goods/select?status=up,hidden&category_id=' + id
  402. }
  403. Fast.api.ajax({
  404. url: url,
  405. data: {
  406. limit: 10,
  407. offset: that.offset,
  408. search: that.searchWhere
  409. },
  410. type: 'GET'
  411. }, function (ret, res) {
  412. that.goodsList = res.data.rows;
  413. that.goodsList.forEach(g => {
  414. that.$set(g, 'checked', false)
  415. })
  416. let selectData = []
  417. that.goodsList.forEach(g => {
  418. if (that.selectedIds.includes(g.id + '')) {
  419. selectData.push(g)
  420. }
  421. })
  422. that.$nextTick(() => {
  423. selectData.forEach(row => {
  424. that.$refs.multipleTable.toggleRowSelection(row);
  425. });
  426. })
  427. that.totalPage = res.data.total;
  428. return false;
  429. })
  430. },
  431. singleSelectionChange(row) {
  432. this.selectedIds = []
  433. this.selectedIds.push(row.id)
  434. this.goodsList.forEach(g => {
  435. if (g.id == row.id) {
  436. this.$set(g, 'checked', true)
  437. } else {
  438. this.$set(g, 'checked', false)
  439. }
  440. })
  441. this.$forceUpdate()
  442. },
  443. multipleSelectionChange(val) {
  444. val.forEach(g => {
  445. if (!this.selectedIds.includes(g.id + '')) {
  446. this.selectedIds.push(g.id + '')
  447. }
  448. })
  449. },
  450. SelectionChange(selection, row) {
  451. if (this.selectedIds.indexOf(row.id + '') != -1) {
  452. this.selectedIds.splice(this.selectedIds.indexOf(row.id + ''), 1)
  453. }
  454. },
  455. changeClick(val) {
  456. this.currentPage = val;
  457. this.offset = 10 * (val - 1);
  458. if (this.category_id == null) {
  459. this.getList()
  460. } else {
  461. this.getList(this.category_id)
  462. }
  463. },
  464. operation() {
  465. let that = this;
  466. let domain = window.location.origin;
  467. if (this.selectedIds.length == 0) {
  468. return false
  469. }
  470. let ids = this.multiple == 'true' ? this.selectedIds.join(',') : this.selectedIds[this.selectedIds.length - 1]
  471. Fast.api.ajax({
  472. url: domain + '/addons/shopro/goods/lists?goods_ids=' + ids + "&per_page=999999999&type=all",
  473. loading: false,
  474. }, function (ret, res) {
  475. Fast.api.close({
  476. data: that.multiple == 'true' ? res.data.data : res.data.data[0],
  477. });
  478. return false;
  479. }, function () {
  480. return false;
  481. })
  482. },
  483. debounceFilter: debounce(function () {
  484. this.getList()
  485. }, 1000),
  486. showLeft(p, c, a, s) {
  487. if (p != null && a === null && c === null && s === null) {
  488. this.categoryData[p].show = !this.categoryData[p].show;
  489. }
  490. if (p != null && c != null && a == null && s === null) {
  491. this.categoryData[p].children[c].show = !this.categoryData[p].children[c].show;
  492. }
  493. if (p != null && c != null && a != null && s === null) {
  494. this.categoryData[p].children[c].children[a].show = !this.categoryData[p].children[c].children[a].show;
  495. }
  496. this.$forceUpdate();
  497. },
  498. selectCategoryLeft(p, c, a, s) {
  499. this.categoryData.forEach(i => {
  500. i.selected = false;
  501. if (i.children && i.children.length > 0) {
  502. i.children.forEach(j => {
  503. j.selected = false;
  504. if (j.children && j.children.length > 0) {
  505. j.children.forEach(k => {
  506. k.selected = false;
  507. if (k.children && k.children.length > 0) {
  508. k.children.forEach(l => {
  509. l.selected = false;
  510. })
  511. }
  512. })
  513. }
  514. })
  515. }
  516. })
  517. let category_id = null;
  518. if (p != null && a === null && c === null && s === null) {
  519. this.categoryData[p].selected = !this.categoryData[p].selected;
  520. category_id = this.categoryData[p].id
  521. }
  522. if (p != null && c != null && a == null && s === null) {
  523. this.categoryData[p].children[c].selected = !this.categoryData[p].children[c].selected;
  524. category_id = this.categoryData[p].children[c].id
  525. }
  526. if (p != null && c != null && a != null && s === null) {
  527. this.categoryData[p].children[c].children[a].selected = !this.categoryData[p].children[c].children[a].selected;
  528. category_id = this.categoryData[p].children[c].children[a].id
  529. }
  530. if (p != null && c != null && a != null && s != null) {
  531. this.categoryData[p].children[c].children[a].children[s].selected = !this.categoryData[p].children[c].children[a].children[s].selected;
  532. category_id = this.categoryData[p].children[c].children[a].children[s].id
  533. }
  534. this.category_id = category_id;
  535. this.offset = 0;
  536. this.getList(category_id)
  537. this.$forceUpdate();
  538. },
  539. },
  540. watch: {
  541. searchWhere(newVal, oldVal) {
  542. if (newVal != oldVal) {
  543. this.offset = 0;
  544. this.currentPage = 1;
  545. this.categoryData.forEach(i => {
  546. i.selected = false;
  547. if (i.children && i.children.length > 0) {
  548. i.children.forEach(j => {
  549. j.selected = false;
  550. if (j.children && j.children.length > 0) {
  551. j.children.forEach(k => {
  552. k.selected = false;
  553. if (k.children && k.children.length > 0) {
  554. k.children.forEach(l => {
  555. l.selected = false;
  556. })
  557. }
  558. })
  559. }
  560. })
  561. }
  562. })
  563. this.debounceFilter();
  564. }
  565. },
  566. },
  567. })
  568. },
  569. api: {
  570. bindevent: function () {
  571. Form.api.bindevent($("form[role=form]"));
  572. }
  573. },
  574. initAddEdit: function (id, type, skuList, skuPrice) {
  575. Vue.directive('enterNumber', {
  576. inserted: function (el) {
  577. let changeValue = (el, type) => {
  578. const e = document.createEvent('HTMLEvents')
  579. e.initEvent(type, true, true)
  580. el.dispatchEvent(e)
  581. }
  582. el.addEventListener("keyup", function (e) {
  583. let input = e.target;
  584. let reg = new RegExp('^((?:(?:[1-9]{1}\\d*)|(?:[0]{1}))(?:\\.(?:\\d){0,2})?)(?:\\d*)?$');
  585. let matchRes = input.value.match(reg);
  586. if (matchRes === null) {
  587. input.value = "";
  588. } else {
  589. if (matchRes[1] !== matchRes[0]) {
  590. input.value = matchRes[1];
  591. }
  592. }
  593. changeValue(input, 'input')
  594. });
  595. }
  596. });
  597. Vue.directive('positiveInteger', {
  598. inserted: function (el) {
  599. el.addEventListener("keypress", function (e) {
  600. e = e || window.event;
  601. let charcode = typeof e.charCode == 'number' ? e.charCode : e.keyCode;
  602. let re = /\d/;
  603. if (!re.test(String.fromCharCode(charcode)) && charcode > 9 && !e.ctrlKey) {
  604. if (e.preventDefault) {
  605. e.preventDefault();
  606. } else {
  607. e.returnValue = false;
  608. }
  609. }
  610. });
  611. }
  612. });
  613. //vue Sku添加页 添加规格和价格数据
  614. var goodsDetail = new Vue({
  615. el: "#goodsDetail",
  616. data() {
  617. return {
  618. editId: id,
  619. type: type,
  620. stepActive: 1,
  621. goodsDetail: {},
  622. goodsDetailInit: {
  623. category_ids: '',
  624. content: '',
  625. dispatch_ids: '',
  626. express_ids: '', //单个数组
  627. store_ids: '',
  628. selfetch_ids: '',
  629. autosend_ids: '',
  630. dispatch_type: '',
  631. expire_day: 0, //有效时间
  632. image: '',
  633. images: '',
  634. is_sku: 0,
  635. original_price: '',
  636. params: '',
  637. params_arr: [],
  638. price: '',
  639. service_ids: '',
  640. show_sales: '',
  641. status: 'up',
  642. subtitle: '',
  643. title: '',
  644. type: 'normal',
  645. views: '',
  646. weigh: '',
  647. weight: '',
  648. stock: '',
  649. stock_warning_switch: false,
  650. stock_warning: null,
  651. sn: '',
  652. autosend_content: ''
  653. },
  654. timeData: {
  655. images_arr: [],
  656. category_ids_arr: [],
  657. dispatch_type_arr: [], //类型
  658. dispatch_ids_arr: [], //id数组
  659. service_ids_arr: [], //服务
  660. },
  661. rules: {
  662. title: [{
  663. required: true,
  664. message: '请输入商品标题',
  665. trigger: 'blur'
  666. }],
  667. subtitle: [{
  668. required: true,
  669. message: '请输入商品副标题',
  670. trigger: 'blur'
  671. }],
  672. status: [{
  673. required: true,
  674. message: '请选择商品状态',
  675. trigger: 'blur'
  676. }],
  677. image: [{
  678. required: true,
  679. message: '请上传商品主图',
  680. trigger: 'change'
  681. }],
  682. images: [{
  683. required: true,
  684. message: '请上传商品轮播图',
  685. trigger: 'change'
  686. }],
  687. category_ids: [{
  688. required: true,
  689. message: '请选择商品分类',
  690. trigger: 'change'
  691. }],
  692. dispatch_type: [{
  693. required: true,
  694. message: '请选择配送方式',
  695. trigger: 'blur'
  696. }],
  697. dispatch_ids: [{
  698. required: true,
  699. message: '请选择运费模板',
  700. trigger: 'blur'
  701. }],
  702. express_ids: [{
  703. required: true,
  704. message: '请选择运费模板',
  705. trigger: 'blur'
  706. }],
  707. store_ids: [{
  708. required: true,
  709. message: '请选择配送模板',
  710. trigger: 'blur'
  711. }],
  712. selfetch_ids: [{
  713. required: true,
  714. message: '请选择自提模板',
  715. trigger: 'blur'
  716. }],
  717. autosend_ids: [{
  718. required: true,
  719. message: '请选择发货模板',
  720. trigger: 'blur'
  721. }],
  722. is_sku: [{
  723. required: true,
  724. message: '请选择商品规格',
  725. trigger: 'blur'
  726. }],
  727. price: [{
  728. required: true,
  729. message: '请输入价格',
  730. trigger: 'blur'
  731. }],
  732. original_price: [{
  733. required: true,
  734. message: '请输入划线价格',
  735. trigger: 'blur'
  736. }],
  737. // weight: [{
  738. // required: true,
  739. // message: '请输入重量',
  740. // trigger: 'blur'
  741. // }],
  742. stock: [{
  743. required: true,
  744. message: '请输入库存',
  745. trigger: 'blur'
  746. }],
  747. service_ids: [{
  748. required: true,
  749. message: '请选择服务标签',
  750. trigger: 'blur'
  751. }]
  752. },
  753. mustDel: ['express_ids', 'store_ids', 'selfetch_ids', 'autosend_ids'],
  754. //选择分类
  755. categoryOptions: [],
  756. //服务
  757. serviceOptions: [],
  758. dispatchType: [],
  759. dispatchOptions: {},
  760. upload: Config.moduleurl,
  761. editor: null,
  762. //多规格
  763. skuList: [],
  764. skuPrice: [],
  765. skuListData: '',
  766. skuPriceData: '',
  767. skuModal: '',
  768. childrenModal: [],
  769. countId: 1,
  770. allEditSkuName: '',
  771. isEditInit: false, // 编辑时候初始化是否完成
  772. isResetSku: 0,
  773. allEditPopover: {
  774. price: false,
  775. stock: false,
  776. stock_warning: false,
  777. weight: false,
  778. sn: false,
  779. },
  780. allEditDatas: "",
  781. allstock_warning_switch: false,
  782. visible: false,
  783. visibless: '',
  784. activeName: null,
  785. activeIndex: null,
  786. defaultProps: {
  787. children: 'children',
  788. label: 'name'
  789. },
  790. selectedcatArr: []
  791. }
  792. },
  793. mounted() {
  794. this.getServiceOptions();
  795. this.getDispatchType();
  796. if (this.editId) {
  797. this.goodsDetail = JSON.parse(JSON.stringify(this.goodsDetailInit));
  798. this.getCategoryOptions(true);
  799. } else {
  800. this.getCategoryOptions();
  801. this.goodsDetail = JSON.parse(JSON.stringify(this.goodsDetailInit));
  802. this.getInit([], [])
  803. this.$nextTick(() => {
  804. Controller.api.bindevent();
  805. });
  806. }
  807. },
  808. methods: {
  809. handleClickss(tab) {
  810. this.activeIndex = Number(tab.index)
  811. },
  812. createCategory() {
  813. let that = this;
  814. Fast.api.open("shopro/category/index", "新建", {
  815. callback(data) {
  816. that.getCategoryOptions();
  817. }
  818. });
  819. },
  820. panelChange(val) {
  821. let that = this;
  822. that.selectedcatArr = [];
  823. let nameArr = []
  824. let idsArr = []
  825. if (val.length > 0) {
  826. val.forEach(j => {
  827. let arr = []
  828. if (j.length == 1) {
  829. that.categoryOptions[that.activeIndex].children.forEach(c => {
  830. if (c.id == j[0]) {
  831. arr.push(c.name)
  832. }
  833. })
  834. } else if (j.length == 2) {
  835. that.categoryOptions[that.activeIndex].children.forEach(c => {
  836. if (c.id == j[0]) {
  837. arr.push(c.name)
  838. c.children.forEach(a => {
  839. if (a.id == j[1]) {
  840. arr.push(a.name)
  841. }
  842. })
  843. }
  844. })
  845. } else if (j.length == 3) {
  846. that.categoryOptions[that.activeIndex].children.forEach(c => {
  847. if (c.id == j[0]) {
  848. arr.push(c.name)
  849. c.children.forEach(a => {
  850. if (a.id == j[1]) {
  851. arr.push(a.name)
  852. a.children.forEach(t => {
  853. if (t.id == j[2]) {
  854. arr.push(t.name)
  855. }
  856. })
  857. }
  858. })
  859. }
  860. })
  861. }
  862. nameArr.push({
  863. label: arr.join('/'),
  864. })
  865. idsArr.push(j[j.length - 1])
  866. })
  867. }
  868. that.selectedcatArr = nameArr;
  869. that.goodsDetail.category_ids = idsArr.join(',');
  870. },
  871. closeTag(val) {
  872. this.timeData.category_ids_arr.splice(val, 1);
  873. this.selectedcatArr.splice(val, 1)
  874. let idsArr = []
  875. this.timeData.category_ids_arr.forEach(j => {
  876. idsArr.push(j[j.length - 1])
  877. })
  878. this.goodsDetail.category_ids = idsArr.join(',');
  879. this.panelChange(this.timeData.category_ids_arr)
  880. this.$forceUpdate()
  881. },
  882. createTemplate(type) {
  883. let that = this;
  884. if (type == 'service') {
  885. Fast.api.open("shopro/goods/service/add", "新建");
  886. } else {
  887. Fast.api.open("shopro/dispatch/" + type + "/add", "新建", {
  888. callback(data) {
  889. if (data.data) {
  890. that.getDispatchTemplateData(type, 'create'); //TODO 判断type
  891. }
  892. }
  893. });
  894. }
  895. },
  896. getInit(skuList, skuPrice) {
  897. // 记录每个规格项真实 id,对应的临时 id
  898. let tempIdArr = {};
  899. for (let i in skuList) {
  900. // 为每个 规格增加当前页面自增计数器,比较唯一用
  901. skuList[i]['temp_id'] = this.countId++
  902. for (let j in skuList[i]['children']) {
  903. // 为每个 规格项增加当前页面自增计数器,比较唯一用
  904. skuList[i]['children'][j]['temp_id'] = this.countId++
  905. // 记录规格项真实 id 对应的 临时 id
  906. tempIdArr[skuList[i]['children'][j]['id']] = skuList[i]['children'][j]['temp_id']
  907. }
  908. }
  909. // for (let i in skuPrice) {
  910. for (var i = 0; i < skuPrice.length; i++) {
  911. let tempSkuPrice = skuPrice[i]
  912. tempSkuPrice['temp_id'] = i + 1
  913. // 将真实 id 数组,循环,找到对应的临时 id 组合成数组
  914. tempSkuPrice['goods_sku_temp_ids'] = [];
  915. let goods_sku_id_arr = tempSkuPrice['goods_sku_ids'].split(',');
  916. for (let ids of goods_sku_id_arr) {
  917. tempSkuPrice['goods_sku_temp_ids'].push(tempIdArr[ids])
  918. }
  919. skuPrice[i] = tempSkuPrice
  920. }
  921. if (this.type == 'copy') {
  922. for (let i in skuList) {
  923. // 为每个 规格增加当前页面自增计数器,比较唯一用
  924. skuList[i].id = 0;
  925. for (let j in skuList[i]['children']) {
  926. skuList[i]['children'][j].id = 0;
  927. }
  928. }
  929. }
  930. if (skuPrice.length > 0) {
  931. skuPrice.forEach(si => {
  932. si.stock_warning_switch = false
  933. if (si.stock_warning || si.stock_warning == 0) {
  934. si.stock_warning_switch = true
  935. }
  936. })
  937. }
  938. this.skuList = skuList;
  939. this.skuPrice = skuPrice;
  940. setTimeout(() => {
  941. // 延迟触发更新下面列表
  942. this.isEditInit = true;
  943. }, 200)
  944. },
  945. getEditData() {
  946. let that = this;
  947. Fast.api.ajax({
  948. url: 'shopro/goods/goods/detail/ids/' + that.editId,
  949. loading: true,
  950. }, function (ret, res) {
  951. for (key in that.goodsDetail) {
  952. if (res.data.detail[key]) {
  953. that.goodsDetail[key] = res.data.detail[key]
  954. } else {
  955. that.goodsDetail.express_ids = res.data.detail.dispatch_group_ids_arr.express ? res.data.detail.dispatch_group_ids_arr.express : '';
  956. that.goodsDetail.store_ids = res.data.detail.dispatch_group_ids_arr.store ? res.data.detail.dispatch_group_ids_arr.store : '';
  957. that.goodsDetail.selfetch_ids = res.data.detail.dispatch_group_ids_arr.selfetch ? res.data.detail.dispatch_group_ids_arr.selfetch : '';
  958. that.goodsDetail.autosend_ids = res.data.detail.dispatch_group_ids_arr.autosend ? res.data.detail.dispatch_group_ids_arr.autosend : '';
  959. }
  960. }
  961. for (key in that.timeData) {
  962. if (res.data.detail[key]) {
  963. that.timeData[key] = res.data.detail[key]
  964. }
  965. }
  966. let activeId = ''
  967. that.timeData.category_ids_arr.forEach(i => {
  968. activeId = i[0];
  969. i.splice(0, 1)
  970. })
  971. if (that.categoryOptions.length > 0) {
  972. that.categoryOptions.forEach((j, index) => {
  973. if (j.id == activeId) {
  974. that.activeName = j.name;
  975. that.activeIndex = index;
  976. }
  977. })
  978. }
  979. let nameArr = [];
  980. that.selectedcatArr = []
  981. if (that.timeData.category_ids_arr.length > 0) {
  982. that.timeData.category_ids_arr.forEach(j => {
  983. let arr = []
  984. if (j.length == 1) {
  985. that.categoryOptions[that.activeIndex].children.forEach(c => {
  986. if (c.id == j[0]) {
  987. arr.push(c.name)
  988. }
  989. })
  990. } else if (j.length == 2) {
  991. that.categoryOptions[that.activeIndex].children.forEach(c => {
  992. if (c.id == j[0]) {
  993. arr.push(c.name)
  994. c.children.forEach(a => {
  995. if (a.id == j[1]) {
  996. arr.push(a.name)
  997. }
  998. })
  999. }
  1000. })
  1001. } else if (j.length == 3) {
  1002. that.categoryOptions[that.activeIndex].children.forEach(c => {
  1003. if (c.id == j[0]) {
  1004. arr.push(c.name)
  1005. c.children.forEach(a => {
  1006. if (a.id == j[1]) {
  1007. arr.push(a.name)
  1008. a.children.forEach(t => {
  1009. if (t.id == j[2]) {
  1010. arr.push(t.name)
  1011. }
  1012. })
  1013. }
  1014. })
  1015. }
  1016. })
  1017. }
  1018. nameArr.push({
  1019. label: arr.join('/'),
  1020. })
  1021. })
  1022. }
  1023. that.selectedcatArr = nameArr;
  1024. that.timeData.dispatch_type_arr.forEach(i => {
  1025. that.getDispatchTemplateData(i, 'edit');
  1026. })
  1027. that.getInit(res.data.skuList, res.data.skuPrice);
  1028. Controller.api.bindevent();
  1029. $('#c-content').html(res.data.detail.content)
  1030. // 库存预警
  1031. that.goodsDetail.stock_warning = res.data.detail.stock_warning
  1032. if (that.goodsDetail.stock_warning || that.goodsDetail.stock_warning == 0) {
  1033. that.goodsDetail.stock_warning_switch = true
  1034. }
  1035. return false;
  1036. })
  1037. },
  1038. submitForm(formName) {
  1039. this.$refs[formName].validate((valid) => {
  1040. if (valid) {
  1041. let that = this;
  1042. let arrForm = JSON.parse(JSON.stringify(that.goodsDetail));
  1043. let params_arrflg = true;
  1044. arrForm.params_arr.forEach(i => {
  1045. for (key in i) {
  1046. if (!i[key]) {
  1047. params_arrflg = false;
  1048. }
  1049. }
  1050. })
  1051. if (!params_arrflg) {
  1052. Toastr.error('参数详情未填写完整');
  1053. return false;
  1054. }
  1055. arrForm.params = JSON.stringify(arrForm.params_arr);
  1056. arrForm.content = $("#c-content").val();
  1057. var arrids = []
  1058. // 发货模板id
  1059. if (arrForm.type == 'normal') {
  1060. if (arrForm.dispatch_type.indexOf('express') != -1 && arrForm.express_ids != '') {
  1061. arrids.push(arrForm.express_ids);
  1062. }
  1063. if (arrForm.dispatch_type.indexOf('store') != -1 && arrForm.store_ids != '') {
  1064. arrids.push(arrForm.store_ids);
  1065. }
  1066. if (arrForm.dispatch_type.indexOf('selfetch') != -1 && arrForm.selfetch_ids != '') {
  1067. arrids.push(arrForm.selfetch_ids);
  1068. }
  1069. arrForm.dispatch_ids = arrids.join(",")
  1070. } else {
  1071. if (arrForm.dispatch_type == 'selfetch' && arrForm.selfetch_ids != '') {
  1072. arrids = []
  1073. arrids.push(arrForm.selfetch_ids);
  1074. } else if (arrForm.dispatch_type == 'autosend' && arrForm.autosend_ids != '') {
  1075. arrids = []
  1076. arrids.push(arrForm.autosend_ids);
  1077. }
  1078. }
  1079. arrForm.dispatch_ids = arrids.join(",")
  1080. that.mustDel.forEach(i => {
  1081. delete arrForm[i]
  1082. })
  1083. let submitSkuList = []
  1084. let submitSkuPrice = []
  1085. if (arrForm.is_sku == 0) {
  1086. // 库存预警
  1087. if (!arrForm.stock_warning_switch) {
  1088. arrForm.stock_warning = null;
  1089. }
  1090. delete arrForm.stock_warning_switch
  1091. } else {
  1092. submitSkuList = JSON.parse(JSON.stringify(that.skuList))
  1093. submitSkuPrice = JSON.parse(JSON.stringify(that.skuPrice))
  1094. submitSkuPrice.forEach(s => {
  1095. if (!s.stock_warning_switch) {
  1096. s.stock_warning = null
  1097. }
  1098. delete s.stock_warning_switch
  1099. })
  1100. }
  1101. if (that.editId && that.type == 'edit') {
  1102. Fast.api.ajax({
  1103. url: 'shopro/goods/goods/edit/ids/' + that.editId,
  1104. loading: true,
  1105. data: {
  1106. row: arrForm,
  1107. sku: {
  1108. listData: JSON.stringify(submitSkuList),
  1109. priceData: JSON.stringify(submitSkuPrice)
  1110. }
  1111. }
  1112. }, function (ret, res) {
  1113. Fast.api.close();
  1114. })
  1115. } else {
  1116. if (this.type == 'copy') {
  1117. delete arrForm.id
  1118. }
  1119. Fast.api.ajax({
  1120. url: 'shopro/goods/goods/add',
  1121. loading: true,
  1122. data: {
  1123. row: arrForm,
  1124. sku: {
  1125. listData: JSON.stringify(submitSkuList),
  1126. priceData: JSON.stringify(submitSkuPrice)
  1127. }
  1128. }
  1129. }, function (ret, res) {
  1130. Fast.api.close();
  1131. })
  1132. }
  1133. } else {
  1134. return false;
  1135. }
  1136. });
  1137. },
  1138. resetForm(formName) {
  1139. this.$refs[formName].resetFields();
  1140. },
  1141. addImg(type, index, multiple) {
  1142. let that = this;
  1143. parent.Fast.api.open("general/attachment/select?multiple=" + multiple, "选择图片", {
  1144. callback: function (data) {
  1145. switch (type) {
  1146. case "image":
  1147. that.goodsDetail.image = data.url;
  1148. break;
  1149. case "images":
  1150. that.goodsDetail.images = that.goodsDetail.images ? that.goodsDetail.images + ',' + data.url : data.url;
  1151. let arrs = that.goodsDetail.images.split(',');
  1152. if (arrs.length > 9) {
  1153. that.timeData.images_arr = arrs.slice(-9)
  1154. } else {
  1155. that.timeData.images_arr = arrs
  1156. }
  1157. that.goodsDetail.images = that.timeData.images_arr.join(',');
  1158. break;
  1159. case "sku":
  1160. that.skuPrice[index].image = data.url;
  1161. break;
  1162. }
  1163. }
  1164. });
  1165. return false;
  1166. },
  1167. delImg(type, index) {
  1168. let that = this;
  1169. switch (type) {
  1170. case "image":
  1171. that.goodsDetail.image = '';
  1172. break;
  1173. case "images":
  1174. that.timeData.images_arr.splice(index, 1);
  1175. that.goodsDetail.images = that.timeData.images_arr.join(",");
  1176. break;
  1177. case "sku":
  1178. that.skuPrice[index].image = '';
  1179. break;
  1180. }
  1181. },
  1182. imagesDrag(){
  1183. this.goodsDetail.images = this.timeData.images_arr.join(",");
  1184. },
  1185. changeGoodsType(type) {
  1186. this.goodsDetail.type = type;
  1187. this.goodsDetail.dispatch_ids_arr = [];
  1188. this.goodsDetail.dispatch_ids = '';
  1189. this.goodsDetail.dispatch_type_arr = [];
  1190. this.goodsDetail.dispatch_type = '';
  1191. this.timeData.dispatch_type_arr = []
  1192. this.goodsDetail.express_ids = ''
  1193. this.goodsDetail.store_ids = ''
  1194. this.goodsDetail.selfetch_ids = ''
  1195. },
  1196. categoryChange(val) {
  1197. this.goodsDetail.category_ids = val.join(',');
  1198. },
  1199. serviceChange(val) {
  1200. this.goodsDetail.service_ids = val.join(',');
  1201. },
  1202. dispatchTypeChange(val) {
  1203. this.goodsDetail.dispatch_type = val.join(',');
  1204. },
  1205. dispatchTypeChanger(val) {
  1206. this.goodsDetail.dispatch_type = val;
  1207. this.getDispatchTemplateData(val, 'virtual');
  1208. },
  1209. getDispatchTemplateData(type, fristEdit) {
  1210. let that = this;
  1211. if (this.goodsDetail.dispatch_type.indexOf(type) == -1 || fristEdit == 'edit' || fristEdit == 'virtual' || fristEdit == 'create') {
  1212. Fast.api.ajax({
  1213. url: 'shopro/dispatch/dispatch/select/type/' + type,
  1214. loading: false,
  1215. type: 'GET',
  1216. }, function (ret, res) {
  1217. that.$set(that.dispatchOptions, type, res.data)
  1218. return false;
  1219. })
  1220. }
  1221. },
  1222. getCategoryOptions(form) {
  1223. let that = this;
  1224. Fast.api.ajax({
  1225. url: 'shopro/category/index',
  1226. loading: false,
  1227. }, function (ret, res) {
  1228. that.categoryOptions = res.data;
  1229. if (that.categoryOptions.length > 0) {
  1230. if (that.activeName && that.activeIndex) {
  1231. } else {
  1232. that.activeName = that.categoryOptions[0].name
  1233. that.activeIndex = 0;
  1234. }
  1235. that.categoryOptions.forEach(i => {
  1236. if (i.children && i.children.length > 0) {
  1237. i.children.forEach(j => {
  1238. if (j.children && j.children.length > 0) {
  1239. j.children.forEach(k => {
  1240. if (k.children && k.children.length > 0) {
  1241. k.children.forEach(g => {
  1242. })
  1243. } else {
  1244. delete k.children;
  1245. }
  1246. })
  1247. } else {
  1248. delete j.children;
  1249. }
  1250. })
  1251. } else {
  1252. delete i.children;
  1253. }
  1254. })
  1255. }
  1256. if (form) {
  1257. that.getEditData()
  1258. }
  1259. return false;
  1260. })
  1261. },
  1262. getDispatchType() {
  1263. let that = this;
  1264. Fast.api.ajax({
  1265. url: 'shopro/dispatch/dispatch/typeList',
  1266. loading: false,
  1267. }, function (ret, res) {
  1268. let arr = []
  1269. for (key in res.data) {
  1270. arr.push({
  1271. id: key,
  1272. name: res.data[key]
  1273. })
  1274. }
  1275. that.dispatchType = arr;
  1276. return false;
  1277. })
  1278. },
  1279. getServiceOptions() {
  1280. let that = this;
  1281. Fast.api.ajax({
  1282. url: 'shopro/goods/service/all',
  1283. loading: false,
  1284. }, function (ret, res) {
  1285. that.serviceOptions = res.data
  1286. return false;
  1287. })
  1288. },
  1289. gotoback(formName) {
  1290. this.$refs[formName].validate((valid) => {
  1291. if (valid) {
  1292. this.stepActive++;
  1293. } else {
  1294. return false;
  1295. }
  1296. });
  1297. },
  1298. gonextback() {
  1299. this.stepActive--;
  1300. },
  1301. addParams() {
  1302. this.goodsDetail.params_arr.push({
  1303. title: '',
  1304. content: ''
  1305. })
  1306. },
  1307. delParams(index) {
  1308. this.goodsDetail.params_arr.splice(index, 1)
  1309. },
  1310. //添加主规格
  1311. addMainSku() {
  1312. // if (this.skuModal !== '') {
  1313. this.skuList.push({
  1314. id: 0,
  1315. temp_id: this.countId++,
  1316. name: this.skuModal,
  1317. pid: 0,
  1318. children: []
  1319. })
  1320. this.skuModal = '';
  1321. // this.skuPrice = [] // 新添加的主规格不清空 skuPrice,当添加主规格第一个子规格的时候清空
  1322. this.buildSkuPriceTable()
  1323. // }
  1324. },
  1325. //添加子规格
  1326. addChildrenSku(k) {
  1327. // if (this.childrenModal[k] !== '') {
  1328. // 检测当前子规格是否已经被添加过了
  1329. let isExist = false
  1330. this.skuList[k].children.forEach(e => {
  1331. if (e.name == this.childrenModal[k] && e.name != "") {
  1332. isExist = true
  1333. }
  1334. })
  1335. if (isExist) {
  1336. Toastr.error('子规格已存在');
  1337. return false;
  1338. }
  1339. this.skuList[k].children.push({
  1340. id: 0,
  1341. temp_id: this.countId++,
  1342. name: this.childrenModal[k],
  1343. pid: this.skuList[k].id,
  1344. })
  1345. this.childrenModal[k] = '';
  1346. // 如果是添加的第一个子规格,清空 skuPrice
  1347. if (this.skuList[k].children.length == 1) {
  1348. this.skuPrice = [] // 规格大变化,清空skuPrice
  1349. this.isResetSku = 1; // 重置规格
  1350. }
  1351. this.buildSkuPriceTable()
  1352. // }
  1353. },
  1354. //删除主规格
  1355. deleteMainSku(k) {
  1356. let data = this.skuList[k]
  1357. // 删除主规格
  1358. this.skuList.splice(k, 1)
  1359. // 如果当前删除的主规格存在子规格,则清空 skuPrice, 不存在子规格则不清空
  1360. if (data.children.length > 0) {
  1361. this.skuPrice = [] // 规格大变化,清空skuPrice
  1362. this.isResetSku = 1; // 重置规格
  1363. }
  1364. this.buildSkuPriceTable()
  1365. },
  1366. //删除子规格
  1367. deleteChildrenSku(k, i) {
  1368. let data = this.skuList[k].children[i]
  1369. this.skuList[k].children.splice(i, 1)
  1370. // 查询 skuPrice 中包含被删除的的子规格的项,然后移除
  1371. let deleteArr = []
  1372. this.skuPrice.forEach((item, index) => {
  1373. item.goods_sku_text.forEach((e, i) => {
  1374. if (e == data.name) {
  1375. deleteArr.push(index)
  1376. }
  1377. })
  1378. })
  1379. deleteArr.sort(function (a, b) {
  1380. return b - a;
  1381. })
  1382. // 移除有相关子规格的项
  1383. deleteArr.forEach((i, e) => {
  1384. this.skuPrice.splice(i, 1)
  1385. })
  1386. // 当前规格项,所有子规格都被删除,清空 skuPrice
  1387. if (this.skuList[k].children.length <= 0) {
  1388. this.skuPrice = [] // 规格大变化,清空skuPrice
  1389. this.isResetSku = 1; // 重置规格
  1390. }
  1391. this.buildSkuPriceTable()
  1392. },
  1393. editStatus(i) {
  1394. if (this.skuPrice[i].status == 'up') {
  1395. this.skuPrice[i].status = 'down'
  1396. } else {
  1397. this.skuPrice[i].status = 'up'
  1398. }
  1399. },
  1400. //组合新的规格价格库存重量编码图片
  1401. buildSkuPriceTable() {
  1402. let arr = [];
  1403. //遍历sku子规格生成新数组,然后执行递归笛卡尔积
  1404. this.skuList.forEach((s1, k1) => {
  1405. let children = s1.children;
  1406. let childrenIdArray = [];
  1407. if (children.length > 0) {
  1408. children.forEach((s2, k2) => {
  1409. childrenIdArray.push(s2.temp_id);
  1410. })
  1411. // 如果 children 子规格数量为 0,则不渲染当前规格, (相当于没有这个主规格)
  1412. arr.push(childrenIdArray);
  1413. }
  1414. })
  1415. this.recursionSku(arr, 0, []);
  1416. },
  1417. //递归找笛卡尔规格集合
  1418. recursionSku(arr, k, temp) {
  1419. if (k == arr.length && k != 0) {
  1420. let tempDetail = []
  1421. let tempDetailIds = []
  1422. temp.forEach((item, index) => {
  1423. for (let sku of this.skuList) {
  1424. for (let child of sku.children) {
  1425. if (item == child.temp_id) {
  1426. tempDetail.push(child.name)
  1427. tempDetailIds.push(child.temp_id)
  1428. }
  1429. }
  1430. }
  1431. })
  1432. let flag = false // 默认添加新的
  1433. for (let i = 0; i < this.skuPrice.length; i++) {
  1434. if (this.skuPrice[i].goods_sku_temp_ids.join(',') == tempDetailIds.join(',')) {
  1435. flag = i
  1436. break;
  1437. }
  1438. }
  1439. if (flag === false) {
  1440. this.skuPrice.push({
  1441. id: 0,
  1442. temp_id: this.skuPrice.length + 1,
  1443. goods_sku_ids: '',
  1444. goods_id: 0,
  1445. weigh: 0,
  1446. image: '',
  1447. stock: 0,
  1448. stock_warning: null,
  1449. stock_warning_switch: false,
  1450. price: 0,
  1451. sn: '',
  1452. weight: 0,
  1453. status: 'up',
  1454. goods_sku_text: tempDetail,
  1455. goods_sku_temp_ids: tempDetailIds,
  1456. });
  1457. } else {
  1458. this.skuPrice[flag].goods_sku_text = tempDetail
  1459. this.skuPrice[flag].goods_sku_temp_ids = tempDetailIds
  1460. }
  1461. return;
  1462. }
  1463. if (arr.length) {
  1464. for (let i = 0; i < arr[k].length; i++) {
  1465. temp[k] = arr[k][i]
  1466. this.recursionSku(arr, k + 1, temp)
  1467. }
  1468. }
  1469. },
  1470. allEditData(type, opt) {
  1471. switch (opt) {
  1472. case 'define':
  1473. this.skuPrice.forEach(i => {
  1474. if (type == 'stock_warning') {
  1475. if (this.allstock_warning_switch) {
  1476. i.stock_warning_switch = true
  1477. if (this.allEditDatas) {
  1478. i[type] = this.allEditDatas
  1479. } else {
  1480. i[type] = 0
  1481. }
  1482. } else {
  1483. i.stock_warning_switch = false
  1484. if (i.stock_warning_switch) {
  1485. i[type] = this.allEditDatas
  1486. } else {
  1487. i[type] = null
  1488. }
  1489. }
  1490. } else {
  1491. i[type] = this.allEditDatas;
  1492. }
  1493. })
  1494. this.allEditDatas = ''
  1495. this.allEditPopover[type] = false;
  1496. this.allstock_warning_switch = false;
  1497. break;
  1498. case 'cancel':
  1499. this.allEditDatas = ''
  1500. this.allEditPopover[type] = false;
  1501. this.allstock_warning_switch = false;
  1502. break;
  1503. }
  1504. },
  1505. changeStockWarningSwitch(type, index) {
  1506. // 0是单规格 1是多规格
  1507. if (type == 0) {
  1508. this.goodsDetail.stock_warning = this.goodsDetail.stock_warning_switch ? 0 : null
  1509. } else if (type == 1) {
  1510. this.skuPrice[index].stock_warning = this.skuPrice[index].stock_warning_switch ? 0 : null
  1511. }
  1512. }
  1513. },
  1514. watch: {
  1515. stepActive(newVal) {
  1516. this.editor = null;
  1517. },
  1518. skuList: {
  1519. handler(newName, oldName) {
  1520. if (this.isEditInit) { // 编辑初始化的时候会修改 skuList 但这时候不触发更新
  1521. this.buildSkuPriceTable();
  1522. }
  1523. },
  1524. deep: true
  1525. }
  1526. },
  1527. })
  1528. }
  1529. };
  1530. return Controller;
  1531. });