cardType.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <view>
  3. <mescroll-body 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. };
  44. },
  45. onLoad() {
  46. // this.getList()
  47. },
  48. onShow() {
  49. this.userInfo = uni.getStorageSync("userInfo")
  50. this.cardTypeData.commonId=uni.getStorageSync("userInfo").id
  51. },
  52. methods: {
  53. mescrollInit(){
  54. },
  55. downCallback(){
  56. },
  57. upCallback(page){
  58. var that = this
  59. uni.showLoading({
  60. title: '数据加载中'
  61. })
  62. this.$request.baseRequest('admin.unimall.cardClassifyInfo', 'list',{
  63. page:page.num,
  64. limit:page.size,
  65. commonId:uni.getStorageSync("userInfo").id
  66. }, failres => {
  67. console.log('res+++++', failres.errmsg)
  68. this.$refs.uToast.show({
  69. type: 'error',
  70. message: failres.errmsg,
  71. })
  72. uni.hideLoading()
  73. }).then(res => {
  74. console.log(res)
  75. if(page.num == 1) this.cardTypeList = [];
  76. let curPageLen = res.data.items.length;
  77. let totalPage = res.data.total;
  78. if(res.data.items.length>0){
  79. for(var i=0;i<res.data.items.length;i++){
  80. res.data.items[i].name=res.data.items[i].circleName[0]
  81. }
  82. var itemIndex=res.data.items.findIndex((item)=>{return item.topMarking==1})
  83. // console.log(itemIndex)
  84. if(itemIndex!=-1){
  85. var data=res.data.items.splice(itemIndex,1)
  86. if(page.num==1){
  87. data.push({circleName:'默认分类',name:'默'})
  88. }
  89. // console.log(data.concat(res.data.items))
  90. res.data.items=data.concat(res.data.items)
  91. }else{
  92. if(page.num==1){
  93. res.data.items=[{circleName:'默认分类',name:'默'}].concat(res.data.items)
  94. }
  95. }
  96. this.cardTypeList=this.cardTypeList.concat(res.data.items)
  97. }else{
  98. if(page.num==1){
  99. this.cardTypeList=[{circleName:'默认分类',name:'默'}]
  100. }
  101. }
  102. this.$nextTick(() => {
  103. console.log(that)
  104. // mescroll.endSuccess(data.result);
  105. that.mescroll.endBySize(curPageLen, totalPage)
  106. });
  107. // if (res.errno == 200) {
  108. uni.hideLoading()
  109. // }
  110. })
  111. },
  112. del(item){
  113. uni.showLoading({
  114. title: '加载中',
  115. mask:true
  116. })
  117. this.$request.baseRequest('admin.unimall.cardClassifyInfo', 'delete',{
  118. commonId:uni.getStorageSync("userInfo").id,
  119. id:item.id
  120. }, failres => {
  121. console.log('res+++++', failres.errmsg)
  122. uni.showToast({
  123. title: failres.errmsg,
  124. icon: 'none',
  125. duration: 2000
  126. })
  127. uni.hideLoading()
  128. }).then(res => {
  129. uni.showToast({
  130. title: '删除成功',
  131. icon: 'none',
  132. duration: 2000
  133. })
  134. uni.hideLoading()
  135. this.mescroll.resetUpScroll( )
  136. }).catch(res => {
  137. uni.showToast({
  138. title: '置顶失败',
  139. icon: 'none',
  140. duration: 2000
  141. })
  142. uni.hideLoading()
  143. })
  144. },
  145. stick(item){
  146. uni.showLoading({
  147. title: '加载中',
  148. mask:true
  149. })
  150. var type='',type1='',data={}
  151. if(item.id){
  152. type='admin.unimall.cardClassifyInfo'
  153. type1='top'
  154. data={
  155. cardClassifyInfo:JSON.stringify({id:item.id})
  156. }
  157. }else{
  158. type='admin.unimall.cardClassifyInfo'
  159. type1='topDefault'
  160. data={
  161. cardClassifyInfo:JSON.stringify({commonId:this.cardTypeData.commonId})
  162. }
  163. }
  164. this.$request.baseRequest(type, type1,data, failres => {
  165. console.log('res+++++', failres.errmsg)
  166. uni.showToast({
  167. title: failres.errmsg,
  168. icon: 'none',
  169. duration: 2000
  170. })
  171. uni.hideLoading()
  172. }).then(res => {
  173. uni.showToast({
  174. title: '置顶成功',
  175. icon: 'none',
  176. duration: 2000
  177. })
  178. uni.hideLoading()
  179. this.mescroll.resetUpScroll( )
  180. }).catch(res => {
  181. uni.showToast({
  182. title: '置顶失败',
  183. icon: 'none',
  184. duration: 2000
  185. })
  186. uni.hideLoading()
  187. })
  188. },
  189. add(){
  190. // if(){
  191. // }
  192. this.show=true
  193. },
  194. confirm(){
  195. if(!this.cardTypeData.circleName){
  196. uni.showToast({
  197. title: '分类名称不能为空!',
  198. icon: 'none',
  199. duration: 2000
  200. })
  201. return
  202. }
  203. if(this.cardTypeData.circleName<2||this.cardTypeData.circleName>8){
  204. uni.showToast({
  205. title: '类别名称2-8个字!',
  206. icon: 'none',
  207. duration: 2000
  208. })
  209. return
  210. }
  211. this.$request.baseRequest('admin.unimall.cardClassifyInfo', 'add',{
  212. cardClassifyInfo:JSON.stringify(this.cardTypeData)
  213. }, failres => {
  214. console.log('res+++++', failres.errmsg)
  215. uni.showToast({
  216. title: failres.errmsg,
  217. icon: 'none',
  218. duration: 2000
  219. })
  220. uni.hideLoading()
  221. }).then(res => {
  222. console.log(res)
  223. // if (res.errno == 200) {
  224. uni.hideLoading()
  225. this.show=false
  226. this.cardTypeData={
  227. commonId:uni.getStorageSync("userInfo").id,
  228. }
  229. this.mescroll.resetUpScroll( )
  230. // }
  231. })
  232. }
  233. }
  234. }
  235. </script>
  236. <style lang="scss" scoped>
  237. </style>