fenlei.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <view>
  3. <view v-for="(item,index) in list" :key="index" class="flex padding justify-between">
  4. <view class="flex align-center">
  5. <view class="text-bold text-xl">{{index+1}}.</view>
  6. <view class="margin-left-xs">{{item.classifyName}}</view>
  7. </view>
  8. <view class="flex align-center">
  9. <view class="btn margin-right-sm" @click="addtype(2,item)">修改</view>
  10. <view class="btn" @click="bindupdata(item)">删除</view>
  11. </view>
  12. </view>
  13. <empty v-if="list.length == 0" content="暂无数据"></empty>
  14. <view class="addguige text-bold" @click="addtype(1)">添加</view>
  15. <!-- 添加规格弹框 -->
  16. <u-popup v-model="show" mode="center" border-radius="14" width="500rpx" height="400rpx">
  17. <view>
  18. <view class="padding" style="margin-bottom: 20rpx;">
  19. <view>商品分类</view>
  20. <view class="flex align-center" style="margin-top: 15rpx;">
  21. <label style="margin-right: 10rpx;">分类名称</label><u-input v-model="typeName" placeholder="请填写分类名称" clearable="false" />
  22. </view>
  23. <view class="flex align-center" style="margin-top: 15rpx;">
  24. <label style="margin-right: 10rpx;">分类排序</label><u-number-box v-model="sort" placeholder="请填写分类排序"></u-number-box>
  25. </view>
  26. </view>
  27. <view class="addguiges" @click="bindAdd()">确定</view>
  28. </view>
  29. </u-popup>
  30. </view>
  31. </template>
  32. <script>
  33. import empty from '@/components/empty.vue'
  34. export default {
  35. components: {
  36. empty
  37. },
  38. data() {
  39. return {
  40. list: [{
  41. id: 1,
  42. name: '清爽夏日',
  43. }, {
  44. id: 2,
  45. name: '牛奶系列',
  46. }, {
  47. id: 3,
  48. name: '鲜榨果汁',
  49. }],
  50. show: false,
  51. typeName: '',
  52. sort:0,
  53. classifyId: '',
  54. shopId: '',
  55. shopName: '',
  56. }
  57. },
  58. onLoad() {
  59. uni.showLoading({
  60. title: '数据加载中...',
  61. mask: true, // 是否显示透明蒙层,防止触摸穿透
  62. mask: false
  63. })
  64. this.shopId = this.$queue.getData("shopId")
  65. this.shopName = this.$queue.getData("shopUserName")
  66. this.getlist()
  67. },
  68. methods: {
  69. addtype(index, item) {
  70. console.log(index, item)
  71. if (index == 1) {
  72. this.show = true
  73. this.typeName = ''
  74. this.classifyId = ''
  75. this.sort = 0
  76. } else if (index == 2) {
  77. this.show = true
  78. this.typeName = item.classifyName
  79. this.classifyId = item.classifyId
  80. if(item.sort){
  81. this.sort = item.sort
  82. }else{
  83. this.sort = 0
  84. }
  85. }
  86. },
  87. //添加商品类型
  88. bindAdd() {
  89. if (!this.typeName) {
  90. uni.showToast({
  91. title: '请填写商品类型',
  92. icon: 'none',
  93. duration: 1000
  94. })
  95. return
  96. }
  97. console.log(this.classifyId)
  98. if (this.classifyId) {
  99. let data = {
  100. classifyId: this.classifyId,
  101. classifyName: this.typeName,
  102. shopId: this.shopId,
  103. shopName: this.shopName,
  104. sort:this.sort,
  105. }
  106. this.$Request.postJson("/admin/goods/updateClassify", data).then(res => {
  107. if (res.code == 0) {
  108. // this.list = res.data
  109. this.show = false
  110. this.typeName = ''
  111. this.classifyId = ''
  112. this.sort = 0
  113. this.getlist()
  114. }
  115. })
  116. } else {
  117. let data = {
  118. classifyName: this.typeName,
  119. shopId: this.shopId,
  120. shopName: this.shopName,
  121. sort:this.sort
  122. }
  123. this.$Request.postJson("/admin/goods/insertClassify", data).then(res => {
  124. if (res.code == 0) {
  125. // this.list = res.data
  126. this.show = false
  127. this.typeName = ''
  128. this.classifyId = ''
  129. this.sort = 0
  130. this.getlist()
  131. }
  132. })
  133. }
  134. },
  135. //获取分类列表
  136. getlist() {
  137. let data = {
  138. shopId: this.shopId
  139. }
  140. this.$Request.getA("/admin/goods/selectAllClassify", data).then(res => {
  141. uni.hideLoading()
  142. if (res.code == 0) {
  143. this.list = res.data
  144. }
  145. })
  146. },
  147. //删除商品类型
  148. bindupdata(e) {
  149. console.log(e)
  150. uni.showModal({
  151. title: '提示',
  152. content: '确定要删除当前类型吗?',
  153. cancelText: "取消", // 取消按钮的文字
  154. confirmText: "确定", // 确认按钮文字
  155. showCancel: true, // 是否显示取消按钮,默认为 true
  156. confirmColor: '#f55850',
  157. cancelColor: '#39B54A',
  158. success: (res) => {
  159. if (res.confirm) {
  160. let data = {
  161. classifyId: e.classifyId
  162. }
  163. this.$Request.getA("/admin/goods/deleteClassify", data).then(res => {
  164. if (res.code == 0) {
  165. uni.showToast({
  166. title: "删除成功",
  167. icon: 'none'
  168. })
  169. this.getlist();
  170. } else {
  171. uni.showModal({
  172. title: '提示',
  173. content: res.msg,
  174. success: function (res) {
  175. if (res.confirm) {
  176. } else if (res.cancel) {
  177. }
  178. }
  179. });
  180. }
  181. });
  182. }
  183. }
  184. })
  185. }
  186. }
  187. }
  188. </script>
  189. <style>
  190. page {
  191. background: #FFFFFF;
  192. }
  193. .btn {
  194. border: 2upx solid #999999;
  195. border-radius: 24px;
  196. color: #333333;
  197. padding: 5rpx 30rpx;
  198. }
  199. .addguige {
  200. width: 90%;
  201. margin: 0 auto;
  202. background: #FCD202;
  203. box-shadow: 0px 10upx 20upx 0px #FFD9B3;
  204. border-radius: 16upx;
  205. text-align: center;
  206. height: 88upx;
  207. line-height: 88upx;
  208. position: fixed;
  209. bottom: 25upx;
  210. left: 0;
  211. right: 0;
  212. }
  213. .addguiges {
  214. width: 90%;
  215. margin: 0 auto;
  216. background: #FCD202;
  217. box-shadow: 0px 10upx 20upx 0px #FFD9B3;
  218. border-radius: 16upx;
  219. text-align: center;
  220. height: 88upx;
  221. line-height: 88upx;
  222. /* position: fixed;
  223. bottom: 25upx;
  224. left: 0;
  225. right: 0; */
  226. }
  227. </style>