cardType.vue 5.6 KB

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