reportFix.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <view class="content">
  3. <view class="supplyInfo">
  4. <view class="update_photo">
  5. <view>问题说明:</view>
  6. <textarea v-model="supplyInfo.content" 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="supplyInfo.name" />
  45. </view>
  46. <view class="tel flex">
  47. <label>联系方式:</label>
  48. <input type="tel" class="card input" v-model="supplyInfo.phone" />
  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. name : "",
  62. phone : "",
  63. content : "",
  64. },
  65. uploadList: [],
  66. imgIdList: [],
  67. pic_id : 0,
  68. };
  69. },
  70. methods: {
  71. submit() {
  72. if (this.imgIdList.length > 0){
  73. this.pic_id = this.imgIdList[0];
  74. }
  75. if (
  76. this.supplyInfo.name === "" ||
  77. this.supplyInfo.phone === ""
  78. ) {
  79. uni.showToast({
  80. title: "报修信息不完善",
  81. icon: "error",
  82. });
  83. return;
  84. }
  85. let md5Sign = md5(
  86. "method=" +
  87. "user" +
  88. "&timestamp=" +
  89. getApp().globalData.globalTimestamp +
  90. "&secret=" +
  91. getApp().globalData.secret
  92. );
  93. let url =
  94. getApp().globalData.shareUrl +
  95. "api/api.php" +
  96. "?method=user&source=repair&action=post_repair&timestamp=" +
  97. getApp().globalData.globalTimestamp +
  98. "&sign=" +
  99. md5Sign;
  100. let postData = {
  101. name: this.supplyInfo.name,
  102. phone: this.supplyInfo.phone,
  103. content: this.supplyInfo.content,
  104. pic_id: this.pic_id,
  105. openId: getApp().globalData.open_id,
  106. };
  107. uni.request({
  108. url: url,
  109. method: "POST",
  110. header: {
  111. "content-type": "application/x-www-form-urlencoded",
  112. },
  113. data: postData,
  114. success: (res) => {
  115. if (res.data.code === 200) {
  116. uni.showToast({
  117. title: "报修信息上传成功!",
  118. icon: "none",
  119. duration: 2000,
  120. });
  121. this.paramRefresh();
  122. setTimeout(function() {
  123. uni.navigateTo({
  124. url: "/pages/selfCenter/my_fix",
  125. });
  126. }, 500)
  127. } else {
  128. uni.showToast({
  129. title: res.data.msg,
  130. icon: "none",
  131. duration: 2500,
  132. });
  133. }
  134. },
  135. fail: () => {
  136. console.log("连接失败");
  137. },
  138. });
  139. },
  140. paramRefresh(){
  141. this.supplyInfo = {
  142. name : "",
  143. phone : "",
  144. content : "",
  145. }
  146. this.uploadList = []
  147. this.imgIdList = []
  148. this.pic_id = 0
  149. },
  150. bindPickerChange(e) {
  151. this.index = e.detail.value;
  152. },
  153. getImage(type) {
  154. let that = this;
  155. if (that.uploadList.length >= 1) {
  156. uni.showToast({
  157. title: "最多上传1张图片",
  158. icon: "none",
  159. duration: 2500,
  160. });
  161. return;
  162. }
  163. uni.chooseImage({
  164. sourceType: [type],
  165. count: 1 - that.uploadList.length,
  166. sizeType: ["original", "compressed"], //可以指定是原图还是压缩图,默认二者都有
  167. success: (res) => {
  168. for (let i = 0; i < res.tempFilePaths.length; i++) {
  169. that.uploadList.push(res.tempFilePaths[i]);
  170. that.uploadFileRequest(res.tempFilePaths[i]);
  171. }
  172. },
  173. });
  174. },
  175. uploadFileRequest(fileVal) {
  176. uni.showLoading({
  177. title: "上传中",
  178. mask: true,
  179. });
  180. let that = this;
  181. let md5Sign = md5(
  182. "method=" +
  183. "upload" +
  184. "&timestamp=" +
  185. getApp().globalData.globalTimestamp +
  186. "&secret=" +
  187. getApp().globalData.secret
  188. );
  189. let url =
  190. getApp().globalData.shareUrl +
  191. "api/api.php" +
  192. "?method=upload&source=repair&timestamp=" +
  193. getApp().globalData.globalTimestamp +
  194. "&sign=" +
  195. md5Sign;
  196. uni.uploadFile({
  197. url: url, //需要设置为全局
  198. filePath: fileVal,
  199. name: "file",
  200. formData: {
  201. file: fileVal,
  202. },
  203. success: (res) => {
  204. let tmpres = JSON.parse(res.data);
  205. console.log(tmpres);
  206. uni.hideLoading();
  207. that.imgIdList.push(tmpres.data.id);
  208. },
  209. fail: (res) => {
  210. console.log("上传请求失败");
  211. console.log(res);
  212. },
  213. });
  214. },
  215. delPhoto(idx) {
  216. this.uploadList.splice(idx, 1);
  217. this.imgIdList.splice(idx, 1);
  218. },
  219. showLarge(src) {
  220. uni.previewImage({
  221. urls: [src],
  222. longPressActions: {
  223. itemList: ["发送给朋友", "保存图片"],
  224. success: function (data) {},
  225. fail: function (err) {
  226. console.log(err.errMsg);
  227. },
  228. },
  229. });
  230. },
  231. },
  232. };
  233. </script>
  234. <style lang="scss" scoped>
  235. .upload-box {
  236. display: flex;
  237. flex-flow: column;
  238. width: 25%;
  239. background-color: #e0e0e0;
  240. height: 140rpx;
  241. border-radius: 10rpx;
  242. padding-top: 15rpx;
  243. image {
  244. width: 60rpx !important;
  245. height: 60rpx !important;
  246. }
  247. }
  248. .upload-box-photo {
  249. width: 25%;
  250. height: 110rpx;
  251. border-radius: 10rpx;
  252. padding-top: 15rpx;
  253. position: relative;
  254. }
  255. .del-icon {
  256. position: absolute;
  257. right: 0;
  258. width: 30rpx;
  259. height: 30rpx;
  260. }
  261. .upload-parent-box {
  262. height: 150rpx;
  263. padding-top: 25rpx;
  264. padding-left: 20rpx;
  265. margin-top: 10px;
  266. margin-bottom: 10px
  267. }
  268. .update_button {
  269. text-align: center;
  270. display: flex;
  271. }
  272. .content {
  273. font-size: 28rpx;
  274. font-weight: 200;
  275. padding: 1% 2%;
  276. .title {
  277. font-size: 30rpx;
  278. margin: 4% 0;
  279. }
  280. label {
  281. display: inline-block;
  282. width: 25%;
  283. vertical-align: middle;
  284. }
  285. .card {
  286. background-color: rgb(248, 247, 247);
  287. border-radius: 10rpx;
  288. }
  289. .flex {
  290. display: flex;
  291. align-items: center;
  292. margin-bottom: 2%;
  293. }
  294. .input {
  295. padding: 0 2%;
  296. margin: 2% 0;
  297. display: inline-block;
  298. width: 80%;
  299. height: 70rpx;
  300. }
  301. .supplyInfo {
  302. border-radius: 40rpx;
  303. padding: 4%;
  304. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  305. margin: 30rpx 0 30rpx 0;
  306. .area {
  307. width: 100%;
  308. height: 400rpx;
  309. padding: 20rpx;
  310. box-sizing: border-box;
  311. margin-top: 10px;
  312. }
  313. .upload-box {
  314. width: 25%;
  315. background-color: #e0e0e0;
  316. height: 110rpx;
  317. border-radius: 10rpx;
  318. padding-top: 15rpx;
  319. }
  320. .upload-box-photo {
  321. width: 25%;
  322. height: 110rpx;
  323. border-radius: 10rpx;
  324. padding-top: 15rpx;
  325. position: relative;
  326. }
  327. .del-icon {
  328. position: absolute;
  329. right: 0;
  330. width: 30rpx;
  331. height: 30rpx;
  332. }
  333. image {
  334. width: 60rpx;
  335. height: 60rpx;
  336. }
  337. .update_button {
  338. text-align: center;
  339. display: flex;
  340. }
  341. }
  342. .info {
  343. margin-top: 2%;
  344. border-radius: 40rpx;
  345. padding: 2% 4%;
  346. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  347. }
  348. .submit {
  349. color: white;
  350. font-weight: normal;
  351. width: 70%;
  352. border-radius: 20rpx;
  353. background-color: #02a7f0;
  354. margin: 50rpx auto;
  355. }
  356. }
  357. </style>