goods-cat.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <view style="position: absolute;width: 100%;height: 100%;top: 0;left: 0;background-color: #fff">
  3. <app-layout>
  4. <view v-if="list.length == 0" class="title">暂无分类,请添加</view>
  5. <view class="dir-left-wrap cat-list">
  6. <view v-for="(item,index) in list" :key="item.value" class="cross-center dir-left-nowrap cat-item">
  7. <view>{{item.label}}</view>
  8. <view @click="delCat(index)" class="close cross-center main-center">
  9. <image @click="delCat(index)" src="./../image/cat-close.png"></image>
  10. </view>
  11. </view>
  12. </view>
  13. <view :class="['add main-between', `${iphone_x? 'iphone_x':''}`]">
  14. <view class="add-btn" @click="add">添加分类</view>
  15. <view class="save-btn" @click="save">保存</view>
  16. </view>
  17. <view class="dialog" v-if="dialog">
  18. <view class="picker-list">
  19. <view class="main-between picker-header">
  20. <view @click="cancel">取消</view>
  21. <view @click="toAdd">新增</view>
  22. </view>
  23. <picker-view indicator-style="height: 36px;" :value="[index]" @change="bindChange">
  24. <picker-view-column>
  25. <view
  26. v-for="(item,idx) in cat" :key="item.value"
  27. :class="[`picker-view`,{
  28. 'sure-color': index_1 === idx,
  29. 'cardinal-color': index_1 === idx + 1 || index_1 === idx - 1,
  30. 'even-color': index_1 === idx + 2 || index_1 === idx - 2,
  31. }]">
  32. {{item.label}}
  33. </view>
  34. </picker-view-column>
  35. <picker-view-column>
  36. <view
  37. v-for="(item,idx) in sec_list" :key="item.value"
  38. :class="[`picker-view`,{
  39. 'sure-color': index_2 === idx,
  40. 'cardinal-color': index_2 === idx + 1 || index_2 === idx - 1,
  41. 'even-color': index_2 === idx + 2 || index_2 === idx - 2,
  42. }]">
  43. {{item.label}}
  44. </view>
  45. </picker-view-column>
  46. <picker-view-column>
  47. <view
  48. v-for="(item,idx) in third_list" :key="item.value"
  49. :class="[`picker-view`,{
  50. 'sure-color': index_3 === idx,
  51. 'cardinal-color': index_3 === idx + 1 || index_3 === idx - 1,
  52. 'even-color': index_3 === idx + 2 || index_3 === idx - 2,
  53. }]">
  54. {{item.label}}
  55. </view>
  56. </picker-view-column>
  57. </picker-view>
  58. </view>
  59. </view>
  60. </app-layout>
  61. </view>
  62. </template>
  63. <script>
  64. import { mapState } from "vuex";
  65. export default {
  66. data() {
  67. return {
  68. iphone_x: false,
  69. cat: [],
  70. sec_list: [],
  71. third_list: [],
  72. list: [],
  73. index: [0,0,0],
  74. index: -1,
  75. dialog: false,
  76. index_1: 0,
  77. index_2: 0,
  78. index_3: 0,
  79. }
  80. },
  81. computed: {
  82. ...mapState({
  83. theme: state => state.mallConfig.theme,
  84. })
  85. },
  86. methods: {
  87. cancel() {
  88. this.dialog = false;
  89. sec_list = [];
  90. third_list = [];
  91. index_1 = 0;
  92. index_2 = 0;
  93. index_3 = 0;
  94. },
  95. toAdd() {
  96. let first = this.cat[this.index_1];
  97. let second = this.sec_list[this.index_2];
  98. let third = this.third_list[this.index_3];
  99. if(second.label == '未选择' ) {
  100. this.list.push(first)
  101. }else if(third.label == '未选择' ) {
  102. this.list.push(second)
  103. }else {
  104. this.list.push(third)
  105. }
  106. this.dialog = false;
  107. },
  108. getCat() {
  109. let that = this;
  110. that.$request({
  111. url: that.$api.app_admin.cat,
  112. }).then(response=>{
  113. that.$hideLoading();
  114. if(response.code == 0) {
  115. that.cat = response.data.list;
  116. }else {
  117. uni.showToast({
  118. title: response.msg,
  119. icon: 'none',
  120. duration: 1000
  121. });
  122. }
  123. }).catch(response => {
  124. that.$hideLoading();
  125. });
  126. },
  127. delCat(index) {
  128. this.list.splice(index,1);
  129. },
  130. bindChange(res) {
  131. let that = this;
  132. if(that.index_1 == res.detail.value[0]) {
  133. if(that.index_2 == res.detail.value[1]) {
  134. that.index_3 = res.detail.value[2];
  135. }else {
  136. that.index_2 = res.detail.value[1];
  137. that.index_3 = 0;
  138. that.third_list = [{label:'未选择',value:''}];
  139. if(that.sec_list[that.index_2].children) {
  140. that.third_list = that.third_list.concat(that.sec_list[that.index_2].children)
  141. }
  142. }
  143. }else {
  144. that.index_1 = res.detail.value[0];
  145. that.index_2 = 0;
  146. that.index_3 = 0;
  147. that.sec_list = [{label:'未选择',value:''}];
  148. that.third_list = [{label:'未选择',value:''}];
  149. if(that.cat[that.index_1].children) {
  150. that.sec_list = that.sec_list.concat(that.cat[that.index_1].children);
  151. if(that.sec_list[0].children) {
  152. that.third_list = that.third_list.concat(that.sec_list[0].children)
  153. }
  154. }
  155. }
  156. },
  157. save() {
  158. uni.setStorage({
  159. key: "goods_cat",
  160. data: this.list
  161. })
  162. setTimeout(function() {
  163. uni.navigateBack();
  164. }, 500)
  165. },
  166. add() {
  167. this.dialog = true;
  168. this.sec_list = [{label:'未选择',value:''}];
  169. this.third_list = [{label:'未选择',value:''}];
  170. if(this.cat[0].children) {
  171. this.sec_list = this.sec_list.concat(this.cat[0].children);
  172. if(this.sec_list[0].children) {
  173. this.third_list = this.third_list.concat(this.sec_list[0].children)
  174. }
  175. }
  176. }
  177. },
  178. onLoad(options) {
  179. let that = this;
  180. that.$showLoading({
  181. type: 'global',
  182. text: '加载中...'
  183. });
  184. uni.getStorage({
  185. key: 'goods_cat',
  186. success(res) {
  187. that.list = res.data
  188. }
  189. })
  190. uni.getSystemInfo({
  191. success: function (res) {
  192. 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) {
  193. that.iphone_x = true;
  194. }
  195. }
  196. })
  197. that.getCat();
  198. }
  199. }
  200. </script>
  201. <style scoped lang="scss">
  202. .cat-list {
  203. background-color: #fff;
  204. padding: #{30rpx};
  205. padding-left: 0;
  206. }
  207. .cat-item {
  208. width: auto;
  209. border-radius: #{33rpx};
  210. background-color: #ECF0FF;
  211. padding-left: #{30rpx};
  212. height: #{66rpx};
  213. line-height: #{66rpx};
  214. color: #446DFD;
  215. margin-left: #{30rpx};
  216. margin-bottom: #{30rpx};
  217. .close {
  218. width: #{60rpx};
  219. height: #{66rpx};
  220. image {
  221. width: #{16rpx};
  222. height: #{16rpx};
  223. display: block;
  224. }
  225. }
  226. }
  227. .title {
  228. font-size: #{32rpx};
  229. color: #999999;
  230. padding-top: #{36rpx};
  231. background-color: #fff;
  232. text-align: center;
  233. }
  234. .add.iphone_x {
  235. height: #{170rpx};
  236. padding-bottom: #{50rpx};
  237. }
  238. .add {
  239. height: #{120rpx};
  240. padding: 0 #{24rpx};
  241. margin: 0 auto;
  242. position: fixed;
  243. bottom: 0;
  244. left: 0;
  245. right: 0;
  246. border-top: #{2rpx} solid #e2e2e2;
  247. background-color: #fff;
  248. .add-btn {
  249. background-color: #fff;
  250. color: #446dfd;
  251. border: #{2rpx} solid #446dfd;
  252. }
  253. }
  254. .add>view {
  255. height: #{80rpx};
  256. width: #{300rpx};
  257. margin-top: #{20rpx};
  258. border-radius: #{40rpx};
  259. background-color: #446dfd;
  260. color: #fff;
  261. font-size: #{28rpx};
  262. text-align: center;
  263. line-height: #{80rpx};
  264. }
  265. .dialog {
  266. position: fixed;
  267. height: 100%;
  268. width: 100%;
  269. bottom: 0;
  270. left: 0;
  271. z-index: 9999;
  272. background-color: rgba(0, 0, 0, .3);
  273. }
  274. .dialog.iphone_x .picker-list{
  275. padding-bottom: #{50rpx};
  276. }
  277. .picker {
  278. width: 100%;
  279. height: #{440rpx};
  280. color:#999999;
  281. }
  282. .dialog.iphone_x .picker{
  283. height:#{490rpx};
  284. }
  285. .picker-list {
  286. background-color: #fff;
  287. padding-top: #{20rpx};
  288. position: fixed;
  289. bottom: 0;
  290. left: 0;
  291. width: 100%;
  292. z-index: 9999;
  293. height: #{520rpx};
  294. border-top-left-radius: #{10rpx};
  295. border-top-right-radius: #{10rpx};
  296. }
  297. .picker-header {
  298. padding: 0 #{24rpx};
  299. color: #446dfd;
  300. font-size: #{32rpx};
  301. }
  302. .dialog {
  303. position: fixed;
  304. height: 100%;
  305. width: 100%;
  306. bottom: 0;
  307. left: 0;
  308. z-index: 9999;
  309. background-color: rgba(0, 0, 0, .3);
  310. }
  311. .picker-view {
  312. line-height: #{72rpx};
  313. text-align:center;
  314. font-size: #{32rpx};
  315. }
  316. .picker-view.sure-color {
  317. color: #446dfd;
  318. }
  319. .picker-view.cardinal-color {
  320. color: #999999;
  321. }
  322. .picker-view.even-color {
  323. color: #cdcdcd;
  324. }
  325. picker-view {
  326. width: 100%;
  327. height: #{440rpx};
  328. }
  329. </style>