goods-attr-edit.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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"></input>
  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. theme: state => state.mallConfig.theme,
  50. userInfo: state => state.user.info,
  51. adminImg: state => state.mallConfig.__wxapp_img.app_admin,
  52. })
  53. },
  54. methods: {
  55. pop(index) {
  56. this.index = index;
  57. },
  58. close() {
  59. this.index = -1;
  60. },
  61. add_attr() {
  62. let that = this;
  63. let para = {
  64. attr_id: that.list.length > 0 ? +that.list[that.list.length -1].attr_id + 1: 1,
  65. attr_name: '',
  66. pic_url: []
  67. }
  68. that.list.push(para);
  69. },
  70. toDelete() {
  71. let that = this;
  72. let arr = [];
  73. for(let i in that.attrList) {
  74. for(let y in that.attrList[i].attr_list) {
  75. if(that.attrList[i].attr_list[y].attr_group_id == that.attr[that.idx].attr_group_id && that.attrList[i].attr_list[y].attr_id == that.list[that.index].attr_id) {
  76. arr.unshift(i);
  77. }
  78. }
  79. }
  80. for(let i in arr) {
  81. that.attrList.splice(arr[i],1)
  82. }
  83. that.list.splice(that.index,1);
  84. that.index = -1;
  85. },
  86. save() {
  87. let that = this;
  88. for(let i in that.list) {
  89. if(!that.list[i].attr_name) {
  90. uni.showToast({
  91. title: '请输入规格值',
  92. icon: 'none',
  93. duration: 1000
  94. });
  95. return false
  96. }
  97. for(let j in that.list) {
  98. if(i != j && that.list[i].attr_name == that.list[j].attr_name) {
  99. uni.showToast({
  100. title: '同一规格组下,规格名不能重复',
  101. icon: 'none',
  102. duration: 1000
  103. });
  104. return false
  105. }
  106. }
  107. }
  108. let change = false;
  109. if(that.list.length > that.attr[that.idx].attr_list.length) {
  110. change = true;
  111. }
  112. for(let i in that.attrList) {
  113. for(let y in that.attrList[i].attr_list) {
  114. for(let j in that.list) {
  115. if(that.attrList[i].attr_list[y].attr_group_id == that.attr[that.idx].attr_group_id && that.attrList[i].attr_list[y].attr_id == that.list[j].attr_id) {
  116. that.attrList[i].attr_list[y].attr_name = that.list[j].attr_name
  117. }
  118. }
  119. }
  120. }
  121. uni.showLoading({
  122. title: '保存中...'
  123. });
  124. if(change) {
  125. uni.removeStorage({
  126. key: 'temp_attr_info',
  127. success(res) {
  128. }
  129. })
  130. }else {
  131. if(that.attrList.length == 0) {
  132. uni.removeStorage({
  133. key: 'temp_attr_info',
  134. success(res) {
  135. console.log(res)
  136. }
  137. })
  138. }else {
  139. uni.setStorage({
  140. key: "temp_attr_info",
  141. data: that.attrList,
  142. success(res) {
  143. },
  144. fail(res) {
  145. uni.hideLoading();
  146. uni.showToast({
  147. title: res.errMsg,
  148. icon: 'none',
  149. duration: 1000
  150. });
  151. }
  152. })
  153. }
  154. }
  155. that.attr[that.idx].attr_list = that.list;
  156. uni.setStorage({
  157. key: "temp_attr",
  158. data: that.attr
  159. })
  160. setTimeout(function() {
  161. uni.navigateBack();
  162. }, 500)
  163. },
  164. },
  165. onLoad(options) {
  166. let that = this;
  167. that.idx = options.index;
  168. uni.getStorage({
  169. key: 'temp_attr',
  170. success(res) {
  171. that.attr = res.data;
  172. that.detail = that.attr[options.index];
  173. that.list = JSON.parse(JSON.stringify(that.detail.attr_list));
  174. }
  175. })
  176. uni.getStorage({
  177. key: 'temp_attr_info',
  178. success(res) {
  179. that.attrList = res.data;
  180. }
  181. })
  182. uni.getSystemInfo({
  183. success: function (res) {
  184. 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) {
  185. that.iphone_x = true;
  186. }
  187. }
  188. })
  189. }
  190. }
  191. </script>
  192. <style scoped lang="scss">
  193. .attr {
  194. background-color: #fff;
  195. position: relative;
  196. padding-left: #{84rpx};
  197. margin-bottom: #{20rpx};
  198. .low-attr {
  199. position: absolute;
  200. z-index: 2;
  201. top: #{24rpx};
  202. height: #{40rpx};
  203. width: #{40rpx};
  204. left: #{24rpx};
  205. }
  206. .attr-item {
  207. height: #{88rpx};
  208. line-height: #{88rpx};
  209. border-top: #{2rpx} solid #e2e2e2;
  210. position: relative;
  211. font-size: #{28rpx};
  212. color: #353535;
  213. input {
  214. height: #{88rpx};
  215. line-height: #{88rpx};
  216. }
  217. }
  218. .attr-item:first-of-type {
  219. border-top: 0;
  220. }
  221. }
  222. .add-attr {
  223. height: #{120rpx};
  224. background-color: #fff;
  225. margin-bottom: #{20rpx};
  226. padding-top: #{24rpx};
  227. .add-attr-btn {
  228. height: #{72rpx};
  229. width: #{320rpx};
  230. border-radius: #{36rpx};
  231. border: #{1rpx} solid #446dfd;
  232. margin: 0 auto;
  233. color: #446dfd;
  234. font-size: #{26rpx};
  235. line-height: #{72rpx};
  236. image {
  237. height: #{28rpx};
  238. width: #{28rpx};
  239. margin-right: #{12rpx};
  240. margin-top: #{22rpx};
  241. }
  242. }
  243. }
  244. .add {
  245. position: fixed;
  246. bottom: 0;
  247. left: 0;
  248. height: #{120rpx};
  249. width: 100%;
  250. z-index: 15;
  251. background-color: #fff;
  252. view {
  253. width: #{702rpx};
  254. line-height: #{80rpx};
  255. height: #{80rpx};
  256. margin: #{20rpx} auto;
  257. border-radius: #{40rpx};
  258. background-color: #446dfd;
  259. color: #fff;
  260. font-size: #{32rpx};
  261. text-align: center;
  262. }
  263. }
  264. .add.iphone_x {
  265. height: #{170rpx};
  266. padding-bottom: #{50rpx};
  267. }
  268. .placeholder {
  269. height: #{120rpx};
  270. }
  271. .placeholder.iphone_x {
  272. height: #{170rpx};
  273. }
  274. .dialog {
  275. position: fixed;
  276. height: 100%;
  277. width: 100%;
  278. bottom: 0;
  279. left: 0;
  280. z-index: 10;
  281. background-color: rgba(0, 0, 0, .3);
  282. .dialog-item {
  283. padding-top: #{20rpx};
  284. position: fixed;
  285. top: 25%;
  286. left: 0;
  287. right: 0;
  288. margin: 0 auto;
  289. width: #{620rpx};
  290. border-radius: #{16rpx};
  291. background-color: #fff;
  292. text-align: center;
  293. }
  294. .btn-area {
  295. height: #{88rpx};
  296. position: relative;
  297. border-top: #{1rpx} solid #e2e2e2;
  298. .line {
  299. height: #{32rpx};
  300. width: #{1rpx};
  301. background-color: #e2e2e2;
  302. position: absolute;
  303. top: #{28rpx};
  304. left: 0;
  305. right: 0;
  306. margin: 0 auto;
  307. }
  308. .submit-btn {
  309. height: #{88rpx};
  310. line-height: #{88rpx};
  311. font-size: #{32rpx};
  312. color: #666;
  313. width: #{310rpx};
  314. text-align: center;
  315. }
  316. .submit-btn.be-submit {
  317. color: #446dfd;
  318. }
  319. }
  320. .dialog-title {
  321. text-align: center;
  322. font-size: 32rpx;
  323. color: #353535;
  324. margin: #{66rpx} 0 #{76rpx};
  325. }
  326. }
  327. </style>