1
0

goods-attr-edit.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. title: '保存中...'
  120. });
  121. if(change) {
  122. uni.removeStorage({
  123. key: 'temp_attr_info'
  124. })
  125. }else {
  126. if(this.attrList.length === 0) {
  127. uni.removeStorage({
  128. key: 'temp_attr_info'
  129. })
  130. }else {
  131. uni.setStorage({
  132. key: "temp_attr_info",
  133. data: this.attrList,
  134. fail(res) {
  135. uni.hideLoading();
  136. uni.showToast({
  137. title: res.errMsg,
  138. icon: 'none',
  139. duration: 1000
  140. });
  141. }
  142. })
  143. }
  144. }
  145. this.attr[this.idx].attr_list = this.list;
  146. uni.setStorage({
  147. key: "temp_attr",
  148. data: this.attr
  149. })
  150. setTimeout(function() {
  151. uni.navigateBack();
  152. }, 500)
  153. },
  154. },
  155. onLoad(options) {
  156. let that = this;
  157. this.idx = options.index;
  158. uni.getStorage({
  159. key: 'temp_attr',
  160. success(res) {
  161. that.attr = res.data;
  162. that.detail = that.attr[options.index];
  163. that.list = JSON.parse(JSON.stringify(that.detail.attr_list));
  164. }
  165. })
  166. uni.getStorage({
  167. key: 'temp_attr_info',
  168. success(res) {
  169. that.attrList = res.data;
  170. }
  171. })
  172. uni.getSystemInfo({
  173. success: function (res) {
  174. 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) {
  175. that.iphone_x = true;
  176. }
  177. }
  178. })
  179. }
  180. }
  181. </script>
  182. <style scoped lang="scss">
  183. .attr {
  184. background-color: #fff;
  185. position: relative;
  186. padding-left: #{84rpx};
  187. margin-bottom: #{20rpx};
  188. .low-attr {
  189. position: absolute;
  190. z-index: 2;
  191. top: #{24rpx};
  192. height: #{40rpx};
  193. width: #{40rpx};
  194. left: #{24rpx};
  195. }
  196. .attr-item {
  197. height: #{88rpx};
  198. line-height: #{88rpx};
  199. border-top: #{2rpx} solid #e2e2e2;
  200. position: relative;
  201. font-size: #{28rpx};
  202. color: #353535;
  203. input {
  204. height: #{88rpx};
  205. line-height: #{88rpx};
  206. }
  207. }
  208. .attr-item:first-of-type {
  209. border-top: 0;
  210. }
  211. }
  212. .add-attr {
  213. height: #{120rpx};
  214. background-color: #fff;
  215. margin-bottom: #{20rpx};
  216. padding-top: #{24rpx};
  217. .add-attr-btn {
  218. height: #{72rpx};
  219. width: #{320rpx};
  220. border-radius: #{36rpx};
  221. border: #{1rpx} solid #446dfd;
  222. margin: 0 auto;
  223. color: #446dfd;
  224. font-size: #{26rpx};
  225. line-height: #{72rpx};
  226. image {
  227. height: #{28rpx};
  228. width: #{28rpx};
  229. margin-right: #{12rpx};
  230. margin-top: #{22rpx};
  231. }
  232. }
  233. }
  234. .add {
  235. position: fixed;
  236. bottom: 0;
  237. left: 0;
  238. height: #{120rpx};
  239. width: 100%;
  240. z-index: 15;
  241. background-color: #fff;
  242. view {
  243. width: #{702rpx};
  244. line-height: #{80rpx};
  245. height: #{80rpx};
  246. margin: #{20rpx} auto;
  247. border-radius: #{40rpx};
  248. background-color: #446dfd;
  249. color: #fff;
  250. font-size: #{32rpx};
  251. text-align: center;
  252. }
  253. }
  254. .add.iphone_x {
  255. height: #{170rpx};
  256. padding-bottom: #{50rpx};
  257. }
  258. .placeholder {
  259. height: #{120rpx};
  260. }
  261. .placeholder.iphone_x {
  262. height: #{170rpx};
  263. }
  264. .dialog {
  265. position: fixed;
  266. height: 100%;
  267. width: 100%;
  268. bottom: 0;
  269. left: 0;
  270. z-index: 10;
  271. background-color: rgba(0, 0, 0, .3);
  272. .dialog-item {
  273. padding-top: #{20rpx};
  274. position: fixed;
  275. top: 25%;
  276. left: 0;
  277. right: 0;
  278. margin: 0 auto;
  279. width: #{620rpx};
  280. border-radius: #{16rpx};
  281. background-color: #fff;
  282. text-align: center;
  283. }
  284. .btn-area {
  285. height: #{88rpx};
  286. position: relative;
  287. border-top: #{1rpx} solid #e2e2e2;
  288. .line {
  289. height: #{32rpx};
  290. width: #{1rpx};
  291. background-color: #e2e2e2;
  292. position: absolute;
  293. top: #{28rpx};
  294. left: 0;
  295. right: 0;
  296. margin: 0 auto;
  297. }
  298. .submit-btn {
  299. height: #{88rpx};
  300. line-height: #{88rpx};
  301. font-size: #{32rpx};
  302. color: #666;
  303. width: #{310rpx};
  304. text-align: center;
  305. }
  306. .submit-btn.be-submit {
  307. color: #446dfd;
  308. }
  309. }
  310. .dialog-title {
  311. text-align: center;
  312. font-size: 32rpx;
  313. color: #353535;
  314. margin: #{66rpx} 0 #{76rpx};
  315. }
  316. }
  317. </style>