subscribe.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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" v-if="item.num">{{item.num}}/{{item.max}}</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 _time2 = dayjs().year(time2YMD.year()).month(time2YMD.month()).date(time2YMD.date()).hour(item.visitTime.split(':')[0]).minute(item.visitTime.split(':')[1]).second(0);
  120. // 自动选中未录满
  121. if(this.isLittleTime(time1 , _time2) && item.max > item.num) {
  122. // 可以点击
  123. isCheck = true
  124. if(!isfuzhi){
  125. isfuzhi = true;
  126. this.current = index
  127. this.form.visitTime = item.visitTime;
  128. }
  129. }
  130. // 获取item
  131. return { id: timeStr + '' + index, text: item.visitTime, visitTime: item.visitTime, max: item.max, num: item.num, isCheck: isCheck}
  132. })
  133. this.times = times
  134. // console.log(times, '---------')
  135. }catch(e){
  136. console.log(e)
  137. //TODO handle the exception
  138. }
  139. },
  140. async getPos(){
  141. const res = await this.$api('signs.getOpenidCabinetPosition', {})
  142. if(res.code != 200) {
  143. throw new Error("")
  144. }
  145. return res.data.map(item => {
  146. return { ...item, id: item.cabinetPositionId, area: item.cabinetAreaName || '未获取', name: item.cabinetPositionName || '未获取' }
  147. })
  148. },
  149. showPos() {
  150. this.$refs.pos.$open().then(res => {
  151. if(res.arr && res.arr.length > 0){
  152. this.form.cabinetPositionId = res.arr[0].cabinetPositionId
  153. this.form.cabinetPositionName = res.arr[0].cabinetPositionName
  154. this.form.andName = (res.arr[0].cabinetAreaName || '未获取到') + '-' + (res.arr[0].cabinetPositionName || '未获取到')
  155. }
  156. })
  157. },
  158. bindDateChange(date){
  159. const dateString = dayjs(date).format('YYYY-MM-DD')
  160. this.form.visitDate = dateString;
  161. this.current = 0;
  162. this.initTimes(dateString)
  163. },
  164. pickeClick(item, index){
  165. if(!item.isCheck) {
  166. this.$refs.uToast.show({type: 'error', message: '不能选择', position: 'top'})
  167. return
  168. }
  169. if(item.num >= item.max) {
  170. this.$refs.uToast.show({type: 'error', message: '时段已经约满', position: 'top'})
  171. return
  172. }
  173. this.form.visitTime = item.text;
  174. this.current = index
  175. },
  176. // 确认预约
  177. async bindDate(){
  178. if(!this.form.cabinetPositionId){
  179. this.$refs.uToast.show({type: 'error', message: '请选择阁位', position: 'top'})
  180. return;
  181. }
  182. if(!this.form.num){
  183. this.$refs.uToast.show({type: 'error', message: '请输入随访人数量', position: 'top'})
  184. return;
  185. }
  186. if(!this.current && this.current != 0){
  187. this.$refs.uToast.show({type: 'error', message: '请选择随访时间', position: 'top'})
  188. return;
  189. }
  190. this.$refs.uToast.show({
  191. type: 'loading',
  192. message: '请稍后',
  193. })
  194. const res = await this.$api('signs.addOpenidVisit', {...this.form})
  195. this.$refs.uToast.hide()
  196. if(res.code == 200){
  197. // 这里此提示会被this.start()方法中的提示覆盖
  198. this.$refs.uToast.show({type: 'success', message: res.msg, position: 'top'})
  199. const {code, visitDate, visitTime, openid, cabinetPositionId, cabinetPositionName} = res.data;
  200. this.$st(() => {
  201. this.$u.route({
  202. url: '/pages/signs/invitation/invitation',
  203. type: "redirectTo",
  204. params: {
  205. code: code,
  206. visitDate: visitDate,
  207. visitTime: visitTime,
  208. }
  209. })
  210. })
  211. }else{
  212. this.$refs.uToast.show({type: 'error', message: res.msg, position: 'top'})
  213. }
  214. },
  215. navToAddress(){
  216. this.$st(() => {
  217. this.$u.route({
  218. url: '/pages/signs/address/address',
  219. type: "navigateTo",
  220. params: {
  221. }
  222. })
  223. })
  224. }
  225. },
  226. }
  227. </script>
  228. <style lang="scss" scoped>
  229. @import "./index.scss";
  230. </style>