addCard.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <template>
  2. <view class="addCard">
  3. <!-- <tm-sheet :margin="[0,0]" color="bg-gradient-blue-accent">
  4. <view style="height: 110rpx;"></view>
  5. </tm-sheet> -->
  6. <uni-menubar :title="`编辑名片`" />
  7. <view class="">
  8. <tm-form ref="formData">
  9. <tm-sheet :padding="[0,32]">
  10. <view class="flex-between list pl-20 pr-20 white">
  11. <view class="left">
  12. 头像
  13. </view>
  14. <view class="right">
  15. <view class="upload">
  16. <tm-upload ref="upload" :code="200" :max="1" :tips="false"
  17. url="https://cardoa.platomix.net/api/upload" url-key="data" :auto-upload="true"
  18. :header="header" :filelist.sync="filelist"></tm-upload>
  19. </view>
  20. </view>
  21. </view>
  22. <tm-input name="name" required title="姓名" adjust-position v-model="form.name">
  23. <template v-slot:rightBtn>
  24. <tm-button open-type="getUserInfo" @getUserInfo='getUserInfo' plan :font-size="20" :height="60" block
  25. :width="120" theme="bg-gradient-blue-accent">微信授权</tm-button>
  26. </template>
  27. </tm-input>
  28. <view class="gray-100 text-size-s pa-20">微信授权用于快速获取您的微信昵称和头像,填充名片姓名和头像</view>
  29. <tm-input name="mobile" required title="手机号" v-model="form.mobile">
  30. <template v-slot:rightBtn>
  31. <tm-button open-type="getPhoneNumber" @getphonenumber="getNumber"
  32. theme="bg-gradient-blue-accent" plan :font-size="20" :height="60" block
  33. :width="120">
  34. 快速获取
  35. </tm-button>
  36. </template>
  37. </tm-input>
  38. <tm-input name="wx" required title="微信" v-model="form.wx"></tm-input>
  39. <tm-input name="email " required title="电子邮箱" v-model="form.email"></tm-input>
  40. </tm-sheet>
  41. <tm-sheet :padding="[0,32]">
  42. <tm-input name="company" required title="公司" adjust-position v-model="form.company"></tm-input>
  43. <tm-input name="title" required title="职务" adjust-position v-model="form.title"></tm-input>
  44. <tm-input v-model="form.industry" @click="show = true" placeholder="请选择行业" required title="行业"
  45. disabled :value="type" right-icon="icon-angle-right"></tm-input>
  46. <tm-input @click="getAddress" required disabled title="选择位置" v-model="form.cityAdress">
  47. <template v-slot:rightBtn>
  48. 点击选择
  49. </template>
  50. </tm-input>
  51. <tm-input :vertical="true" name="address" :height="120" adjust-position title="详细地址"
  52. v-model="form.address" :maxlength="512" :border-bottom="false" :required="true"
  53. placeholder="请输入详细楼号,门牌号等" input-type="textarea" bg-color="grey-lighten-5" clear></tm-input>
  54. </tm-sheet>
  55. <!-- <tm-sheet :padding="[40,32]">
  56. <view class="mt-20">
  57. <view style="height: 60rpx;line-height: 60rpx;font-size: 24rpx;" class="white pl-20 pr-20 list">
  58. 是否公开此名片供大众看?
  59. </view>
  60. <view style="height: 80rpx;" class="white pl-20 pr-20 list">
  61. <tm-groupradio name="shiguche" @change="shiguchechange">
  62. <tm-radio :size="25" color="blue" v-model="checked" label="公开"></tm-radio>
  63. <tm-radio :size="25" color="blue" v-model="checked" label="部分公开"></tm-radio>
  64. <tm-radio :size="25" color="blue" v-model="checked" label="不公开"></tm-radio>
  65. </tm-groupradio>
  66. </view>
  67. </view>
  68. <view class="mt-20">
  69. <view style="height: 60rpx;line-height: 60rpx;font-size: 24rpx;" class="white pl-20 pr-20 list">
  70. 是否允许他人转发您的名片?
  71. </view>
  72. <view style="height: 80rpx;" class="white pl-20 pr-20 list">
  73. <tm-groupradio name="shiguche" @change="shiguchechange">
  74. <tm-radio :size="25" color="blue" v-model="checked" label="允许"></tm-radio>
  75. <tm-radio :size="25" color="blue" v-model="checked" label="不允许"></tm-radio>
  76. </tm-groupradio>
  77. </view>
  78. </view>
  79. <view class="mt-20">
  80. <view style="height: 60rpx;line-height: 60rpx;font-size: 24rpx;" class="white pl-20 pr-20 list">
  81. 是否允许他人克隆您的名片?
  82. </view>
  83. <view style="height: 80rpx;" class="white pl-20 pr-20 list">
  84. <tm-groupradio name="shiguche" @change="shiguchechange">
  85. <tm-radio :size="25" color="blue" v-model="checked" label="允许"></tm-radio>
  86. <tm-radio :size="25" color="blue" v-model="checked" label="不允许"></tm-radio>
  87. </tm-groupradio>
  88. </view>
  89. </view>
  90. </tm-sheet> -->
  91. <view class="mt-50 mb-50 pl-30 pr-30 ">
  92. <tm-button @click="postUp" theme="bg-gradient-blue-accent" block>提交数据</tm-button>
  93. </view>
  94. </tm-form>
  95. <tm-maskFlow v-model="show">
  96. <view class="maskShow pl-20 pr-20">
  97. <view class="text-align-center pt-20 pb-20">
  98. 请选择1~3个行业
  99. </view>
  100. <view class="maskContent">
  101. <tm-button size="s" @click="checked1 = !checked1"
  102. :theme="checked1?'bg-gradient-blue-accent':'grey-lighten-4'" :shadow="0">家装
  103. </tm-button>
  104. <tm-button size="s" @click="checked2 = !checked2"
  105. :theme="checked2?'bg-gradient-blue-accent':'grey-lighten-4'" :shadow="0">环保装饰
  106. </tm-button>
  107. <tm-button size="s" @click="checked3 = !checked3"
  108. :theme="checked3?'bg-gradient-blue-accent':'grey-lighten-4'" :shadow="0">全屋整装
  109. </tm-button>
  110. </view>
  111. <view class="maskFoot">
  112. <tm-row>
  113. <tm-col :grid="6">
  114. <tm-button @click="show=false" size="m" theme="grey-lighten-4" :shadow="0">取消
  115. </tm-button>
  116. </tm-col>
  117. <tm-col :grid="6">
  118. <tm-button @click="sureClick" size="m" theme="bg-gradient-blue-accent" :shadow="0">确定
  119. </tm-button>
  120. </tm-col>
  121. </tm-row>
  122. </view>
  123. </view>
  124. </tm-maskFlow>
  125. </view>
  126. <tm-dialog v-model="dialogShow" content="您还没有开通权限,请联系管理员开通!" confirmColor="blue" :showCancel="true"
  127. :over-close="false" disabled></tm-dialog>
  128. <tm-dialog v-model="registerShow" content="必填项不能为空" confirmColor="blue"></tm-dialog>
  129. <uni-suspension v-if='userInfo.card_id' />
  130. </view>
  131. </template>
  132. <script>
  133. export default {
  134. data() {
  135. return {
  136. form: {
  137. id: '',
  138. name: "", //姓名
  139. picture: "", //头像
  140. mobile_type: 2, //绑定手机类型:1,微信绑定手机号;2,手动输入手机号
  141. mobile: "", //手机号码
  142. wx: "", //微信号
  143. email: "", //电子邮箱
  144. company: "", //公司
  145. title: "", //职位
  146. industry: "", //行业
  147. address: "", //详细地址,
  148. cityAdress: "", //详细地址,
  149. latitude: "", //维度
  150. longitude: "", //经度
  151. },
  152. cityAdress: "",
  153. defaultCity: [],
  154. show: false,
  155. checked1: false,
  156. checked2: false,
  157. checked3: false,
  158. filelist: [],
  159. header: {
  160. 'Authorization': uni.getStorageSync('token'),
  161. 'Content-Type': 'multipart/form-data'
  162. },
  163. dialogVal: "",
  164. dialog: false,
  165. edit: "",
  166. dialogShow: false,
  167. registerShow: false
  168. }
  169. },
  170. onLoad(option) {
  171. this.$tm.request.get('card/read').then(res => {
  172. this.form = res.data
  173. this.filelist = [res.data.picture]
  174. })
  175. },
  176. mounted() {
  177. this.$tm.request.get('user/read').then(res => {
  178. if (res.data.vip < 1) {
  179. this.dialogShow = true
  180. }
  181. })
  182. },
  183. methods: {
  184. getUserInfo(res) {
  185. if (res.userInfo.avatarUrl !== '') {
  186. this.filelist = [res.userInfo.avatarUrl]
  187. this.$refs.upload.pushFile(this.filelist)
  188. }
  189. this.form.name = res.userInfo.nickName
  190. },
  191. getNumber(res) {
  192. this.$tm.request.post('card/getphone', {
  193. code: res.detail.code
  194. }).then(result => {
  195. this.form.mobile_type = 1
  196. this.form.mobile = result.data.phone_info.phoneNumber
  197. })
  198. },
  199. postUp() {
  200. this.form.picture = this.filelist[0]
  201. if (this.form.name == '' || this.form.picture == '' || this.form.mobile == '' || this.form.wx == '' || this
  202. .form.email == '' || this.form.industry == '' || this.form.company == '' || this.form.title == '' ||
  203. this.form.address == '' || this.form.cityAdress == '') {
  204. this.registerShow = true
  205. return false
  206. }
  207. console.log(this.form);
  208. if (!this.form.id) {
  209. this.$tm.request.post('card/create', this.form).then(async res => {
  210. if (res.code == 200) {
  211. await this.$tm.request.post('user/update', {
  212. nickname: this.form.name,
  213. avatar: this.form.picture
  214. })
  215. uni.showToast({
  216. title: "创建成功",
  217. icon: "success",
  218. duration: 1000
  219. })
  220. this.$tm.request.get('card/read').then(res => {
  221. if (res.data.card_id) {
  222. this.$tm.vx.commit('user/setUserInfo', res.data)
  223. setTimeout(() => {
  224. uni.redirectTo({
  225. url: '/pages/index/index'
  226. })
  227. }, 1000)
  228. }
  229. })
  230. } else {
  231. uni.showToast({
  232. title: "创建失败",
  233. icon: "none",
  234. duration: 1000
  235. })
  236. setTimeout(() => {
  237. uni.redirectTo({
  238. url: '/pages/index/index'
  239. })
  240. }, 1000)
  241. }
  242. })
  243. } else {
  244. this.$tm.request.post('card/update', this.form).then(async res => {
  245. if (res.code == 200) {
  246. await this.$tm.request.post('user/update', {
  247. nickname: this.form.name,
  248. avatar: this.form.picture
  249. })
  250. uni.showToast({
  251. title: "编辑成功",
  252. icon: "success",
  253. duration: 1000
  254. })
  255. this.$tm.request.get('card/read').then(res => {
  256. if (res.data.card_id) {
  257. this.$tm.vx.commit('user/setUserInfo', res.data)
  258. setTimeout(() => {
  259. uni.redirectTo({
  260. url: '/pages/index/index'
  261. })
  262. }, 1000)
  263. }
  264. })
  265. }
  266. })
  267. }
  268. },
  269. vehicle() {
  270. this.show = true
  271. },
  272. sureClick() {
  273. let arr = []
  274. if (this.checked1 === true) {
  275. arr.push('家装')
  276. }
  277. if (this.checked2 === true) {
  278. arr.push('环保装饰')
  279. }
  280. if (this.checked3 === true) {
  281. arr.push('全屋装饰')
  282. }
  283. this.form.industry = arr.join(',')
  284. this.show = false
  285. },
  286. getAddress() {
  287. let that = this
  288. uni.chooseLocation({
  289. latitude: that.form.latitude * 1,
  290. longitude: that.form.longitude * 1,
  291. success: function(res) {
  292. that.form.cityAdress = res.address
  293. that.form.latitude = res.latitude
  294. that.form.longitude = res.longitude
  295. }
  296. });
  297. }
  298. }
  299. }
  300. </script>
  301. <style lang="scss" scoped>
  302. .list {
  303. border-bottom: 1px solid #E0E0E0;
  304. }
  305. .left {
  306. width: 100rpx;
  307. height: 150rpx;
  308. margin-right: 40rpx;
  309. line-height: 150rpx;
  310. text-align: center;
  311. }
  312. .right {
  313. flex: 1;
  314. position: relative;
  315. }
  316. .maskShow {
  317. width: 80vw;
  318. height: 60vh;
  319. background-color: #fff;
  320. border-radius: 50rpx;
  321. position: relative;
  322. .maskFoot {
  323. width: 100%;
  324. position: absolute;
  325. bottom: 20rpx;
  326. }
  327. }
  328. </style>