index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. <template>
  2. <view class="content">
  3. <view class="header"></view>
  4. <view class="form">
  5. <view class="form_title">
  6. 合作伙伴信息
  7. </view>
  8. <view class="form_item">
  9. <span class="icon">*</span>姓名
  10. <uni-easyinput placeholder="请输入姓名" v-model="name"></uni-easyinput>
  11. </view>
  12. <view class="form_item">
  13. <span class="icon">*</span>手机号
  14. <uni-easyinput type="number" placeholder="请输入手机号" v-model="phone"></uni-easyinput>
  15. </view>
  16. <view class="form_item">
  17. <span class="icon">*</span>单位名称
  18. <uni-easyinput placeholder="请输入单位名称" v-model="company"></uni-easyinput>
  19. </view>
  20. <view class="form_title">
  21. 项目信息登记
  22. </view>
  23. <view class="form_item">
  24. <span class="icon">*</span>客户名称
  25. <uni-easyinput placeholder="请输入客户名称" v-model="clientName"></uni-easyinput>
  26. </view>
  27. <view class="form_item">
  28. <span class="icon">*</span>项目名称
  29. <uni-easyinput placeholder="请输入项目名称" v-model="projectName"></uni-easyinput>
  30. </view>
  31. <view class="form_item">
  32. <span class="icon">*</span>项目金额
  33. <uni-easyinput type="number" placeholder="请输入项目金额" v-model="projectAmount"></uni-easyinput>
  34. </view>
  35. <view class="form_item">
  36. <span class="icon">*</span>预计投标时间
  37. <picker mode="date" fields="month" :start="getCurrentDate()" :value="biddingTime"
  38. @change="bindDateChange">
  39. <uni-easyinput disabled placeholder="请选择预计投标时间" suffixIcon="calendar-filled" v-model="biddingTime">
  40. </uni-easyinput>
  41. </picker>
  42. </view>
  43. <view class="form_item">
  44. <span class="icon">*</span>所属行业
  45. <uni-data-select placeholder="请选择所属行业" v-model="industry" :localdata="range"></uni-data-select>
  46. </view>
  47. <view class="form_item">
  48. <span class="icon">*</span>产品类型(多选)
  49. <uni-data-checkbox multiple v-model="productType" :localdata="hobby"></uni-data-checkbox>
  50. </view>
  51. <view class="form_item">
  52. 项目基本情况
  53. <uni-easyinput type="textarea" :maxlength="-1" placeholder="建议填写竞争情况 , 客户情况"
  54. v-model="projectInformation">
  55. </uni-easyinput>
  56. </view>
  57. <view class="form_item">
  58. 附件材料(建议上传项目相关信息或清单图片)
  59. <uni-file-picker ref="filePicker" limit="3" title="最多上传3张图片" :value="projectImgList"
  60. fileMediatype="image" :image-styles="imageStyles" mode="grid" @select="select"
  61. @delete="handleDelete">
  62. </uni-file-picker>
  63. </view>
  64. <button class="form_button" @click="handleSubmit">提交</button>
  65. <view class="footer">
  66. 本系统由新华三江西代表处提供技术支持
  67. </view>
  68. </view>
  69. </view>
  70. <!-- 用于图片压缩的canvas画布 -->
  71. <canvas :style="{
  72. width:cw+'px',
  73. height:cw+'px',
  74. position:'absolute', zIndex: -1, left: '-10000rpx' , top: '-10000rpx'}" canvas-id="zipCanvas">
  75. </canvas>
  76. <!--画布结束-->
  77. </template>
  78. <script setup>
  79. import {
  80. ref,
  81. onMounted
  82. } from 'vue'
  83. import {
  84. myRequest
  85. } from "@/util/api.js"
  86. // 图片压缩方法
  87. import
  88. getLessLimitSizeImage
  89. from "@/util/imageCompress.js"
  90. onMounted(() => {
  91. const accredit = uni.getStorageSync('accredit')
  92. if (accredit) {
  93. submit()
  94. }
  95. })
  96. //画板边长默认是屏幕宽度,正方形画布
  97. const cw = uni.getSystemInfoSync().windowWidth
  98. // 用户姓名绑定数据
  99. const name = ref(uni.getStorageSync('form_name') || '')
  100. // 用户手机号绑定数据
  101. const phone = ref(uni.getStorageSync('form_phone') || '')
  102. // 用户单位绑定数据
  103. const company = ref(uni.getStorageSync('form_company') || '')
  104. // 客户名称
  105. const clientName = ref(uni.getStorageSync('form_content') ? JSON.parse(uni.getStorageSync('form_content')).clientName :
  106. '')
  107. // 项目名称
  108. const projectName = ref(uni.getStorageSync('form_content') ? JSON.parse(uni.getStorageSync('form_content'))
  109. .projectName : '')
  110. // 项目金额
  111. const projectAmount = ref(uni.getStorageSync('form_content') ? JSON.parse(uni.getStorageSync('form_content'))
  112. .projectAmount : '')
  113. // 预计投标时间
  114. const biddingTime = ref(uni.getStorageSync('form_content') ? JSON.parse(uni.getStorageSync('form_content'))
  115. .biddingTime : '')
  116. // 所属行业
  117. const industry = ref(uni.getStorageSync('form_content') ? JSON.parse(uni.getStorageSync('form_content')).industry : '')
  118. // 产品类型
  119. const productType = ref(uni.getStorageSync('form_content') ? JSON.parse(uni.getStorageSync('form_content'))
  120. .productType : [])
  121. // 项目基本情况
  122. const projectInformation = ref(uni.getStorageSync('form_content') ? JSON.parse(uni.getStorageSync('form_content'))
  123. .projectInformation : '')
  124. // 显示的图片数据
  125. const projectImgList = ref(uni.getStorageSync('form_content') ? JSON.parse(uni.getStorageSync('form_content'))
  126. .projectImgList : [])
  127. // 上传的图片数据
  128. const subImgList = ref(uni.getStorageSync('form_content') ? JSON.parse(uni.getStorageSync('form_content'))
  129. .subImgList : [])
  130. // 微信手机号码绑定数据
  131. const wxPhone = ref(uni.getStorageSync('wxPhone') || '')
  132. // 所属行业数组数据
  133. const range = ref(
  134. [{
  135. value: 0,
  136. text: "政府"
  137. },
  138. {
  139. value: 1,
  140. text: "教育"
  141. },
  142. {
  143. value: 2,
  144. text: "医疗"
  145. },
  146. {
  147. value: 3,
  148. text: "企业"
  149. },
  150. {
  151. value: 4,
  152. text: "公检法"
  153. },
  154. {
  155. value: 5,
  156. text: "交通"
  157. },
  158. {
  159. value: 6,
  160. text: "分销&SMB"
  161. },
  162. {
  163. value: 7,
  164. text: "其他"
  165. }
  166. ]
  167. )
  168. // 产品类型数组
  169. const hobby = ref(
  170. [{
  171. text: '网络',
  172. value: 0
  173. }, {
  174. text: '安全',
  175. value: 1
  176. }, {
  177. text: 'IT',
  178. value: 2
  179. }, {
  180. text: '云智',
  181. value: 3
  182. }, {
  183. text: 'PC',
  184. value: 4
  185. }, {
  186. text: 'AI视觉',
  187. value: 5
  188. }]
  189. )
  190. // 图片上传框的样式
  191. const imageStyles = {
  192. width: 75,
  193. height: 75,
  194. border: {
  195. color: "#ccc",
  196. width: 1,
  197. style: 'dashed',
  198. radius: '5px'
  199. }
  200. }
  201. // 上传组件元素
  202. const filePicker = ref(null)
  203. // 日期选择框绑定回调
  204. const bindDateChange = (e) => {
  205. const val = e.detail.value
  206. biddingTime.value = val
  207. }
  208. // 提交按钮回调
  209. const handleSubmit = () => {
  210. const flag = handleValidate()
  211. if (flag) {
  212. uni.setStorageSync('form_name', name.value);
  213. uni.setStorageSync('form_phone', phone.value);
  214. uni.setStorageSync('form_company', company.value);
  215. const formContent = {
  216. clientName: clientName.value,
  217. projectName: projectName.value,
  218. projectAmount: projectAmount.value,
  219. biddingTime: biddingTime.value,
  220. industry: industry.value,
  221. productType: productType.value,
  222. projectInformation: projectInformation.value,
  223. projectImgList: projectImgList.value,
  224. subImgList: subImgList.value
  225. }
  226. uni.setStorageSync('form_content', JSON.stringify(formContent));
  227. if (!wxPhone.value) {
  228. uni.showModal({
  229. title: '提示',
  230. content: '本次操作需要获取您的手机号码',
  231. success: (res) => {
  232. if (res.confirm) {
  233. uni.navigateTo({
  234. url: "/pages/authorization/authorization"
  235. })
  236. } else if (res.cancel) {}
  237. }
  238. });
  239. } else {
  240. uni.showModal({
  241. title: '提示',
  242. content: '确认提交吗',
  243. success: (res) => {
  244. if (res.confirm) {
  245. submit()
  246. } else if (res.cancel) {}
  247. }
  248. });
  249. }
  250. }
  251. }
  252. // 验证表格信息是否符合规范
  253. const handleValidate = () => {
  254. const reName = /^[\u4e00-\u9fa5]{2,4}$/
  255. const rePhone = /^[1][3,4,5,7,8,9][0-9]{9}$/
  256. const reProjectAmount = /^\+?[1-9][0-9]*$/
  257. if (name.value == '') {
  258. uni.showToast({
  259. title: '请输入姓名',
  260. icon: 'none'
  261. })
  262. return false
  263. }
  264. if (!reName.test(name.value)) {
  265. uni.showToast({
  266. title: '姓名格式有误',
  267. icon: 'none'
  268. })
  269. return false
  270. }
  271. if (phone.value == '') {
  272. uni.showToast({
  273. title: '请输入手机号',
  274. icon: 'none'
  275. })
  276. return false
  277. }
  278. if (!rePhone.test(phone.value)) {
  279. uni.showToast({
  280. title: '手机格式有误',
  281. icon: 'none'
  282. })
  283. return false
  284. }
  285. if (company.value == '') {
  286. uni.showToast({
  287. title: '请输入单位名称',
  288. icon: 'none'
  289. })
  290. return false
  291. }
  292. if (clientName.value == '') {
  293. uni.showToast({
  294. title: '请输入客户名称',
  295. icon: 'none'
  296. })
  297. return false
  298. }
  299. if (projectName.value == '') {
  300. uni.showToast({
  301. title: '请输入项目名称',
  302. icon: 'none'
  303. })
  304. return false
  305. }
  306. if (projectAmount.value == '') {
  307. uni.showToast({
  308. title: '请输入项目金额',
  309. icon: 'none'
  310. })
  311. return false
  312. }
  313. if (!reProjectAmount.test(projectAmount.value)) {
  314. uni.showToast({
  315. title: '项目金额请输入正整数',
  316. icon: 'none'
  317. })
  318. return false
  319. }
  320. if (biddingTime.value == '') {
  321. uni.showToast({
  322. title: '请选择预计投标时间',
  323. icon: 'none'
  324. })
  325. return false
  326. }
  327. if (industry.value === '') {
  328. uni.showToast({
  329. title: '请选择所属行业',
  330. icon: 'none'
  331. })
  332. return false
  333. }
  334. if (productType.value.length == 0) {
  335. uni.showToast({
  336. title: '请选择产品类型',
  337. icon: 'none'
  338. })
  339. return false
  340. }
  341. return true
  342. }
  343. // 请求提交接口回调
  344. const submit = async () => {
  345. const bProduct = []
  346. productType.value.forEach(item => {
  347. bProduct.push(hobby.value[item].text)
  348. })
  349. const res = await myRequest({
  350. url: "/informationReporting/add",
  351. method: "post",
  352. data: {
  353. name: name.value,
  354. phone: phone.value,
  355. company: company.value,
  356. customerName: clientName.value,
  357. entryName: projectName.value,
  358. projectAmount: projectAmount.value,
  359. tenderTime: biddingTime.value,
  360. content: projectInformation.value,
  361. trade: range.value[industry.value].text,
  362. bProduct,
  363. wxPhone: wxPhone.value,
  364. bFile: subImgList.value
  365. }
  366. })
  367. // console.log(res)
  368. if (res.success && res.code == 1) {
  369. uni.showToast({
  370. title: '提交成功',
  371. duration: 3000
  372. })
  373. clientName.value = ''
  374. projectName.value = ''
  375. projectAmount.value = ''
  376. biddingTime.value = ''
  377. industry.value = ''
  378. productType.value = []
  379. projectInformation.value = ''
  380. subImgList.value = []
  381. projectImgList.value = []
  382. filePicker.value.clearFiles()
  383. uni.removeStorageSync('form_content')
  384. uni.setStorageSync('accredit', false)
  385. } else {
  386. uni.showToast({
  387. title: res.message,
  388. icon: 'error'
  389. })
  390. }
  391. }
  392. // 获取当前时间 YY-MM-DD
  393. const getCurrentDate = () => {
  394. const date = new Date();
  395. let year = date.getFullYear();
  396. let month = date.getMonth() + 1;
  397. let day = date.getDate();
  398. month = month > 9 ? month : '0' + month;
  399. day = day > 9 ? day : '0' + day;
  400. return `${year}-${month}-${day}`;
  401. }
  402. // 选择图片回调
  403. const select = (e) => {
  404. // console.log(e);
  405. e.tempFiles.forEach((item) => {
  406. //这里的id和页面中写的html代码的canvas的id要一致
  407. let canvasId = 'zipCanvas'
  408. //原图的路径
  409. let imagePath = item.path;
  410. //大小限制1024kb
  411. let limitSize = 1024;
  412. //初始绘画区域是画布自身的宽度也就是屏幕宽度
  413. let drawWidth = uni.getSystemInfoSync().windowWidth;
  414. getLessLimitSizeImage(canvasId, imagePath, limitSize, drawWidth, (resPath) => {
  415. uni.showLoading({
  416. title: '上传中'
  417. });
  418. uni.uploadFile({
  419. url: `https://chtech.ncjti.edu.cn/gradiate-school/reporting/file/fileUpDown`,
  420. filePath: resPath,
  421. name: 'file',
  422. success: (uploadFileRes) => {
  423. subImgList.value.push((JSON.parse(uploadFileRes.data).data).join())
  424. projectImgList.value.push({
  425. url: item.path,
  426. name: ""
  427. })
  428. uni.hideLoading();
  429. },
  430. fail: () => {
  431. uni.showToast({
  432. title: '上传失败',
  433. icon: 'error'
  434. })
  435. }
  436. });
  437. })
  438. })
  439. }
  440. // 删除图片回调
  441. const handleDelete = (e) => {
  442. // console.log(e);
  443. const num = projectImgList.value.findIndex(v => v.url === e.tempFilePath);
  444. subImgList.value.splice(num, 1);
  445. projectImgList.value.splice(num, 1);
  446. }
  447. </script>
  448. <style lang="scss" scoped>
  449. .content {
  450. width: 100vw;
  451. .header {
  452. width: 750rpx;
  453. height: 300rpx;
  454. border-radius: 0 0 10% 10%;
  455. background-color: #1E7DFB;
  456. }
  457. .form {
  458. position: absolute;
  459. top: 42rpx;
  460. left: 30rpx;
  461. right: 30rpx;
  462. padding: 0 32rpx;
  463. border-radius: 10rpx;
  464. background-color: #fff;
  465. .form_title {
  466. line-height: 105rpx;
  467. font-weight: bold;
  468. font-size: 34rpx;
  469. }
  470. .form_item {
  471. margin-bottom: 20rpx;
  472. font-size: 28rpx;
  473. .icon {
  474. color: #D43030;
  475. }
  476. :deep .uni-easyinput {
  477. margin-top: 10rpx;
  478. background-color: #F2F2F2;
  479. }
  480. :deep .uni-stat__select {
  481. margin-top: 10rpx;
  482. background-color: #F2F2F2;
  483. }
  484. :deep .uni-data-checklist {
  485. margin-top: 10rpx !important;
  486. background-color: #F2F2F2;
  487. }
  488. }
  489. .form_button {
  490. margin-top: 65rpx;
  491. background-color: #1E7DFB;
  492. color: #fff;
  493. font-size: 28rpx;
  494. }
  495. .footer {
  496. margin: 70rpx 0;
  497. text-align: center;
  498. font-size: 24rpx;
  499. color: #999999;
  500. }
  501. }
  502. }
  503. </style>