calling-card-form.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <template>
  2. <view class="calling-card-form-container">
  3. <JHeader width="50" height="50" title="名片表单"></JHeader>
  4. <view>
  5. <view style="font-size: 34rpx;font-weight: bold;">
  6. 使用申明
  7. </view>
  8. <view style="margin-top: 14rpx;font-size: 28rpx;color: #706f6f;">
  9. <view>1. 请确保微信号、qq号和邮箱百分百有效,之后将用于首页电子名片的信息显示。</view>
  10. <view>2. 在未经您同意及确认之前,本程序不会将您的注册信息用于任何其它商业目的。</view>
  11. <view>3. 本程序将对您所提供的资料进行严格的管理及保护,本程序将使用相应的技术,防止您的个人资料丢失、被盗用或遭篡改。</view>
  12. <view>4. 请您放心使用!</view>
  13. </view>
  14. <view
  15. style="display: flex;align-items: center;margin-top: 14rpx;font-size: 28rx;color: #222229;"
  16. >
  17. <radio
  18. style="transform:scale(0.8)" border-color="#000000" color="#CE2601" :checked="isReadAgreement"
  19. @click="isReadAgreement = !isReadAgreement"
  20. />
  21. <view>
  22. 同意向小程序提供个人信息
  23. </view>
  24. </view>
  25. </view>
  26. <FieldPaneCCF v-model="form.basicInfo" :fields="applyOne" title="基本信息"></FieldPaneCCF>
  27. <FieldPaneCCF v-model="form.relatesInfo" :fields="applyTow" title="企业信息"></FieldPaneCCF>
  28. <ATFUpload
  29. :title="uploadFields[0].label" :img-url="form.imgs[uploadFields[0].field]"
  30. @upload="handleSaveImg(uploadFields[0].field, $event)" @delete="handleDeleteImg(uploadFields[0].field)"
  31. ></ATFUpload>
  32. <ATFMoreUpload
  33. :title="uploadFields[1].label" :imgs="form.imgs[uploadFields[1].field]"
  34. @upload="handleSaveImg(uploadFields[1].field, $event)" @delete="handleDeleteImg(uploadFields[1].field, $event)"
  35. ></ATFMoreUpload>
  36. <ATFUpload
  37. v-if="String(form.relatesInfo.isEnterprise) === 'true'"
  38. :title="uploadFields[2].label" :img-url="form.imgs[uploadFields[2].field]"
  39. @upload="handleSaveImg(uploadFields[2].field, $event)" @delete="handleDeleteImg(uploadFields[2].field)"
  40. ></ATFUpload>
  41. <view class="buts">
  42. <button class="btn" @click="submit()">
  43. 提交
  44. </button>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import FieldPaneCCF from './components/field-pane-ccf.vue'
  50. import { addEnterpriseUserSaveApi, updateByIdEnterpriseUserApi } from '../../../api/anotherTFInterface'
  51. export default {
  52. name: 'CallingCardForm',
  53. components: {
  54. FieldPaneCCF
  55. },
  56. onLoad(options) {
  57. if (Number(options.id)) {
  58. this.form.basicInfo.buyerId = options.id
  59. this.form.relatesInfo.isEnterprise = 'false'
  60. this.getElectronicCard(options.id)
  61. }
  62. },
  63. data() {
  64. return {
  65. isReadAgreement: false,
  66. applyOne: [
  67. {
  68. label: 'ID:',
  69. field: 'enterpriseUserId',
  70. type: 'input',
  71. placeholder: '请输入名片ID'
  72. },
  73. {
  74. label: '用户ID:',
  75. field: 'buyerId',
  76. type: 'input',
  77. placeholder: '请输入用户D'
  78. },
  79. {
  80. label: '关联标签:',
  81. field: 'label',
  82. type: 'input',
  83. placeholder: '请输入关联标签'
  84. },
  85. {
  86. label: '昵称:',
  87. field: 'name',
  88. type: 'input',
  89. placeholder: '请输入昵称'
  90. },
  91. {
  92. label: '性别:',
  93. field: 'sex',
  94. type: 'radio',
  95. placeholder: '请选择性别'
  96. },
  97. {
  98. label: '生日:',
  99. field: 'birthday',
  100. type: 'time',
  101. placeholder: '请选择生日时间'
  102. },
  103. {
  104. label: '手机号:',
  105. field: 'phone',
  106. type: 'input',
  107. placeholder: '请输入手机号'
  108. },
  109. {
  110. label: '座机:',
  111. field: 'landline',
  112. type: 'input',
  113. placeholder: '请输入座机'
  114. },
  115. {
  116. label: '邮箱:',
  117. field: 'mailbox',
  118. type: 'input',
  119. placeholder: '请输入邮箱'
  120. },
  121. {
  122. label: '微信号:',
  123. field: 'weChatSignal',
  124. type: 'input',
  125. placeholder: '请输入微信号'
  126. },
  127. {
  128. label: '个人简介',
  129. type: 'textarea',
  130. field: 'personalProfile',
  131. placeholder: '请填写个人简介'
  132. },
  133. {
  134. label: '地址',
  135. type: 'textarea',
  136. field: 'address',
  137. placeholder: '请填写地址'
  138. },
  139. // {
  140. // label: '是否启用:',
  141. // field: 'state',
  142. // type: 'radio',
  143. // placeholder: '是否启用'
  144. // },
  145. // {
  146. // label: '是否加入黑名单:',
  147. // field: 'ifBlack',
  148. // type: 'radio',
  149. // placeholder: '是否加入黑名单'
  150. // },
  151. {
  152. label: '样式:',
  153. field: 'styleId',
  154. type: 'select',
  155. placeholder: '请选择样式'
  156. }
  157. ],
  158. applyTow: [
  159. {
  160. label: '是否企业:',
  161. field: 'isEnterprise',
  162. type: 'radio',
  163. placeholder: '是否企业'
  164. },
  165. {
  166. label: '企业名称:',
  167. field: 'enterpriseName',
  168. type: 'input',
  169. placeholder: '请输入企业名称'
  170. },
  171. {
  172. label: '担任职务:',
  173. field: 'enterpriseDuties',
  174. type: 'input',
  175. placeholder: '请输入担任职务'
  176. },
  177. {
  178. label: '部门:',
  179. field: 'enterpriseDepartment',
  180. type: 'input',
  181. placeholder: '请输入部门'
  182. }
  183. ],
  184. uploadFields: [
  185. {
  186. label: '用户名片头像',
  187. field: 'headImage'
  188. },
  189. {
  190. label: '图片介绍',
  191. field: 'pictureIntroduction'
  192. },
  193. {
  194. label: '企业头像',
  195. field: 'enterpriseHeadImage'
  196. }
  197. ],
  198. form: {
  199. basicInfo: {
  200. buyerId: '',
  201. enterpriseUserId: '',
  202. label: '',
  203. name: '',
  204. sex: '',
  205. birthday: '',
  206. phone: '',
  207. landline: '',
  208. mailbox: '',
  209. weChatSignal: '',
  210. personalProfile: '',
  211. address: '',
  212. // state: '',
  213. // ifBlack: '',
  214. styleId: ''
  215. },
  216. relatesInfo: {
  217. isEnterprise: '',
  218. enterpriseName: '',
  219. enterpriseDuties: '',
  220. enterpriseDepartment: ''
  221. },
  222. imgs: {
  223. headImage: '',
  224. pictureIntroduction: [],
  225. enterpriseHeadImage: ''
  226. }
  227. }
  228. }
  229. },
  230. methods: {
  231. // 获取名片详情
  232. async getElectronicCard(id) {
  233. uni.showLoading()
  234. try {
  235. const data = await this.$store.dispatch('user/getElectronicCardAction')
  236. uni.hideLoading()
  237. this.form.basicInfo.buyerId = data.buyerId || ''
  238. this.form.basicInfo.enterpriseUserId = data.enterpriseUserId || ''
  239. this.form.basicInfo.label = data.label || ''
  240. this.form.basicInfo.name = data.name || ''
  241. this.form.basicInfo.sex = String(data.sex) || ''
  242. this.form.basicInfo.birthday = data.birthday || ''
  243. this.form.basicInfo.phone = data.phone || ''
  244. this.form.basicInfo.landline = data.landline || ''
  245. this.form.basicInfo.mailbox = data.mailbox || ''
  246. this.form.basicInfo.weChatSignal = data.weChatSignal || ''
  247. this.form.basicInfo.personalProfile = data.personalProfile || ''
  248. this.form.basicInfo.address = data.address || ''
  249. // this.form.basicInfo.state = String(data.state) || ''
  250. // this.form.basicInfo.ifBlack = String(data.ifBlack) || ''
  251. this.form.basicInfo.styleId = data.styleId || ''
  252. this.form.imgs.headImage = data.headImage || ''
  253. this.form.imgs.pictureIntroduction = data.pictureIntroduction.split(',') || []
  254. this.form.relatesInfo.isEnterprise = String(data.isEnterprise) || ''
  255. this.form.relatesInfo.enterpriseName = data.enterpriseName || ''
  256. this.form.relatesInfo.enterpriseDuties = data.enterpriseDuties || ''
  257. this.form.relatesInfo.enterpriseDepartment = data.enterpriseDepartment || ''
  258. this.form.imgs.enterpriseHeadImage = data.enterpriseHeadImage || ''
  259. } catch (err) {
  260. console.log(err)
  261. uni.hideLoading()
  262. }
  263. },
  264. handleSaveImg(field, imgUrl) {
  265. console.log(field, imgUrl)
  266. if ((field === 'headImage') || (field === 'enterpriseHeadImage')) {
  267. this.form.imgs[field] = imgUrl
  268. } else if (field === 'pictureIntroduction') {
  269. this.form.imgs[field].push(imgUrl)
  270. }
  271. this.$forceUpdate()
  272. console.log(this.form.imgs[this.uploadFields[0].field])
  273. },
  274. // 点击提交按钮
  275. submit() {
  276. if (!this.isReadAgreement) return this.$showToast('请先同意小程序获取用户信息')
  277. const data = {
  278. ...this.form.basicInfo,
  279. // ifBlack: this.form.basicInfo.ifBlack ? Number(this.form.basicInfo.ifBlack) : '',
  280. ...this.form.relatesInfo,
  281. isEnterprise: this.form.relatesInfo.isEnterprise === 'true' ? true : this.form.relatesInfo.isEnterprise === 'false' ? false : '',
  282. ...this.form.imgs,
  283. pictureIntroduction: this.form.imgs.pictureIntroduction.join(',')
  284. }
  285. console.log(data)
  286. if (!data.name) {
  287. this.$showToast('缺少昵称')
  288. return
  289. }
  290. if (!data.sex) {
  291. this.$showToast('缺少性别')
  292. return
  293. }
  294. if (!data.styleId) {
  295. this.$showToast('缺少样式')
  296. return
  297. }
  298. if (typeof data.isEnterprise !== 'boolean') {
  299. this.$showToast('请选择是否企业')
  300. return
  301. }
  302. if ((typeof data.isEnterprise === 'boolean') && data.isEnterprise && !data.enterpriseName) {
  303. this.$showToast('缺少企业名称')
  304. return
  305. }
  306. uni.showModal({
  307. title: '提示',
  308. content: '确认提交名片表单?',
  309. success: (res) => {
  310. if (res.confirm) {
  311. if (data.buyerId) {
  312. updateByIdEnterpriseUserApi(data).then((res) => {
  313. this.$showToast('修改名片成功')
  314. setTimeout(() => {
  315. uni.navigateBack()
  316. }, 2000)
  317. })
  318. } else {
  319. addEnterpriseUserSaveApi(data).then((res) => {
  320. this.$showToast('添加名片成功')
  321. setTimeout(() => {
  322. uni.navigateBack()
  323. }, 2000)
  324. })
  325. }
  326. }
  327. }
  328. })
  329. },
  330. // 删除当前图片
  331. handleDeleteImg(field, imgUrl) {
  332. if ((field === 'headImage') || (field === 'enterpriseHeadImage')) {
  333. this.form.imgs[field] = ''
  334. } else if (field === 'pictureIntroduction') {
  335. this.form.imgs[field].splice(this.form.imgs[field].findIndex((item) => item === imgUrl), 1)
  336. }
  337. this.$forceUpdate()
  338. console.log(this.form.imgs[field])
  339. }
  340. }
  341. }
  342. </script>
  343. <style lang="less" scoped>
  344. .calling-card-form-container {
  345. padding: 40upx 40upx 140upx 40upx;
  346. box-sizing: border-box;
  347. .buts {
  348. position: fixed;
  349. bottom: -1px;
  350. z-index: 2;
  351. padding: 20upx 40upx;
  352. left: 0;
  353. display: flex;
  354. justify-content: center;
  355. align-items: center;
  356. background-color: #fff;
  357. width: 100%;
  358. box-sizing: border-box;
  359. margin-top: 272upx;
  360. }
  361. .btn {
  362. display: flex;
  363. justify-content: center;
  364. align-items: center;
  365. height: 72upx;
  366. width: 306upx;
  367. font-size: 32upx;
  368. color: #fff;
  369. margin: 0;
  370. background-color: #07b9b9;
  371. border-radius: 100px;
  372. &:last-child {
  373. background-color: #fa5151;
  374. }
  375. &.withdraw {
  376. width: 100%;
  377. background: #999;
  378. letter-spacing: 10upx;
  379. }
  380. }
  381. }
  382. </style>