subscribe.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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.blessingPositionName" 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>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="button-wrap">
  57. <button type="default" class="u-reset-button sing-btn" @click="bindDate">
  58. 确认预约
  59. </button>
  60. </view>
  61. </view>
  62. <!-- 阁位 -->
  63. <c-form-type-action-sheet ref="pos" title="请选择阁位" :loadData="getPos">
  64. <template v-slot="{item}">
  65. <view>{{item.name}}</view>
  66. </template>
  67. </c-form-type-action-sheet>
  68. <!-- 提示框 -->
  69. <u-toast ref="uToast"></u-toast>
  70. </view>
  71. </template>
  72. <script>
  73. import dayjs from '@/common/dayjs/dayjs.min.js'
  74. export default {
  75. data() {
  76. return {
  77. form: {
  78. blessingPositionId: '',
  79. blessingPositionName: '',
  80. num: '',
  81. beginDate: dayjs().format('YYYY-MM-DD'),
  82. visitDate: dayjs().format('YYYY-MM-DD'),
  83. visitTime: ''
  84. },
  85. current: null,
  86. times: []
  87. };
  88. },
  89. mounted() {
  90. this.initTimes(this.form.visitDate)
  91. },
  92. methods: {
  93. /**
  94. * 比较时间大小 时间
  95. * @param {dayjs} time1
  96. * @param {dayjs} time2
  97. */
  98. isLittleTime(time1, time2){
  99. const diff = time1.diff(time2,'minutes' )
  100. if(diff >= 0){
  101. return false
  102. }else{
  103. return true
  104. }
  105. },
  106. async initTimes(date = '') {
  107. try{
  108. const res = await this.$api('signs.getOpenidVisitDateTime', {visitDate: date})
  109. const timeStr = dayjs().unix()
  110. this.current = null;
  111. let isfuzhi = false
  112. const time1 = dayjs()
  113. const time2YMD = dayjs(date)
  114. const times = res.data.map((item, index) => {
  115. let isCheck = false // 点击
  116. const _time2 = dayjs().year(time2YMD.year()).month(time2YMD.month()).day(time2YMD.day()).hour(item.visitTime.split(':')[0]).minute(item.visitTime.split(':')[1]).second(0);
  117. // 自动选中未录满
  118. if(this.isLittleTime(time1 , _time2) && item.max > item.num) {
  119. // 可以点击
  120. isCheck = true
  121. if(!isfuzhi){
  122. isfuzhi = true;
  123. this.current = index
  124. this.form.visitTime = item.visitTime;
  125. }
  126. }
  127. // 获取item
  128. return { id: timeStr + '' + index, text: item.visitTime, visitTime: item.visitTime, max: item.max, num: item.num, isCheck: isCheck}
  129. })
  130. this.times = times
  131. console.log(times, '---------')
  132. }catch(e){
  133. //TODO handle the exception
  134. }
  135. },
  136. async getPos(){
  137. const res = await this.$api('signs.getOpenidBlessingPosition', {})
  138. if(res.code != 200) {
  139. throw new Error("")
  140. }
  141. return res.data.map(item => {
  142. return { ...item, id: item.blessingPositionId, name: item.blessingPositionName }
  143. })
  144. },
  145. showPos() {
  146. this.$refs.pos.$open().then(res => {
  147. if(res.arr && res.arr.length > 0){
  148. this.form.blessingPositionId = res.arr[0].blessingPositionId
  149. this.form.blessingPositionName = res.arr[0].blessingPositionName
  150. }
  151. })
  152. },
  153. bindDateChange(date){
  154. const dateString = dayjs(date).format('YYYY-MM-DD')
  155. this.form.visitDate = dateString;
  156. this.current = 0;
  157. this.initTimes(dateString)
  158. },
  159. pickeClick(item, index){
  160. if(!item.isCheck) {
  161. this.$refs.uToast.show({type: 'error', message: '不能选择', position: 'top'})
  162. return
  163. }
  164. if(item.num >= item.max) {
  165. this.$refs.uToast.show({type: 'error', message: '时段已经约满', position: 'top'})
  166. return
  167. }
  168. this.form.visitTime = item.text;
  169. this.current = index
  170. },
  171. // 确认预约
  172. async bindDate(){
  173. if(!this.form.blessingPositionId){
  174. this.$refs.uToast.show({type: 'error', message: '请选择阁位', position: 'top'})
  175. return;
  176. }
  177. if(!this.form.num){
  178. this.$refs.uToast.show({type: 'error', message: '请输入随访人数量', position: 'top'})
  179. return;
  180. }
  181. if(!this.current && this.current != 0){
  182. this.$refs.uToast.show({type: 'error', message: '请选择随访时间', position: 'top'})
  183. return;
  184. }
  185. this.$refs.uToast.show({
  186. type: 'loading',
  187. message: '请稍后',
  188. })
  189. const res = await this.$api('signs.addOpenidVisit', {...this.form})
  190. this.$refs.uToast.hide()
  191. if(res.code == 200){
  192. // 这里此提示会被this.start()方法中的提示覆盖
  193. this.$refs.uToast.show({type: 'success', message: res.msg, position: 'top'})
  194. const {code, visitDate, visitTime, openid, blessingPositionId, blessingPositionName} = res.data;
  195. this.$st(() => {
  196. this.$u.route({
  197. url: '/pages/signs/invitation/invitation',
  198. type: "redirectTo",
  199. params: {
  200. code: code,
  201. visitDate: visitDate,
  202. visitTime: visitTime,
  203. }
  204. })
  205. })
  206. }else{
  207. this.$refs.uToast.show({type: 'error', message: res.msg, position: 'top'})
  208. }
  209. },
  210. navToAddress(){
  211. this.$st(() => {
  212. this.$u.route({
  213. url: '/pages/signs/address/address',
  214. type: "navigateTo",
  215. params: {
  216. }
  217. })
  218. })
  219. }
  220. },
  221. }
  222. </script>
  223. <style lang="scss" scoped>
  224. @import "./index.scss";
  225. </style>