create.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <view>
  3. <view class="form">
  4. <view class="li ddflex">
  5. <view class="label">头像</view>
  6. <view class="photo ddflex flex" @tap="uploadImgs()">
  7. <image :src="avatar ? avatar : '../../static/images/userimg.png'" mode="aspectFill" class="userimg"></image>
  8. <image src="../../static/images/rico.png" class="rico"></image>
  9. </view>
  10. </view>
  11. <view class="li ddflex">
  12. <view class="label">姓名</view>
  13. <input v-model="realName" placeholder="请填写你的真实姓名" placeholder-class="placeholder" class="ipt flex" />
  14. </view>
  15. <view class="li ddflex">
  16. <view class="label">个人简介</view>
  17. <input v-if="!brief" @tap="jumpUrl('/card/editDesc/editDesc')" :disabled="true" maxlength="11" type="number" placeholder="请作简单自我介绍" placeholder-class="placeholder" class="ipt flex" />
  18. <view class="fflex" v-else style="color: #47C776;" @tap="jumpUrl('/card/editDesc/editDesc')">已完善</view>
  19. <image src="../../static/images/rico.png" class="rico"></image>
  20. </view>
  21. </view>
  22. <view class="form">
  23. <view class="tit ddflex"><view class="flex">联系信息</view></view>
  24. <view class="li ddflex">
  25. <view class="label">手机</view>
  26. <input v-model="phone" maxlength="11" type="number" placeholder="请填写手机号" placeholder-class="placeholder" class="ipt flex" />
  27. <view class="tong ddflex" @click="intWechatNumber"><image src="../static/images/wxth.png"></image>微信同号</view>
  28. </view>
  29. <view class="li ddflex">
  30. <view class="label">邮箱</view>
  31. <input v-model="email" placeholder="请填写邮箱地址" placeholder-class="placeholder" class="ipt flex" />
  32. </view>
  33. <view class="li ddflex">
  34. <view class="label">微信号</view>
  35. <input v-model="wechat" placeholder="请填写微信号" placeholder-class="placeholder" class="ipt flex" />
  36. </view>
  37. </view>
  38. <view class="form">
  39. <view class="tit ddflex"><view class="flex">公司信息</view></view>
  40. <view class="li ddflex">
  41. <view class="label">公司</view>
  42. <input v-model="companyName" placeholder="请填写公司名称" placeholder-class="placeholder" class="ipt flex" />
  43. </view>
  44. <view class="li ddflex">
  45. <view class="label">职位</view>
  46. <input v-model="job" placeholder="请填写职位" placeholder-class="placeholder" class="ipt flex" />
  47. </view>
  48. <view class="li ddflex" @click="jumpUrl('/card/industry/industry?isPoistion=true')">
  49. <view class="label">行业</view>
  50. <!-- <input v-model="position" placeholder="请填写职位" placeholder-class="placeholder" class="ipt flex" /> -->
  51. <view :class="'flex' + (industryName ? '' :' placeholder')">{{industryName ? industryName : '请填写行业'}}</view>
  52. <image src="../../static/images/rico.png" class="rico"></image>
  53. </view>
  54. <view class="li ddflex">
  55. <view class="label">所在地区</view>
  56. <view :class="['item flex', city ? 'active' : '']">
  57. <!-- #ifdef MP-WEIXIN -->
  58. <picker class="picker flex" mode="region" :value="morCity" @change="bindCity">
  59. <view :class="city?'':'placeholder'">{{ city ? city : '请选择地区' }}</view>
  60. </picker>
  61. <!-- #endif -->
  62. <!-- #ifdef APP-PLUS -->
  63. <pickerAddress class="picker flex" @change="bindAddressChange">
  64. <view :class="city?'':'placeholder'">{{ city ? city : '请选择地区' }}</view>
  65. </pickerAddress>
  66. <!-- #endif -->
  67. </view>
  68. <image src="../../static/images/rico.png" class="rico"></image>
  69. <!-- <picker class="picker flex">
  70. <view class="placeholder">请选择省份城市</view>
  71. <image src="../../static/images/rico.png" class="rico"></image>
  72. </picker> -->
  73. </view>
  74. <view class="li ddflex">
  75. <view class="label">地址</view>
  76. <input v-model="address" placeholder="填写街道地址" placeholder-class="placeholder" class="ipt flex" />
  77. </view>
  78. </view>
  79. <view class="bot">
  80. <view class="btn" @click="submitCard()">{{ isEdit ? '保存' : '确认创建' }}</view>
  81. </view>
  82. </view>
  83. </template>
  84. <script>
  85. const req = require('../../utils/request.js');
  86. const api = require('../../utils/api.js');
  87. const util = require('../../utils/util.js');
  88. var app = getApp();
  89. import pickerAddress from '../../components/wangding-pickerAddress/wangding-pickerAddress.vue';
  90. export default {
  91. components: { pickerAddress },
  92. data() {
  93. return {
  94. avatar: '',
  95. realName: '',
  96. phone: '',
  97. wechat: '',
  98. email: '',
  99. companyName: '',
  100. job:'',//职业
  101. industryName: '',//行业
  102. tradeId: '',//行业id
  103. message: '',
  104. isEdit: false,
  105. id: '' ,//名片id
  106. nums: 0,
  107. brief:'',//简介
  108. address:'',//详细地址
  109. city: '',
  110. areaCode: '',
  111. morCity: [],
  112. userCard:null,//用户IP名片
  113. };
  114. },
  115. onLoad(opt) {
  116. this.isEdit = opt.isEdit;
  117. this.id = opt.id;
  118. console.log('getUserCard')
  119. this.getUserCard()
  120. },
  121. methods: {
  122. getUserInfo(){
  123. return new Promise((resolve,reject)=>{
  124. req.getRequest('/api/user/info',{},res=>{
  125. this.avatar = res.avatar;
  126. this.realName = res.realName ? res.realName : res.nickName;
  127. this.phone = res.mobile;
  128. resolve();
  129. })
  130. })
  131. },
  132. // 用户名片信息
  133. getUserCard(){
  134. req.getRequest('/api/v3/visiting/card/userInfo', {}, res => {
  135. console.log('getUserCard',res)
  136. this.userCard = res
  137. if(!res){
  138. this.getCompanyData()
  139. this.getUserInfo()
  140. }else{
  141. this.id = res.id
  142. this.avatar = res.avatar;
  143. this.realName = res.realName;
  144. this.brief = res.brief;
  145. this.phone = res.phone;
  146. this.wechat = res.wechat;
  147. this.email = res.email;
  148. this.companyName = res.companyName;
  149. this.industryName = res.industryName;
  150. this.tradeId = res.tradeId;
  151. this.address = res.address;
  152. this.job = res.job;
  153. res.areaCode = JSON.parse(res.areaCode)
  154. this.morCity = [res.areaCode.id.substring(0,2)+'0000',res.areaCode.id.substring(0,4)+'00',res.areaCode.id]
  155. this.city = res.areaCode.name
  156. this.areaCode = this.morCity[2];
  157. }
  158. });
  159. },
  160. getCompanyData(){
  161. req.getRequest('/api/CKBCompany/info',{},res=>{
  162. if(res){
  163. this.companyName = res.title
  164. this.industryName = res.trade
  165. this.tradeId = res.industryId
  166. this.address = res.address
  167. this.morCity = JSON.parse(res.areaCode).map(item=>{return item.id})
  168. this.areaCode = JSON.parse(res.areaCode).map(item=>{return item.id})[2]
  169. this.city = JSON.parse(res.areaCode).map(item=>{return item.name}).join('')
  170. }
  171. })
  172. },
  173. jumpUrl(url) {
  174. uni.navigateTo({
  175. url: url
  176. });
  177. },
  178. uploadImgs() {
  179. let that = this;
  180. uni.chooseImage({
  181. count: 1,
  182. sizeType: ['original', 'compressed'],
  183. sourceType: ['album', 'camera'],
  184. success: function({ tempFilePaths }) {
  185. var promise = Promise.all(
  186. tempFilePaths.map(tempFilePath => {
  187. return new Promise(function(resolve, reject) {
  188. req.uploadFile('/api/upload', tempFilePath, res => {
  189. that.avatar = res.src;
  190. });
  191. });
  192. })
  193. );
  194. promise
  195. .then(function(results) {
  196. console.log(results);
  197. })
  198. .catch(function(err) {
  199. console.log(err);
  200. });
  201. }
  202. });
  203. },
  204. intMessage(e){
  205. this.nums = e.detail.value.length
  206. },
  207. intWechatNumber(){
  208. this.wechat = this.phone
  209. },
  210. bindCity: function(e) {
  211. this.morCity = e.detail.code;
  212. this.city = e.detail.value.join().replace(/[,]/g, '');
  213. this.areaCode = e.detail.code[2];
  214. },
  215. bindAddressChange(data) {
  216. this.morCity = data.ids;
  217. this.city = data.data[0] + data.data[1] + data.data[2];
  218. this.areaCode = data.ids[2];
  219. },
  220. /**
  221. * 提交名片
  222. */
  223. submitCard() {
  224. let that = this;
  225. if (!this.avatar) return req.msg('请上传头像');
  226. if (!this.realName) return req.msg('请填写你的真实姓名');
  227. if (!this.brief) return req.msg('请填写个人简介');
  228. if (!this.phone) return req.msg('请填写手机号');
  229. if (!this.wechat) return req.msg('请填写微信号');
  230. if (!this.email) return req.msg('请填写邮箱地址');
  231. if (!this.companyName) return req.msg('请填写公司名称');
  232. if (!this.job) return req.msg('请填写职位')
  233. if (!this.industryName) return req.msg('请填写行业');
  234. if (!this.areaCode) return req.msg('请选择所在地区');
  235. if (!this.address) return req.msg('请填写详细地址');
  236. var dataP = {};
  237. dataP.avatar = this.avatar;
  238. dataP.realName = this.realName;
  239. dataP.brief = this.brief;
  240. dataP.phone = this.phone;
  241. dataP.wechat = this.wechat;
  242. dataP.email = this.email;
  243. dataP.companyName = this.companyName;
  244. dataP.job = this.job;
  245. dataP.industryName = this.industryName;
  246. dataP.tradeId = this.tradeId;
  247. dataP.areaCode = {
  248. id:this.areaCode,
  249. name :this.city
  250. };
  251. dataP.areaCode = JSON.stringify(dataP.areaCode)
  252. dataP.address = this.address;
  253. var url = '';
  254. if (this.id) {
  255. dataP.id = this.id;
  256. }
  257. req.postRequest(
  258. '/api/v3/visiting/card/saveOrUpdate',
  259. dataP,
  260. json => {
  261. if (that.id) {
  262. req.msg('保存成功');
  263. setTimeout(function() {
  264. uni.navigateBack({
  265. delta: 1
  266. });
  267. }, 1500);
  268. } else {
  269. req.msg('名片创建成功');
  270. setTimeout(function() {
  271. that.jumpUrl('/card/index/index');
  272. }, 1500);
  273. }
  274. },
  275. true
  276. );
  277. }
  278. }
  279. };
  280. </script>
  281. <style>
  282. @import './create.css';
  283. </style>