reportFix.vue 8.4 KB

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