edit.vue 5.3 KB

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