calling-card-form.vue 9.2 KB

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