reportFix.vue 8.2 KB

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