goods-attr.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <template>
  2. <app-layout>
  3. <view>
  4. <view class="attr" v-for="(item,index) in list" :key="index">
  5. <image @click='pop(index)' class='low-attr' src='./../image/low.png'></image>
  6. <view class="attr-item dir-left-nowrap">
  7. <view class="attr-label">规格名</view>
  8. <view class='dir-left-nowrap cross-center'>
  9. <input placeholder-style="color: #cdcdcd" placeholder="请输入规格" @input="changeName(item)" class='input' v-model="item.attr_group_name"></input>
  10. </view>
  11. </view>
  12. <view class="attr-item dir-left-nowrap">
  13. <view class="attr-label">规格值</view>
  14. <view @click="changeValue(index)">
  15. <view class="attr_name" v-if="item.attr_list.length > 0">
  16. <image class="to-more" src='/static/image/icon/arrow-right.png'></image>
  17. <view class="attr-name-list t-omit">
  18. <text v-for="(attr,idx) in item.attr_list" :key="idx"><text v-if="idx > 0">;</text>{{attr.attr_name}}</text>
  19. </view>
  20. </view>
  21. <view v-else class='cat-info dir-right-nowrap cross-center'>
  22. <image class="to-more" src='/static/image/icon/arrow-right.png'></image>
  23. <text style="color: #cdcdcd">未选择</text>
  24. </view>
  25. </view>
  26. <view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class='title'>设置价格、库存等规格明细</view>
  32. <view class='info-item cross-center main-between'>
  33. <view class="form-label">规格明细</view>
  34. <view @click="chooseDetail">
  35. <view class='cat-info dir-right-nowrap cross-center'>
  36. <image class="to-more" src='/static/image/icon/arrow-right.png'></image>
  37. <text v-if="attr.length > 0">已设置</text>
  38. <text style="color: #cdcdcd" v-else>未设置,点击设置</text>
  39. </view>
  40. </view>
  41. </view>
  42. <view v-if="list.length < 5" class='add-attr' @click='add_attr'>
  43. <view class='add-attr-btn main-center'>
  44. <image src='./../image/add.png'></image>
  45. <view>增加规格</view>
  46. </view>
  47. </view>
  48. <view :class="['placeholder', `${iphone_x? 'iphone_x':''}`]"></view>
  49. <view :class="['add', `${iphone_x? 'iphone_x':''}`]">
  50. <view @click="save">保存</view>
  51. </view>
  52. <view class='dialog' v-if="index > -1">
  53. <view class='dialog-item'>
  54. <view class='dialog-title'>确定删除这个规格吗?</view>
  55. <view class="submit-info">删除后,规格名与规格值都将被删除</view>
  56. <view class="main-center btn-area">
  57. <view class="submit-btn" @click='close'>取消</view>
  58. <view class="line"></view>
  59. <view class="submit-btn be-submit" @click='toDelete'>确认</view>
  60. </view>
  61. </view>
  62. </view>
  63. </app-layout>
  64. </template>
  65. <script>
  66. import { mapState } from "vuex";
  67. export default {
  68. data() {
  69. return {
  70. list: [],
  71. attr: [],
  72. iphone_x: false,
  73. noDetail: true,
  74. first: true,
  75. index: -1,
  76. }
  77. },
  78. computed: {
  79. ...mapState({
  80. theme: state => state.mallConfig.theme,
  81. })
  82. },
  83. methods: {
  84. changeName(item) {
  85. let that = this;
  86. if(that.attr.length > 0) {
  87. for(let i in that.attr) {
  88. for(let j in that.attr[i].attr_list) {
  89. if(item.attr_group_id == that.attr[i].attr_list[j].attr_group_id) {
  90. that.attr[i].attr_list[j].attr_group_name = item.attr_group_name
  91. }
  92. }
  93. }
  94. uni.setStorage({
  95. key: "temp_attr_info",
  96. data: that.attr,
  97. success(res) {
  98. uni.hideLoading();
  99. },
  100. fail(res) {
  101. uni.hideLoading();
  102. uni.showToast({
  103. title: res.errMsg,
  104. icon: 'none',
  105. duration: 1000
  106. });
  107. }
  108. })
  109. }
  110. },
  111. pop(index) {
  112. this.index = index;
  113. if(!this.list[this.index].attr_group_name && this.list[this.index].attr_list.length == 0) {
  114. this.list.splice(this.index,1);
  115. this.index = -1;
  116. this.attr = [];
  117. uni.removeStorage({
  118. key: 'temp_attr_info',
  119. success(res) {
  120. }
  121. })
  122. }
  123. },
  124. close() {
  125. this.index = -1;
  126. },
  127. changeValue(index) {
  128. uni.setStorage({
  129. key: "temp_attr",
  130. data: this.list
  131. })
  132. uni.navigateTo({
  133. url: '/pages/app_admin/goods-attr-edit/goods-attr-edit?index=' + index
  134. })
  135. },
  136. chooseDetail() {
  137. let that = this;
  138. if(that.list.length == 0) {
  139. uni.showToast({
  140. title: '请输入规格信息',
  141. icon: 'none',
  142. duration: 1000
  143. });
  144. return false
  145. }else {
  146. let number = 1;
  147. for(let i in that.list) {
  148. number *= +that.list[i].attr_list.length;
  149. }
  150. if(number > 1000) {
  151. uni.showToast({
  152. title: '规格组合超出1000,请删减规格值再继续操作',
  153. icon: 'none',
  154. duration: 1000
  155. });
  156. return false
  157. }
  158. }
  159. for(let i in that.list) {
  160. if(!that.list[i].attr_group_name || that.list[i].attr_list.length == 0) {
  161. uni.showToast({
  162. title: '请完善规格信息',
  163. icon: 'none',
  164. duration: 1000
  165. });
  166. return false
  167. }
  168. }
  169. uni.setStorage({
  170. key: "temp_attr",
  171. data: that.list
  172. })
  173. uni.navigateTo({
  174. url: '/pages/app_admin/goods-attr-info/goods-attr-info'
  175. })
  176. },
  177. toDelete() {
  178. this.list.splice(this.index,1);
  179. this.index = -1;
  180. this.attr = [];
  181. uni.removeStorage({
  182. key: 'temp_attr_info',
  183. success(res) {
  184. }
  185. })
  186. },
  187. save() {
  188. let that = this;
  189. if(that.list.length == 0) {
  190. uni.showToast({
  191. title: '请输入规格信息',
  192. icon: 'none',
  193. duration: 1000
  194. });
  195. return false
  196. }
  197. for(let i in that.list) {
  198. if(!that.list[i].attr_group_name || that.list[i].attr_list.length == 0 || that.attr.length == 0) {
  199. uni.showToast({
  200. title: '请完善规格信息',
  201. icon: 'none',
  202. duration: 1000
  203. });
  204. return false
  205. }
  206. }
  207. uni.setStorage({
  208. key: "goods_attr_groups",
  209. data: that.list
  210. })
  211. uni.showLoading({
  212. title: '保存中...'
  213. });
  214. uni.setStorage({
  215. key: "goods_attr",
  216. data: that.attr,
  217. success(res) {
  218. uni.hideLoading();
  219. setTimeout(function() {
  220. uni.navigateBack();
  221. }, 500)
  222. },
  223. fail(res) {
  224. uni.hideLoading();
  225. uni.showToast({
  226. title: res.errMsg,
  227. icon: 'none',
  228. duration: 1000
  229. });
  230. }
  231. })
  232. },
  233. add_attr() {
  234. let that = this;
  235. let para = {
  236. attr_group_id: that.list.length + 1,
  237. attr_group_name: '',
  238. attr_list: []
  239. }
  240. that.list.push(para)
  241. that.attr = [];
  242. uni.removeStorage({
  243. key: 'temp_attr_info',
  244. success(res) {
  245. }
  246. })
  247. }
  248. },
  249. onLoad(options) {
  250. let that = this;
  251. that.$showLoading({
  252. type: 'global',
  253. text: '加载中...'
  254. });
  255. let loadAttr = false;
  256. uni.getStorage({
  257. key: 'goods_attr_groups',
  258. success(res) {
  259. that.list = res.data
  260. uni.setStorage({
  261. key: "temp_attr",
  262. data: that.list
  263. })
  264. loadAttr = true;
  265. },
  266. fail(res) {
  267. uni.getStorage({
  268. key: 'temp_attr',
  269. success(res) {
  270. that.list = res.data;
  271. }
  272. })
  273. loadAttr = true;
  274. }
  275. })
  276. uni.getStorage({
  277. key: 'goods_attr',
  278. success(res) {
  279. that.attr = res.data;
  280. uni.setStorage({
  281. key: "temp_attr_info",
  282. data: res.data
  283. })
  284. that.$hideLoading();
  285. that.first = false;
  286. },
  287. fail(res) {
  288. uni.getStorage({
  289. key: 'temp_attr_info',
  290. success(res) {
  291. that.attr = res.data;
  292. that.first = false;
  293. that.$hideLoading();
  294. },
  295. fail(res) {
  296. that.first = false;
  297. that.$hideLoading();
  298. }
  299. })
  300. }
  301. })
  302. uni.getSystemInfo({
  303. success: function (res) {
  304. if(res.model.indexOf('iPhone X') > -1 || res.model.indexOf('iPhone 11') > -1 || res.model.indexOf('iPhone11') > -1 || res.model.indexOf('iPhone12') > -1 || res.model.indexOf('Unknown Device') > -1) {
  305. that.iphone_x = true;
  306. }
  307. }
  308. })
  309. },
  310. onShow() {
  311. let that = this;
  312. if(!that.first) {
  313. uni.getStorage({
  314. key: 'temp_attr',
  315. success(res) {
  316. that.list = res.data
  317. },
  318. fail() {
  319. that.list = [];
  320. }
  321. })
  322. uni.getStorage({
  323. key: 'temp_attr_info',
  324. success(res) {
  325. that.attr = res.data;
  326. },
  327. fail() {
  328. that.attr = [];
  329. }
  330. })
  331. }
  332. }
  333. }
  334. </script>
  335. <style scoped lang="scss">
  336. .attr {
  337. background-color: #fff;
  338. position: relative;
  339. padding-left: #{84rpx};
  340. margin-bottom: #{20rpx};
  341. .low-attr {
  342. position: absolute;
  343. z-index: 2;
  344. top: #{24rpx};
  345. height: #{40rpx};
  346. width: #{40rpx};
  347. left: #{24rpx};
  348. }
  349. .attr-item {
  350. height: #{88rpx};
  351. line-height: #{88rpx};
  352. border-top: #{2rpx} solid #e2e2e2;
  353. position: relative;
  354. font-size: #{28rpx};
  355. color: #999;
  356. color: #353535;
  357. .attr-label {
  358. width: #{174rpx};
  359. flex-shrink: 0;
  360. }
  361. .attr_name {
  362. .to-more {
  363. right: #{24rpx};
  364. top: #{32rpx};
  365. position: absolute;
  366. margin-left: 0;
  367. }
  368. .attr-name-list {
  369. width: #{432rpx};
  370. }
  371. }
  372. .cat-info {
  373. width: #{442rpx};
  374. }
  375. .to-more {
  376. height: #{24rpx};
  377. width: #{12rpx};
  378. margin-left: #{10rpx};
  379. }
  380. }
  381. .attr-item:first-of-type {
  382. border-top: 0;
  383. }
  384. }
  385. .title {
  386. font-size: #{28rpx};
  387. color: #999;
  388. margin: #{30rpx} #{24rpx} #{13rpx};
  389. }
  390. .info-item {
  391. height: #{88rpx};
  392. line-height: #{88rpx};
  393. font-size: #{28rpx};
  394. background-color: #fff;
  395. padding: 0 #{24rpx};
  396. color: #353535;
  397. .form-label {
  398. width: #{176rpx};
  399. }
  400. .cat-info {
  401. width: #{526rpx};
  402. color: #666;
  403. .to-more {
  404. height: #{24rpx};
  405. width: #{12rpx};
  406. margin-left: #{10rpx};
  407. }
  408. }
  409. }
  410. .add-attr {
  411. height: #{120rpx};
  412. background-color: #fff;
  413. margin-top: 20rpx;
  414. padding-top: #{24rpx};
  415. .add-attr-btn {
  416. height: #{72rpx};
  417. width: #{320rpx};
  418. border-radius: #{36rpx};
  419. border: #{2rpx} solid #446dfd;
  420. margin: 0 auto;
  421. color: #446dfd;
  422. font-size: #{26rpx};
  423. line-height: #{72rpx};
  424. image {
  425. height: #{28rpx};
  426. width: #{28rpx};
  427. margin-right: #{12rpx};
  428. margin-top: #{22rpx};
  429. }
  430. }
  431. }
  432. .add {
  433. position: fixed;
  434. bottom: 0;
  435. left: 0;
  436. height: #{120rpx};
  437. width: 100%;
  438. z-index: 15;
  439. background-color: #fff;
  440. view {
  441. width: #{702rpx};
  442. line-height: #{80rpx};
  443. height: #{80rpx};
  444. margin: #{20rpx} auto;
  445. border-radius: #{40rpx};
  446. background-color: #446dfd;
  447. color: #fff;
  448. font-size: #{32rpx};
  449. text-align: center;
  450. }
  451. }
  452. .add.iphone_x {
  453. height: #{170rpx};
  454. padding-bottom: #{50rpx};
  455. }
  456. .placeholder {
  457. height: #{120rpx};
  458. }
  459. .placeholder.iphone_x {
  460. height: #{170rpx};
  461. }
  462. .dialog {
  463. position: fixed;
  464. height: 100%;
  465. width: 100%;
  466. bottom: 0;
  467. left: 0;
  468. z-index: 10;
  469. background-color: rgba(0, 0, 0, .3);
  470. .dialog-item {
  471. padding-top: #{20rpx};
  472. position: fixed;
  473. top: 25%;
  474. left: 0;
  475. right: 0;
  476. margin: 0 auto;
  477. width: #{620rpx};
  478. border-radius: #{16rpx};
  479. background-color: #fff;
  480. text-align: center;
  481. }
  482. .submit-info {
  483. font-size: #{28rpx};
  484. color: #999999;
  485. padding: #{34rpx} 0 #{52rpx};
  486. }
  487. .btn-area {
  488. height: #{88rpx};
  489. position: relative;
  490. border-top: #{1rpx} solid #e2e2e2;
  491. .line {
  492. height: #{32rpx};
  493. width: #{1rpx};
  494. background-color: #e2e2e2;
  495. position: absolute;
  496. top: #{28rpx};
  497. left: 0;
  498. right: 0;
  499. margin: 0 auto;
  500. }
  501. .submit-btn {
  502. height: #{88rpx};
  503. line-height: #{88rpx};
  504. font-size: #{32rpx};
  505. color: #666;
  506. width: #{310rpx};
  507. text-align: center;
  508. }
  509. .submit-btn.be-submit {
  510. color: #446dfd;
  511. }
  512. }
  513. .dialog-title {
  514. text-align: center;
  515. font-size: #{32rpx};
  516. color: #353535;
  517. margin: #{23rpx} 0 0;
  518. }
  519. }
  520. </style>