SkuOneStore.vue 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  1. <template>
  2. <view class="sku-view">
  3. <!-- 是否是多规格 -->
  4. <view class="switch-view clearfix">
  5. <view class="float_left">启用多规格</view>
  6. <view class="float_right"><u-switch size="40" @change="specTypeChange" v-model="specType"></u-switch></view>
  7. </view>
  8. <view class="sku-name-view" v-if="specType">
  9. <view class="sku-ul">
  10. <view class="sku-li" v-for="(item, index) in spec_group" :key="index">
  11. <view class="sku-label clearfix">
  12. <view class="float_left">
  13. {{ item.groupSpec.specName }}
  14. <text class="custom-icon custom-icon-delete" @click="deletSpecGroup(index)"></text>
  15. </view>
  16. <view class="float_right sku-val-add-btn" @click="openSkuLabelPop('sku_val_pop', index, item.groupSpec.specId)">
  17. <text class="custom-icon custom-icon-xinzeng"></text>
  18. 新增规格值
  19. </view>
  20. </view>
  21. <view class="sku-val-ul">
  22. <view class="sku-val-li" v-for="(ic, inc) in item.params" :key="inc">
  23. {{ ic.specName }}
  24. <text class="custom-icon custom-icon-delete" @click="deletSpecValue(index, inc)"></text>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="sku-group" v-if="specType">
  31. <view class="sku-group-tit clearfix">
  32. <text>规格组合</text>
  33. <view class="rest-btn float_right" @click="openSkuLabelPop('sku_label_pop')">添加规格组合</view>
  34. </view>
  35. <!-- 同步规格 -->
  36. <view class="sku-group-main">
  37. <view class="sku-top">
  38. <view class="sku-top-li">
  39. <view class="label">规格图片</view>
  40. <view class="sku-main"><upload :images="set.specImage ? [set.specImage] : []" @handleRemove="imgRemoveTotal" @uploadSuccess="uploadSuccessTotal" /></view>
  41. <u-button size="mini" type="primary" @click="synchro('specImage')">同步</u-button>
  42. </view>
  43. <view class="sku-top-li">
  44. <view class="label">是否销售</view>
  45. <view class="input-view"><u-switch size="30" v-model="set.isSale"></u-switch></view>
  46. <u-button size="mini" type="primary" @click="synchro('isSale')">同步</u-button>
  47. </view>
  48. <view class="sku-top-li">
  49. <view class="label">销售价</view>
  50. <view class="input-view">
  51. <input v-if="!set.enabledLadder" type="digit" placeholder="请输入" placeholder-class="input-pl" v-model="set.salePrice" />
  52. <view class="other-view" v-else>
  53. <u-button size="mini" type="primary" @click="openLadder(-1, set)">{{ set.ladderPrice.length > 0 ? '已设置' : '去设置' }}</u-button>
  54. </view>
  55. </view>
  56. <u-button size="mini" type="primary" @click="synchro('salePrice')">同步</u-button>
  57. </view>
  58. </view>
  59. <view class="sku-top">
  60. <view class="sku-top-li">
  61. <view class="label">会员价</view>
  62. <view class="input-view"><input type="digit" placeholder="请输入" placeholder-class="input-pl" v-model="set.memberPrice" /></view>
  63. <u-button size="mini" type="primary" @click="synchro('memberPrice')">同步</u-button>
  64. </view>
  65. <view class="sku-top-li">
  66. <view class="label">市场价</view>
  67. <view class="input-view"><input type="digit" placeholder="请输入" placeholder-class="input-pl" v-model="set.marketPrice" /></view>
  68. <u-button size="mini" type="primary" @click="synchro('marketPrice')">同步</u-button>
  69. </view>
  70. <view class="sku-top-li">
  71. <view class="label">起订数量</view>
  72. <view class="input-view"><input type="number" placeholder="请输入" placeholder-class="input-pl" v-model="set.setNum" /></view>
  73. <u-button size="mini" type="primary" @click="synchro('setNum')">同步</u-button>
  74. </view>
  75. </view>
  76. <view class="sku-top">
  77. <view class="sku-top-li">
  78. <view class="label">启用阶梯价</view>
  79. <view class="input-view"><u-switch size="30" v-model="set.enabledLadder"></u-switch></view>
  80. <u-button size="mini" type="primary" @click="synchro('enabledLadder')">同步</u-button>
  81. </view>
  82. <view class="sku-top-li">
  83. <view class="label">商品条码</view>
  84. <view class="input-view"><input type="text" placeholder="请输入" placeholder-class="input-pl" v-model="set.barCode" /></view>
  85. <u-button size="mini" type="primary" @click="synchro('barCode')">同步</u-button>
  86. </view>
  87. <view class="sku-top-li">
  88. <view class="label">重量/g</view>
  89. <view class="input-view"><input type="digit" placeholder="请输入" placeholder-class="input-pl" v-model="set.weight" /></view>
  90. <u-button size="mini" type="primary" @click="synchro('weight')">同步</u-button>
  91. </view>
  92. </view>
  93. </view>
  94. <!-- 单个规格 -->
  95. <view>
  96. <view v-if="specMultipleUnit.length > 1" style="border-bottom: 1px solid #EEEEEE;">
  97. <u-tabs-swiper @change="tabChange" ref="tabs" name="unitName" :current="tab_current" :list="specMultipleUnit" :is-scroll="false"></u-tabs-swiper>
  98. </view>
  99. <view class="sku-group-main" v-for="(sku, index) in specMultipleUnit[tab_current].specMultiple" :key="index">
  100. <view class="sku-group-label clearfix">
  101. <view class="float_left">
  102. <text>{{ specMultipleUnit[tab_current].unitName }};</text>
  103. <text>{{ sku.specName }};</text>
  104. </view>
  105. <view class="float_right">
  106. <text class="default-label">默认:</text>
  107. <view class="default-switch"><u-switch size="30" v-model="sku.isDefault" @change="isDefaultChange($event, index)"></u-switch></view>
  108. </view>
  109. </view>
  110. <view class="sku-top">
  111. <view class="sku-top-li">
  112. <view class="label">规格图片</view>
  113. <view class="sku-main">
  114. <upload :images="sku.specImage ? [sku.specImage] : []" @uploadSuccess="uploadSuccess($event, index)" @handleRemove="imgRemove(index)" />
  115. </view>
  116. </view>
  117. <view class="sku-top-li">
  118. <view class="label">是否销售</view>
  119. <view class="other-view"><u-switch size="30" v-model="sku.isSale"></u-switch></view>
  120. </view>
  121. <view class="sku-top-li">
  122. <view class="label">销售价</view>
  123. <input v-if="!sku.enabledLadder" type="digit" placeholder="请输入" placeholder-class="input-pl" v-model="sku.salePrice" />
  124. <view class="other-view" v-else>
  125. <u-button size="mini" type="primary" @click="openLadder(index, sku)">{{ sku.ladderPrice.length > 0 ? '已设置' : '去设置' }}</u-button>
  126. </view>
  127. </view>
  128. </view>
  129. <view class="sku-top">
  130. <view class="sku-top-li">
  131. <view class="label">会员价</view>
  132. <input type="digit" placeholder="请输入" placeholder-class="input-pl" v-model="sku.memberPrice" />
  133. </view>
  134. <view class="sku-top-li">
  135. <view class="label">市场价</view>
  136. <input type="digit" placeholder="请输入" placeholder-class="input-pl" v-model="sku.marketPrice" />
  137. </view>
  138. <view class="sku-top-li">
  139. <view class="label">起订数量</view>
  140. <input type="number" placeholder="请输入" placeholder-class="input-pl" v-model="sku.setNum" />
  141. </view>
  142. </view>
  143. <view class="sku-top">
  144. <view class="sku-top-li">
  145. <view class="label">启用阶梯价</view>
  146. <view class="other-view"><u-switch size="30" v-model="sku.enabledLadder"></u-switch></view>
  147. </view>
  148. <view class="sku-top-li">
  149. <view class="label">商品条码</view>
  150. <input type="text" placeholder="请输入" placeholder-class="input-pl" v-model="sku.barCode" />
  151. </view>
  152. <view class="sku-top-li">
  153. <view class="label">重量/g</view>
  154. <input type="digit" placeholder="请输入" placeholder-class="input-pl" v-model="sku.weight" />
  155. </view>
  156. </view>
  157. </view>
  158. </view>
  159. </view>
  160. <!-- 不启用多规格 单位 -->
  161. <view class="sku-group unit-group" v-else>
  162. <view class="sku-group-main" v-for="(item, index) in unit_data" :key="index">
  163. <view class="sku-group-label clearfix">
  164. <text class="float_left">{{ item.unitName }}</text>
  165. <view class="float_right">
  166. <text class="default-label">默认:</text>
  167. <view class="default-switch"><u-switch size="30" v-model="item.isDefault" @change="isDefaultChange($event, index)"></u-switch></view>
  168. </view>
  169. </view>
  170. <view class="sku-top">
  171. <view class="sku-top-li">
  172. <view class="label">规格图片</view>
  173. <view class="sku-main" style="height: auto;">
  174. <upload :images="item.specImage ? [item.specImage] : []" @uploadSuccess="uploadSuccess($event, index)" @handleRemove="imgRemove(index)" />
  175. </view>
  176. </view>
  177. <view class="sku-top-li">
  178. <view class="label">是否销售</view>
  179. <view class="other-view"><u-switch size="30" v-model="item.isSale"></u-switch></view>
  180. </view>
  181. <view class="sku-top-li">
  182. <view class="label">销售价</view>
  183. <input v-if="!item.enabledLadder" type="digit" placeholder="请输入" placeholder-class="input-pl" v-model="item.salePrice" />
  184. <view class="other-view" v-else>
  185. <u-button size="mini" type="primary" @click="openLadder(index, item)">{{ item.ladderPrice.length > 0 ? '已设置' : '去设置' }}</u-button>
  186. </view>
  187. </view>
  188. </view>
  189. <view class="sku-top">
  190. <view class="sku-top-li">
  191. <view class="label">会员价</view>
  192. <input type="digit" placeholder="请输入" placeholder-class="input-pl" v-model="item.memberPrice" />
  193. </view>
  194. <view class="sku-top-li">
  195. <view class="label">市场价</view>
  196. <input type="digit" placeholder="请输入" placeholder-class="input-pl" v-model="item.marketPrice" />
  197. </view>
  198. <view class="sku-top-li">
  199. <view class="label">起订数量</view>
  200. <input type="number" placeholder="请输入" placeholder-class="input-pl" v-model="item.setNum" />
  201. </view>
  202. </view>
  203. <view class="sku-top">
  204. <view class="sku-top-li">
  205. <view class="label">启用阶梯价</view>
  206. <view class="other-view"><u-switch size="30" v-model="item.enabledLadder"></u-switch></view>
  207. </view>
  208. <view class="sku-top-li">
  209. <view class="label">商品条码</view>
  210. <input type="text" placeholder="请输入" placeholder-class="input-pl" v-model="item.barCode" />
  211. </view>
  212. <view class="sku-top-li">
  213. <view class="label">重量/g</view>
  214. <input type="digit" placeholder="请输入" placeholder-class="input-pl" v-model="item.weight" />
  215. </view>
  216. </view>
  217. </view>
  218. </view>
  219. <view class="submit-btn"><view class="btn-min" @click="skuConfirm">确定</view></view>
  220. <!-- 选择规格组 -->
  221. <u-popup v-model="sku_label_pop" border-radius="16" mode="bottom">
  222. <view class="pop-view">
  223. <view class="handel-btn clearfix">
  224. <text class="float_left" @click="cancelSkuLabelPop('sku_label_pop')">取消</text>
  225. <text class="float_right" @click="specConfitm">确定</text>
  226. </view>
  227. <view class="pop-cont">
  228. <block v-for="(item, index) in spec_list" :key="index">
  229. <view class="sku-li clearfix" :class="[spec_group.find(its => its.groupSpec.specId === item.id) ? 'sku-on' : '']" @click="changeSpec(item.id)">
  230. <text class="sku-val-label float_left">{{ item.specName }}</text>
  231. <text class="custom-icon custom-icon-radio float_right" style="color: #999999;" v-if="spec_group.find(its => its.groupSpec.specId === item.id)"></text>
  232. <text class="custom-icon float_right" v-else :class="[temporary_spec_id === item.id ? 'custom-icon-xuanze_xuanzhong' : 'custom-icon-xuanze']"></text>
  233. </view>
  234. </block>
  235. </view>
  236. </view>
  237. </u-popup>
  238. <!-- 选择规格值 -->
  239. <u-popup v-model="sku_val_pop" border-radius="16" mode="bottom">
  240. <view class="pop-view">
  241. <view class="handel-btn clearfix">
  242. <text class="float_left" @click="cancelSkuLabelPop('sku_val_pop')">取消</text>
  243. <text class="float_right" @click="specValueConfirm">确定</text>
  244. </view>
  245. <view class="pop-cont">
  246. <view class="sku-li clearfix" v-for="(item, index) in spec_data_child" :key="index" @click="selSpecChild(item.id)">
  247. <text class="sku-val-label float_left">{{ item.specName }}</text>
  248. <text class="custom-icon float_right" :class="[temporary_spec_chid.indexOf(item.id) > -1 ? 'custom-icon-xuanze_xuanzhong' : 'custom-icon-xuanze']"></text>
  249. </view>
  250. </view>
  251. </view>
  252. </u-popup>
  253. <!-- 阶梯价 -->
  254. <u-popup v-model="ladder_show" border-radius="16" mode="bottom">
  255. <view class="pop-view">
  256. <view class="handel-btn clearfix">
  257. <text class="float_left" @click="cancelSkuLabelPop('ladder_show')">取消</text>
  258. <text class="float_right" @click="ladderPriceConfirm">确定</text>
  259. </view>
  260. <view class="pop-cont">
  261. <view class="sku-li" v-for="(ladder, ladderI) in ladderPrice" :key="ladderI">
  262. <view class="input-view"><input disabled type="digit" v-model="ladder.from" /></view>
  263. <view class="input-view">
  264. <input @blur="ladderBlur($event, ladderI)" type="digit" v-if="ladderI !== ladderPrice.length - 1" v-model="ladder.to" />
  265. <input v-else disabled value="∞" />
  266. <u-tag :text="unitName || '件'" mode="light" />
  267. </view>
  268. =
  269. <view class="input-view">
  270. <input type="digit" v-model="ladder.price" />
  271. <u-tag text="元" mode="light" />
  272. <u-icon
  273. name="shanchu"
  274. v-if="ladderPrice.length > 2 && ladderI !== ladderPrice.length - 1"
  275. color="#ff4501"
  276. custom-prefix="custom-icon"
  277. @click="delLadderPrice(ladderI)"
  278. ></u-icon>
  279. </view>
  280. </view>
  281. </view>
  282. <view @click="addLadderprice" class="btn-view" :style="{ backgroundColor: ladderPrice.length > 2 ? '#999999' : '' }">新增</view>
  283. </view>
  284. </u-popup>
  285. </view>
  286. </template>
  287. <script>
  288. import upload from '@/components/qiniu/QiniuUpload.vue';
  289. const ladderPrice = [
  290. {
  291. from: 1,
  292. price: '',
  293. to: 2
  294. },
  295. {
  296. from: 3,
  297. price: '',
  298. to: 4
  299. },
  300. {
  301. from: 5,
  302. price: '',
  303. to: 999999999
  304. }
  305. ];
  306. export default {
  307. components: {
  308. upload
  309. },
  310. data() {
  311. return {
  312. set: {
  313. specImage: '',
  314. enabledLadder: false,
  315. ladderPrice: [],
  316. salePrice: '',
  317. marketPrice: '',
  318. memberPrice:'',
  319. setNum: '',
  320. barCode: '',
  321. weight: '',
  322. isSale: 5
  323. },
  324. ladderPrice: [],
  325. ladder_show: false,
  326. specMultiple: [], //组合好的规格明细
  327. spec_group_index: '', // 当前规格下标
  328. spec_data_child: [],
  329. specImage: '',
  330. barCode: {},
  331. weight: {},
  332. specType: false,
  333. current: 0, // tabs组件的current值,表示当前活动的tab选项
  334. sku_label_pop: false,
  335. sku_val_pop: false,
  336. unit_data: [],
  337. spec_list: [],
  338. spec_group: [], // 属性组
  339. specMultipleUnit: [],
  340. tab_current: 0,
  341. temporary_spec_id: '', // 临时存储规格id
  342. temporary_spec_chid: [], // 临时存储属性值id
  343. unit_data_obj: [] // 单位数据
  344. };
  345. },
  346. watch: {
  347. specType(val) {
  348. if (val) {
  349. // this.specGroupRest();
  350. }
  351. }
  352. },
  353. onLoad(options) {
  354. this.specType = parseInt(options.specType) === 2;
  355. // 存一份原始单位数据
  356. this.unit_data_obj = JSON.parse(options.unitData);
  357. this.getAllSpecManage();
  358. this.initialization(options);
  359. },
  360. methods: {
  361. // 初始化
  362. initialization(options) {
  363. const unitData = JSON.parse(options.unitData);
  364. console.log(unitData);
  365. if (!this.specType) {
  366. this.unit_data = unitData.map(item => {
  367. let params = {};
  368. let obj = {
  369. enabledLadder: false,
  370. isDefault: item.isDefault === 5,
  371. salePrice: '',
  372. marketPrice: '',
  373. memberPrice:'',
  374. setNum: 1,
  375. isSale: item.isSale !== 4,
  376. barCode: '',
  377. weight: '',
  378. specImage: '',
  379. ladderPrice: [],
  380. salePriceAreaType: 1,
  381. ...item
  382. };
  383. if (item.salePrice) {
  384. params = {
  385. ...obj,
  386. ...item.salePrice,
  387. isDefault: item.isDefault === 5,
  388. isSale: item.isSale !== 4,
  389. enabledLadder: item.enabledLadder === 1
  390. };
  391. } else {
  392. params = { ...obj, enabledLadder: item.enabledLadder === 1 };
  393. }
  394. return params;
  395. });
  396. console.log(this.unit_data);
  397. } else {
  398. const obj = {};
  399. this.specMultiple = JSON.parse(options.specMultiple);
  400. this.spec_group = JSON.parse(options.specGroup).map(item => {
  401. return {
  402. groupSpec: item.groupSpec,
  403. params: item.params.map(sku => {
  404. return {
  405. specId: sku.specValueId,
  406. specName: sku.specValueName
  407. };
  408. })
  409. };
  410. });
  411. let specMultipleUnit = unitData.map(item => {
  412. return {
  413. unitId: item.unitId,
  414. unitName: item.unitName,
  415. conversion: item.conversion || 0,
  416. isMaster: item.isMaster,
  417. specMultiple: []
  418. };
  419. });
  420. console.log(this.specMultiple);
  421. specMultipleUnit.forEach(item => {
  422. this.specMultiple.forEach(sku => {
  423. if (sku.unitId === item.unitId) {
  424. const specName = sku.specGroup.map(spec => spec.specValueName).join('_');
  425. const specId = sku.specGroup.map(spec => spec.specValueId).join('_');
  426. const groupSpecName = sku.specGroup.map(spec => spec.specName).join('_');
  427. const groupSpecId = sku.specGroup.map(spec => spec.specId).join('_');
  428. const specMultipleItem = {
  429. isDefault: sku.isDefault === 5,
  430. isSale: sku.isSale !== 4,
  431. specImage: sku.specImage,
  432. enabledLadder: sku.salePrice.enabledLadder === 1,
  433. ladderPrice: sku.salePrice.ladderPrice,
  434. salePrice: sku.salePrice.salePrice,
  435. marketPrice: sku.salePrice.marketPrice,
  436. memberPrice: sku.memberPrice,
  437. setNum: sku.salePrice.setNum,
  438. barCode: sku.barCode,
  439. weight: sku.weight,
  440. specGroup: sku.specGroup,
  441. unitId: item.unitId,
  442. unitName: item.unitName,
  443. specName: specName,
  444. specId: specId,
  445. groupSpecName: groupSpecName,
  446. groupSpecId: groupSpecId
  447. };
  448. item.specMultiple.push(specMultipleItem);
  449. }
  450. });
  451. });
  452. this.specMultipleUnit = specMultipleUnit;
  453. }
  454. },
  455. // 单位切换
  456. tabChange(current) {
  457. this.tab_current = current;
  458. },
  459. // 获取属性列表
  460. getAllSpecManage() {
  461. this.$u.api
  462. .getAllSpecManage({
  463. page: 1,
  464. pageSize: 100
  465. })
  466. .then(res => {
  467. this.spec_list = res.data;
  468. });
  469. },
  470. // 默认属性切换
  471. isDefaultChange(value, unitIndex) {
  472. if (value) {
  473. if (!this.specType) {
  474. this.unit_data.forEach((item, index) => {
  475. if (index !== unitIndex) {
  476. item.isDefault = false;
  477. }
  478. });
  479. } else {
  480. this.specMultipleUnit.forEach((item,index)=>{
  481. if (index !== this.tab_current) {
  482. item.specMultiple.forEach(sku=>{
  483. sku.isDefault = false;
  484. })
  485. }else{
  486. item.specMultiple.forEach((sku,skuindex)=>{
  487. if (skuindex !== unitIndex) {
  488. sku.isDefault = false;
  489. }
  490. })
  491. }
  492. })
  493. }
  494. }
  495. },
  496. //弹窗打开
  497. openSkuLabelPop(key, index, specId) {
  498. this[key] = true;
  499. if (key === 'sku_val_pop') {
  500. this.spec_group_index = index;
  501. const obj = this.spec_list.find(item => item.id === specId);
  502. this.spec_data_child = obj.child || [];
  503. this.temporary_spec_chid = this.spec_group[index].params.map(item => item.specId);
  504. }
  505. },
  506. // 弹窗取消
  507. cancelSkuLabelPop(key) {
  508. this[key] = false;
  509. },
  510. // 单位切换
  511. tabsChange(index) {
  512. this.current = index;
  513. },
  514. // 图片上传成功
  515. uploadSuccess(imgUrl, index) {
  516. if (this.specType) {
  517. this.specMultipleUnit[this.tab_current].specMultiple[index].specImage = imgUrl;
  518. } else {
  519. this.unit_data[index].specImage = imgUrl;
  520. }
  521. },
  522. // 删除图片
  523. imgRemove(index) {
  524. if (this.specType) {
  525. this.specMultipleUnit[this.tab_current].specMultiple[index].specImage = '';
  526. } else {
  527. this.unit_data[index].specImage = '';
  528. }
  529. },
  530. // 同步规格上传成功
  531. uploadSuccessTotal(imgUrl) {
  532. this.set.specImage = imgUrl;
  533. },
  534. // 同步规格图片删除
  535. imgRemoveTotal(arr) {
  536. this.set.specImage = '';
  537. },
  538. // 选择规格组
  539. changeSpec(id) {
  540. if (this.spec_group.find(its => its.groupSpec.specId === id)) {
  541. return;
  542. }
  543. if (this.temporary_spec_id !== id) {
  544. this.temporary_spec_id = id;
  545. }
  546. },
  547. // 切换多规格开关
  548. specTypeChange(val) {
  549. if (val && !this.specMultipleUnit.length) {
  550. this.specMultipleUnit = this.unit_data_obj.map(item => {
  551. return {
  552. unitId: item.unitId,
  553. unitName: item.unitName,
  554. conversion: item.conversion || 0,
  555. isMaster: item.isMaster,
  556. specMultiple: []
  557. };
  558. });
  559. }
  560. },
  561. // 选择属性名
  562. specConfitm() {
  563. const obj = this.spec_list.find(item => item.id === this.temporary_spec_id);
  564. if (obj) {
  565. this.spec_group.push({
  566. groupSpec: {
  567. specName: obj.specName,
  568. specId: obj.id
  569. },
  570. params: []
  571. });
  572. }
  573. this.sku_label_pop = false;
  574. this.temporary_spec_id = '';
  575. },
  576. // 选择属性值
  577. selSpecChild(id) {
  578. const index = this.temporary_spec_chid.indexOf(id);
  579. if (index === -1) {
  580. this.temporary_spec_chid.push(id);
  581. } else {
  582. this.temporary_spec_chid.splice(index, 1);
  583. }
  584. },
  585. // 选择属性值确定
  586. specValueConfirm() {
  587. const target = this.$u.deepClone(this.temporary_spec_chid);
  588. this.spec_group[this.spec_group_index].params = target.map(item => {
  589. const specName = this.spec_data_child.find(itemf => itemf.id === item).specName;
  590. return {
  591. specId: item,
  592. specName: specName
  593. };
  594. });
  595. this.sku_val_pop = false;
  596. this.temporary_spec_chid = [];
  597. this.specGroupRest();
  598. },
  599. // 重排规格组合
  600. specGroupRest() {
  601. const skuArr = this.spec_group.map(item => {
  602. item.params = item.params.map(itemP => {
  603. return {
  604. ...itemP,
  605. groupSpecName: item.groupSpec.specName,
  606. groupSpecId: item.groupSpec.specId
  607. };
  608. });
  609. return item.params;
  610. });
  611. let skuArrDo = [];
  612. if (skuArr.length) {
  613. skuArrDo = this.doExchange(skuArr);
  614. }
  615. // 备份一份规格明细,用来填充重排规格组之前的图片
  616. const cloneUnitData = this.$u.deepClone(this.specMultipleUnit);
  617. this.specMultipleUnit = this.specMultipleUnit.map((item, index) => {
  618. const cloneSpecGroup = cloneUnitData[index].specMultiple || [];
  619. return {
  620. ...item,
  621. specMultiple: skuArrDo.map(itemSp => {
  622. const indexSS = cloneSpecGroup.findIndex(itemC => itemC.id === itemSp.id);
  623. let obj = {};
  624. if (indexSS > -1) {
  625. obj = {
  626. ...itemSp,
  627. isDefault: cloneSpecGroup[indexSS].isDefault,
  628. isSale: cloneSpecGroup[indexSS].isSale !== 4,
  629. specImage: cloneSpecGroup[indexSS].specImage,
  630. enabledLadder: cloneSpecGroup[indexSS].enabledLadder === 1,
  631. ladderPrice: cloneSpecGroup[indexSS].ladderPrice,
  632. salePrice: cloneSpecGroup[indexSS].salePrice,
  633. marketPrice: cloneSpecGroup[indexSS].marketPrice,
  634. memberPrice: cloneSpecGroup[indexSS].memberPrice,
  635. setNum: cloneSpecGroup[indexSS].setNum,
  636. barCode: cloneSpecGroup[indexSS].barCode,
  637. weight: cloneSpecGroup[indexSS].weight
  638. };
  639. } else {
  640. obj = {
  641. ...itemSp,
  642. isDefault: itemSp.isDefault || false,
  643. isSale: itemSp.isSale || 5,
  644. specImage: itemSp.specImage || '',
  645. enabledLadder: itemSp.enabledLadder || false,
  646. ladderPrice: itemSp.ladderPrice || [],
  647. salePrice: itemSp.salePrice || 0,
  648. marketPrice: itemSp.marketPrice || 0,
  649. memberPrice: itemSp.memberPrice || 0,
  650. setNum: itemSp.setNum || 1,
  651. barCode: itemSp.barCode || '',
  652. weight: itemSp.weight || 0
  653. };
  654. }
  655. return obj;
  656. })
  657. };
  658. });
  659. },
  660. // 规格组合
  661. doExchange(doubleArrays) {
  662. console.log(doubleArrays);
  663. const len = doubleArrays.length;
  664. if (len >= 2) {
  665. const len1 = doubleArrays[0].length;
  666. const len2 = doubleArrays[1].length;
  667. const newlen = len1 * len2;
  668. const temp = new Array(newlen);
  669. let index = 0;
  670. for (let i = 0; i < len1; i++) {
  671. for (let j = 0; j < len2; j++) {
  672. temp[index] = {
  673. groupSpecId: doubleArrays[0][i].groupSpecId + '_' + doubleArrays[1][j].groupSpecId,
  674. groupSpecName: doubleArrays[0][i].groupSpecName + '_' + doubleArrays[1][j].groupSpecName,
  675. specId: doubleArrays[0][i].specId + '_' + doubleArrays[1][j].specId,
  676. specName: doubleArrays[0][i].specName + '_' + doubleArrays[1][j].specName,
  677. specImage: '',
  678. setNum: 1,
  679. isSale: true,
  680. salePrice: 0,
  681. enabledLadder: 0,
  682. ladderPrice: [],
  683. marketPrice: 0,
  684. memberPrice:'',
  685. barCode: '',
  686. weight: '',
  687. isDefault: false
  688. };
  689. index++;
  690. }
  691. }
  692. let newArray = new Array(len - 1);
  693. newArray[0] = temp;
  694. if (len > 2) {
  695. let _count = 1;
  696. for (let i = 2; i < len; i++) {
  697. newArray[_count] = doubleArrays[i];
  698. _count++;
  699. }
  700. }
  701. return this.doExchange(newArray);
  702. } else {
  703. return doubleArrays[0].map(item => {
  704. return {
  705. ...item,
  706. specImage: '',
  707. setNum: 1,
  708. isSale: true,
  709. barCode: '',
  710. weight: '',
  711. isDefault: false,
  712. salePrice: 0,
  713. enabledLadder: false,
  714. ladderPrice: [],
  715. marketPrice: 0,
  716. memberPrice:'',
  717. };
  718. });
  719. }
  720. },
  721. // 删除规格组
  722. deletSpecGroup(index) {
  723. this.spec_group.splice(index, 1);
  724. this.specGroupRest();
  725. },
  726. // 删除规格值
  727. deletSpecValue(index, iVal) {
  728. this.spec_group[index].params.splice(iVal, 1);
  729. this.specGroupRest();
  730. },
  731. // 同步
  732. synchro(key) {
  733. this.specMultipleUnit[this.tab_current].specMultiple.forEach(item => {
  734. item[key] = this.set[key];
  735. });
  736. },
  737. // 阶梯价输入框失去焦点
  738. ladderBlur(e, index) {
  739. let val = Number(e.detail.value);
  740. const target = this.$u.deepClone(this.ladderPrice);
  741. if (val <= target[index].from) {
  742. val = target[index].from + 1;
  743. target[index].to = val;
  744. }
  745. target[index + 1].from = val + 1;
  746. if (index === 0) {
  747. target[index + 1].to = val + 2;
  748. if (target[index + 2]) {
  749. target[index + 2].from = val + 3;
  750. }
  751. }
  752. this.ladderPrice = target;
  753. },
  754. // 阶梯价弹窗确定
  755. ladderPriceConfirm() {
  756. if (this.sku_index === -1) {
  757. this.set.ladderPrice = this.ladderPrice;
  758. } else {
  759. if (this.specType) {
  760. // 多规格
  761. this.specMultipleUnit[this.tab_current].specMultiple[this.sku_index].ladderPrice = this.ladderPrice;
  762. } else {
  763. // 单规格
  764. this.unit_data[this.sku_index].ladderPrice = this.ladderPrice;
  765. }
  766. }
  767. this.ladder_show = false;
  768. },
  769. // 阶梯价删除
  770. delLadderPrice(index) {
  771. const target = this.$u.deepClone(this.ladderPrice);
  772. target.splice(index, 1);
  773. target[0].from = 1;
  774. target[target.length - 1].from = target[0].to + 1;
  775. this.ladderPrice = target;
  776. },
  777. // 打开阶梯价弹窗
  778. openLadder(index, row) {
  779. this.sku_index = index;
  780. this.ladderPrice = row.ladderPrice.length > 0 ? row.ladderPrice : this.$u.deepClone(ladderPrice);
  781. this.ladder_show = true;
  782. },
  783. // 增加一条阶梯价
  784. addLadderprice() {
  785. if (this.ladderPrice.length >= 3) {
  786. return;
  787. }
  788. const target = this.$u.deepClone(this.ladderPrice);
  789. if (!target.length) {
  790. target.push({
  791. from: 1,
  792. price: '',
  793. to: 2
  794. });
  795. } else {
  796. const upL = target[0];
  797. target.splice(1, '', {
  798. from: upL.to + 1,
  799. price: '',
  800. to: upL.to + 2
  801. });
  802. if (target.length === 3) {
  803. target[target.length - 1].from = upL.to + 3;
  804. }
  805. }
  806. this.ladderPrice = target;
  807. },
  808. // 规格确定
  809. skuConfirm() {
  810. if (!this.specType) {
  811. const specMultiple = this.unit_data.map(item => {
  812. const salePriceS = {
  813. conversion: item.conversion || 0,
  814. unitName: item.unitName,
  815. unitId: item.unitId,
  816. isMaster: item.isMaster,
  817. deleteStatus: 4,
  818. enabledLadder: item.enabledLadder ? 1 : 0,
  819. salePriceAreaType: 1,
  820. salePrice: item.salePrice,
  821. ladderPrice: item.ladderPrice,
  822. marketPrice: item.marketPrice,
  823. memberPrice:item.memberPrice,
  824. setNum: item.setNum
  825. };
  826. return {
  827. barCode: item.barCode,
  828. weight: item.weight,
  829. unitId: item.unitId,
  830. unitName: item.unitName,
  831. isMaster: item.isMaster,
  832. conversion: item.conversion || 0,
  833. specImage: item.specImage,
  834. specGroup: [],
  835. salePrice: salePriceS,
  836. customerTypePrice: [],
  837. customerPrice: [],
  838. isDefault: item.isDefault ? 5 : 4
  839. };
  840. });
  841. console.log('specMultiple', specMultiple);
  842. this._prePage().form.specMultiple = specMultiple;
  843. } else {
  844. console.log(this.specMultipleUnit);
  845. let specMultiple = [];
  846. this.specMultipleUnit.forEach(item => {
  847. item.specMultiple.forEach(sku => {
  848. const groupSpecName = sku.groupSpecName.split('_');
  849. const groupSpecId = sku.groupSpecId.toString().split('_');
  850. const specName = sku.specName.split('_');
  851. const specId = sku.specId.toString().split('_');
  852. const specGroup = groupSpecName.map((item, index) => {
  853. return {
  854. specId: groupSpecId[index],
  855. specName: item,
  856. specValueName: specName[index],
  857. specValueId: specId[index]
  858. };
  859. });
  860. specMultiple.push({
  861. barCode: sku.barCode,
  862. weight: sku.weight,
  863. isDefault: sku.isDefault ? 5 : 4,
  864. unitId: item.unitId,
  865. unitName: item.unitName,
  866. isMaster: item.isMaster,
  867. conversion: item.conversion,
  868. specImage: sku.specImage,
  869. specGroup: specGroup,
  870. salePrice: {
  871. unitName: item.unitName,
  872. unitId: item.unitId,
  873. isMaster: item.isMaster,
  874. conversion: item.conversion,
  875. deleteStatus: 4,
  876. enabledLadder: sku.enabledLadder ? 1 : 0,
  877. salePriceAreaType: 1,
  878. salePrice: sku.salePrice,
  879. ladderPrice: sku.ladderPrice,
  880. marketPrice: sku.marketPrice,
  881. memberPrice:sku.memberPrice,
  882. setNum: sku.setNum,
  883. isSale: sku.isSale
  884. },
  885. customerPrice: [],
  886. customerTypePrice: []
  887. });
  888. });
  889. });
  890. const specGroup = this.spec_group.map(item => {
  891. return {
  892. groupSpec: item.groupSpec,
  893. params: item.params.map(sku => {
  894. return {
  895. specValueId: sku.specId,
  896. specValueName: sku.specName
  897. };
  898. })
  899. };
  900. });
  901. console.log('specMultiple', specMultiple);
  902. console.log('spec_group', specGroup);
  903. this._prePage().form.specMultiple = specMultiple;
  904. this._prePage().form.specGroup = specGroup;
  905. }
  906. this._prePage().form.specType = this.specType ? 2 : 1;
  907. console.log('specType', this.specType);
  908. // return
  909. uni.navigateBack();
  910. }
  911. }
  912. };
  913. </script>
  914. <style scoped lang="scss">
  915. .sku-view {
  916. padding-bottom: 140rpx;
  917. .switch-view {
  918. line-height: 100rpx;
  919. padding: 0 24rpx;
  920. background-color: #ffffff;
  921. border-bottom: 1px solid #f5f5f5;
  922. }
  923. }
  924. .sku-name-view {
  925. padding: 0 24rpx;
  926. .sku-ul {
  927. padding-top: 30rpx;
  928. .sku-li {
  929. margin-bottom: 30rpx;
  930. .sku-label {
  931. .float_left {
  932. padding: 0 20rpx;
  933. line-height: 50rpx;
  934. border-radius: 8rpx;
  935. font-size: 24rpx;
  936. display: inline-block;
  937. border: 1px dotted $uni-color-primary;
  938. color: $uni-color-primary;
  939. .custom-icon {
  940. margin-left: 20rpx;
  941. }
  942. }
  943. .sku-val-add-btn {
  944. font-size: 24rpx;
  945. color: $uni-color-primary;
  946. .custom-icon-xinzeng {
  947. font-size: 24rpx;
  948. }
  949. }
  950. }
  951. .sku-val-ul {
  952. padding-top: 14rpx;
  953. .sku-val-li {
  954. padding: 0 20rpx;
  955. line-height: 50rpx;
  956. border-radius: 8rpx;
  957. font-size: 24rpx;
  958. display: inline-block;
  959. background-color: $uni-color-primary;
  960. color: #ffffff;
  961. margin-right: 10rpx;
  962. .custom-icon {
  963. margin-left: 20rpx;
  964. }
  965. }
  966. }
  967. }
  968. }
  969. }
  970. .sku-group {
  971. .sku-group-tit {
  972. padding: 20rpx 24rpx;
  973. line-height: 50rpx;
  974. font-size: 24rpx;
  975. .rest-btn {
  976. line-height: 50rpx;
  977. background-color: $uni-color-primary;
  978. border-radius: 6rpx;
  979. padding: 0 20rpx;
  980. color: #ffffff;
  981. }
  982. }
  983. .sku-group-main {
  984. background-color: #ffffff;
  985. margin-bottom: 30rpx;
  986. .sku-group-label {
  987. line-height: 74rpx;
  988. height: 70rpx;
  989. padding: 0 46rpx;
  990. position: relative;
  991. border-bottom: 1px solid #f5f5f5;
  992. .float_right {
  993. height: 68rpx;
  994. line-height: 68rpx;
  995. .default-label {
  996. font-size: 24rpx;
  997. margin-right: 24rpx;
  998. }
  999. .default-switch {
  1000. display: inline-block;
  1001. vertical-align: middle;
  1002. transform: translateY(4rpx);
  1003. }
  1004. }
  1005. &::before {
  1006. content: '';
  1007. position: absolute;
  1008. display: block;
  1009. width: 6rpx;
  1010. height: 34rpx;
  1011. background-color: $uni-color-primary;
  1012. left: 24rpx;
  1013. top: 50%;
  1014. transform: translateY(-50%);
  1015. }
  1016. }
  1017. .sku-top {
  1018. font-size: 24rpx;
  1019. padding: 20rpx 0;
  1020. display: flex;
  1021. width: 750rpx;
  1022. border-bottom: 1px solid #f5f5f5;
  1023. &:last-child {
  1024. border-bottom: 0 none;
  1025. }
  1026. .sku-top-li {
  1027. flex: 5;
  1028. text-align: center;
  1029. border-right: 1px solid #f5f5f5;
  1030. input {
  1031. border: 1px solid #f5f5f5;
  1032. line-height: 60rpx;
  1033. height: 60rpx;
  1034. display: block;
  1035. margin: 20rpx;
  1036. }
  1037. .other-view {
  1038. margin: 20rpx 0;
  1039. height: 60rpx;
  1040. line-height: 60rpx;
  1041. }
  1042. .label {
  1043. .yuan {
  1044. color: $uni-color-primary;
  1045. }
  1046. }
  1047. .sku-main {
  1048. margin: 20rpx 0;
  1049. }
  1050. .input-view {
  1051. margin: 20rpx 0;
  1052. // min-height: 128rpx;
  1053. view {
  1054. padding-bottom: 10rpx;
  1055. text {
  1056. margin-right: 10rpx;
  1057. }
  1058. input {
  1059. border: 1px solid #f5f5f5;
  1060. line-height: 50rpx;
  1061. height: 50rpx;
  1062. width: 150rpx;
  1063. vertical-align: middle;
  1064. display: inline-block;
  1065. }
  1066. }
  1067. }
  1068. &:last-child {
  1069. border-bottom: 0 none;
  1070. }
  1071. }
  1072. }
  1073. }
  1074. }
  1075. .unit-group {
  1076. margin-top: 20rpx;
  1077. .sku-group-main {
  1078. .sku-top {
  1079. padding-bottom: 0;
  1080. .sku-top-li {
  1081. input {
  1082. border: 1px solid #f5f5f5;
  1083. line-height: 60rpx;
  1084. height: 60rpx;
  1085. display: block;
  1086. margin: 20rpx;
  1087. }
  1088. .sku-main {
  1089. line-height: 60rpx;
  1090. height: 60rpx;
  1091. margin: 20rpx;
  1092. }
  1093. }
  1094. }
  1095. }
  1096. }
  1097. .pop-view {
  1098. .handel-btn {
  1099. padding: 0 30rpx;
  1100. line-height: 90rpx;
  1101. border-bottom: 1px solid #f5f5f5;
  1102. .float_right {
  1103. color: $uni-color-primary;
  1104. }
  1105. }
  1106. .pop-cont {
  1107. max-height: 800rpx;
  1108. overflow: auto;
  1109. padding: 0 30rpx;
  1110. .sku-li {
  1111. line-height: 80rpx;
  1112. border-bottom: 1px solid #f5f5f5;
  1113. .custom-icon {
  1114. font-size: 40rpx;
  1115. color: $uni-color-primary;
  1116. }
  1117. .input-view {
  1118. display: inline-block;
  1119. margin-right: 10rpx;
  1120. input {
  1121. width: 120rpx;
  1122. border: 1px solid #eee;
  1123. border-radius: 4rpx;
  1124. height: 50rpx;
  1125. line-height: 50rpx;
  1126. text-align: center;
  1127. display: inline-block;
  1128. vertical-align: middle;
  1129. margin: 0 10rpx;
  1130. }
  1131. }
  1132. }
  1133. .sku-on {
  1134. color: #999999;
  1135. }
  1136. }
  1137. .btn-view {
  1138. height: 80rpx;
  1139. margin-top: 30rpx;
  1140. line-height: 80rpx;
  1141. text-align: center;
  1142. color: #ffffff;
  1143. background-color: $uni-color-primary;
  1144. &.disabled-btn {
  1145. background-color: #999999;
  1146. }
  1147. }
  1148. }
  1149. </style>