factoryBuildingsAdd.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <view>
  3. <!-- <cu-custom bgColor="bg-blue" :isBack="true" v-if="title == '发布产品供需'">
  4. <block slot="backText">返回</block>
  5. <block slot="content">发布产品供需</block>
  6. </cu-custom>
  7. <cu-custom bgColor="bg-blue" :isBack="true" v-if="title == '修改产品供需'">
  8. <block slot="backText">返回</block>
  9. <block slot="content">修改产品供需</block>
  10. </cu-custom>
  11. <cu-custom bgColor="bg-blue" :isBack="true" v-if="title == '查看产品供需'">
  12. <block slot="backText">返回</block>
  13. <block slot="content">查看产品供需</block>
  14. </cu-custom> -->
  15. <view :class="['custom-header', { 'is-back': isBack }, bgColor]">
  16. <view class="back-container" @click="handleBack">
  17. <view class="back-text">返回</view>
  18. </view>
  19. <view class="content-container">
  20. <view class="content-text">{{title}}</view>
  21. </view>
  22. </view>
  23. <form @submit="formSubmit" class="cu-list menu">
  24. <view class="input1">
  25. <view class="title">
  26. 供需类别
  27. </view>
  28. <picker class="title2" @change="bindPickerChange" :value="index" :range="parkList">
  29. <view class="input2">{{parkList[index]}}</view>
  30. </picker>
  31. </view>
  32. <view class="cu-form-group margin-top">
  33. <view class="title">
  34. {{t1}}
  35. </view>
  36. <input v-model="inputForm.des2" :placeholder="t1s" :disabled="ischeck"></input>
  37. </view>
  38. <view class="cu-form-group margin-top">
  39. <view class="title">
  40. {{t2}}
  41. </view>
  42. <input v-model="inputForm.des3" :placeholder="t2s" :disabled="ischeck"></input>
  43. </view>
  44. <view class="cu-form-group margin-top">
  45. <view class="title">
  46. {{t3}}
  47. </view>
  48. <textarea v-model="inputForm.des4" :placeholder="t3s" :disabled="ischeck"></textarea>
  49. </view>
  50. <view class="cu-form-group margin-top">
  51. <uni-file-picker style="margin-bottom: 10px;" limit="3" ref="picFile" v-model="picLists"
  52. fileMediatype="image" mode="grid" title="图片上传" :auto-upload="autoUpload" @select="select"
  53. @progress="progress" @success="success" @fail="fail" @delete="deleteFile"
  54. :imageStyles="imageStyles" :disabled="ischeck">
  55. </uni-file-picker>
  56. </view>
  57. <view style="height: 40rpx;"></view>
  58. <view class="padding-xl" v-if="!ischeck">
  59. <button form-type="submit" class="cu-btn block bg-blue margin-tb-sm lg">提交</button>
  60. </view>
  61. </form>
  62. </view>
  63. </template>
  64. <script>
  65. var graceChecker = require("@/common/graceChecker.js");
  66. import revenueListService from '@/api/revenue/revenueListService'
  67. import loginService from '@/api/auth/loginService.js'
  68. export default {
  69. onShow() {
  70. this.$auth.checkLogin()
  71. },
  72. data() {
  73. return {
  74. title: '发布产品供需',
  75. bgColor: 'bg-blue', // 背景颜色
  76. inputForm: {
  77. qyId:'0',
  78. id: '',
  79. des1: '1',
  80. des2: '',
  81. des3: '',
  82. des4: '',
  83. des6: '',
  84. },
  85. t1: '可供产品',
  86. t1s: '请填写可供产品',
  87. t2: '可供数量',
  88. t2s: '请填写可供数量',
  89. t3: '详细描述',
  90. t3s: '请填写详细描述',
  91. autoUpload: false,
  92. picLists: [],
  93. picUrl: [],
  94. imageStyles: {
  95. width: 90,
  96. height: 90
  97. },
  98. parkList: [ "供", "需"],
  99. index:0,
  100. ischeck: false,
  101. }
  102. },
  103. created() {
  104. //this.getParkList()
  105. },
  106. mounted() {
  107. },
  108. async onLoad(query) {
  109. if (query && query.ischeck) {
  110. this.ischeck = true
  111. this.title = "查看楼宇信息";
  112. }
  113. if (query && query.id && !query.ischeck) {
  114. this.title = "修改楼宇信息";
  115. }
  116. if (query && query.id) {
  117. let {
  118. data
  119. } = await loginService.queryByIdBuild(query.id)
  120. console.log(data)
  121. if (data.pic != null) {
  122. data.pic = data.pic.split(",")
  123. var list = data.pic
  124. list.forEach(item => {
  125. this.picUrl.push({
  126. 'url': item,
  127. 'uuid': item
  128. })
  129. this.picLists.push({
  130. 'url': item,
  131. 'uuid': item
  132. })
  133. })
  134. } else {
  135. data.pic = []
  136. }
  137. this.inputForm = this.recover(this.inputForm, data)
  138. }
  139. },
  140. methods: {
  141. getParkList() {
  142. loginService.parkList({
  143. current: 1,
  144. size: 1000000,
  145. }).then(({
  146. data
  147. }) => {
  148. this.parkList = data.records.map((item) => {
  149. return {
  150. label: item.parkName,
  151. value: item.id
  152. }
  153. })
  154. console.log(this.parkList, '=============>')
  155. }).catch(e => {
  156. console.log(e)
  157. })
  158. },
  159. bindPickerChange: function(e) {
  160. if(e.detail.value==0){
  161. this.t1='可供产品';
  162. this.t1s= '请填写可供产品';
  163. this.t2= '可供数量';
  164. this.t2s= '请填写可供数量';
  165. }else{
  166. this.t1='需求名称';
  167. this.t1s= '请填写需求名称';
  168. this.t2= '需求数量';
  169. this.t2s= '请填写需求数量';
  170. }
  171. console.log('picker发送选择改变,携带值为', e.detail.value)
  172. this.index = e.detail.value;
  173. this.inputForm.des1=e.detail.value+1;
  174. },
  175. // 获取上传进度
  176. progress(e) {
  177. console.log('上传进度:', e)
  178. },
  179. // 上传成功
  180. success(e) {
  181. console.log('上传成功')
  182. },
  183. // 上传失败
  184. fail(e) {
  185. console.log('上传失败:', e)
  186. },
  187. deleteFile(e) {
  188. this.picUrl.splice(e.index, 1)
  189. },
  190. // 获取上传状态
  191. select(e) {
  192. console.log('选择文件:', e)
  193. var _this = this
  194. var i = 0
  195. upload()
  196. function upload() {
  197. if (i >= e.tempFiles.length) {
  198. return;
  199. }
  200. var item = e.tempFiles[i]
  201. uni.showLoading({
  202. title: "上传中",
  203. mask: true
  204. });
  205. uni.uploadFile({
  206. url: '/yd_qycpfb/file/upload?uploadPath=userdir', // 仅为示例,非真实的接口地址
  207. filePath: item.url,
  208. name: 'file',
  209. formData: {
  210. 'fileName': item.name
  211. },
  212. header: {
  213. 'token': _this.$auth.getUserToken()
  214. },
  215. success: (res) => {
  216. var data = res.data
  217. if (typeof data['error'] != "undefined") {
  218. uni.showToast({
  219. icon: 'none',
  220. title: '上传失败,请联系开发!'
  221. });
  222. _this.$refs.picFile.clearFiles(_this.picLists.length)
  223. } else {
  224. _this.picUrl.push({
  225. url: data,
  226. uuid: item.uuid
  227. })
  228. i++;
  229. upload()
  230. }
  231. },
  232. fail: () => {
  233. uni.hideLoading();
  234. uni.showToast({
  235. icon: 'none',
  236. title: '上传失败,请联系开发!'
  237. });
  238. _this.$refs.picFile.clearFiles(_this.picLists.length)
  239. },
  240. complete: function() {
  241. uni.hideLoading();
  242. }
  243. });
  244. }
  245. },
  246. formSubmit: function(e) {
  247. //定义表单规则
  248. var rule = [{
  249. name: "des2",
  250. checkType: "notnull",
  251. checkRule: "",
  252. errorMsg: "名称不能为空"
  253. },
  254. ];
  255. //进行表单检查
  256. var formData = this.inputForm;
  257. var checkRes = graceChecker.check(formData, rule);
  258. console.log(checkRes, '===================>checkRes')
  259. if (checkRes) {
  260. uni.showLoading()
  261. this.inputForm.des6 = [];
  262. this.picUrl.forEach(item => {
  263. this.inputForm.des6.push(item.url)
  264. })
  265. this.inputForm.des6 = this.inputForm.des6.toString();
  266. loginService.productSave(this.inputForm).then(({
  267. data
  268. }) => {
  269. uni.showToast({
  270. title: "产品供需发布成功!",
  271. icon: "success"
  272. });
  273. uni.navigateTo({
  274. url: '/pages/product/productList?w=1'
  275. })
  276. }).catch((e) => {
  277. })
  278. } else {
  279. uni.showToast({
  280. title: graceChecker.error,
  281. icon: "none"
  282. });
  283. }
  284. }
  285. }
  286. }
  287. </script>
  288. <style>
  289. /* .file-title) {
  290. font-size: 17px !important;
  291. } */
  292. input,textarea{
  293. color: #8799a3;
  294. }
  295. .input1{
  296. background-color: #ffffff;
  297. padding: 1upx 40upx;
  298. display: flex;
  299. align-items: center;
  300. padding-top: 20upx;
  301. border-bottom: 1px solid #eee;
  302. }
  303. .input1 .title {
  304. text-align: justify;
  305. padding-right: 30upx;
  306. font-size: 30upx;
  307. position: relative;
  308. height: 60upx;
  309. line-height: 60upx;
  310. border: ;
  311. }
  312. .title2{
  313. width: 75%;
  314. text-align: left;
  315. }
  316. .input2 {
  317. flex: 1;
  318. font-size: 30upx;
  319. color: #555;
  320. padding-right: 20upx;
  321. }
  322. .uni-input{
  323. }
  324. .custom-header {
  325. display: flex;
  326. align-items: center;
  327. justify-content: center;
  328. padding: 10px;
  329. width: 100%;
  330. }
  331. .is-back {
  332. position: relative;
  333. }
  334. .back-container {
  335. position: absolute;
  336. left: 10px;
  337. cursor: pointer;
  338. }
  339. .back-text {
  340. color: white; /* 返回按钮文本颜色 */
  341. }
  342. .content-container {
  343. flex: 1;
  344. text-align: center;
  345. }
  346. .content-text {
  347. color: white; /* 标题文本颜色 */
  348. font-weight: bold;
  349. }
  350. /* 背景颜色 */
  351. .bg-blue {
  352. background-color: #4285f4; /* 假设这是一个蓝色背景 */
  353. }
  354. </style>