add.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <zz-form :cols="formCols" :data="formData" :rules="formRules" labelWidth="120" ref="form">
  3. <template slot="communityId">
  4. <el-select class="width65" v-model="formData.communityId" clearable @change="handleChange">
  5. <el-option
  6. :label="item.communityName"
  7. :value="item.id"
  8. v-for="item in $store.getters['getAreaSelect']"
  9. :key="item.id"
  10. ></el-option>
  11. </el-select>
  12. </template>
  13. <template slot="cameraSettings">
  14. <el-select class="width65" v-model="formData.cameraSettings" clearable>
  15. <el-option label="是" :value="1"></el-option>
  16. <el-option label="否" :value="0"></el-option>
  17. </el-select>
  18. </template>
  19. <template slot="typeValue">
  20. <el-cascader
  21. :key="typeValueKey"
  22. ref="typeValue"
  23. v-model="typeValueW"
  24. :props="defaultProps"
  25. :options="deviceArr"
  26. @change="deviceArrToggle"
  27. ></el-cascader>
  28. <!-- <div style="text-align: center; margin-top: 20px">
  29. <el-transfer
  30. style="text-align: left; display: inline-block"
  31. v-model="formData.deviceIds"
  32. filterable
  33. :props="{
  34. key: 'id',
  35. label: 'deviceName'
  36. }"
  37. :titles="['待选列表', '已选列表']"
  38. :data="devicesArr"
  39. ></el-transfer>
  40. </div> -->
  41. </template>
  42. <template slot="deviceIds">
  43. <div style="text-align: center">
  44. <el-transfer
  45. style="text-align: left; display: inline-block"
  46. v-model="formData.deviceIds"
  47. filterable
  48. :props="{
  49. key: 'id',
  50. label: 'deviceName'
  51. }"
  52. :titles="['待选列表', '已选列表']"
  53. :data="devicesArr"
  54. ></el-transfer>
  55. </div>
  56. </template>
  57. <el-date-picker
  58. class="width100"
  59. slot="startDate"
  60. v-model="effectiveDate"
  61. value-format="yyyy-MM-dd "
  62. type="daterange"
  63. range-separator="至"
  64. start-placeholder="选择开始日期"
  65. end-placeholder="选择结束日期"
  66. @change="effectiveDateToggle"
  67. :editable="false"
  68. ></el-date-picker>
  69. <el-cascader
  70. ref="userName"
  71. v-model="formData.peopleId"
  72. :props="defaultProps1"
  73. slot="peopleId"
  74. :options="findUser"
  75. @change="findUserToggle"
  76. ></el-cascader>
  77. </zz-form>
  78. </template>
  79. <script >
  80. export default {
  81. props: ['params'],
  82. data() {
  83. return {
  84. formData: {
  85. communityId: '',
  86. inspectionName: '',
  87. cameraSettings: '',
  88. peopleId: '',
  89. peopleName: '',
  90. startDate: '',
  91. endDate: '',
  92. deviceIds: [],
  93. type: '',
  94. typeValue: '',
  95. remark: ''
  96. },
  97. formRules: {
  98. communityId: [this.$valid.selectRequired('社区')],
  99. peopleId: [this.$valid.selectRequired('巡检人员')],
  100. startDate: [this.$valid.selectRequired('巡检时间')],
  101. inspectionName: [this.$valid.inputRequired('巡检计划名称')],
  102. address: this.$valid.custome({
  103. validator(rule, value, cb) {
  104. const rl = rule;
  105. let regExp = /^.{1,20}$/;
  106. if (!value) {
  107. rl.message = '请输入地址';
  108. cb(new Error());
  109. } else if (!regExp.test(value)) {
  110. rl.message = '不能超过20个字';
  111. cb(new Error());
  112. } else {
  113. cb();
  114. }
  115. }
  116. }),
  117. repairName: this.$valid.custome({
  118. validator(rule, value, cb) {
  119. const rl = rule;
  120. let regExp = /^.{1,20}$/;
  121. if (!value) {
  122. rl.message = '请输入报修人';
  123. cb(new Error());
  124. } else if (!regExp.test(value)) {
  125. rl.message = '不能超过20个字';
  126. cb(new Error());
  127. } else {
  128. cb();
  129. }
  130. }
  131. }),
  132. typeValue: [this.$valid.selectRequired('设备/设施类型')],
  133. deviceIds: this.$valid.custome({
  134. validator(rule, value, cb) {
  135. const rl = rule;
  136. if (!value.length) {
  137. rl.message = '已选列表不能为空';
  138. cb(new Error());
  139. } else {
  140. cb();
  141. }
  142. }
  143. })
  144. },
  145. formCols: [
  146. [
  147. {
  148. label: '所属社区',
  149. prop: 'communityId',
  150. slot: 'communityId'
  151. },
  152. {
  153. label: '巡检计划名称',
  154. prop: 'inspectionName',
  155. input: true
  156. },
  157. {
  158. label: '设备/设施类型',
  159. prop: 'typeValue',
  160. slot: 'typeValue'
  161. },
  162. {
  163. label: '',
  164. prop: 'deviceIds',
  165. slot: 'deviceIds'
  166. },
  167. {
  168. label: '巡检时间',
  169. prop: 'startDate',
  170. slot: 'startDate'
  171. },
  172. {
  173. label: '巡检人员',
  174. prop: 'peopleId',
  175. slot: 'peopleId'
  176. },
  177. {
  178. label: '拍照要求',
  179. prop: 'cameraSettings',
  180. slot: 'cameraSettings'
  181. },
  182. {
  183. label: ' 备注信息',
  184. prop: 'remark',
  185. maxlength: '100',
  186. rows: 3,
  187. textarea: true
  188. }
  189. ]
  190. ],
  191. findUser: [],
  192. deviceArr: [],
  193. devicesArr: [],
  194. defaultProps: {
  195. value: 'id', // 唯一标识
  196. label: 'label', // 标签显示
  197. children: 'children'
  198. },
  199. defaultProps1: {
  200. value: 'id', // 唯一标识
  201. label: 'label', // 标签显示
  202. children: 'children',
  203. emitPath: false
  204. },
  205. typeValueKey: 0,
  206. typeValueW: [],
  207. effectiveDate: []
  208. };
  209. },
  210. methods: {
  211. submit() {
  212. new Promise((resolve) => {
  213. this.$refs.form.validate(resolve);
  214. }).then(() => {
  215. var loading = this.$loading();
  216. let url = '/sc-community/inspection/add';
  217. let initData = JSON.parse(JSON.stringify(this.formData));
  218. if (this.params.todo === 'edit') {
  219. url = '/sc-community/inspection/update';
  220. }
  221. this.$http
  222. .post(url, initData)
  223. .then(({ status, msg }) => {
  224. if (status == 0) {
  225. this.$message.success(msg);
  226. this.params.callback();
  227. this.$emit('close');
  228. } else {
  229. this.$message.error(msg);
  230. }
  231. loading.close();
  232. })
  233. .catch(() => {
  234. loading.close();
  235. });
  236. });
  237. },
  238. findUserToggle() {
  239. this.formData.peopleName = this.$refs.userName.getCheckedNodes()[0].label;
  240. },
  241. deviceArrToggle() {
  242. this.formData.typeValue = this.typeValueW[this.typeValueW.length - 1];
  243. if (!!this.formData.typeValue) {
  244. this.formData.type = this.$refs.typeValue.getCheckedNodes()[0].data.type;
  245. }
  246. this.getTypes();
  247. },
  248. getTypes() {
  249. this.$http
  250. .get('/sc-community/inspection/getDevices', {
  251. type: this.formData.type,
  252. typeId: this.formData.typeValue,
  253. communityId: this.formData.communityId
  254. })
  255. .then(({ data, msg }) => {
  256. this.devicesArr = data || [];
  257. });
  258. },
  259. handleChange(e) {
  260. if (!!this.formData.typeValue) {
  261. this.formData.typeValue = '';
  262. this.formData.type = '';
  263. this.typeValueKey++;
  264. this.getTypes();
  265. }
  266. },
  267. effectiveDateToggle(va) {
  268. let arr = va;
  269. if (!arr) {
  270. arr = ['', ''];
  271. }
  272. this.formData.startDate = arr[0] + '00:00:00';
  273. this.formData.endDate = arr[1] + '23:59:59';
  274. },
  275. getDetails(id, resolve) {
  276. this.$http.get('/sc-community/inspection/find/' + id).then(({ data, msg }) => {
  277. const {
  278. communityId,
  279. inspectionName,
  280. cameraSettings,
  281. peopleId,
  282. peopleName,
  283. startDate,
  284. endDate,
  285. remark,
  286. type,
  287. typeValue,
  288. id
  289. } = data;
  290. this.formData = {
  291. communityId: communityId,
  292. inspectionName: inspectionName,
  293. cameraSettings: cameraSettings,
  294. peopleId: peopleId,
  295. peopleName: peopleName,
  296. startDate: startDate,
  297. endDate: endDate,
  298. deviceIds: [],
  299. type: type,
  300. typeValue: typeValue,
  301. remark: remark,
  302. id: id
  303. };
  304. this.typeValueW = typeValue;
  305. this.effectiveDate = [data.startDate, data.endDate];
  306. resolve && resolve(true);
  307. });
  308. },
  309. getSelectDevice(id) {
  310. this.$http.get('/sc-community/inspection/getInspectionDevices?id=' + id).then(({ data, msg }) => {
  311. if (!!data && data.length > 0) {
  312. let deviceIds = [];
  313. data.map((item) => {
  314. deviceIds.push(item.deviceId);
  315. });
  316. this.formData.deviceIds = deviceIds;
  317. }
  318. });
  319. }
  320. },
  321. created() {
  322. this.deviceArr = this.params.deviceArr;
  323. this.findUser = this.params.arrData;
  324. if (!!this.params.data && !!this.params.data.id) {
  325. new Promise((resolve) => {
  326. this.getDetails(this.params.data.id, resolve);
  327. }).then((_) => {
  328. this.getTypes();
  329. this.getSelectDevice(this.params.data.id);
  330. });
  331. }
  332. }
  333. };
  334. </script>
  335. <style scoped lang='scss' scoped>
  336. /deep/ .el-date-editor .el-range-separator {
  337. padding: 0;
  338. }
  339. </style>