eat.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <view>
  3. <view class="navbox">
  4. <uni-nav-bar color="#ffffff" left-icon="left" title="就餐预订" :background-color="backgroundColor"
  5. :border="false" statusBar='true' fixed="true" @clickLeft='getBack'>
  6. </uni-nav-bar>
  7. </view>
  8. <image :src="navbg" class="navbg"></image>
  9. <view class="zxmain" :style="'margin-top:-'+marTop+'rpx;'">
  10. <view class="ytbox">
  11. <uni-forms ref="form" class="ytforms" :modelValue="datainfo">
  12. <view class="ytsbox">
  13. <view class="yttit">预订信息</view>
  14. <view class="pt5">
  15. <uni-forms-item label="就餐日期" name="orderFoodTime">
  16. <picker mode="date" class="pickbox"
  17. @change="bindTimeChangea">
  18. <view class="flexc flex1">
  19. <view class="flex1 " :class="datainfo.orderFoodTime?'co16 fw5 f14':'coa f14'">
  20. {{datainfo.orderFoodTime||'请选择'}}</view>
  21. <image :src="hupimg" class="hupimg"></image>
  22. </view>
  23. </picker>
  24. </uni-forms-item>
  25. <uni-forms-item label="就餐类型" name="orderFoodType">
  26. <picker class="pickbox" range-key='label' :value="jclxidx"
  27. :range="jclxlist" @change="bindTimeChangeb">
  28. <view class="flexc flex1">
  29. <!-- <view class="flex1 " :class="orderFoodType?'co16 fw5 f14':'coa f14'">
  30. {{orderFoodType||'请选择'}}</view> -->
  31. <view class="flex1 f14" v-if="datainfo.orderFoodType&&!jclx">{{statusFormat(datainfo.orderFoodType,jclxlist,'jclx')}}</view>
  32. <view class="flex1 f14" v-else :class="jclx?'':'coa'">{{jclx||"请选择就餐类型"}}</view>
  33. <image :src="hupimg" class="hupimg"></image>
  34. </view>
  35. </picker>
  36. </uni-forms-item>
  37. <uni-forms-item label="姓名" class="disable" name="orderFoodUser">
  38. <view class="intit">{{datainfo.orderFoodUser}}</view>
  39. <!-- <uni-easyinput :inputBorder="false" disabled v-model="datainfo.visitName" placeholder="请输入姓名">
  40. </uni-easyinput> -->
  41. </uni-forms-item>
  42. <uni-forms-item label="部 门" class="disable" name="orderFoodDept">
  43. <view class="intit">{{datainfo.orderFoodDept}}</view>
  44. <!-- <uni-easyinput :inputBorder="false" disabled type="number" v-model="datainfo.visitPhone"
  45. placeholder="请输入手机号码">
  46. </uni-easyinput> -->
  47. </uni-forms-item>
  48. </view>
  49. <view class="ybtn flexcc" @click="getSubmit">确认提交</view>
  50. <view class="tips">* 为响应国家号召,请您视真实情况填写,珍惜粮食,适量定 餐,避免剩餐,减少浪费。</view>
  51. </view>
  52. </uni-forms>
  53. </view>
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. import {checkPermi,checkRole} from "@/utils/permission"; // 权限判断函数
  59. import {getFoodAdd,getFoodPut,getFoodDetail} from "@/api/mine/work.js"
  60. import {getDictionaryFn} from "@/api/mine/register.js"
  61. import {selectValueKey} from "@/utils/common.js"
  62. export default {
  63. components: {},
  64. data() {
  65. return {
  66. hupimg:require("@/static/images/order/hup.png"),
  67. navbg:require("@/static/images/navbg.png"),
  68. backgroundColor: "transparent",
  69. nvaHeight: 44,
  70. marTop: 0, //距离顶部的距离
  71. stubarHeight: 0, //
  72. datainfo:{
  73. "orderFoodTime": "",//就餐时间
  74. "orderFoodType": "",//1:午餐 2:晚餐
  75. "orderFoodUser":"",//就餐人员名称
  76. "orderFoodUserId":"",//就餐人员id(用户id)
  77. "orderFoodDept":"",//就餐人员部门
  78. "orderFoodDeptId":"",//就餐人员部门id
  79. },
  80. jclx:'',
  81. jclxidx:'',
  82. jclxlist:[],
  83. ptype:'add',
  84. id:'',
  85. name:this.$store.state.user.name,
  86. userId:this.$store.state.user.userId,
  87. deptId:this.$store.state.user.deptId,
  88. deptName:this.$store.state.user.deptName,
  89. }
  90. },
  91. onPageScroll(e) {
  92. var scrollTop = Number(e.scrollTop);
  93. if (scrollTop > 0) {
  94. this.backgroundColor = '#0491FD'
  95. } else {
  96. this.backgroundColor = 'transparent'
  97. }
  98. },
  99. onLoad: function(e) {
  100. if(e.data){
  101. var data=JSON.parse(decodeURIComponent(e.data))
  102. if(data.type){
  103. this.ptype=data.type;
  104. this.id=data.id;
  105. this.getDetail()
  106. }
  107. }else{
  108. this.datainfo.orderFoodUser=this.name;
  109. this.datainfo.orderFoodUserId=this.userId;
  110. this.datainfo.orderFoodDept=this.deptName;
  111. this.datainfo.orderFoodDeptId=this.deptId;
  112. this.time()
  113. }
  114. this.init()
  115. // this.getDataFn()
  116. uni.getSystemInfo({
  117. success: (e) => {
  118. this.stubarHeight = Number(e.statusBarHeight);
  119. this.nvaHeight = Number(e.statusBarHeight) + 44;
  120. this.tabscheight = Number(this.nvaHeight) * 2 + 100;
  121. }
  122. })
  123. },
  124. onShow() {},
  125. mounted() {
  126. this.getHeightFn()
  127. },
  128. methods: {
  129. checkPermi,
  130. checkRole,
  131. getBack() {
  132. uni.navigateBack({
  133. delta: 1
  134. })
  135. },
  136. statusFormat(ite,list,type) {
  137. var aite=selectValueKey(list, ite);
  138. if(type=='jclx'){
  139. this.jclxidx=aite.key
  140. }
  141. return aite.actions;
  142. },
  143. init() {
  144. // 就餐类型
  145. getDictionaryFn('jiucan').then(res=>{
  146. if(res.code==200){
  147. this.jclxlist = res.data.map(v => {
  148. return {
  149. label: v.dictLabel,
  150. value: v.dictValue
  151. }
  152. })
  153. }
  154. })
  155. },
  156. time() {
  157. var date = new Date();
  158. var y = date.getFullYear();
  159. var m = date.getMonth() + 1;
  160. var d = date.getDate();
  161. var yearStr = y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d)
  162. // var timeStr = (h < 10 ? ('0' + h) : h) + ':' + (min < 10 ? ('0' + min) : min) + ':' + (s < 10 ? (
  163. // '0' + s) : s);
  164. this.datainfo.orderFoodTime= yearStr
  165. },
  166. bindTimeChangea(e){
  167. var val=e.detail.value;
  168. this.datainfo.orderFoodTime=val
  169. },
  170. bindTimeChangeb(e){
  171. var val=e.detail.value;
  172. this.datainfo.orderFoodType=this.jclxlist[val].value
  173. this.jclx=this.jclxlist[val].label
  174. },
  175. getHeightFn() {
  176. let query = uni.createSelectorQuery().in(this);
  177. //需要给黄色区域设置一个id标识,在这里是demo
  178. query.select('.navbox').boundingClientRect(data => {
  179. var top = data.top < 0 ? -data.top : data.top;
  180. var stubarHeight = Number(this.stubarHeight);
  181. this.marTop = stubarHeight > 0 ? 692 - Number(data.height) * 2 : 692 - Number(data.height) *
  182. 2 + 40 //赋值,待会要用
  183. if (top <= this.nvaHeight) {
  184. const opacity = top / 100 // 计算透明度值
  185. const color = `rgba(4, 145, 253, ${opacity})`
  186. this.backgroundColor = color // 更新盒子背景颜色
  187. } else {
  188. this.backgroundColor = '#00A9F0'
  189. }
  190. }).exec();
  191. },
  192. getSubmit() {
  193. var that=this;
  194. var params = JSON.parse(JSON.stringify(this.datainfo))
  195. if(!params.orderFoodTime){
  196. this.$toast("请选择就餐日期")
  197. return
  198. }
  199. if(!this.jclx){
  200. this.$toast("请选择就餐类型")
  201. return
  202. }
  203. uni.showLoading({
  204. title:"加载中"
  205. })
  206. if(this.ptype=='add'){
  207. getFoodAdd(params).then(res => {
  208. uni.hideLoading()
  209. if (res.code == 200) {
  210. this.$toast("预约成功")
  211. setTimeout(function(){
  212. uni.$emit('refreshfoodlist')
  213. uni.navigateBack({
  214. delta:1
  215. })
  216. },1200)
  217. } else {
  218. this.$toast(res.msg)
  219. }
  220. })
  221. }else{
  222. getFoodPut(params).then(res => {
  223. uni.hideLoading()
  224. if (res.code == 200) {
  225. this.$toast("修改成功")
  226. setTimeout(function(){
  227. uni.$emit('refreshfoodlist')
  228. uni.navigateBack({
  229. delta:1
  230. })
  231. },1200)
  232. } else {
  233. this.$toast(res.msg)
  234. }
  235. })
  236. }
  237. },
  238. getDetail(){
  239. getFoodDetail(this.id).then(res=>{
  240. if(res.code==200){
  241. this.datainfo=JSON.parse(JSON.stringify(res.data))
  242. }
  243. })
  244. }
  245. },
  246. }
  247. </script>
  248. <style>
  249. /* page {
  250. background: #ffffff;
  251. } */
  252. </style>
  253. <style lang="scss" scoped>
  254. .ytbox /deep/ .uni-forms .uni-forms-item{padding: 10rpx 26rpx 10rpx;border: 2rpx solid #0391FD;margin-bottom: 24rpx;border-radius: 12rpx;}
  255. .ytbox /deep/ .uni-forms-item__label{flex: 0 0 auto;width: 144rpx !important;font-size: 28rpx;font-weight: bold;position: relative;color: #161616;text-align-last: justify;}
  256. .ytbox /deep/ .uni-forms-item__label text{flex: 1;}
  257. .ytbox /deep/ .uni-forms-item__label .is-required{position: absolute;right: 0;color: #F10C31;margin-top: 16rpx;}
  258. .ytbox /deep/ uni-textarea{flex: 1;width: auto;text-align: right;}
  259. .ytbox /deep/ .uni-textarea-placeholder{font-size: 28rpx;color: #DDDDDD !important;}
  260. .ytbox /deep/ .uni-easyinput__placeholder-class{font-size: 28rpx;color: #DDDDDD;}
  261. .ytbox /deep/ .uni-forms-item__content{display: flex;align-items: center;flex-direction: row;}
  262. .ytbox /deep/ .uni-easyinput{flex: 1;text-align: right;}
  263. .ytbox /deep/ .uni-easyinput__content-input{font-size: 28rpx;}
  264. .ytbox /deep/ .uni-forms-item__error{margin-top:20rpx;left: auto;right: 0;}
  265. .disable{background: #EFF0F2;border: none !important;}
  266. .ytbox{width: 684rpx;margin: 0 auto;padding-top: 24rpx;position: relative;flex: 1;overflow: auto;background-color: #ffffff;padding-bottom: 4rpx;border-radius: 14rpx;}
  267. .ytforms{
  268. .yttit{font-size: 28rpx;font-weight: bold;margin-bottom: 56rpx;
  269. color: #161616;display: flex;align-items: center;padding: 0rpx 26rpx;box-sizing: border-box;position: relative;
  270. &::before{content: '';width: 6rpx;height: 34rpx;background: $com-cd3;border-radius: 4rpx;position: absolute;top: 50%;transform: translateY(-50%);left: 0rpx;}
  271. }
  272. .ytsbox{background-color: #ffffff;padding: 32rpx 28rpx 0;border-radius: 14rpx;margin-bottom: 24rpx;
  273. .intit{font-weight: 500;flex: 1;font-size: 26rpx;text-align: right;color: #666666;}
  274. .pickbox{flex: 1;text-align: right;font-weight: 500;font-size: 28rpx;color: #161616;
  275. .hupimg{width: 18rpx;height: 14rpx;margin-left: 12rpx;flex: 0 0 auto;}
  276. }
  277. }
  278. }
  279. // 按钮
  280. .ybtn{width: 100%;height: 90rpx;background: $com-cd3;border-radius: 14rpx;margin: 100rpx auto 0;font-size: 28rpx;font-weight: 500;color: #FFFFFF;
  281. &.btn1{background-color: #9a9c9e;}
  282. }
  283. .tips{font-weight: bold;margin-top: 28rpx;
  284. font-size: 22rpx;line-height: 34rpx;
  285. color: #FF0000;}
  286. .navbox{position: fixed;left: 0;right: 0;top: 0;z-index: 4; }
  287. .navbg{width: 100%;height: 692rpx;}
  288. .zxmain{position: relative;padding: 20rpx 32rpx 40rpx;box-sizing: border-box;display: flex;
  289. min-height: calc(100vh - 44px);
  290. }
  291. </style>