putSupply.vue 9.8 KB

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