Onlinewarranty.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <template>
  2. <view class="contain">
  3. <view class="main">
  4. <!-- 注意,如果需要兼容微信小程序,最好通过setRules方法设置rules规则 -->
  5. <u--form labelPosition="left" :model="model1" :rules="rules" ref="form1">
  6. <!-- <u-form-item labelWidth='180' label="任务名称:" prop="userInfo.contactPerson" borderBottom ref="item1">
  7. <u--input v-model="model1.userInfo.contactPerson" border="none"></u--input>
  8. </u-form-item> -->
  9. <u-form-item labelWidth='180' label="报修区域:" prop="userInfo.repairRegionName" borderBottom
  10. @click="showSex = true;" ref="item1" :required=true>
  11. <u--input v-model="model1.userInfo.repairRegionName" disabled disabledColor="#ffffff"
  12. placeholder="请选择报修区域" border="none"></u--input>
  13. <u-icon name="arrow-right" class="ml5"></u-icon>
  14. </u-form-item>
  15. <u-form-item labelWidth='180' label="报修位置:" prop="userInfo.repairPositionName" borderBottom
  16. @click="showfloors();" ref="item1" :required=true>
  17. <u--input v-model="model1.userInfo.repairPositionName" disabled disabledColor="#ffffff"
  18. placeholder="请选择报修位置" border="none"></u--input>
  19. <u-icon name="arrow-right" class="ml5"></u-icon>
  20. </u-form-item>
  21. {{model1.userInfo.repairType}}
  22. <u-form-item labelWidth='180' label="报修类型:" prop="userInfo.repairTypeName" borderBottom
  23. @click="showtaskdegree = true;" ref="item1" :required=true>
  24. <u--input v-model="model1.userInfo.repairTypeName" disabled disabledColor="#ffffff"
  25. placeholder="请选择报修类型" border="none"></u--input>
  26. <u-icon name="arrow-right" class="ml5"></u-icon>
  27. </u-form-item>
  28. <u-form-item labelWidth='180' label="联系人:" prop="userInfo.contactPerson" borderBottom ref="item1"
  29. :required=true>
  30. <u--input v-model="model1.userInfo.contactPerson" border="none" placeholder="请输入"></u--input>
  31. </u-form-item>
  32. <u-form-item labelWidth='180' label="联系电话:" prop="userInfo.contactPhone" borderBottom ref="item1"
  33. :required=true>
  34. <u--input v-model="model1.userInfo.contactPhone" border="none" placeholder="请输入"></u--input>
  35. </u-form-item>
  36. <u-form-item labelWidth='180' class="ms" label="故障描述:" prop="userInfo.faultDes" ref="item1"
  37. :required=true>
  38. </u-form-item>
  39. <u-form-item labelWidth='180' borderBottom style="padding: 0;">
  40. <u-textarea v-model="model1.userInfo.faultDes" border="none" placeholder="请输入" height="140"
  41. style="padding: 0 20rpx;"></u-textarea>
  42. </u-form-item>
  43. <u-form-item class="ms" labelWidth='180' label="上传照片:" prop="userInfo.faultPics" ref="item1"
  44. :required=true>
  45. </u-form-item>
  46. <u-form-item labelWidth='180' borderBottom>
  47. <view class="uploadPart">
  48. <view class="allimg" v-for="img in fileList1">
  49. <image :src="img" mode="aspectFill" class="newimg"></image>
  50. <u-icon @click="deletePic(img)" class="mytrash" name="close-circle" color="#999"
  51. size="30"></u-icon>
  52. </view>
  53. <span @click="uploadImg" class="uploadBtn" v-if="fileList1.length<3"><u-icon color="#5c8fff"
  54. size="30px" name="camera-fill"></u-icon></span>
  55. </view>
  56. </u-form-item>
  57. </u--form>
  58. </view>
  59. <view class="tijiao">
  60. <u-button type="primary" text="提交" @click="editdata"></u-button>
  61. </view>
  62. <u-picker @cancel='showtaskdegree = false' :itemHeight="80" @confirm='degreeconfirm' :show="showtaskdegree"
  63. :columns="columnshowtaskdegree" keyName="label">
  64. </u-picker>
  65. <u-picker @cancel='showSex = false' :itemHeight="80" @confirm='typeconfirm' :show="showSex"
  66. :columns="columnsquyu" keyName="label">
  67. </u-picker>
  68. <u-picker :show="showfloor" ref="uPicker" :itemHeight="80" :loading="loading" @confirm="confirmfloor"
  69. @cancel='cancelfloor' keyName="orgName" :columns="columns" @change="changeHandler"></u-picker>
  70. <u-picker :show="showfloor2" ref="uPicker" :itemHeight="80" :loading="loading" @confirm="confirmfloor"
  71. @cancel='cancelfloor' keyName="orgName" :columns="columns2" @change="changeHandler"></u-picker>
  72. </view>
  73. </template>
  74. <script>
  75. const BaseApi = require("@/http/baseApi.js");
  76. export default {
  77. components: {},
  78. data() {
  79. return {
  80. uploadUrl: BaseApi.BaseApi + '/uploadFile',
  81. loading: false,
  82. fileList1: [],
  83. xiangji: require('@/static/index/xj.png'),
  84. columns: [
  85. [],
  86. [],
  87. []
  88. ],
  89. columns2: [
  90. [],
  91. []
  92. ],
  93. columnData: [],
  94. columnDatalist: [],
  95. showfloor: false,
  96. showfloor2: false,
  97. myposition: '',
  98. showSex: false,
  99. showday: false,
  100. showPicker: false,
  101. showtaskdegree: false,
  102. showtaskpeople: false,
  103. model1: {
  104. userInfo: {
  105. id: "",
  106. buildingId: "", // 楼栋ID
  107. storeyId: "", // 层数ID
  108. houseId: "", // 房间ID
  109. repairPositionName: "", //报修位置名称
  110. repairRegion: '', //报修修区域
  111. repairRegionName: "", //报修区域名称
  112. repairType: '', //报修类型
  113. repairTypeName: "", //报修类型
  114. contactPerson: "", //联系人
  115. contactPhone: "", //电话
  116. faultDes: "", // 故障描述
  117. faultPics: "", //图片
  118. },
  119. },
  120. columnsquyu: [
  121. [{
  122. label: '公共区域',
  123. id: 1
  124. }, {
  125. label: '室内',
  126. id: 2
  127. }]
  128. ],
  129. columnshowtaskdegree: [
  130. [{
  131. label: '水',
  132. id: 1
  133. }, {
  134. label: '电',
  135. id: 2
  136. },
  137. {
  138. label: '其他',
  139. id: 3
  140. },
  141. ]
  142. ],
  143. rules: {
  144. 'userInfo.contactPerson': {
  145. type: 'string',
  146. required: true,
  147. message: '请填写联系人',
  148. trigger: ['blur', 'change']
  149. },
  150. 'userInfo.faultDes': {
  151. type: 'string',
  152. required: true,
  153. message: '请填写故障描述',
  154. trigger: ['blur', 'change']
  155. },
  156. "userInfo.faultPics": {
  157. type: 'string',
  158. required: true,
  159. message: '请上传照片',
  160. trigger: ['blur', 'change']
  161. },
  162. 'userInfo.contactPhone': [{
  163. required: true,
  164. message: '请填写联系电话',
  165. trigger: ['change', 'blur'],
  166. },
  167. {
  168. // 自定义验证函数,见上说明
  169. validator: (rule, value, callback) => {
  170. // 上面有说,返回true表示校验通过,返回false表示不通过
  171. // uni.$u.test.mobile()就是返回true或者false的
  172. return uni.$u.test.mobile(value);
  173. },
  174. message: '手机号码不正确',
  175. // 触发器可以同时用blur和change
  176. trigger: ['change', 'blur'],
  177. }
  178. ],
  179. 'userInfo.repairRegionName': {
  180. type: 'string',
  181. required: true,
  182. message: '请选择报修区域',
  183. trigger: ['blur', 'change']
  184. },
  185. 'userInfo.repairRegionName': {
  186. type: 'string',
  187. required: true,
  188. message: '请选择报修区域',
  189. trigger: ['blur', 'change']
  190. },
  191. 'userInfo.repairPositionName': {
  192. type: 'string',
  193. required: true,
  194. message: '请选择报修位置',
  195. trigger: ['blur', 'change']
  196. },
  197. 'userInfo.repairTypeName': {
  198. type: 'string',
  199. required: true,
  200. message: '请选择报修类型',
  201. trigger: ['blur', 'change']
  202. },
  203. },
  204. };
  205. },
  206. watch:{
  207. "model1.userInfo.repairRegionName"(newval,oldval){
  208. if(newval!=oldval){
  209. this.model1.userInfo.repairPositionName = '';
  210. this.model1.userInfo.buildingId = '';
  211. this.model1.userInfo.storeyId = '';
  212. this.model1.userInfo.houseId = '';
  213. }
  214. }
  215. },
  216. onLoad() {
  217. this.getfloor();
  218. // this.loadmore();
  219. },
  220. methods: {
  221. //显示区域选择
  222. showfloors() {
  223. if (this.model1.userInfo.repairRegionName == '公共区域') {
  224. this.showfloor2 = true;
  225. } else {
  226. this.showfloor = true;
  227. }
  228. },
  229. // 删除图片
  230. deletePic(event) {
  231. this.fileList1.splice(event.index, 1)
  232. },
  233. // 新增图片
  234. uploadImg() {
  235. uni.chooseImage({
  236. count: 3,
  237. success: (chooseImageRes) => {
  238. const tempFilePaths = chooseImageRes.tempFilePaths;
  239. for (let i = 0; i < tempFilePaths.length; i++) {
  240. uni.uploadFile({
  241. url: BaseApi.BaseApi + '/uploadFile',
  242. filePath: tempFilePaths[i],
  243. name: 'file',
  244. formData: {
  245. 'user': 'test'
  246. },
  247. success: (uploadFileRes) => {
  248. //console.log(uploadFileRes);
  249. this.fileList1.push(JSON.parse(uploadFileRes.data).data)
  250. console.log(this.fileList1);
  251. this.model1.userInfo.faultPics = this.fileList1.join(',')
  252. }
  253. });
  254. }
  255. }
  256. });
  257. },
  258. changeHandler(e) {
  259. console.log(e)
  260. const {
  261. columnIndex,
  262. value,
  263. values, // values为当前变化列的数组内容
  264. index,
  265. indexs,
  266. picker = this.$refs.uPicker
  267. } = e
  268. if (columnIndex == 0) {
  269. picker.setColumnValues(1, this.alldata[index].childrenList)
  270. if (this.model1.userInfo.repairRegionName == '室内') {
  271. if (this.alldata[indexs[0]].childrenList[0].childrenList == null) {
  272. picker.setColumnValues(2, [])
  273. } else {
  274. picker.setColumnValues(2, this.alldata[indexs[0]].childrenList[0].childrenList)
  275. }
  276. }
  277. } else if (this.model1.userInfo.repairRegionName == '室内' && columnIndex == 1) {
  278. // picker为选择器this实例,变化第三列对应的选项
  279. if (this.alldata[indexs[0]].childrenList[indexs[1]].childrenList == null) {
  280. picker.setColumnValues(2, [])
  281. } else {
  282. picker.setColumnValues(2, this.alldata[indexs[0]].childrenList[indexs[1]].childrenList)
  283. }
  284. }
  285. },
  286. confirmfloor(e) {
  287. if(this.model1.userInfo.repairRegionName == '室内'){
  288. if (e.value[2] == undefined) {
  289. this.model1.userInfo.repairPositionName = e.value[0].orgName + '/' + e.value[1].orgName;
  290. this.model1.userInfo.buildingId = e.value[0].orgId;
  291. this.model1.userInfo.storeyId = e.value[1].orgId;
  292. this.model1.userInfo.houseId = '';
  293. } else {
  294. this.model1.userInfo.repairPositionName = e.value[0].orgName + '/' + e.value[1].orgName + '/' + e
  295. .value[2].orgName;
  296. this.model1.userInfo.buildingId = e.value[0].orgId;
  297. this.model1.userInfo.storeyId = e.value[1].orgId;
  298. this.model1.userInfo.houseId = e.value[2].orgId;
  299. }
  300. this.showfloor = false;
  301. }else{
  302. this.model1.userInfo.repairPositionName = e.value[0].orgName + '/' + e.value[1].orgName;
  303. this.model1.userInfo.buildingId = e.value[0].orgId;
  304. this.model1.userInfo.storeyId = e.value[1].orgId;
  305. this.model1.userInfo.houseId = '';
  306. this.showfloor2 = false;
  307. }
  308. },
  309. cancelfloor() {
  310. if(this.model1.userInfo.repairRegionName == '室内'){
  311. this.showfloor = false;
  312. }else{
  313. this.showfloor2 = false;
  314. }
  315. },
  316. getfloor() {
  317. this.$api.get('/control/getOrgStructureTree', {})
  318. .then(res => {
  319. if (res.data.code == 0) {
  320. this.alldata = res.data.data[0].childrenList;
  321. this.columns = [
  322. this.alldata,
  323. this.alldata[0].childrenList,
  324. []
  325. ]
  326. this.columns2 = [
  327. this.alldata,
  328. this.alldata[0].childrenList,
  329. ]
  330. } else {
  331. this.showdct = true
  332. }
  333. })
  334. },
  335. onShowDatePicker() { //显示
  336. this.showPicker = true;
  337. },
  338. returndata() {
  339. uni.navigateBack({
  340. delta: 1
  341. });
  342. },
  343. editdata() {
  344. this.$refs.form1.validate().then(res => {
  345. this.$api.post('/repairorder', this.model1.userInfo)
  346. .then(res => {
  347. uni.navigateBack({
  348. delta: 1
  349. });
  350. })
  351. }).catch(errors => {
  352. // uni.$u.toast('校验失败')
  353. })
  354. },
  355. typeconfirm(e) {
  356. this.model1.userInfo.repairRegion = e.value[0].id;
  357. this.model1.userInfo.repairRegionName = e.value[0].label;
  358. this.showSex = false;
  359. this.$refs.form1.validateField('userInfo.repairRegionName')
  360. },
  361. degreeconfirm(e) {
  362. this.model1.userInfo.repairType = e.value[0].id;
  363. this.model1.userInfo.repairTypeName = e.value[0].label;
  364. this.showtaskdegree = false;
  365. this.$refs.form1.validateField('userInfo.repairTypeName')
  366. },
  367. },
  368. onReady() {
  369. //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
  370. this.$refs.form1.setRules(this.rules)
  371. },
  372. };
  373. </script>
  374. <style lang="scss" scoped>
  375. .uploadPart {
  376. display: flex;
  377. justify-content: center;
  378. width: 100%;
  379. .uploadBtn {
  380. width: 160rpx;
  381. height: 160rpx;
  382. background-color: #ECF0FF;
  383. text-align: center;
  384. border-radius: 4rpx;
  385. display: flex;
  386. align-items: center;
  387. justify-content: center;
  388. }
  389. .allimg {
  390. position: relative;
  391. }
  392. .newimg {
  393. width: 160rpx;
  394. height: 160rpx;
  395. margin-right: 10rpx;
  396. }
  397. .mytrash {
  398. position: absolute;
  399. top: 2px;
  400. right: 10px;
  401. }
  402. }
  403. </style>