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