address.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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"></view>
  9. </view>
  10. <view class="form-item__input__wrap">
  11. <view class="form-item__input" @click="showArea">
  12. <input placeholder-class="input-placeholder" class="input" type="text" :value="form.blessingAreaName" 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" @click="showPos">
  24. <input placeholder-class="input-placeholder" class="input" type="text" :value="form.blessingPositionName" placeholder="请选择阁位" disabled />
  25. <view class="icon"><image style="width: 16rpx;height: 16rpx;" src="/static/app/page3/arrow-down.png" mode="aspectFit"></image></view>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="form-item">
  30. <view class="form-item__title">
  31. <view class="name">经办人验证码</view>
  32. <view class="extra">
  33. </view>
  34. </view>
  35. <view class="form-item__input__wrap">
  36. <view class="form-item__input">
  37. <input placeholder-class="input-placeholder" class="input" type="text" v-model="form.code" placeholder="请输入验证码" />
  38. </view>
  39. </view>
  40. </view>
  41. <view class="tip-btn" :class="{disable: send}" @click="getCode">{{tips}}</view>
  42. </view>
  43. <view class="button-wrap">
  44. <button type="default" class="u-reset-button sing-btn" @click="confirm">
  45. 确认绑定
  46. </button>
  47. </view>
  48. </view>
  49. <!-- 区域 -->
  50. <c-form-type-action-sheet ref="area" title="请选择区域" :loadData="getArea">
  51. <template v-slot="{item}">
  52. <view>{{item.name}}</view>
  53. </template>
  54. </c-form-type-action-sheet>
  55. <!-- 阁位 -->
  56. <c-form-type-action-sheet ref="pos" title="请选择阁位" :loadData="getPos">
  57. <template v-slot="{item}">
  58. <view>{{item.name}}</view>
  59. </template>
  60. </c-form-type-action-sheet>
  61. <!-- 验证码 -->
  62. <u-code :seconds="seconds" @end="end" @start="start" ref="uCode" @change="codeChange"></u-code>
  63. <!-- 提示框 -->
  64. <u-toast ref="uToast"></u-toast>
  65. </view>
  66. </template>
  67. <script>
  68. export default {
  69. data() {
  70. return {
  71. tips: '获取验证码',
  72. seconds: 60,
  73. send: false,
  74. form: {
  75. blessingAreaId: '',
  76. blessingAreaName: '',
  77. blessingPositionId: '',
  78. blessingPositionName: '',
  79. code: '',
  80. },
  81. };
  82. },
  83. mounted() {
  84. // this.initTimes()
  85. },
  86. methods: {
  87. async getArea(keyWord){
  88. const res = await this.$api('signs.getBlessingArea', {})
  89. if(res.code != 200) {
  90. throw new Error("")
  91. }
  92. return res.data.map(item => {
  93. return { ...item, id: item.blessingAreaId, name: item.blessingAreaName }
  94. })
  95. },
  96. showArea() {
  97. this.$refs.area.$open().then(res => {
  98. if(res.arr && res.arr.length > 0){
  99. this.form.blessingAreaId = res.arr[0].blessingAreaId
  100. this.form.blessingAreaName = res.arr[0].blessingAreaName
  101. }
  102. })
  103. },
  104. async getPos(){
  105. const res = await this.$api('signs.getBlessingPosition', {blessingAreaId: this.form.blessingAreaId})
  106. if(res.code != 200) {
  107. throw new Error("")
  108. }
  109. return res.data.map(item => {
  110. return { ...item, id: item.blessingPositionId, name: item.blessingPositionName }
  111. })
  112. },
  113. showPos() {
  114. this.$refs.pos.$open({}).then(res => {
  115. if(res.arr && res.arr.length > 0){
  116. this.form.blessingPositionId = res.arr[0].blessingPositionId
  117. this.form.blessingPositionName = res.arr[0].blessingPositionName
  118. }
  119. })
  120. },
  121. end() {
  122. this.send = false;
  123. },
  124. start() {
  125. this.send = true;
  126. },
  127. codeChange(text) {
  128. this.tips = text;
  129. },
  130. getCode() {
  131. if(!this.form.blessingPositionId){
  132. this.$refs.uToast.show({type: 'error', message: '请选择阁位', position: 'top'})
  133. return;
  134. }
  135. if(this.$refs.uCode.canGetCode) {
  136. // 模拟向后端请求验证码
  137. this.$refs.uToast.show({
  138. type: 'loading',
  139. message: '正在获取验证码',
  140. })
  141. // TODO 发起请求:
  142. this.$api('signs.sendCode', {blessingPositionId: this.form.blessingPositionId}).then(res => {
  143. this.$refs.uToast.hide()
  144. if(res.code == 200){
  145. // 这里此提示会被this.start()方法中的提示覆盖
  146. this.$refs.uToast.show({type: 'success', message: '验证码已发送', position: 'top'})
  147. // 通知验证码组件内部开始倒计时
  148. this.$refs.uCode.start()
  149. }else{
  150. this.$refs.uToast.show({type: 'error', message: res.msg, position: 'top'})
  151. }
  152. })
  153. } else {
  154. uni.$u.toast('倒计时结束后再发送');
  155. }
  156. },
  157. confirm(){
  158. if(!this.form.blessingPositionId){
  159. this.$refs.uToast.show({type: 'error', message: '请选择阁位', position: 'top'})
  160. return;
  161. }
  162. if(!this.form.code){
  163. this.$refs.uToast.show({type: 'error', message: '请填写经办人验证码', position: 'top'})
  164. return;
  165. }
  166. this.$refs.uToast.show({
  167. type: 'loading',
  168. message: '请稍后',
  169. })
  170. this.$api('signs.openidBinding', {blessingPositionId: this.form.blessingPositionId, code: this.form.code}).then(res => {
  171. this.$refs.uToast.hide()
  172. if(res.code == 200){
  173. // 这里此提示会被this.start()方法中的提示覆盖
  174. this.$refs.uToast.show({type: 'success', message: res.msg, position: 'top'})
  175. uni.navigateBack({
  176. delta: 1
  177. })
  178. }else{
  179. this.$refs.uToast.show({type: 'error', message: res.msg, position: 'top'})
  180. }
  181. })
  182. }
  183. }
  184. }
  185. </script>
  186. <style lang="scss" scoped>
  187. @import "./index.scss";
  188. </style>