productAdd.vue 7.7 KB

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