giveFamilyCard.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view class="box">
  3. <u-form labelPosition="top" :model="form" :rules="rules" ref="uForm">
  4. <!-- <u-form-item labelWidth="auto" label="被赠送会员编号" prop="memberNo">-->
  5. <!-- <u-input v-model="form.memberNo" placeholder="请输入被赠送会员编号" border="bottom">-->
  6. <!-- <u-text text="Vip." color="#000000" slot="prefix" margin="0 3px 0 0" type="tips"></u-text>-->
  7. <!-- </u-input>-->
  8. <!-- </u-form-item>-->
  9. <u-form-item labelWidth="auto" label="亲属手机号" prop="memberPhone" borderBottom>
  10. <view class="flex-row">
  11. <u-input v-model="form.memberPhone" type="number" placeholder="请输入亲属手机号" border="none"></u-input>
  12. <view class="customStyle" @click="getMemberList">
  13. <tex>查询</tex>
  14. </view>
  15. </view>
  16. </u-form-item>
  17. <u-form-item v-if="isSelectRelation" labelWidth="auto" label="亲属关系" prop="relation" borderBottom @click="showRelation = true" ref="item1">
  18. <u--input v-model="form.relation" disabled disabledColor="#ffffff" placeholder="请选择亲属关系" border="none"></u--input>
  19. <u-icon slot="right" name="arrow-right"></u-icon>
  20. </u-form-item>
  21. <u-form-item v-else labelWidth="auto" label="亲属关系" prop="relation" borderBottom ref="item2">
  22. <u--input v-model="form.relation" disabledColor="#ffffff" placeholder="请输入亲属关系" border="none"></u--input>
  23. </u-form-item>
  24. <!-- <u-form-item labelWidth="auto" label="每月消费上限" prop="amountCap">-->
  25. <!-- <u-input v-model="form.amountCap" type="digit" placeholder="请输入每月消费上限" border="bottom"-->
  26. <!-- ></u-input>-->
  27. <!-- </u-form-item>-->
  28. </u-form>
  29. <view class="op-btn-wrap">
  30. <view class="h-btn" @click="handleGive">
  31. <text>确定
  32. <text class="presentCount" v-if="count !== null">(剩余可赠送{{count}}次)</text>
  33. </text>
  34. </view>
  35. </view>
  36. <uni-popup ref="popup" type="bottom" @change="popupChange">
  37. <view class="popup">
  38. <view class="flex-row justify-center popupTitle">
  39. <text>选择亲属</text>
  40. </view>
  41. <view class="popupContent">
  42. <view class="flex-row popupItem" v-for="(item,index) in memberList" :key="index" @click="selectMember(item)">
  43. <view class="flex-col justify-center">
  44. <image :src="item.url ||'/static/me/ud4.png'" class="loveImage "></image>
  45. </view>
  46. <view class="flex-col justify-around ">
  47. <text class="popupName">{{item.ncikName}}({{item.no}})</text>
  48. <text class="popupPhone">{{item.cellPhone}}</text>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="popupClose" @click="popupClose">
  53. <u-icon name="close" color="#c8c8c8" size="22"></u-icon>
  54. </view>
  55. </view>
  56. </uni-popup>
  57. <u-action-sheet :show="showRelation" :actions="actions" title="请选择亲属关系" @close="showRelation = false" @select="relationSelect">
  58. </u-action-sheet>
  59. </view>
  60. </template>
  61. <script>
  62. export default {
  63. name: "giveFamilyCard",
  64. data() {
  65. return {
  66. isSelectRelation:true,
  67. showMember:false,
  68. showRelation: false,
  69. memberList:[],
  70. actions: [],
  71. store:{},
  72. form: {
  73. memberNo: '',
  74. memberPhone: '',
  75. amountCap: '',
  76. relation: ''
  77. },
  78. count: null,
  79. rules: {
  80. // 'memberNo': {
  81. // type: 'string',
  82. // required: true,
  83. // min: 8,
  84. // max: 10,
  85. // message: '请输入会员编号',
  86. // trigger: ['blur', 'change']
  87. // },
  88. 'memberPhone': {
  89. type: 'string',
  90. required: true,
  91. min: 11,
  92. max: 11,
  93. // pattern: this.$phonePattern,
  94. message: '请输入正确的手机号',
  95. trigger: []
  96. },
  97. // 'amountCap': {
  98. // type: 'number',
  99. // required: true,
  100. // pattern: this.$phonePattern,
  101. // message: '请输入每月消费上限',
  102. // trigger: ['blur', 'change']
  103. // },
  104. 'relation': {
  105. type: 'string',
  106. required: true,
  107. message: '请选择亲属关系',
  108. trigger: ['blur', 'change']
  109. },
  110. }
  111. }
  112. },
  113. onReady() {
  114. //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
  115. this.$refs.uForm.setRules(this.rules)
  116. },
  117. onShow() {
  118. this.presentCount()
  119. this.loveCardRelation()
  120. this.store = uni.getStorageSync('storeInfo');
  121. this.form.storeName = this.store.storeName
  122. this.form.storeId = this.store.storeId
  123. },
  124. methods: {
  125. selectMember(item){
  126. this.form.memberNo = item.no
  127. this.form.memberPhone = item.cellPhone
  128. this.$refs.popup.close()
  129. },
  130. popupClose(){
  131. this.$refs.popup.close()
  132. },
  133. popupChange(e){
  134. console.log(e)
  135. if (!e.show){
  136. this.memberList = []
  137. }
  138. },
  139. getMemberList(){
  140. // this.rules.memberPhone.min = 7
  141. // this.rules.memberPhone.message = '至少输入手机号中的7位'
  142. this.$refs.uForm.validateField('memberPhone',(e)=>{
  143. console.log('校验结果',e)
  144. if (e.length == 0 ){
  145. this.$api.getByPhone({
  146. phone:this.form.memberPhone
  147. }).then(res=>{
  148. this.memberList = res.data.data
  149. this.getImgUrlByOssId(this.memberList)
  150. this.$refs.popup.open()
  151. console.log('获取到的用户列表', this.memberList)
  152. })
  153. }
  154. })
  155. },
  156. getImgUrlByOssId(list) {
  157. if (list) {
  158. for (let i=0;i<list.length;i++){
  159. let data = null
  160. data = list[i].selfPhoto
  161. if (data) {
  162. this.$api.getImage(data).then(res => {
  163. list[i].url = res.data.data[0].url.replace(/^http:/, "https:")
  164. this.$set(list,i,list[i])
  165. });
  166. }
  167. }
  168. }
  169. },
  170. loveCardRelation() {
  171. this.$api.loveCardRelation().then(res => {
  172. this.actions = []
  173. if (res.data.rows) {
  174. for (let i of res.data.rows) {
  175. let relation = {
  176. name: i.dictValue
  177. }
  178. this.actions.push(relation)
  179. }
  180. }
  181. })
  182. },
  183. relationSelect(e) {
  184. if (e.name === '自定义'){
  185. this.rules.relation.message = '请输入亲属关系'
  186. this.isSelectRelation = false
  187. }else {
  188. this.form.relation = e.name
  189. }
  190. },
  191. handleGive() {
  192. if (this.count == 0) {
  193. uni.$u.toast('可赠送次数不足!')
  194. return
  195. }
  196. // this.rules.memberPhone.min = 11
  197. // this.rules.memberPhone.message = '请输入正确的手机号'
  198. this.$refs.uForm.validate().then(res => {
  199. this.$api.giveFamilyCard(this.form).then((res) => {
  200. console.log(res)
  201. uni.showToast({
  202. duration: 2000,
  203. title: '赠送成功'
  204. });
  205. uni.navigateBack({delta: 1})
  206. }
  207. )
  208. })
  209. },
  210. presentCount() {
  211. this.$api.presentCount().then(res => {
  212. this.count = res.data.data
  213. })
  214. }
  215. }
  216. }
  217. </script>
  218. <style scoped>
  219. @import "./index.scss";
  220. </style>