foodInfomation.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <view class='content'>
  3. <view class='wrap'>
  4. <view v-for='item in foodInfomations'>
  5. <view>{{item.classify}}</view>
  6. <view style='margin:10rpx;' class='flex justify-space-between align-item-center' v-for='(item1,index) in item.data'>
  7. <view class='flex align-item-center'>
  8. <u-checkbox-group
  9. placement="column"
  10. @change="checkboxChange($event,item1)">
  11. <u-checkbox
  12. :customStyle="{marginBottom: '8px'}"
  13. :key="index"
  14. :name='item1.dishName'
  15. :checked='item1.checked'
  16. >
  17. </u-checkbox>
  18. </u-checkbox-group>
  19. <image v-if='!item1.edit' style='width:200rpx;height:200rpx;margin-right:20rpx;' :src="item1.dishImage" mode="aspectFill"></image>
  20. <u-upload v-else height='100' width='100' :fileList="item1[`fileList${item1.id}`]" @afterRead="afterRead($event,item1,item)" @delete="deletePic($event,item1,item)" :name="item1.id" multiple
  21. :maxCount="1">
  22. </u-upload>
  23. <view>
  24. <view v-if='!item1.edit'>{{item1.dishName}}</view>
  25. <u--input v-else inputAlign='right' v-model="item1.dishName" placeholder="输入菜品名称" border="none"></u--input>
  26. <view v-if='!item1.edit'>{{item1.dishPrice}}</view>
  27. <u--input v-else inputAlign='right' v-model="item1.dishPrice" placeholder="输入菜品单价" border="none"></u--input>
  28. </view>
  29. </view>
  30. <view>
  31. <view v-if='!item1.edit' @click='edit(item1)' class='button1 button'>编辑</view>
  32. <view v-if='item1.edit' @click='submit(item1)' class='button1 button'>确定</view>
  33. <view v-if='item1.edit' @click='item1.edit = false' class='default_button'>取消</view>
  34. <view v-if='!item1.edit' class='default_button'>置顶</view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <view style='padding:10px;' class='footer flex justify-space-between align-item-center'>
  40. <u-checkbox-group
  41. placement="column"
  42. @change="checkboxAllChange">
  43. <u-checkbox
  44. :customStyle="{marginBottom: '8px'}"
  45. name='全选'
  46. label='全选'
  47. :checked="checkAll"
  48. >
  49. </u-checkbox>
  50. </u-checkbox-group>
  51. <view class='flex align-item-center'>
  52. <view @click='del' style='margin-right:10rpx;' class='caution_button'>删除</view>
  53. <view @click='add' class='button'>添加</view>
  54. </view>
  55. </view>
  56. <u-modal :show="isSubmit" content='确定删除菜品?' @confirm="$u.debounce(confirmSubmit, 500)" showCancelButton
  57. @cancel="isSubmit=false" @close="isSubmit=false" closeOnClickOverlay></u-modal>
  58. </view>
  59. </template>
  60. <script>
  61. var that
  62. import uploadImage from '@/components/ossutil/uploadFile.js';
  63. export default {
  64. data() {
  65. return {
  66. foodInfomations:[],
  67. currect:{},
  68. checkList:[],
  69. checkAll:false,
  70. dataList:[],
  71. isSubmit:false,
  72. }
  73. },
  74. onLoad() {
  75. that = this
  76. if(uni.getStorageSync('myCateringdustry')){
  77. this.currect=JSON.parse(uni.getStorageSync('myCateringdustry'))
  78. this.getList()
  79. }
  80. },
  81. onShow(){
  82. },
  83. methods: {
  84. // 删除图片
  85. deletePic(event,item1,item) {
  86. console.log(item1,item)
  87. item1[`fileList${item1.id}`].splice(event.index, 1)
  88. this.$forceUpdate()
  89. // that.indoorImageArray.splice(event.index, 1)
  90. // that.currectData.indoorImage =that.indoorImageArray.toString()
  91. },
  92. // 新增图片
  93. async afterRead(event,item1,item) {
  94. console.log(item1,item)
  95. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  96. let lists = [].concat(event.file)
  97. let fileListLen = item1[`fileList${item1.id}`].length
  98. lists.map((item2) => {
  99. item1[`fileList${item1.id}`].push({
  100. ...item2,
  101. status: 'uploading',
  102. message: '上传中'
  103. })
  104. })
  105. for (let i = 0; i < lists.length; i++) {
  106. const result = await this.uploadFilePromise(lists[i].url,item1)
  107. let item = item1[`fileList${item1.id}`][fileListLen]
  108. item1[`fileList${item1.id}`].splice(fileListLen, 1, Object.assign(item, {
  109. status: 'success',
  110. message: '',
  111. url: result
  112. }))
  113. fileListLen++
  114. this.$forceUpdate()
  115. }
  116. },
  117. uploadFilePromise(res,item) {
  118. return new Promise((resolve, reject) => {
  119. uploadImage(res, 'cardImages/',
  120. result => {
  121. item.dishImage = result
  122. resolve(res)
  123. }
  124. )
  125. })
  126. },
  127. submit(item){
  128. this.$request.baseRequest('admin.tourism.foodDishesInfo', 'update', {
  129. foodDishesInfo:JSON.stringify(item)
  130. }, failres => {
  131. uni.showToast({
  132. icon: "none",
  133. title: failres.errmsg,
  134. duration: 3000
  135. });
  136. }).then(res => {
  137. uni.showToast({
  138. icon: "success",
  139. title: '编辑菜品成功',
  140. duration: 2000
  141. });
  142. this.getList()
  143. })
  144. },
  145. del(){
  146. this.isSubmit = true
  147. },
  148. confirmSubmit(){
  149. uni.showLoading({
  150. title: '加载中',
  151. mask: true
  152. })
  153. for(var i = 0;i<this.checkList.length;i++){
  154. this.$request.baseRequest('admin.tourism.foodDishesInfo', 'delete', {
  155. id:this.checkList[i].id
  156. }, failres => {
  157. uni.showToast({
  158. icon: "none",
  159. title: failres.errmsg,
  160. duration: 3000
  161. });
  162. uni.hideLoading()
  163. }).then(res => {
  164. this.isSubmit = false
  165. if(this.checkList.length==1||i==this.checkList.length-1){
  166. uni.hideLoading()
  167. uni.showToast({
  168. icon: "success",
  169. title: '删除菜品成功',
  170. duration: 2000
  171. });
  172. this.getList()
  173. }
  174. })
  175. }
  176. },
  177. checkboxAllChange(e){
  178. console.log(e)
  179. this.checkAll = !this.checkAll;
  180. for(var i = 0; i < this.foodInfomations.length; i++){
  181. for(var q = 0; q < this.foodInfomations[i].data.length; q++){
  182. this.foodInfomations[i].data[q].checked = this.checkAll
  183. }
  184. }
  185. console.log(this.foodInfomations)
  186. this.$forceUpdate()
  187. },
  188. edit(item){
  189. console.log(item)
  190. item.edit = true
  191. this.$forceUpdate()
  192. },
  193. checkboxChange(e,item1){
  194. console.log(e,item1)
  195. var checkData = this.checkList.filter((item)=>{return item.id==item1.id})
  196. item1.checked = !item1.checked
  197. if(e[0]){
  198. if(checkData.length==0){
  199. this.checkList.push(item1)
  200. }else{
  201. var checkindex = this.checkList.findIndex((item)=>{return item.id==item1.id})
  202. this.checkList[checkindex]=item1
  203. }
  204. }else{
  205. var checkindex = this.checkList.findIndex((item)=>{return item.id==item1.id})
  206. this.checkList.splice(checkindex,1)
  207. }
  208. },
  209. add(){
  210. uni.navigateTo({
  211. url:'/pageA/enter/myCateringdustry/addfood?foodId='+this.currect.id+'&shopNames='+this.currect.shopNames
  212. })
  213. },
  214. deWeightFour(arr) {
  215. var obj = {};
  216. arr = arr.reduce(function(a, b) {
  217. obj[b.classify] ? '' : obj[b.classify] = true && a.push({classify:b.classify,data:[]});
  218. return a;
  219. }, [])
  220. return arr;
  221. },
  222. getList(){
  223. this.$request.baseRequest('admin.tourism.foodDishesInfo', 'list', {
  224. foodId:this.currect.id,
  225. page:1,
  226. limit:9999
  227. }, failres => {
  228. uni.showToast({
  229. icon: "none",
  230. title: failres.errmsg,
  231. duration: 3000
  232. });
  233. }).then(res => {
  234. var arr = res.data.items
  235. var newArr = this.deWeightFour(arr);
  236. for(var i=0;i<arr.length;i++){
  237. this.dataList=res.data.items
  238. var currectList=newArr.filter((item)=>{return item.classify==arr[i].classify})
  239. arr[i].checked = false
  240. arr[i].edit = false
  241. arr[i][`fileList${arr[i].id}`]=[{url:arr[i].dishImage}]
  242. currectList[0].data.push(arr[i])
  243. }
  244. this.foodInfomations = newArr
  245. console.log(this.foodInfomations)
  246. })
  247. },
  248. }
  249. }
  250. </script>
  251. <style lang='scss' scoped>
  252. .button1{
  253. margin-bottom:20rpx;
  254. }
  255. </style>