cardType.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <view>
  3. <mescroll-body :up="upOption" ref="mescrollRef" @init="mescrollInit" @up="upCallback" @down="downCallback">
  4. <u-list @scrolltolower="scrolltolower">
  5. <u-list-item v-for='item in cardTypeList'>
  6. <view class='flex'>
  7. {{item.name}}
  8. {{item.circleName}}
  9. <u-icon v-if='item.circleName!="默认分类"' @click="del(item)" name="trash-fill" color="#2979ff" size="28"></u-icon>
  10. <u-icon @click="stick(item)" name="pushpin" color="#2979ff" size="28"></u-icon>
  11. </view>
  12. </u-list-item>
  13. </u-list>
  14. </mescroll-body>
  15. <u-modal showCancelButton='true'
  16. @confirm='$u.debounce(confirm, 500)'
  17. @cancel='show=false' :show="show" title="新增分类" >
  18. <view class="slot-content">
  19. <u--input
  20. v-model="cardTypeData.circleName"
  21. placeholder="输入分类名称,2-8个字符"
  22. border="none"
  23. ></u--input>
  24. </view>
  25. </u-modal>
  26. <view class="footer">
  27. <view @click='add' class='button'>新增</view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  33. export default {
  34. mixins: [MescrollMixin],
  35. data() {
  36. return {
  37. show:false,
  38. page:1,
  39. limit:20,
  40. cardTypeList:[],
  41. cardTypeData:{},
  42. userInfo:{},
  43. upOption:{
  44. page:{
  45. num : 0 ,
  46. size : 10 ,
  47. time : null
  48. }
  49. }
  50. };
  51. },
  52. onLoad() {
  53. // this.getList()
  54. },
  55. onShow() {
  56. this.userInfo = uni.getStorageSync("userInfo")
  57. this.cardTypeData.commonId=uni.getStorageSync("userInfo").id
  58. },
  59. methods: {
  60. mescrollInit(){
  61. },
  62. downCallback(){
  63. },
  64. upCallback(page){
  65. var that = this
  66. uni.showLoading({
  67. title: '数据加载中'
  68. })
  69. this.$request.baseRequest('admin.unimall.cardClassifyInfo', 'list',{
  70. page:page.num,
  71. limit:page.size,
  72. commonId:uni.getStorageSync("userInfo").id
  73. }, failres => {
  74. console.log('res+++++', failres.errmsg)
  75. this.$refs.uToast.show({
  76. type: 'error',
  77. message: failres.errmsg,
  78. })
  79. uni.hideLoading()
  80. }).then(res => {
  81. console.log(res)
  82. if(page.num == 1) this.cardTypeList = [];
  83. let curPageLen = res.data.items.length;
  84. let totalPage = res.data.total;
  85. if(res.data.items.length>0){
  86. for(var i=0;i<res.data.items.length;i++){
  87. res.data.items[i].name=res.data.items[i].circleName[0]
  88. }
  89. var itemIndex=res.data.items.findIndex((item)=>{return item.topMarking==1})
  90. // console.log(itemIndex)
  91. if(itemIndex!=-1){
  92. var data=res.data.items.splice(itemIndex,1)
  93. if(page.num==1){
  94. data.push({circleName:'默认分类',name:'默'})
  95. }
  96. // console.log(data.concat(res.data.items))
  97. res.data.items=data.concat(res.data.items)
  98. }else{
  99. if(page.num==1){
  100. res.data.items=[{circleName:'默认分类',name:'默'}].concat(res.data.items)
  101. }
  102. }
  103. this.cardTypeList=this.cardTypeList.concat(res.data.items)
  104. }else{
  105. if(page.num==1){
  106. this.cardTypeList=[{circleName:'默认分类',name:'默'}]
  107. }
  108. }
  109. this.$nextTick(() => {
  110. console.log(that)
  111. // mescroll.endSuccess(data.result);
  112. that.mescroll.endBySize(curPageLen, totalPage)
  113. });
  114. // if (res.errno == 200) {
  115. uni.hideLoading()
  116. // }
  117. })
  118. },
  119. del(item){
  120. uni.showLoading({
  121. title: '加载中',
  122. mask:true
  123. })
  124. this.$request.baseRequest('admin.unimall.cardClassifyInfo', 'delete',{
  125. commonId:uni.getStorageSync("userInfo").id,
  126. id:item.id
  127. }, failres => {
  128. console.log('res+++++', failres.errmsg)
  129. uni.showToast({
  130. title: failres.errmsg,
  131. icon: 'none',
  132. duration: 2000
  133. })
  134. uni.hideLoading()
  135. }).then(res => {
  136. uni.showToast({
  137. title: '删除成功',
  138. icon: 'none',
  139. duration: 2000
  140. })
  141. uni.hideLoading()
  142. this.mescroll.resetUpScroll( )
  143. }).catch(res => {
  144. uni.showToast({
  145. title: '置顶失败',
  146. icon: 'none',
  147. duration: 2000
  148. })
  149. uni.hideLoading()
  150. })
  151. },
  152. stick(item){
  153. uni.showLoading({
  154. title: '加载中',
  155. mask:true
  156. })
  157. var type='',type1='',data={}
  158. if(item.id){
  159. type='admin.unimall.cardClassifyInfo'
  160. type1='top'
  161. data={
  162. cardClassifyInfo:JSON.stringify({id:item.id})
  163. }
  164. }else{
  165. type='admin.unimall.cardClassifyInfo'
  166. type1='topDefault'
  167. data={
  168. cardClassifyInfo:JSON.stringify({commonId:this.cardTypeData.commonId})
  169. }
  170. }
  171. this.$request.baseRequest(type, type1,data, failres => {
  172. console.log('res+++++', failres.errmsg)
  173. uni.showToast({
  174. title: failres.errmsg,
  175. icon: 'none',
  176. duration: 2000
  177. })
  178. uni.hideLoading()
  179. }).then(res => {
  180. uni.showToast({
  181. title: '置顶成功',
  182. icon: 'none',
  183. duration: 2000
  184. })
  185. uni.hideLoading()
  186. this.mescroll.resetUpScroll( )
  187. }).catch(res => {
  188. uni.showToast({
  189. title: '置顶失败',
  190. icon: 'none',
  191. duration: 2000
  192. })
  193. uni.hideLoading()
  194. })
  195. },
  196. add(){
  197. // if(){
  198. // }
  199. this.show=true
  200. },
  201. confirm(){
  202. if(!this.cardTypeData.circleName){
  203. uni.showToast({
  204. title: '分类名称不能为空!',
  205. icon: 'none',
  206. duration: 2000
  207. })
  208. return
  209. }
  210. if(this.cardTypeData.circleName<2||this.cardTypeData.circleName>8){
  211. uni.showToast({
  212. title: '类别名称2-8个字!',
  213. icon: 'none',
  214. duration: 2000
  215. })
  216. return
  217. }
  218. this.$request.baseRequest('admin.unimall.cardClassifyInfo', 'add',{
  219. cardClassifyInfo:JSON.stringify(this.cardTypeData)
  220. }, failres => {
  221. console.log('res+++++', failres.errmsg)
  222. uni.showToast({
  223. title: failres.errmsg,
  224. icon: 'none',
  225. duration: 2000
  226. })
  227. uni.hideLoading()
  228. }).then(res => {
  229. console.log(res)
  230. // if (res.errno == 200) {
  231. uni.hideLoading()
  232. this.show=false
  233. this.cardTypeData={
  234. commonId:uni.getStorageSync("userInfo").id,
  235. }
  236. this.mescroll.resetUpScroll( )
  237. // }
  238. })
  239. }
  240. }
  241. }
  242. </script>
  243. <style lang="scss" scoped>
  244. </style>