list.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <view class="menu">
  3. <view class="stutoa mtop">
  4. <view class="stutoap">
  5. <picker mode="date" @change="bindDateChange">
  6. <view class="flexc">
  7. <view class=" f15 co16 f500">{{time||'请选择时间'}}</view>
  8. <image :src="upimg"></image>
  9. </view>
  10. </picker>
  11. </view>
  12. </view>
  13. <view class="pl6">
  14. <xl-list :datype='datype' :datalist="list" :wtdt="wtdt" @getDel="getDel" @getPreimg='getPreimg' :dintype='diningrange' @getDetail="getDetail"></xl-list>
  15. </view>
  16. <image :src="addimg" class="addimg" @click="getAdd" v-if="checkPermi(['system:recipe:add'])"></image>
  17. <pop-up :type='type' @getClose='getClose' :imgobj='imgobj'></pop-up>
  18. </view>
  19. </template>
  20. <script>
  21. import xlList from "@/work/components/list/list.vue"
  22. import popUp from "@/work/components/popup/popup.vue"
  23. import {getRecipelistFn,getRecipedelFn} from "@/api/work/menu.js"
  24. import {getDictionaryFn} from '@/api/mine/register.js'
  25. import {checkPermi,checkRole} from "@/utils/permission"; // 权限判断函数
  26. export default {
  27. components:{
  28. xlList,popUp
  29. },
  30. data(){
  31. return{
  32. searchimg: require("@/mine/static/score/search.png"),
  33. addimg: require("@/static/images/tadd.png"),
  34. upimg: require("@/mine/static/score/up.png"),
  35. list:[],
  36. datype:2,
  37. pageSize: 10,
  38. pageNum: 1,
  39. reachflag: true,
  40. wtdt: '',
  41. time:'',
  42. type:0,
  43. imgobj:{},
  44. diningrange:[]
  45. }
  46. },
  47. onUnload() {
  48. uni.$off('refreshleavelist')
  49. },
  50. onReachBottom() {
  51. if (this.reachflag) {
  52. this.pageNum++
  53. this.getDataFn()
  54. }
  55. },
  56. onLoad: function(e) {
  57. uni.$on('refreshmenulist', (e) => {
  58. this.reachflag = true;
  59. this.pageNum = 1;
  60. this.list = [];
  61. this.getDataFn();
  62. })
  63. this.init()
  64. this.getDataFn()
  65. },
  66. methods:{
  67. checkPermi,checkRole,
  68. init(){
  69. //就餐类型
  70. getDictionaryFn('dining_type').then(res=>{
  71. if(res.code==200){
  72. this.diningrange = res.data.map(v => {
  73. return {
  74. dictLabel: v.dictLabel,
  75. dictValue: v.dictValue
  76. }
  77. })
  78. }
  79. })
  80. },
  81. getClose(){
  82. this.type=0
  83. },
  84. getPreimg(data){
  85. this.type=1
  86. this.imgobj=JSON.parse(JSON.stringify(data))
  87. },
  88. getDel(id){
  89. var that=this;
  90. getRecipedelFn(id).then(res=>{
  91. if (res.code == 200) {
  92. that.$toast('删除成功')
  93. setTimeout(function(){
  94. that.reachflag = true;
  95. that.pageNum = 1;
  96. that.list = [];
  97. that.getDataFn();
  98. },1500)
  99. } else {
  100. that.$toast(res.msg)
  101. }
  102. })
  103. },
  104. toTree2(arr){
  105. var list=this.list;
  106. let newA = JSON.parse(JSON.stringify(arr));
  107. if(list&&list.length){
  108. list.forEach(ite=>{
  109. for(var i =0;i<newA.length;i++){
  110. if(ite.ayear === newA[i].ayear&&ite.amonth === newA[i].amonth){
  111. ite.children.push(newA[i])
  112. }else{
  113. var obj={
  114. ayear:newA[i].ayear,
  115. amonth:newA[i].amonth,
  116. check:true,
  117. children:[]
  118. }
  119. obj.children.push(newA[i])
  120. list.push(obj)
  121. }
  122. }
  123. })
  124. return list
  125. }else{
  126. var newArrs = [];
  127. var larr=[]
  128. const map = new Map();
  129. newArrs = newA.filter(v => !map.has(v.ayear)&&!map.has(v.amonth) && map.set(v.ayear, 1)&& map.set(v.amonth, 1));
  130. newArrs.forEach(ite=>{
  131. var obj={
  132. ayear:ite.ayear,
  133. amonth:ite.amonth,
  134. check:true
  135. }
  136. larr.push(obj)
  137. })
  138. larr.forEach(ite=>{
  139. ite.children = newA.filter(e => {
  140. return ite.ayear === e.ayear&&ite.amonth === e.amonth
  141. })
  142. })
  143. return larr
  144. }
  145. },
  146. bindDateChange(e){
  147. var val=e.detail.value;
  148. this.time=val;
  149. this.reachflag = true;
  150. this.pageNum = 1;
  151. this.list = [];
  152. this.getDataFn();
  153. },
  154. getAdd(){
  155. this.$tab.navigateTo(`/work/pages/menu/add`)
  156. },
  157. getDetail(id){
  158. this.$tab.navigateTo(`/work/pages/menu/add?id=`+id)
  159. },
  160. getDataFn(a) {
  161. var params = {
  162. pageSize: this.pageSize,
  163. pageNum: this.pageNum,
  164. }
  165. if(this.time){
  166. params.createDate=this.time
  167. }
  168. getRecipelistFn(params).then(res => {
  169. if (res.code == 200) {
  170. this.total = res.total;
  171. if (res.rows.length < this.pageSize) {
  172. this.reachflag = false
  173. this.wtdt = '到底了~';
  174. } else {
  175. var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum -1)
  176. if (num < res.total) {
  177. this.reachflag = true
  178. this.wtdt = '上拉加载更多'
  179. } else {
  180. this.reachflag = false
  181. this.wtdt = '到底了~';
  182. }
  183. }
  184. // 数据处理
  185. var newArr=res.rows;
  186. if(newArr&&newArr.length){
  187. var timeArr=[];
  188. Object.keys(newArr).some((key) => {
  189. if(newArr[key].urls){
  190. newArr[key].urls=newArr[key].urls.split(',')
  191. }else{
  192. newArr[key].urls=[]
  193. }
  194. if(newArr[key].createDate){
  195. var time=newArr[key].createDate.split('-');
  196. // var a=time[0].split('-')
  197. newArr[key].ayear=time[0];
  198. newArr[key].amonth=time[1];
  199. }
  200. })
  201. this.list=this.toTree2(newArr)
  202. }else{
  203. this.list=[]
  204. }
  205. } else {
  206. this.$toast(res.msg)
  207. }
  208. })
  209. },
  210. },
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. .menu{padding: 96rpx 24rpx 0rpx;min-height: 100vh;background-color: #ffffff;box-sizing: border-box;
  215. .mtop{position: fixed;left: 0;right: 0;top: 0;padding:12rpx 24rpx;background: #ffffff;z-index: 1;}
  216. .addimg{width: 136rpx;height: 136rpx;position: fixed;right: 24rpx;bottom: 44rpx;border-radius: 50%;z-index: 1;}
  217. }
  218. .stutoa{font-size: 28rpx;font-weight: bold;color: #666666;
  219. text{color: #4775EA;padding: 0 8rpx;}
  220. image{width: 22rpx;height: 12rpx;margin-left: 24rpx;}
  221. .stutoap{padding: 16rpx 0;margin: 0 6rpx;}
  222. }
  223. </style>