goods-attr-edit.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <app-layout>
  3. <view class='add-attr' @click='add_attr'>
  4. <view class='add-attr-btn main-center'>
  5. <image src='./../image/add.png'></image>
  6. <view>增加规格值</view>
  7. </view>
  8. </view>
  9. <view>
  10. <view class="attr" v-for="(item, index) in list" :key="index">
  11. <image @click='pop(index)' class='low-attr' src='./../image/low.png'></image>
  12. <view class="attr-item">
  13. <input placeholder-style="color: #cdcdcd" placeholder="请输入规格值" class='input' v-model="item.attr_name"/>
  14. </view>
  15. </view>
  16. </view>
  17. <view :class="['placeholder', `${iphone_x? 'iphone_x':''}`]"></view>
  18. <view :class="['add', `${iphone_x? 'iphone_x':''}`]">
  19. <view @click="save">保存</view>
  20. </view>
  21. <view class='dialog' v-if="index > -1">
  22. <view class='dialog-item'>
  23. <view class='dialog-title'>确定删除这个规格值吗?</view>
  24. <view class="main-center btn-area">
  25. <view class="submit-btn" @click='close'>取消</view>
  26. <view class="line"></view>
  27. <view class="submit-btn be-submit" @click='toDelete'>删除</view>
  28. </view>
  29. </view>
  30. </view>
  31. </app-layout>
  32. </template>
  33. <script>
  34. import { mapState } from "vuex";
  35. export default {
  36. data() {
  37. return {
  38. iphone_x: false,
  39. detail: {},
  40. index: -1,
  41. list: [],
  42. idx: -1,
  43. attrList: [],
  44. attr: []
  45. }
  46. },
  47. computed: {
  48. ...mapState({
  49. userInfo: state => state.user.info,
  50. adminImg: state => state.mallConfig.__wxapp_img.app_admin
  51. })
  52. },
  53. methods: {
  54. pop(index) {
  55. this.index = index;
  56. },
  57. close() {
  58. this.index = -1;
  59. },
  60. add_attr() {
  61. this.list.push({
  62. attr_id: this.list.length > 0 ? +this.list[this.list.length -1].attr_id + 1 : 1,
  63. attr_name: '',
  64. pic_url: ''
  65. });
  66. },
  67. toDelete() {
  68. let arr = [];
  69. for(let i in this.attrList) {
  70. for(let y in this.attrList[i].attr_list) {
  71. let { attr_group_id, attr_id } = this.attrList[i].attr_list[y];
  72. if(attr_group_id == this.attr[this.idx].attr_group_id && attr_id == this.list[this.index].attr_id) {
  73. arr.unshift(i);
  74. }
  75. }
  76. }
  77. for(let i in arr) {
  78. this.attrList.splice(arr[i],1);
  79. }
  80. this.list.splice(this.index,1);
  81. this.index = -1;
  82. },
  83. save() {
  84. for(let i in this.list) {
  85. if(!this.list[i].attr_name) {
  86. uni.showToast({
  87. title: '请输入规格值',
  88. icon: 'none',
  89. duration: 1000
  90. });
  91. return false
  92. }
  93. for(let j in this.list) {
  94. if(i !== j && this.list[i].attr_name === this.list[j].attr_name) {
  95. uni.showToast({
  96. title: '同一规格组下,规格名不能重复',
  97. icon: 'none',
  98. duration: 1000
  99. });
  100. return false
  101. }
  102. }
  103. }
  104. let change = false;
  105. if(this.list.length > this.attr[this.idx].attr_list.length) {
  106. change = true;
  107. }
  108. for(let i in this.attrList) {
  109. for(let y in this.attrList[i].attr_list) {
  110. for(let j in this.list) {
  111. let { attr_group_id, attr_id } = this.attrList[i].attr_list[y];
  112. if(attr_group_id == this.attr[this.idx].attr_group_id && attr_id == this.list[j].attr_id) {
  113. this.attrList[i].attr_list[y].attr_name = this.list[j].attr_name;
  114. }
  115. }
  116. }
  117. }
  118. uni.showLoading({
  119. mask: true,
  120. title: '保存中...'
  121. });
  122. if(change) {
  123. this.$storage.removeStorageSync('temp_attr_info');
  124. }else {
  125. if(this.attrList.length === 0) {
  126. this.$storage.removeStorageSync('temp_attr_info');
  127. }else {
  128. this.$storage.setStorageSync('temp_attr_info', this.attrList);
  129. }
  130. }
  131. this.attr[this.idx].attr_list = this.list;
  132. this.$storage.setStorageSync('temp_attr', this.attr);
  133. setTimeout(function() {
  134. uni.navigateBack();
  135. }, 500)
  136. },
  137. },
  138. onLoad(options) { this.$commonLoad.onload(options);
  139. let that = this;
  140. that.idx = options.index;
  141. if(that.$storage.getStorageSync('temp_attr')) {
  142. that.attr = that.$storage.getStorageSync('temp_attr');
  143. that.detail = that.attr[options.index];
  144. that.list = JSON.parse(JSON.stringify(that.detail.attr_list));
  145. }
  146. that.attrList = that.$storage.getStorageSync('temp_attr_info') ? that.$storage.getStorageSync('temp_attr_info') : [];
  147. uni.getSystemInfo({
  148. success: function (res) {
  149. 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) {
  150. that.iphone_x = true;
  151. }
  152. }
  153. })
  154. }
  155. }
  156. </script>
  157. <style scoped lang="scss">
  158. .attr {
  159. background-color: #fff;
  160. position: relative;
  161. padding-left: #{84rpx};
  162. margin-bottom: #{20rpx};
  163. .low-attr {
  164. position: absolute;
  165. z-index: 2;
  166. top: #{24rpx};
  167. height: #{40rpx};
  168. width: #{40rpx};
  169. left: #{24rpx};
  170. }
  171. .attr-item {
  172. height: #{88rpx};
  173. line-height: #{88rpx};
  174. border-top: #{2rpx} solid #e2e2e2;
  175. position: relative;
  176. font-size: #{28rpx};
  177. color: #353535;
  178. input {
  179. height: #{88rpx};
  180. line-height: #{88rpx};
  181. }
  182. }
  183. .attr-item:first-of-type {
  184. border-top: 0;
  185. }
  186. }
  187. .add-attr {
  188. height: #{120rpx};
  189. background-color: #fff;
  190. margin-bottom: #{20rpx};
  191. padding-top: #{24rpx};
  192. .add-attr-btn {
  193. height: #{72rpx};
  194. width: #{320rpx};
  195. border-radius: #{36rpx};
  196. border: #{1rpx} solid #446dfd;
  197. margin: 0 auto;
  198. color: #446dfd;
  199. font-size: #{26rpx};
  200. line-height: #{72rpx};
  201. image {
  202. height: #{28rpx};
  203. width: #{28rpx};
  204. margin-right: #{12rpx};
  205. margin-top: #{22rpx};
  206. }
  207. }
  208. }
  209. .add {
  210. position: fixed;
  211. bottom: 0;
  212. left: 0;
  213. height: #{120rpx};
  214. width: 100%;
  215. z-index: 15;
  216. background-color: #fff;
  217. view {
  218. width: #{702rpx};
  219. line-height: #{80rpx};
  220. height: #{80rpx};
  221. margin: #{20rpx} auto;
  222. border-radius: #{40rpx};
  223. background-color: #446dfd;
  224. color: #fff;
  225. font-size: #{32rpx};
  226. text-align: center;
  227. }
  228. }
  229. .add.iphone_x {
  230. height: #{170rpx};
  231. padding-bottom: #{50rpx};
  232. }
  233. .placeholder {
  234. height: #{120rpx};
  235. }
  236. .placeholder.iphone_x {
  237. height: #{170rpx};
  238. }
  239. .dialog {
  240. position: fixed;
  241. height: 100%;
  242. width: 100%;
  243. bottom: 0;
  244. left: 0;
  245. z-index: 10;
  246. background-color: rgba(0, 0, 0, .3);
  247. .dialog-item {
  248. padding-top: #{20rpx};
  249. position: fixed;
  250. top: 25%;
  251. left: 0;
  252. right: 0;
  253. margin: 0 auto;
  254. width: #{620rpx};
  255. border-radius: #{16rpx};
  256. background-color: #fff;
  257. text-align: center;
  258. }
  259. .btn-area {
  260. height: #{88rpx};
  261. position: relative;
  262. border-top: #{1rpx} solid #e2e2e2;
  263. .line {
  264. height: #{32rpx};
  265. width: #{1rpx};
  266. background-color: #e2e2e2;
  267. position: absolute;
  268. top: #{28rpx};
  269. left: 0;
  270. right: 0;
  271. margin: 0 auto;
  272. }
  273. .submit-btn {
  274. height: #{88rpx};
  275. line-height: #{88rpx};
  276. font-size: #{32rpx};
  277. color: #666;
  278. width: #{310rpx};
  279. text-align: center;
  280. }
  281. .submit-btn.be-submit {
  282. color: #446dfd;
  283. }
  284. }
  285. .dialog-title {
  286. text-align: center;
  287. font-size: 32rpx;
  288. color: #353535;
  289. margin: #{66rpx} 0 #{76rpx};
  290. }
  291. }
  292. </style>