goods-attr.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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"/>
  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. export default {
  67. data() {
  68. return {
  69. list: [],
  70. attr: [],
  71. iphone_x: false,
  72. noDetail: true,
  73. first: true,
  74. index: -1,
  75. }
  76. },
  77. methods: {
  78. changeName(item) {
  79. let that = this;
  80. if(this.attr.length > 0) {
  81. for(let i in this.attr) {
  82. for(let j in this.attr[i].attr_list) {
  83. if(item.attr_group_id == this.attr[i].attr_list[j].attr_group_id) {
  84. this.attr[i].attr_list[j].attr_group_name = item.attr_group_name;
  85. }
  86. }
  87. }
  88. this.$storage.setStorageSync('temp_attr_info', that.attr);
  89. uni.hideLoading();
  90. }
  91. },
  92. pop(index) {
  93. this.index = index;
  94. if(!this.list[this.index].attr_group_name && this.list[this.index].attr_list.length === 0) {
  95. this.list.splice(this.index,1);
  96. this.index = -1;
  97. this.attr = [];
  98. this.$storage.removeStorageSync('temp_attr_info');
  99. }
  100. },
  101. close() {
  102. this.index = -1;
  103. },
  104. changeValue(index) {
  105. this.$storage.setStorageSync('temp_attr', this.list);
  106. uni.navigateTo({
  107. url: `/pages/app_admin/goods-attr-edit/goods-attr-edit?index=${index}`
  108. })
  109. },
  110. chooseDetail() {
  111. if(this.list.length === 0) {
  112. uni.showToast({
  113. title: '请输入规格信息',
  114. icon: 'none',
  115. duration: 1000
  116. });
  117. return false
  118. }else {
  119. let number = 1;
  120. for(let i in this.list) {
  121. number *= +this.list[i].attr_list.length;
  122. }
  123. if(number > 1000) {
  124. uni.showToast({
  125. title: '规格组合超出1000,请删减规格值再继续操作',
  126. icon: 'none',
  127. duration: 1000
  128. });
  129. return false
  130. }
  131. }
  132. for(let i in this.list) {
  133. if(!this.list[i].attr_group_name || this.list[i].attr_list.length == 0) {
  134. uni.showToast({
  135. title: '请完善规格信息',
  136. icon: 'none',
  137. duration: 1000
  138. });
  139. return false;
  140. }
  141. }
  142. this.$storage.setStorageSync('temp_attr', this.list);
  143. uni.navigateTo({
  144. url: '/pages/app_admin/goods-attr-info/goods-attr-info'
  145. })
  146. },
  147. toDelete() {
  148. this.list.splice(this.index,1);
  149. this.index = -1;
  150. this.attr = [];
  151. this.$storage.removeStorageSync('temp_attr_info');
  152. },
  153. save() {
  154. let that = this;
  155. if(that.list.length === 0) {
  156. uni.showToast({
  157. title: '请输入规格信息',
  158. icon: 'none',
  159. duration: 1000
  160. });
  161. return false
  162. }
  163. for(let i in that.list) {
  164. if(!that.list[i].attr_group_name || that.list[i].attr_list.length === 0 || that.attr.length === 0) {
  165. uni.showToast({
  166. title: '请完善规格信息',
  167. icon: 'none',
  168. duration: 1000
  169. });
  170. return false;
  171. }
  172. }
  173. this.$storage.setStorageSync('goods_attr_groups', this.list);
  174. uni.showLoading({
  175. mask: true,
  176. title: '保存中...'
  177. });
  178. this.$storage.setStorageSync('goods_attr', this.attr);
  179. setTimeout(function() {
  180. uni.hideLoading();
  181. uni.navigateBack();
  182. }, 500);
  183. },
  184. add_attr() {
  185. this.list.push({
  186. attr_group_id: this.list.length + 1,
  187. attr_group_name: '',
  188. attr_list: []
  189. });
  190. this.attr = [];
  191. this.$storage.removeStorageSync('temp_attr_info');
  192. }
  193. },
  194. onLoad() { this.$commonLoad.onload();
  195. let that = this;
  196. that.$showLoading({
  197. type: 'global',
  198. text: '加载中...'
  199. });
  200. let loadAttr = false;
  201. if(that.$storage.getStorageSync('goods_attr_groups')) {
  202. that.list = that.$storage.getStorageSync('goods_attr_groups');
  203. that.$storage.setStorageSync('temp_attr', that.list);
  204. loadAttr = true;
  205. }else {
  206. that.list = that.$storage.getStorageSync('temp_attr');
  207. loadAttr = true;
  208. }
  209. if(that.$storage.getStorageSync('goods_attr')) {
  210. that.attr = that.$storage.getStorageSync('goods_attr');
  211. that.$storage.setStorageSync('temp_attr_info', that.$storage.getStorageSync('goods_attr'));
  212. that.$hideLoading();
  213. that.first = false;
  214. }else {
  215. that.first = false;
  216. that.$hideLoading();
  217. }
  218. uni.getSystemInfo({
  219. success: function (res) {
  220. 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) {
  221. that.iphone_x = true;
  222. }
  223. }
  224. })
  225. },
  226. onShow() {
  227. let that = this;
  228. if(!this.first) {
  229. that.list = that.$storage.getStorageSync('temp_attr') ? that.$storage.getStorageSync('temp_attr') : [];
  230. that.attr = that.$storage.getStorageSync('temp_attr_info') ? that.$storage.getStorageSync('temp_attr_info') : [];
  231. }
  232. }
  233. }
  234. </script>
  235. <style scoped lang="scss">
  236. .attr {
  237. background-color: #fff;
  238. position: relative;
  239. padding-left: #{84rpx};
  240. margin-bottom: #{20rpx};
  241. .low-attr {
  242. position: absolute;
  243. z-index: 2;
  244. top: #{24rpx};
  245. height: #{40rpx};
  246. width: #{40rpx};
  247. left: #{24rpx};
  248. }
  249. .attr-item {
  250. height: #{88rpx};
  251. line-height: #{88rpx};
  252. border-top: #{2rpx} solid #e2e2e2;
  253. position: relative;
  254. font-size: #{28rpx};
  255. color: #999;
  256. color: #353535;
  257. .attr-label {
  258. width: #{174rpx};
  259. flex-shrink: 0;
  260. }
  261. .attr_name {
  262. .to-more {
  263. right: #{24rpx};
  264. top: #{32rpx};
  265. position: absolute;
  266. margin-left: 0;
  267. }
  268. .attr-name-list {
  269. width: #{432rpx};
  270. }
  271. }
  272. .cat-info {
  273. width: #{442rpx};
  274. }
  275. .to-more {
  276. height: #{24rpx};
  277. width: #{12rpx};
  278. margin-left: #{10rpx};
  279. }
  280. }
  281. .attr-item:first-of-type {
  282. border-top: 0;
  283. }
  284. }
  285. .title {
  286. font-size: #{28rpx};
  287. color: #999;
  288. margin: #{30rpx} #{24rpx} #{13rpx};
  289. }
  290. .info-item {
  291. height: #{88rpx};
  292. line-height: #{88rpx};
  293. font-size: #{28rpx};
  294. background-color: #fff;
  295. padding: 0 #{24rpx};
  296. color: #353535;
  297. .form-label {
  298. width: #{176rpx};
  299. }
  300. .cat-info {
  301. width: #{526rpx};
  302. color: #666;
  303. .to-more {
  304. height: #{24rpx};
  305. width: #{12rpx};
  306. margin-left: #{10rpx};
  307. }
  308. }
  309. }
  310. .add-attr {
  311. height: #{120rpx};
  312. background-color: #fff;
  313. margin-top: 20rpx;
  314. padding-top: #{24rpx};
  315. .add-attr-btn {
  316. height: #{72rpx};
  317. width: #{320rpx};
  318. border-radius: #{36rpx};
  319. border: #{2rpx} solid #446dfd;
  320. margin: 0 auto;
  321. color: #446dfd;
  322. font-size: #{26rpx};
  323. line-height: #{72rpx};
  324. image {
  325. height: #{28rpx};
  326. width: #{28rpx};
  327. margin-right: #{12rpx};
  328. margin-top: #{22rpx};
  329. }
  330. }
  331. }
  332. .add {
  333. position: fixed;
  334. bottom: 0;
  335. left: 0;
  336. height: #{120rpx};
  337. width: 100%;
  338. z-index: 15;
  339. background-color: #fff;
  340. view {
  341. width: #{702rpx};
  342. line-height: #{80rpx};
  343. height: #{80rpx};
  344. margin: #{20rpx} auto;
  345. border-radius: #{40rpx};
  346. background-color: #446dfd;
  347. color: #fff;
  348. font-size: #{32rpx};
  349. text-align: center;
  350. }
  351. }
  352. .add.iphone_x {
  353. height: #{170rpx};
  354. padding-bottom: #{50rpx};
  355. }
  356. .placeholder {
  357. height: #{120rpx};
  358. }
  359. .placeholder.iphone_x {
  360. height: #{170rpx};
  361. }
  362. .dialog {
  363. position: fixed;
  364. height: 100%;
  365. width: 100%;
  366. bottom: 0;
  367. left: 0;
  368. z-index: 10;
  369. background-color: rgba(0, 0, 0, .3);
  370. .dialog-item {
  371. padding-top: #{20rpx};
  372. position: fixed;
  373. top: 25%;
  374. left: 0;
  375. right: 0;
  376. margin: 0 auto;
  377. width: #{620rpx};
  378. border-radius: #{16rpx};
  379. background-color: #fff;
  380. text-align: center;
  381. }
  382. .submit-info {
  383. font-size: #{28rpx};
  384. color: #999999;
  385. padding: #{34rpx} 0 #{52rpx};
  386. }
  387. .btn-area {
  388. height: #{88rpx};
  389. position: relative;
  390. border-top: #{1rpx} solid #e2e2e2;
  391. .line {
  392. height: #{32rpx};
  393. width: #{1rpx};
  394. background-color: #e2e2e2;
  395. position: absolute;
  396. top: #{28rpx};
  397. left: 0;
  398. right: 0;
  399. margin: 0 auto;
  400. }
  401. .submit-btn {
  402. height: #{88rpx};
  403. line-height: #{88rpx};
  404. font-size: #{32rpx};
  405. color: #666;
  406. width: #{310rpx};
  407. text-align: center;
  408. }
  409. .submit-btn.be-submit {
  410. color: #446dfd;
  411. }
  412. }
  413. .dialog-title {
  414. text-align: center;
  415. font-size: #{32rpx};
  416. color: #353535;
  417. margin: #{23rpx} 0 0;
  418. }
  419. }
  420. </style>