edit.vue 16 KB

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