subscribe.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <view class="sign-page">
  3. <view class="view-wrap">
  4. <view class="card">
  5. <view class="form-item">
  6. <view class="form-item__title">
  7. <view class="name">请选择阁位</view>
  8. <view class="extra" @click="navToAddress">添加阁位</view>
  9. </view>
  10. <view class="form-item__input__wrap" @click="showPos">
  11. <view class="form-item__input">
  12. <input placeholder-class="input-placeholder" class="input" type="text" :value="form.andName" placeholder="请选择阁位" disabled />
  13. <view class="icon"><image style="width: 16rpx;height: 16rpx;" src="/static/app/page3/arrow-down.png" mode="aspectFit"></image></view>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="form-item">
  18. <view class="form-item__title">
  19. <view class="name">人数随访人数</view>
  20. <view class="extra"></view>
  21. </view>
  22. <view class="form-item__input__wrap">
  23. <view class="form-item__input">
  24. <input placeholder-class="input-placeholder" class="input" type="number" v-model="form.num" placeholder="点击输入到访人数" />
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="divide"></view>
  30. <view class="card">
  31. <view class="date-name">预约时间</view>
  32. <view class="date-box">
  33. <c-datepicker v-model="form.day" @change="bindDateChange" :beginDate="form.beginDate"></c-datepicker>
  34. <view class="date-divide"></view>
  35. <view class="date-time-wrap">
  36. <view class="label">可选时间段</view>
  37. <view class="time-range" v-if="times.length > 0">
  38. <swiper class="picker-view" vertical :autoplay="false" :display-multiple-items="9">
  39. <swiper-item v-for="(item, index) in times" :key="item.id">
  40. <view class="picker-item" :hover-stay-time="100" hover-class="hover-active" :class="{active: index == current}" @click="pickeClick(item, index)">
  41. <view class="value" :class="{not : !item.isCheck}">{{item.text}}</view>
  42. <view class="tig">可预约{{item.max - item.num}}人</view>
  43. <view class="stauts-wrap">
  44. <view class="mark" v-if="index == current">
  45. <image style="width: 30rpx;height: 30rpx;" src="/static/app/page3/mark.png" mode="aspectFit"></image>
  46. </view>
  47. <text v-else-if="item.num >= item.max" class="msg">已约满</text>
  48. </view>
  49. </view>
  50. </swiper-item>
  51. </swiper>
  52. <view class="cover-swiper"></view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <view class="button-wrap">
  58. <button type="default" class="u-reset-button sing-btn" @click="bindDate">
  59. 确认预约
  60. </button>
  61. </view>
  62. </view>
  63. <!-- 阁位 -->
  64. <c-form-type-action-sheet ref="pos" title="请选择阁位" :loadData="getPos">
  65. <template v-slot="{item}">
  66. <view>{{item.area}}-{{item.name}}</view>
  67. </template>
  68. </c-form-type-action-sheet>
  69. <!-- 提示框 -->
  70. <u-toast ref="uToast"></u-toast>
  71. </view>
  72. </template>
  73. <script>
  74. import dayjs from '@/common/dayjs/dayjs.min.js'
  75. export default {
  76. data() {
  77. return {
  78. form: {
  79. cabinetPositionId: '',
  80. cabinetPositionName: '',
  81. andName: '',
  82. num: '',
  83. day: dayjs().add(1, 'day').format('YYYY/MM/DD'),
  84. beginDate: dayjs().format('YYYY-MM-DD'),
  85. visitDate: dayjs().add(1, 'day').format('YYYY-MM-DD'),
  86. visitTime: ''
  87. },
  88. current: null,
  89. times: []
  90. };
  91. },
  92. mounted() {
  93. this.initTimes(this.form.visitDate)
  94. },
  95. methods: {
  96. /**
  97. * 比较时间大小 时间
  98. * @param {dayjs} time1
  99. * @param {dayjs} time2
  100. */
  101. isLittleTime(time1, time2){
  102. const diff = time1.diff(time2,'minutes' )
  103. if(diff >= 0){
  104. return false
  105. }else{
  106. return true
  107. }
  108. },
  109. async initTimes(date = '') {
  110. try{
  111. const res = await this.$api('signs.getOpenidVisitDateTime', {visitDate: date})
  112. const timeStr = dayjs().unix()
  113. this.current = null;
  114. let isfuzhi = false
  115. const time1 = dayjs()
  116. const time2YMD = dayjs(date)
  117. const times = res.data.map((item, index) => {
  118. let isCheck = false // 点击
  119. const textStr = item.visitTime;
  120. const _visitTime = item.visitTime.split('-')
  121. const visitTime = _visitTime[_visitTime.length - 1]
  122. const _time2 = dayjs().year(time2YMD.year()).month(time2YMD.month()).date(time2YMD.date()).hour(visitTime.split(':')[0]).minute(visitTime.split(':')[1]).second(0);
  123. // 自动选中未录满
  124. if(this.isLittleTime(time1 , _time2) && item.max > item.num) {
  125. // 可以点击
  126. isCheck = true
  127. if(!isfuzhi){
  128. isfuzhi = true;
  129. this.current = index
  130. this.form.visitTime = visitTime;
  131. }
  132. }
  133. // 获取item
  134. return { id: timeStr + '' + index, text: item.visitTime, visitTime: visitTime, max: item.max, num: item.num, isCheck: isCheck}
  135. })
  136. this.times = times
  137. // console.log(times, '---------')
  138. }catch(e){
  139. console.log(e)
  140. //TODO handle the exception
  141. }
  142. },
  143. async getPos(){
  144. const res = await this.$api('signs.getOpenidCabinetPosition', {})
  145. if(res.code != 200) {
  146. throw new Error("")
  147. }
  148. return res.data.map(item => {
  149. return { ...item, id: item.cabinetPositionId, area: item.cabinetAreaName || '未获取', name: item.cabinetPositionName || '未获取' }
  150. })
  151. },
  152. showPos() {
  153. this.$refs.pos.$open().then(res => {
  154. if(res.arr && res.arr.length > 0){
  155. this.form.cabinetPositionId = res.arr[0].cabinetPositionId
  156. this.form.cabinetPositionName = res.arr[0].cabinetPositionName
  157. this.form.andName = (res.arr[0].cabinetAreaName || '未获取到') + '-' + (res.arr[0].cabinetPositionName || '未获取到')
  158. }
  159. })
  160. },
  161. bindDateChange(date){
  162. const dateString = dayjs(date).format('YYYY-MM-DD')
  163. this.form.visitDate = dateString;
  164. this.current = 0;
  165. this.initTimes(dateString)
  166. },
  167. pickeClick(item, index){
  168. if(!item.isCheck) {
  169. this.$refs.uToast.show({type: 'error', message: '不能选择', position: 'top'})
  170. return
  171. }
  172. if(item.num >= item.max) {
  173. this.$refs.uToast.show({type: 'error', message: '时段已经约满', position: 'top'})
  174. return
  175. }
  176. this.form.visitTime = item.visitTime;
  177. this.current = index
  178. },
  179. // 确认预约
  180. async bindDate(){
  181. if(!this.form.cabinetPositionId){
  182. this.$refs.uToast.show({type: 'error', message: '请选择阁位', position: 'top'})
  183. return;
  184. }
  185. if(!this.form.num){
  186. this.$refs.uToast.show({type: 'error', message: '请输入随访人数量', position: 'top'})
  187. return;
  188. }
  189. if(!this.current && this.current != 0){
  190. this.$refs.uToast.show({type: 'error', message: '请选择随访时间', position: 'top'})
  191. return;
  192. }
  193. this.$refs.uToast.show({
  194. type: 'loading',
  195. message: '请稍后',
  196. })
  197. const res = await this.$api('signs.addOpenidVisit', {...this.form})
  198. this.$refs.uToast.hide()
  199. if(res.code == 200){
  200. // 这里此提示会被this.start()方法中的提示覆盖
  201. this.$refs.uToast.show({type: 'success', message: res.msg, position: 'top'})
  202. const {code, visitDate, visitTime, openid, cabinetPositionId, cabinetPositionName} = res.data;
  203. this.$st(() => {
  204. this.$u.route({
  205. url: '/pages/signs/invitation/invitation',
  206. type: "redirectTo",
  207. params: {
  208. code: code,
  209. visitDate: visitDate,
  210. visitTime: visitTime,
  211. }
  212. })
  213. })
  214. }else{
  215. this.$refs.uToast.show({type: 'error', message: res.msg, position: 'top'})
  216. }
  217. },
  218. navToAddress(){
  219. this.$st(() => {
  220. this.$u.route({
  221. url: '/pages/signs/address/address',
  222. type: "navigateTo",
  223. params: {
  224. }
  225. })
  226. })
  227. }
  228. },
  229. }
  230. </script>
  231. <style lang="scss" scoped>
  232. @import "./index.scss";
  233. </style>