goods-cat.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template>
  2. <app-layout>
  3. <view v-if="list.length > 0" class="dir-left-wrap cat-list">
  4. <view v-for="(item,index) in list" :key="item.value" class="cross-center dir-left-nowrap cat-item" :style="{'color':color, 'background-color': mch_id == 0 ? '#ECF0FF':'#FFECEC'}">
  5. <view>{{item.label}}</view>
  6. <view @click="delCat(index)" class="close cross-center main-center">
  7. <image :src="mch_id == 0 ? './../image/cat-close.png': './../image/mch-cat-close.png'"></image>
  8. </view>
  9. </view>
  10. </view>
  11. <view v-if="mch_id || mch_id == 0" class='add-cat' @click='add'>
  12. <view class='add-cat-btn main-center' :style="{'border-color': color,'color': color}">
  13. <image :src="mch_id == 0 ? './../image/add.png': './../image/mch-add.png'"></image>
  14. <view>添加分类</view>
  15. </view>
  16. </view>
  17. <view :class="['add main-between', `${iphone_x? 'iphone_x':''}`]">
  18. <view v-if="!(type == 'mall' && mch_id > 0)" class="add-btn" :style="{'border-color': color,'color': color}" @click="settingCat">分类管理</view>
  19. <view :style="{'background-color':color}" class="save-btn" :class="{'all' : type == 'mall' && mch_id > 0}" @click="save">保存</view>
  20. </view>
  21. <view class="dialog" v-if="dialog">
  22. <view class="picker-list">
  23. <view class="main-between picker-header" :style="{'color': color}">
  24. <view @click="cancel">取消</view>
  25. <view @click="toAdd">新增</view>
  26. </view>
  27. <picker-view indicator-style="height: 34px;" @change="bindChange">
  28. <picker-view-column>
  29. <view
  30. v-for="(item,idx) in cat" :key="item.value"
  31. :style="{'color': index_1 == idx ? color : index_1 == idx + 1 || index_1 == idx - 1 ? '#999999' : index_1 == idx + 2 || index_1 == idx - 2 ? '#cdcdcd' : ''}"
  32. class="picker-view t-omit">
  33. {{item.label}}
  34. </view>
  35. </picker-view-column>
  36. <picker-view-column>
  37. <view
  38. v-for="(item,idx) in sec_list" :key="item.value"
  39. :style="{'color': index_2 == idx ? color : index_2 == idx + 1 || index_2 == idx - 1 ? '#999999' : index_2 == idx + 2 || index_2 == idx - 2 ? '#cdcdcd' : ''}"
  40. class="picker-view t-omit">
  41. {{item.label}}
  42. </view>
  43. </picker-view-column>
  44. <picker-view-column>
  45. <view
  46. v-for="(item,idx) in third_list" :key="item.value"
  47. :style="{'color': index_3 == idx ? color : index_3 == idx + 1 || index_3 == idx - 1 ? '#999999' : index_3 == idx + 2 || index_3 == idx - 2 ? '#cdcdcd' : ''}"
  48. class="picker-view t-omit">
  49. {{item.label}}
  50. </view>
  51. </picker-view-column>
  52. </picker-view>
  53. </view>
  54. </view>
  55. </app-layout>
  56. </template>
  57. <script>
  58. export default {
  59. data() {
  60. return {
  61. iphone_x: false,
  62. first: true,
  63. cat: [],
  64. sec_list: [],
  65. third_list: [],
  66. list: [],
  67. mch_id: null,
  68. dialog: false,
  69. index_1: 0,
  70. index_2: 0,
  71. index_3: 0,
  72. type: '',
  73. color: ''
  74. }
  75. },
  76. methods: {
  77. settingCat() {
  78. uni.navigateTo({
  79. url: `/pages/goods-edit/cat-setting/cat-setting?mch_id=` + this.mch_id
  80. })
  81. },
  82. cancel() {
  83. this.dialog = false;
  84. this.sec_list = [];
  85. this.third_list = [];
  86. this.index_1 = 0;
  87. this.index_2 = 0;
  88. this.index_3 = 0;
  89. },
  90. toAdd() {
  91. let that = this;
  92. let first = that.cat[that.index_1];
  93. let second = that.sec_list[that.index_2];
  94. let third = that.third_list[that.index_3];
  95. let para;
  96. if(second.label == '未选择' ) {
  97. para = first;
  98. }else if(third.label == '未选择' ) {
  99. para = second;
  100. }else {
  101. para = third;
  102. }
  103. if(that.list.length > 0) {
  104. for(let item of that.list) {
  105. if(item.value == para.value) {
  106. uni.showToast({
  107. title: '请勿重复添加',
  108. icon: 'none',
  109. duration: 1000
  110. });
  111. return false
  112. }
  113. }
  114. }
  115. setTimeout(()=>{
  116. that.list.push(para)
  117. that.dialog = false;
  118. that.index_1 = 0;
  119. that.index_2 = 0;
  120. that.index_3 = 0;
  121. })
  122. },
  123. getCat() {
  124. let that = this;
  125. let url = this.mch_id == 0 ? that.$api.app_admin.cat : that.type == 'mall' ? that.$api.mch.cat : that.$api.mch.mch_cat;
  126. let para;
  127. that.$request({
  128. url: url,
  129. data: {
  130. mch_id: that.mch_id
  131. }
  132. }).then(response=>{
  133. that.$hideLoading();
  134. uni.hideLoading();
  135. that.first = false;
  136. if(response.code == 0) {
  137. that.cat = response.data.list;
  138. if(that.list.length > 0) {
  139. let list = JSON.parse(JSON.stringify(that.list));
  140. that.list = [];
  141. for(let item of list) {
  142. for(let cat of that.cat) {
  143. if(item.value == cat.value) {
  144. that.list.push(item)
  145. }else {
  146. if(cat.children) {
  147. for(let sec of cat.children) {
  148. if(item.value == sec.value) {
  149. that.list.push(item)
  150. }else {
  151. if(sec.children) {
  152. for(let third of sec.children) {
  153. if(item.value == third.value) {
  154. that.list.push(item)
  155. }
  156. }
  157. }
  158. }
  159. }
  160. }
  161. }
  162. }
  163. }
  164. }
  165. }else {
  166. uni.showToast({
  167. title: response.msg,
  168. icon: 'none',
  169. duration: 1000
  170. });
  171. }
  172. }).catch(response => {
  173. that.$hideLoading();
  174. uni.hideLoading();
  175. });
  176. },
  177. delCat(index) {
  178. this.list.splice(index,1);
  179. },
  180. bindChange(res) {
  181. let that = this;
  182. if(res.detail.value[0] < 0) {
  183. res.detail.value[0] = 0;
  184. }
  185. if(that.index_1 == res.detail.value[0]) {
  186. if(that.index_2 == res.detail.value[1]) {
  187. that.index_3 = +res.detail.value[2];
  188. }else {
  189. that.index_2 = +res.detail.value[1];
  190. that.index_3 = 0;
  191. that.third_list = [{label:'未选择',value:''}];
  192. if(that.sec_list[that.index_2].children) {
  193. that.third_list = that.third_list.concat(that.sec_list[that.index_2].children)
  194. }
  195. }
  196. }else {
  197. that.index_1 = +res.detail.value[0];
  198. that.index_2 = 0;
  199. that.index_3 = 0;
  200. that.sec_list = [{label:'未选择',value:''}];
  201. that.third_list = [{label:'未选择',value:''}];
  202. if(that.cat[that.index_1].children) {
  203. that.sec_list = that.sec_list.concat(that.cat[that.index_1].children);
  204. if(that.sec_list[0].children) {
  205. that.third_list = that.third_list.concat(that.sec_list[0].children)
  206. }
  207. }
  208. }
  209. },
  210. save() {
  211. if(this.mch_id == 0) {
  212. this.$storage.setStorageSync('goods_cat', this.list);
  213. }else if(this.type == 'mall') {
  214. this.$storage.setStorageSync('mch_goods_cat', this.list);
  215. }else {
  216. this.$storage.setStorageSync('mch_goods_mch_cat', this.list);
  217. }
  218. setTimeout(function() {
  219. uni.navigateBack();
  220. }, 500)
  221. },
  222. add() {
  223. this.dialog = true;
  224. this.sec_list = [{label:'未选择',value:''}];
  225. this.third_list = [{label:'未选择',value:''}];
  226. if(this.cat[0].children) {
  227. this.sec_list = this.sec_list.concat(this.cat[0].children);
  228. if(this.sec_list[0].children) {
  229. this.third_list = this.third_list.concat(this.sec_list[0].children)
  230. }
  231. }
  232. }
  233. },
  234. onShow() {
  235. if(!this.first) {
  236. uni.showLoading({
  237. mask: true,
  238. });
  239. this.getCat();
  240. }
  241. },
  242. onLoad(options) { this.$commonLoad.onload(options);
  243. let that = this;
  244. that.$showLoading({
  245. type: 'global',
  246. text: '加载中...'
  247. });
  248. this.type = options.type ? options.type : '';
  249. this.mch_id = options.mch_id ? options.mch_id : 0;
  250. this.color = options.mch_id ? '#ff4544' : '#446dfd';
  251. if(this.mch_id == 0) {
  252. this.list = this.$storage.getStorageSync('goods_cat') ? this.$storage.getStorageSync('goods_cat') : [];
  253. }else if(this.type == 'mall') {
  254. this.list = this.$storage.getStorageSync('mch_goods_cat') ? this.$storage.getStorageSync('mch_goods_cat') : [];
  255. }else {
  256. this.list = this.$storage.getStorageSync('mch_goods_mch_cat') ? this.$storage.getStorageSync('mch_goods_mch_cat') : [];
  257. }
  258. uni.getSystemInfo({
  259. success: function (res) {
  260. 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) {
  261. that.iphone_x = true;
  262. }
  263. }
  264. })
  265. that.getCat();
  266. }
  267. }
  268. </script>
  269. <style scoped lang="scss">
  270. .add-cat {
  271. height: #{120rpx};
  272. background-color: #fff;
  273. padding-top: #{24rpx};
  274. .add-cat-btn {
  275. height: #{72rpx};
  276. width: #{320rpx};
  277. border-radius: #{36rpx};
  278. border: #{2rpx} solid;
  279. margin: 0 auto;
  280. font-size: #{26rpx};
  281. line-height: #{72rpx};
  282. image {
  283. height: #{28rpx};
  284. width: #{28rpx};
  285. margin-right: #{12rpx};
  286. margin-top: #{22rpx};
  287. }
  288. }
  289. }
  290. .cat-list {
  291. background-color: #fff;
  292. padding: #{30rpx};
  293. padding-left: 0;
  294. padding-bottom: 0;
  295. }
  296. .cat-item {
  297. width: auto;
  298. border-radius: #{33rpx};
  299. padding-left: #{30rpx};
  300. height: #{66rpx};
  301. line-height: #{66rpx};
  302. margin-left: #{30rpx};
  303. margin-bottom: #{30rpx};
  304. .close {
  305. width: #{60rpx};
  306. height: #{66rpx};
  307. image {
  308. width: #{16rpx};
  309. height: #{16rpx};
  310. display: block;
  311. }
  312. }
  313. }
  314. .title {
  315. font-size: #{32rpx};
  316. color: #999999;
  317. padding-top: #{36rpx};
  318. background-color: #fff;
  319. text-align: center;
  320. }
  321. .add.iphone_x {
  322. height: #{170rpx};
  323. padding-bottom: #{50rpx};
  324. }
  325. .add {
  326. height: #{120rpx};
  327. padding: 0 #{24rpx};
  328. margin: 0 auto;
  329. position: fixed;
  330. bottom: 0;
  331. left: 0;
  332. right: 0;
  333. border-top: #{2rpx} solid #e2e2e2;
  334. background-color: #fff;
  335. .add-btn {
  336. background-color: #fff;
  337. border: #{2rpx} solid;
  338. }
  339. }
  340. .add>view {
  341. height: #{80rpx};
  342. width: #{300rpx};
  343. margin-top: #{20rpx};
  344. border-radius: #{40rpx};
  345. color: #fff;
  346. font-size: #{28rpx};
  347. text-align: center;
  348. line-height: #{80rpx};
  349. &.all {
  350. width: #{702rpx};
  351. }
  352. }
  353. .dialog {
  354. position: fixed;
  355. height: 100%;
  356. width: 100%;
  357. bottom: 0;
  358. left: 0;
  359. z-index: 9999;
  360. background-color: rgba(0, 0, 0, .3);
  361. }
  362. .dialog.iphone_x .picker-list{
  363. padding-bottom: #{50rpx};
  364. }
  365. .picker {
  366. width: 100%;
  367. height: #{440rpx};
  368. color:#999999;
  369. }
  370. .dialog.iphone_x .picker{
  371. height:#{490rpx};
  372. }
  373. .picker-list {
  374. background-color: #fff;
  375. padding-top: #{20rpx};
  376. position: fixed;
  377. bottom: 0;
  378. left: 0;
  379. width: 100%;
  380. z-index: 9999;
  381. height: #{520rpx};
  382. border-top-left-radius: #{10rpx};
  383. border-top-right-radius: #{10rpx};
  384. }
  385. .picker-header {
  386. padding: 0 #{24rpx};
  387. font-size: #{32rpx};
  388. }
  389. .dialog {
  390. position: fixed;
  391. height: 100%;
  392. width: 100%;
  393. bottom: 0;
  394. left: 0;
  395. z-index: 9999;
  396. background-color: rgba(0, 0, 0, .3);
  397. }
  398. .picker-view {
  399. height: 34px;
  400. line-height: 34px;
  401. text-align:center;
  402. font-size: #{32rpx};
  403. }
  404. picker-view {
  405. width: 100%;
  406. height: #{440rpx};
  407. }
  408. </style>