index.vue 12 KB

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