edit.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <view>
  3. <view class="wrap">
  4. <u--form ref="form1" label-position="left" :model="cardObj" :rules="rules" label-width="80">
  5. <u-form-item label="姓名" prop="cardObj.name" border-bottom>
  6. <u--input v-model="cardObj.name" border="none"></u--input>
  7. </u-form-item>
  8. <u-form-item label="电话" prop="cardObj.phone" border-bottom>
  9. <u--input v-model="cardObj.phone" border="none"></u--input>
  10. </u-form-item>
  11. <u-form-item label="公司" prop="company" border-bottom>
  12. <u--input v-model="cardObj.company" border="none"></u--input>
  13. </u-form-item>
  14. <u-form-item label="地址" prop="address" border-bottom>
  15. <u--input v-model="cardObj.address" border="none"></u--input>
  16. </u-form-item>
  17. <u-form-item label="职位" prop="job" border-bottom>
  18. <u--input v-model="cardObj.job" border="none"></u--input>
  19. </u-form-item>
  20. <u-form-item label="微信" prop="wechat" border-bottom>
  21. <u--input v-model="cardObj.wechat" border="none"></u--input>
  22. </u-form-item>
  23. <u-form-item label="QQ" prop="wechat" border-bottom>
  24. <u--input v-model="cardObj.qq" border="none"></u--input>
  25. </u-form-item>
  26. <u-form-item label="邮箱" prop="email" border-bottom>
  27. <u--input v-model="cardObj.email" border="none"></u--input>
  28. </u-form-item>
  29. <u-form-item label="业务介绍" prop="intro" border-bottom>
  30. <u--textarea v-model="cardObj.intro" border="none"></u--textarea>
  31. </u-form-item>
  32. <u-form-item label="头像" prop="intro" border-bottom>
  33. <u-upload
  34. :file-list="fileList1" name="5" :max-count="1" :preview-full-image="true"
  35. @afterRead="afterRead"
  36. @delete="deletePic"
  37. >
  38. </u-upload>
  39. </u-form-item>
  40. </u--form>
  41. <view class="wrap">
  42. <view style="float:left;width: 40px;">
  43. <u-checkbox-group v-model="checked" change="changeClick()">
  44. <u-checkbox shape="circle"></u-checkbox>
  45. </u-checkbox-group>
  46. </view>
  47. <text style="float:left;color:#04498c" @click="goAgree()">同意用户服务协议&隐私政策</text>
  48. </view>
  49. </view>
  50. <view class="bottom-block"></view>
  51. <view class="bottombtn" type="primary" @click="onSave">立即保存</view>
  52. </view>
  53. </template>
  54. <script>
  55. import {
  56. request
  57. } from '@/utils/request'
  58. import { USER_INFO } from '../../constant'
  59. export default {
  60. name: 'Edit',
  61. components: {},
  62. data() {
  63. return {
  64. checked: false,
  65. cardObj: {},
  66. fileList1: [],
  67. isAdd: true,
  68. rules: {
  69. 'cardObj.name': {
  70. type: 'string',
  71. required: true,
  72. message: '必填',
  73. trigger: ['blur', 'change']
  74. },
  75. 'cardObj.phone': {
  76. type: 'string',
  77. required: true,
  78. message: '必填',
  79. trigger: ['blur', 'change']
  80. }
  81. }
  82. }
  83. },
  84. mounted() { },
  85. async onLoad(options) {
  86. if (uni.getStorageSync(USER_INFO)) {
  87. var user = uni.getStorageSync(USER_INFO)
  88. const res = await request('uni-card', 'getMyCard', {
  89. uid: user.id
  90. }, {
  91. showloading: true
  92. })
  93. if (res.uid == null) { this.isAdd = true } else {
  94. if (res.uid != user.id) {
  95. uni.navigateTo({
  96. url: '/pages/index'
  97. })
  98. }
  99. this.cardObj = res
  100. this.isAdd = false
  101. this.fileList1.push({
  102. url: res.head_img
  103. })
  104. }
  105. }
  106. },
  107. methods: {
  108. goAgree() {
  109. uni.navigateTo({
  110. url: '/pages/agree'
  111. })
  112. },
  113. changeClick() {
  114. console.log('this.checked', this.checked)
  115. },
  116. async onSave() {
  117. if (!this.checked) {
  118. this.$showToast('请点击同意用户服务协议&隐私政策')
  119. return
  120. }
  121. if (!this.cardObj.name) {
  122. this.$showToast('请填写姓名')
  123. return
  124. }
  125. if (!this.cardObj.phone) {
  126. this.$showToast('请填写电话')
  127. return
  128. }
  129. var user = uni.getStorageSync(USER_INFO)
  130. this.cardObj.uid = user.id
  131. const res = await request('uni-card', 'saveCard', this.cardObj, {
  132. showloading: true
  133. })
  134. console.log('res', res)
  135. this.$showToast('保存成功')
  136. uni.navigateTo({
  137. url: '/pages/index'
  138. })
  139. },
  140. deletePic(event) {
  141. this.fileList1 = []
  142. this.cardObj.head_img = ''
  143. },
  144. async afterRead(event) {
  145. console.log('event', event)
  146. const result = await this.uploadFilePromise(event.file.url)
  147. },
  148. uploadFilePromise(url) {
  149. return new Promise((resolve, reject) => {
  150. var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
  151. var maxLen = $chars.length
  152. var noncestr = ''
  153. for (var i = 0; i < 32; i++) {
  154. noncestr += $chars.charAt(Math.floor(Math.random() * maxLen))
  155. }
  156. var that = this
  157. uniCloud.uploadFile({
  158. filePath: url,
  159. cloudPath: noncestr + '.jpg',
  160. onUploadProgress(progressEvent) {
  161. console.log('上传进度', progressEvent)
  162. var percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
  163. },
  164. success(e) {
  165. console.log('uploadFile', e)
  166. that.fileList1.push({
  167. url: e.fileID
  168. })
  169. that.cardObj.head_img = e.fileID
  170. },
  171. fail() { },
  172. complete() { }
  173. })
  174. })
  175. }
  176. }
  177. }
  178. </script>
  179. <style>
  180. /deep/.u-scroll-bar {
  181. background: red !important;
  182. }
  183. .wrap {
  184. padding: 20px;
  185. }
  186. .bottombtn {
  187. position: fixed;
  188. bottom: 0;
  189. width: 100%;
  190. height: 60px;
  191. background: #007AFF;
  192. color: #fff;
  193. line-height: 60px;
  194. text-align: center;
  195. }
  196. .bottom-block {
  197. display: block;
  198. width: 100%;
  199. height: 80px;
  200. }
  201. </style>