edit.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <template>
  2. <view style="background: #ffffff;">
  3. <my_form ref="form" :form="form" @isUncomplete="isUncomplete" @onUploading="onUploading" @isShowAll="isShowAll">
  4. <template v-if="isShow" slot="head">
  5. <view class="headportrait" hover-class="navigator-hover">
  6. <view class="content">
  7. <My_upload maxCount="1" ref="upload" @onLoading="imageOnLoading" @uploadCallback="uploadCallback"></My_upload>
  8. <button class="avatar-box" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  9. </button>
  10. <view style="display: flex;align-items: center;">
  11. <view style="border-radius: 50%;width: 56px;height: 56px;border:2px solid #ffffff">
  12. <u--image :width="56" :height="56" shape="circle" :src="headportrait">
  13. <template v-slot:loading>
  14. <u-loading-icon />
  15. </template>
  16. </u--image>
  17. </view>
  18. <view :style="'width:'+tovw(255)" />
  19. <view class="iconfont icon-a-wodetiaozhuan" />
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. </my_form>
  25. <view v-if="!origin" style="height: 70px;" />
  26. <view class="footer">
  27. <view class="add" :class="uncomplete ? 'forbidden' : ''" hover-class="navigator-hover"
  28. @click="uncomplete || loading ? '' : submit()">
  29. <u-loading-icon v-if="loading" />
  30. <block v-else>
  31. {{ origin == 'my' ? '保存' : '保存名片' }}
  32. </block>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import {formattedFiles} from '../../utils/settleFiles.js'
  39. export default {
  40. data() {
  41. return {
  42. sys_enterpriseid: 0,
  43. form: [],
  44. attachmentids: [],
  45. uncomplete: true,
  46. onUpload:false,
  47. copyUncomplete: false,
  48. loading: false,
  49. headportrait: "https://yossys06593.obs.cn-east-3.myhuaweicloud.com:443/202404231713854678447B26b4363.svg",
  50. userid: 0,
  51. isShow: true,
  52. isSubmit:false,
  53. origin:''
  54. }
  55. },
  56. onLoad(options) {
  57. this.userid = options.id
  58. this.origin = options.origin
  59. this.init()
  60. uni.setNavigationBarTitle({
  61. title: '修改名片'
  62. });
  63. },
  64. onUnload() {
  65. if (!this.isSubmit) this.$refs.form.deleteFiles()
  66. },
  67. methods: {
  68. onChooseAvatar (e) {
  69. let ext = e.detail.avatarUrl.substr(e.detail.avatarUrl.lastIndexOf('.')+1)
  70. let name = `${Date.now()}.${ext}`
  71. let temp = {
  72. name:name,
  73. type:'image',
  74. url:e.detail.avatarUrl
  75. }
  76. this.afterRead({file:[temp]})
  77. },
  78. afterRead({ file }) {
  79. const that = this;
  80. file.forEach(v => {
  81. // #ifdef H5
  82. this.getArrayBuffer(v).then(data => that.handleUploadFile(this.requestType(v), data))
  83. // #endif
  84. // #ifndef H5
  85. uni.getFileSystemManager().readFile({
  86. filePath: v.url,
  87. success: data => that.handleUploadFile(this.requestType(v), data.data),
  88. fail: console.error
  89. })
  90. // #endif
  91. });
  92. },
  93. /* 请求类型 */
  94. requestType(file) {
  95. // #ifdef H5
  96. var ext = file.name.substr(file.name.lastIndexOf(".") + 1);
  97. // #endif
  98. // #ifndef H5
  99. var ext = file.type.split("/")[1] || file.url.substr(file.url.lastIndexOf(".") + 1) || file.name.substr(file.name.lastIndexOf(".") + 1);
  100. // #endif
  101. //文件名称
  102. return {
  103. "classname": "system.attachment.huawei.OBS",
  104. "method": "getFileName",
  105. "content": {
  106. "filename": `${Date.now()}.${ext}`,
  107. "filetype": ext,
  108. "parentid": uni.getStorageSync('siteP').appfolderid
  109. }
  110. }
  111. },
  112. handleUploadFile(file, data) {
  113. this.loading = true;
  114. this.$Http.basic(file).then(res => {
  115. if (res.msg == "成功") {
  116. this.uploadFile(res.data, data)
  117. } else {
  118. uni.showToast({
  119. title: `${data.filename}.${data.serialfilename}`,
  120. icon: "none"
  121. })
  122. }
  123. })
  124. },
  125. getArrayBuffer(file) {
  126. return new Promise((resolve, reject) => {
  127. let xhr = new XMLHttpRequest()
  128. xhr.open('GET', file.url, true)
  129. xhr.responseType = 'blob'
  130. xhr.onload = function () {
  131. if (this.status == 200) {
  132. let myBlob = this.response
  133. let files = new window.File([myBlob], file.name, { type: file.url.substr(file.url.lastIndexOf(".") + 1) }) // myBlob.type 自定义文件名
  134. const reader = new FileReader();
  135. reader.readAsArrayBuffer(files);
  136. reader.onload = () => resolve(reader.result);
  137. reader.onerror = (error) => reject(error);
  138. } else {
  139. reject(false)
  140. }
  141. }
  142. xhr.send()
  143. })
  144. },
  145. /* 上传成功反馈 */
  146. uploadFile(res, data) {
  147. var that = this;
  148. that.loading = true;
  149. uni.request({
  150. url: res.uploadurl,
  151. method: "PUT",
  152. data,
  153. header: {
  154. 'content-type': 'application/octet-stream'
  155. },
  156. success() {
  157. that.$Http.basic({
  158. "classname": "system.attachment.huawei.OBS",
  159. "method": "uploadSuccess",
  160. "content": {
  161. "serialfilename": res.serialfilename
  162. }
  163. }).then(s => {
  164. console.log("文件上传反馈", s)
  165. that.loading = false;
  166. if (!that.cutoff(s.msg)) that.uploadCallback(s.data.attachmentids, "sys_users", that.userid)
  167. }).catch(err => {
  168. that.loading = false;
  169. console.error(err)
  170. })
  171. },
  172. fail(err) {
  173. that.loading = false;
  174. console.log(err)
  175. }
  176. })
  177. },
  178. init() {
  179. let form = [{
  180. key: "name",
  181. type: "text",
  182. label: "姓名",
  183. isMust: true,//是否必填
  184. value: "",
  185. }, {
  186. key: "phonenumber",
  187. type: "text",
  188. label: "手机号",
  189. isMust: true,//是否必填
  190. value: "",
  191. placeholder: "请输入手机号",
  192. inputmode: 'number',
  193. verify: [this.getReg("phonenumber")]
  194. }, {
  195. key: "email",
  196. type: "text",
  197. label: "邮箱",
  198. isMust: false,//是否必填
  199. value: "",
  200. verify: [this.getReg("email")]
  201. }, {
  202. key: "address",
  203. type: "text",
  204. label: "地址",
  205. isMust: false,//是否必填
  206. value: "",
  207. },];
  208. if (!this.origin) {
  209. form.push({
  210. key: "remarks",
  211. type: "textarea",
  212. label: "自我介紹",
  213. isMust: false,//是否必填
  214. value: '',
  215. },{
  216. key: "attachmentids",
  217. type: "upload",
  218. label: "图片",
  219. placeholder: "可上传多个图片",
  220. accept: "image*/",
  221. ownertable: "temporary",
  222. ownerid: 999,
  223. usetype: 'default',
  224. allowUpload: true,
  225. allowDelete: true,
  226. value: [],
  227. marginTop: 10
  228. })
  229. }
  230. this.$Http.basic({
  231. "id": 20240514161502,
  232. "content": {
  233. userid:this.userid
  234. },
  235. }).then(res => {
  236. console.log("获取个人信息", res)
  237. // if (this.cutoff(res.msg)) return;
  238. if (res.msg == '成功') {
  239. this.headportraits = res.data.attinfos;
  240. this.headportrait = this.headportraits.find(v => v.usetype == "headportrait") && this.headportraits.find(v => v.usetype == "headportrait").url || this.headportrait;
  241. form = form.map(v => {
  242. if (v.key == 'attachmentids') {
  243. v.value = formattedFiles(res.data.attinfos.filter(item => item.usetype != 'headportrait'))
  244. } else {
  245. v.value = res.data[v.key] || v.value
  246. }
  247. return v
  248. })
  249. }
  250. this.form = form;
  251. })
  252. },
  253. onUploading(ing) {
  254. this.onUpload = ing;
  255. },
  256. isUncomplete(uncomplete) {
  257. console.log(uncomplete);
  258. this.uncomplete = uncomplete;
  259. },
  260. submit() {
  261. this.loading = true;
  262. let that = this;
  263. this.$refs.form.submit().then(data => {
  264. this.$Http.basic({
  265. "id": 20240511151602,
  266. "content": {
  267. ...data
  268. }
  269. }).then(async res => {
  270. this.loading = false;
  271. console.log("修改信息", res)
  272. if (this.cutoff(res.msg)) return;
  273. if (!this.origin && data.files.temporarys.length) {
  274. this.onUpload = true;
  275. await this.$Http.basic({
  276. "classname": "system.attachment.Attachment",
  277. "method": "createFileLink",
  278. "content": {
  279. ownertable: 'sys_users',
  280. ownerid: res.data.userid,
  281. usetype: 'default',
  282. attachmentids: data.files.temporarys
  283. }
  284. }).then(async s => {
  285. this.isSubmit = true;
  286. this.onUpload = false;
  287. console.log("绑定附加", s)
  288. if (this.cutoff(s.msg)) return;
  289. })
  290. };
  291. this.loading = true;
  292. if (!this.origin && data.files.linksids.length) {
  293. await this.$Http.basic({
  294. "classname": "system.attachment.Attachment",
  295. "method": "deleteFileLink",
  296. "content": {
  297. linksids: data.files.linksids
  298. }
  299. })
  300. }
  301. if (this.attachmentids.length) {
  302. this.uploadCallback(this.attachmentids, "sys_users", this.userid).then(s => {
  303. if (s) getUserMsg()
  304. });
  305. if (this.headportraits.length) this.$Http.basic({
  306. "classname": "system.attachment.Attachment",
  307. "method": "deleteFileLink",
  308. "content": {
  309. linksids: this.headportraits.map(v => v.linksid)
  310. }
  311. })
  312. } else {
  313. this.$Http.editUser(res.data.userid)
  314. uni.navigateBack()
  315. }
  316. })
  317. })
  318. },
  319. isShowAll(e) {
  320. this.isShow = !e;
  321. },
  322. imageOnLoading(e) {
  323. if (e) {
  324. this.copyUncomplete = this.uncomplete;
  325. this.uncomplete = true;
  326. } else {
  327. this.uncomplete = this.copyUncomplete;
  328. }
  329. },
  330. uploadCallback(attachmentids, ownertable = 'temporary', ownerid = '99999999') {
  331. if (ownertable == 'temporary') this.imageOnLoading(true)
  332. return new Promise((resolve, reject) => {
  333. this.$Http.basic({
  334. "classname": "system.attachment.Attachment",
  335. "method": "createFileLink",
  336. "content": {
  337. "usetype": "headportrait",
  338. ownertable,
  339. ownerid,
  340. attachmentids
  341. },
  342. }).then(res => {
  343. console.log('绑定附件', res)
  344. if (ownertable == 'temporary') this.imageOnLoading(false)
  345. if (this.cutoff(res.msg)) return resolve(false);
  346. this.headportrait = res.data[0].url;
  347. resolve(true)
  348. if (ownertable == 'temporary' && this.linksid) this.$Http.basic({
  349. "classname": "system.attachment.Attachment",
  350. "method": "deleteFileLink",
  351. "content": {
  352. linksids: [this.linksid]
  353. }
  354. }).then(res => {
  355. console.log("处理删除附件", res)
  356. if (this.cutoff(res.msg)) return;
  357. });
  358. if (ownertable == 'temporary') {
  359. this.attachmentids = attachmentids;
  360. console.log(res.data[0],'结果');
  361. this.headportrait = res.data[0].url;
  362. this.linksid = res.data[0].linksid;
  363. }
  364. })
  365. })
  366. },
  367. },
  368. }
  369. </script>
  370. <style lang="scss" scoped>
  371. .headportrait {
  372. width: 100vw;
  373. padding-left: 10px;
  374. background: #fff;
  375. .content {
  376. display: flex;
  377. align-items: center;
  378. border-bottom: 1px solid #DDDDDD;
  379. box-sizing: border-box;
  380. height: 76px;
  381. padding: 10px;
  382. padding-left: 0;
  383. position: relative;
  384. .avatar-box {
  385. width: 100%;
  386. height: 76px;
  387. position: absolute;
  388. left: 0;
  389. top: 0;
  390. opacity: 0;
  391. }
  392. .label {
  393. font-family: Source Han Sans SC, Source Han Sans SC;
  394. font-size: 14px;
  395. color: #666666;
  396. width: 110px;
  397. }
  398. }
  399. }
  400. .upload-type {
  401. display: flex;
  402. flex-direction: column;
  403. font-family: Source Han Sans SC, Source Han Sans SC;
  404. font-weight: 400;
  405. font-size: 16px;
  406. color: #333333;
  407. .type-line {
  408. padding: 12px 0;
  409. display: flex;
  410. justify-content: space-evenly;
  411. align-items: center;
  412. border-bottom: 1px #DDDDDD solid;
  413. .line-1 {
  414. display: flex;
  415. align-items: center;
  416. align-content: center;
  417. text {
  418. margin-right: 10px;
  419. }
  420. image {
  421. width: 24px !important;
  422. height: 24px !important;
  423. }
  424. }
  425. text {}
  426. }
  427. }
  428. .footer {
  429. position: fixed;
  430. bottom: 0;
  431. width: 100vw;
  432. height: 65px;
  433. background: #FFFFFF;
  434. box-shadow: 0px -2px 6px 1px rgba(0, 0, 0, 0.16);
  435. box-sizing: border-box;
  436. padding: 5px 10px;
  437. .add {
  438. display: flex;
  439. align-items: center;
  440. justify-content: center;
  441. width: 100%;
  442. height: 45px;
  443. background: #C30D23;
  444. border-radius: 5px;
  445. font-family: PingFang SC, PingFang SC;
  446. font-size: 14px;
  447. color: #FFFFFF;
  448. }
  449. .forbidden {
  450. opacity: .6;
  451. }
  452. }
  453. </style>