fieldForm.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <template>
  2. <view class="content">
  3. <view class="supplyInfo">
  4. <view class="flex">
  5. <label>公司名称:</label>
  6. <input type="text" v-model="supplyInfo.name" class="input card" />
  7. </view>
  8. <view class="flex">
  9. <label>活动人数:</label>
  10. <input type="number" v-model="supplyInfo.nums" class="input card" />
  11. </view>
  12. <view class="update_photo">
  13. <view class="title"></view>
  14. <view style="margin-bottom: 20rpx;">上传资料:</view>
  15. <view class="update_container card upload-parent-box">
  16. <view class="update_button display-flex">
  17. <view class="upload-box" @click="getImage('album')">
  18. <view class="img">
  19. <image src="/static/appeal/photo.png" class="photo"></image>
  20. </view>
  21. <view class="txt">上传</view>
  22. </view>
  23. <view
  24. class="display-flex upload-box-photo"
  25. v-for="(item, index) in uploadList"
  26. :key="index"
  27. >
  28. <image
  29. :src="item"
  30. mode="aspectFit"
  31. style="width: 100%; height: 100%"
  32. @click="showLarge(item)"
  33. />
  34. <image
  35. src="../../static/del.png"
  36. class="del-icon"
  37. mode="aspectFit"
  38. style="width: 30rpx; height: 30rpx"
  39. @click="delPhoto(index)"
  40. ></image>
  41. </view>
  42. </view>
  43. </view>
  44. <view class="approve-box">
  45. <view class="approve-title">请下载格式审批单,填写信息并加盖企业公章后上传</view>
  46. <view class="approve-content">格式审批单下载:<text>临空产业园党群服务中心线上预约审批单</text></view>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="info">
  51. <view class="title">联系信息</view>
  52. <view class="name flex">
  53. <label>联系人:</label>
  54. <input type="text" class="card input" v-model="company.name" />
  55. </view>
  56. <view class="tel flex">
  57. <label>联系电话:</label>
  58. <input type="text" class="card input" v-model="company.tel" />
  59. </view>
  60. </view>
  61. <button class="submit" @tap="submit">提交</button>
  62. </view>
  63. </template>
  64. <script>
  65. import md5 from "@/common/md5.js";
  66. export default {
  67. data() {
  68. return {
  69. supplyInfo: {
  70. name: "",
  71. nums: "",
  72. },
  73. company: {
  74. name: uni.getStorageSync("supply_name") || "",
  75. tel: uni.getStorageSync("supply_tel") || "",
  76. },
  77. uploadList: [],
  78. imgIdList: [],
  79. timeObj:{},
  80. };
  81. },
  82. onLoad(option) {
  83. this.timeObj = option;
  84. console.log(this.timeObj)
  85. },
  86. methods: {
  87. submit() {
  88. if (
  89. !this.company.name ||
  90. !this.company.tel
  91. ){
  92. uni.showToast({
  93. title: "联系信息不完善",
  94. icon: "error",
  95. });
  96. return;
  97. }
  98. this.subscribeFn()
  99. },
  100. subscribeFn(){ //订阅通知消息
  101. let that = this;
  102. uni.requestSubscribeMessage({
  103. tmplIds: [
  104. //"XQcYMt2Tz4OZnrpXMTjetRIwPVftkJeM_XUkNPBtu8c",
  105. "iZ3IABacOX7-EjGIyKnPtX2x3eJoYcwVqsOdEdRGvqU",//测试环境模板id
  106. ],
  107. success(res) {
  108. that.submitFieldRequest();
  109. },
  110. });
  111. },
  112. submitFieldRequest(){
  113. let md5Sign = md5(
  114. "method=" +
  115. "area" +
  116. "&timestamp=" +
  117. getApp().globalData.globalTimestamp +
  118. "&secret=" +
  119. getApp().globalData.secret
  120. );
  121. let url =
  122. getApp().globalData.shareUrl +
  123. "api/api.php" +
  124. "?method=area&source=area&action=order&timestamp=" +
  125. getApp().globalData.globalTimestamp +
  126. "&sign=" +
  127. md5Sign;
  128. let postData = {
  129. area_id:this.timeObj.id,
  130. date:this.timeObj.day || getApp().globalData.nowTime, //预约日期
  131. hours:this.timeObj.hour, //预约时段,多个时段之间用,隔开
  132. company_name :this.supplyInfo.name,
  133. number : this.supplyInfo.nums,
  134. contact_name : this.company.name,
  135. contact_phone : this.company.tel,
  136. file_atttach_id : this.imgIdList.join(),
  137. openId: getApp().globalData.open_id,
  138. };
  139. uni.request({
  140. url: url,
  141. method: "POST",
  142. header: {
  143. "content-type": "application/x-www-form-urlencoded",
  144. },
  145. data: postData,
  146. success: (res) => {
  147. if (res.data.code === 200) {
  148. uni.showToast({
  149. title: "提交成功",
  150. icon: "none",
  151. duration: 2000,
  152. });
  153. console.log(postData)
  154. uni.setStorageSync("supply_name", this.company.name);
  155. uni.setStorageSync("supply_tel", this.company.tel);
  156. setTimeout(() => {
  157. uni.navigateBack({});
  158. }, 1500);
  159. } else {
  160. uni.showToast({
  161. title: res.data.msg,
  162. icon: "none",
  163. duration: 2500,
  164. });
  165. }
  166. },
  167. fail: () => {
  168. console.log("连接失败");
  169. },
  170. });
  171. },
  172. getImage(type) {
  173. let that = this;
  174. if (that.uploadList.length >= 3) {
  175. uni.showToast({
  176. title: "最多上传3张图片",
  177. icon: "none",
  178. duration: 2500,
  179. });
  180. return;
  181. }
  182. uni.chooseImage({
  183. sourceType: [type],
  184. count: 3 - that.uploadList.length,
  185. sizeType: ["original", "compressed"], //可以指定是原图还是压缩图,默认二者都有
  186. success: (res) => {
  187. for (let i = 0; i < res.tempFilePaths.length; i++) {
  188. that.uploadList.push(res.tempFilePaths[i]);
  189. that.uploadFileRequest(res.tempFilePaths[i]);
  190. }
  191. },
  192. });
  193. },
  194. uploadFileRequest(fileVal) {
  195. uni.showLoading({
  196. title: "上传中",
  197. mask: true,
  198. });
  199. let that = this;
  200. let md5Sign = md5(
  201. "method=" +
  202. "upload" +
  203. "&timestamp=" +
  204. getApp().globalData.globalTimestamp +
  205. "&secret=" +
  206. getApp().globalData.secret
  207. );
  208. let url =
  209. getApp().globalData.shareUrl +
  210. "api/api.php" +
  211. "?method=upload&source=area&timestamp=" +
  212. getApp().globalData.globalTimestamp +
  213. "&sign=" +
  214. md5Sign;
  215. uni.uploadFile({
  216. url: url, //需要设置为全局
  217. filePath: fileVal,
  218. name: "file",
  219. formData: {
  220. file: fileVal,
  221. },
  222. success: (res) => {
  223. let tmpres = JSON.parse(res.data);
  224. console.log(tmpres);
  225. uni.hideLoading();
  226. that.imgIdList.push(tmpres.data.id);
  227. },
  228. fail: (res) => {
  229. console.log("上传请求失败");
  230. console.log(res);
  231. },
  232. });
  233. },
  234. delPhoto(idx) {
  235. this.uploadList.splice(idx, 1);
  236. this.imgIdList.splice(idx, 1);
  237. },
  238. showLarge(src) {
  239. uni.previewImage({
  240. urls: [src],
  241. longPressActions: {
  242. itemList: ["发送给朋友", "保存图片"],
  243. success: function (data) {},
  244. fail: function (err) {
  245. console.log(err.errMsg);
  246. },
  247. },
  248. });
  249. },
  250. },
  251. };
  252. </script>
  253. <style lang="scss" scoped>
  254. .upload-parent-box {
  255. height: 150rpx;
  256. padding-top: 25rpx;
  257. padding-left: 20rpx;
  258. }
  259. .upload-box {
  260. display: flex;
  261. flex-flow: column;
  262. width: 25%;
  263. background-color: #e0e0e0;
  264. height: 140rpx;
  265. border-radius: 10rpx;
  266. padding-top: 15rpx;
  267. color: #000;
  268. image {
  269. width: 60rpx !important;
  270. height: 60rpx !important;
  271. }
  272. }
  273. .upload-box-photo {
  274. width: 25%;
  275. height: 110rpx;
  276. border-radius: 10rpx;
  277. padding-top: 15rpx;
  278. position: relative;
  279. }
  280. .del-icon {
  281. position: absolute;
  282. right: 0;
  283. width: 30rpx;
  284. height: 30rpx;
  285. }
  286. .update_button {
  287. text-align: center;
  288. display: flex;
  289. }
  290. .content {
  291. font-size: 28rpx;
  292. font-weight: 200;
  293. padding: 1% 2%;
  294. .title {
  295. font-size: 30rpx;
  296. margin: 4% 0;
  297. color: #000;
  298. }
  299. label {
  300. display: inline-block;
  301. width: 25%;
  302. vertical-align: middle;
  303. color: #7f7f7f;
  304. }
  305. .card {
  306. background-color: rgb(248, 247, 247);
  307. border-radius: 10rpx;
  308. }
  309. .flex {
  310. display: flex;
  311. align-items: center;
  312. margin-bottom: 2%;
  313. }
  314. .input {
  315. padding: 0 2%;
  316. margin: 2% 0;
  317. display: inline-block;
  318. width: 80%;
  319. height: 70rpx;
  320. }
  321. .supplyInfo {
  322. border-radius: 40rpx;
  323. padding: 4%;
  324. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  325. margin: 30rpx 0 30rpx 0;
  326. color: #7f7f7f;
  327. .area {
  328. height: 200rpx;
  329. padding: 20rpx;
  330. box-sizing: border-box;
  331. }
  332. .picker {
  333. width: 80%;
  334. height: 70rpx;
  335. background: rgb(248, 247, 247);
  336. display: flex;
  337. align-items: center;
  338. position: relative;
  339. .pick {
  340. width: 100%;
  341. }
  342. .picker_title {
  343. display: flex;
  344. width: 100%;
  345. margin-left: 30rpx;
  346. align-items: center;
  347. justify-content: space-between;
  348. .triangle-down {
  349. width: 0;
  350. height: 0;
  351. border-top: 15rpx solid rgb(173, 173, 173);
  352. border-left: 15rpx solid transparent;
  353. border-right: 15rpx solid transparent;
  354. position: absolute;
  355. right: 10rpx;
  356. }
  357. }
  358. }
  359. .upload-box {
  360. width: 25%;
  361. background-color: #e0e0e0;
  362. height: 110rpx;
  363. border-radius: 10rpx;
  364. padding-top: 15rpx;
  365. }
  366. .upload-box-photo {
  367. width: 25%;
  368. height: 110rpx;
  369. border-radius: 10rpx;
  370. padding-top: 15rpx;
  371. position: relative;
  372. }
  373. .del-icon {
  374. position: absolute;
  375. right: 0;
  376. width: 30rpx;
  377. height: 30rpx;
  378. }
  379. image {
  380. width: 60rpx;
  381. height: 60rpx;
  382. }
  383. .update_button {
  384. text-align: center;
  385. display: flex;
  386. }
  387. }
  388. .approve-box {
  389. width: 100%;
  390. font-size: 24rpx;
  391. margin-top: 25rpx;
  392. padding-left: 20rpx;
  393. .approve-content {
  394. display: flex;
  395. margin: 20rpx 0 30rpx 0;
  396. text{
  397. color:#00a7f0;
  398. cursor: pointer;
  399. }
  400. }
  401. }
  402. .info {
  403. margin-top: 2%;
  404. border-radius: 40rpx;
  405. padding: 2% 4%;
  406. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  407. color: #7f7f7f;
  408. }
  409. .submit {
  410. color: white;
  411. font-weight: normal;
  412. width: 70%;
  413. border-radius: 20rpx;
  414. background-color: #02a7f0;
  415. margin: 50rpx auto;
  416. }
  417. }
  418. </style>