reportFix.vue 8.5 KB

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