selectVisitPerson.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <template>
  2. <view class="container">
  3. <uni-popup ref="popup" type="bottom" :maskClick="true">
  4. <view class="content">
  5. <form @submit="formSubmit" @reset="formReset">
  6. <text class="contentTitle">新增访查对象</text>
  7. <!-- <input class="input" type="text" focus="true" v-model="visiterInfo" placeholder-class="placeholder" placeholder="请填写访查对象信息" /> -->
  8. <scroll-view scroll-y="true" class="scroll-Y">
  9. <view v-for="(item,index) in templateData" class="formItem">
  10. <text :class="[item.required?'label requred':'label']">{{item.title}}:</text>
  11. <input class="value" :name="`${index}`" type="text" placeholder-class="placeholder"
  12. :value="formDefaultData&&formDefaultData[index].value" placeholder="请输入相应内容" />
  13. </view>
  14. </scroll-view>
  15. <view class="bottomBtnGroup">
  16. <button class="cancel" @click="cancelAdd">取消</button>
  17. <button class="comfirm" formType='submit'>确定</button>
  18. </view>
  19. </form>
  20. </view>
  21. </uni-popup>
  22. <view class="pageTitle">
  23. <text class="pageTitleLeft">访查对象</text>
  24. <text class="pageTitleRight" @click="manageHandle">{{edit?'完成':'管理'}}</text>
  25. </view>
  26. <view class="listWrap">
  27. <view class="list" v-for="(item,index) in investigationUsers" :key="index"
  28. @click="selectPersonHandle({...item,index})">
  29. <view class="infoWrap">
  30. <text v-if="t.showFiled" v-for="(t,i) in item.contentVOs" class="infoTag">{{t.value}}</text>
  31. </view>
  32. <view v-if="item.investigationStatus==1||item.investigationStatus==2"
  33. :class="[item.investigationStatus==1||item.investigationStatus==2?item.investigationStatus==1?'status done':'status checking':'status']">
  34. {{item.investigationStatus==1?'已完成':'进行中'}}
  35. </view>
  36. <text v-if="!edit&&current.investigationId ==item.investigationId "
  37. class="checked">当前选中</text>
  38. <text v-if="edit" class="editBtn" @click="editInvestigationUser(item,index)">编辑</text>
  39. <text v-if="edit" class="delBtn" @click="delInvestigationUser(item,index)">删除</text>
  40. </view>
  41. </view>
  42. <view class="bottom" @click="addVisiter">
  43. + 新增访查对象
  44. <!-- <image src="" mode=""></image> -->
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import {
  50. mapState
  51. } from 'vuex';
  52. export default {
  53. data() {
  54. return {
  55. // status:1,
  56. edit: false, //是否编辑状态
  57. visiterInfo: '',
  58. current: null, //当前选中对象
  59. index: null, //当前选中的对象在列表中的下标
  60. formDefaultData:null, //受访者表单默认数据
  61. currentEditInvestigationUsers:null,
  62. };
  63. },
  64. computed: {
  65. ...mapState({
  66. investigationUsers: state => {
  67. return JSON.parse(JSON.stringify(state.checkMainPoints.investigationUsers));
  68. },
  69. currentSelectedInvestigationUser: state => state.checkMainPoints.currentSelectedInvestigationUser,
  70. templateData: state => state.selectVisitPerson.templateData,
  71. }),
  72. },
  73. watch: {
  74. currentSelectedInvestigationUser: function(newVal, oldVal) {
  75. const index = this.investigationUsers.findIndex(item => item.id == newVal.id);
  76. this.current = newVal;
  77. this.index = index;
  78. },
  79. },
  80. onLoad({
  81. checkId,
  82. situationType,
  83. deptId,
  84. pageTemplateId
  85. }) {
  86. // console.log('this.investigationUsers', this.investigationUsers);
  87. this.checkId = Number(checkId);
  88. this.situationType = situationType;
  89. this.deptId = deptId;
  90. this.pageTemplateId = pageTemplateId;
  91. this.current = this.currentSelectedInvestigationUser;
  92. const index = this.investigationUsers.findIndex(item => item.investigationId == this.currentSelectedInvestigationUser.investigationId);
  93. if (index >= 0) {
  94. this.index = index;
  95. } else {
  96. this.index = 0
  97. }
  98. },
  99. onUnload() {
  100. this.$store.commit('checkMainPoints/comChangeState', {
  101. key: 'currentSelectedInvestigationUser',
  102. data: this.current
  103. });
  104. this.$store.commit('checkMainPoints/comChangeState', {
  105. key: 'ifReloadPageData',
  106. data: true
  107. })
  108. },
  109. methods: {
  110. formSubmit: function(e) {
  111. try{
  112. const formdata = e.detail.value;
  113. const contentVOs = Object.keys(formdata).map(t => {
  114. if(this.templateData[Number(t)].required&&formdata[t].length==0){
  115. throw '有必填项未填写!'
  116. }else{
  117. return {
  118. title: this.templateData[Number(t)].title,
  119. value: formdata[t],
  120. filedType: 'Text',
  121. required:this.templateData[Number(t)].required,
  122. showFiled:this.templateData[Number(t)].showFiled
  123. }
  124. }
  125. });
  126. this.commitInvestigationUser(contentVOs);
  127. }catch(err){
  128. console.log({err})
  129. uni.showModal({
  130. title: '提示',
  131. content: '请完整填写表单必填项!',
  132. showCancel:false,
  133. });
  134. }
  135. },
  136. formReset: function(e) {
  137. console.log('清空数据')
  138. },
  139. manageHandle() {
  140. if (!this.edit) {
  141. this.edit = true;
  142. } else {
  143. this.edit = false;
  144. }
  145. },
  146. addVisiter() {
  147. this.$store.dispatch({
  148. type: 'selectVisitPerson/commActions',
  149. key: 'getTemplateData',
  150. data: {
  151. pageTemplateId: this.pageTemplateId
  152. }
  153. }).then(data => {
  154. this.$store.commit('selectVisitPerson/comChangeState', {
  155. key: 'templateData',
  156. data: data
  157. });
  158. })
  159. this.$refs.popup.open();
  160. },
  161. cancelAdd() {
  162. this.$refs.popup.close();
  163. this.visiterInfo = '';
  164. },
  165. //提交受访者信息
  166. commitInvestigationUser(data) {
  167. if(!this.edit){
  168. this.$store.dispatch({
  169. type: 'selectVisitPerson/commActions',
  170. key: 'addInvestigationUser',
  171. data: {
  172. checkId: this.checkId,
  173. contentVOs: data,
  174. deptId: Number(this.deptId)
  175. }
  176. }).then(data => {
  177. if (data) {
  178. uni.showModal({
  179. title: '提示',
  180. content: '添加成功,是否立即返回?',
  181. success: (res) => {
  182. if (res.confirm) {
  183. this.cancelAdd();
  184. uni.navigateBack({
  185. delta: 1
  186. });
  187. this.reloadData(true);
  188. }
  189. if (res.cancel) {
  190. this.cancelAdd();
  191. this.reloadData();
  192. }
  193. }
  194. });
  195. }
  196. })
  197. }else{
  198. this.$store.dispatch({
  199. type: 'selectVisitPerson/commActions',
  200. key: 'editInvestigationUser',
  201. data: {
  202. id: this.currentEditInvestigationUsers.investigationId,
  203. contentVOs: data,
  204. }
  205. }).then(data => {
  206. if (data) {
  207. uni.showModal({
  208. title: '提示',
  209. content: '编辑成功,是否立即返回?',
  210. success: (res) => {
  211. if (res.confirm) {
  212. this.cancelAdd();
  213. uni.navigateBack({
  214. delta: 1
  215. });
  216. this.reloadData(true);
  217. }
  218. if (res.cancel) {
  219. this.cancelAdd();
  220. this.reloadData();
  221. }
  222. }
  223. });
  224. }
  225. })
  226. }
  227. },
  228. //编辑受访者
  229. /**
  230. * @param {Object} item
  231. * @param {Number} index
  232. */
  233. editInvestigationUser(item, index){
  234. this.$store.dispatch({
  235. type: 'selectVisitPerson/commActions',
  236. key: 'getTemplateData',
  237. data: {
  238. pageTemplateId: this.pageTemplateId
  239. }
  240. }).then(data => {
  241. this.$store.commit('selectVisitPerson/comChangeState', {
  242. key: 'templateData',
  243. data: data
  244. });
  245. });
  246. this.currentEditInvestigationUsers = item;
  247. this.formDefaultData = this.investigationUsers[index].contentVOs;
  248. this.$refs.popup.open();
  249. },
  250. //删除受访者
  251. /**
  252. * @param {Object} item
  253. * @param {Number} index
  254. */
  255. delInvestigationUser(item, index) {
  256. const {
  257. investigationId
  258. } = item;
  259. this.$store.dispatch({
  260. type: 'selectVisitPerson/commActions',
  261. key: 'delInvestigationUser',
  262. data: {
  263. checkId: this.checkId,
  264. investigationId: investigationId
  265. }
  266. }).then(data => {
  267. // console.log(index,this.index);
  268. if (index == this.index) {
  269. //当删除的是当前选中的对象
  270. const prevInvestigationUser = this.index > 0 ? this.investigationUsers[this.index - 1] :
  271. null;
  272. this.current = prevInvestigationUser;
  273. }
  274. this.reloadData();
  275. });
  276. },
  277. //操作后重新获取数据
  278. /**
  279. * @param {Boolean} bool 判断是否直接将最新添加设置当前选中
  280. */
  281. reloadData(bool) {
  282. this.$store.dispatch({
  283. type: 'checkMainPoints/commActions',
  284. key: 'getInvestigationUsers',
  285. data: {
  286. checkId: this.checkId,
  287. situationType: this.situationType,
  288. deptId: this.deptId
  289. }
  290. }).then(data => {
  291. this.$store.commit('checkMainPoints/comChangeState', {
  292. key: 'investigationUsers',
  293. data: data
  294. });
  295. if (bool) {
  296. this.$store.commit('checkMainPoints/comChangeState', {
  297. key: 'currentSelectedInvestigationUser',
  298. data: data[data.length - 1]
  299. })
  300. }
  301. //还未设置默认受访对象时
  302. if (!this.currentSelectedInvestigationUser) {
  303. this.$store.commit('checkMainPoints/comChangeState', {
  304. key: 'currentSelectedInvestigationUser',
  305. data: data[0]
  306. })
  307. }
  308. });
  309. },
  310. selectPersonHandle(item) {
  311. this.current = item;
  312. this.index = item.index;
  313. this.$store.commit('checkMainPoints/comChangeState', {
  314. key: 'currentSelectedInvestigationUser',
  315. data: item
  316. })
  317. }
  318. }
  319. }
  320. </script>
  321. <style lang="less" scoped>
  322. .container {
  323. .content {
  324. position: relative;
  325. height: 60vh;
  326. padding: 0 40rpx;
  327. padding-top: 35rpx;
  328. border-radius: 25rpx 25rpx 0px 0px;
  329. background-color: #FFFFFF;
  330. .contentTitle {
  331. font-size: 30rpx;
  332. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  333. font-weight: 400;
  334. color: #292C33;
  335. }
  336. .input {
  337. color: #292C33;
  338. height: 87.5rpx;
  339. margin-top: 35rpx;
  340. border-bottom: 0.62rpx solid #DADEE6;
  341. }
  342. .placeholder {
  343. font-size: 22.5rpx;
  344. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  345. font-weight: 400;
  346. color: #A1A7B3;
  347. }
  348. .scroll-Y {
  349. padding-top: 40rpx;
  350. height: 100%;
  351. .formItem {
  352. display: flex;
  353. height: 75rpx;
  354. flex-direction: row;
  355. justify-content: flex-start;
  356. align-items: center;
  357. margin-bottom: 10rpx;
  358. .label {
  359. position: relative;
  360. display: flex;
  361. width: 25%;
  362. height: 100%;
  363. justify-content: flex-start;
  364. align-items: center;
  365. font-size: 22.5rpx;
  366. color: #000000;
  367. padding-left: 15rpx;
  368. &.requred {
  369. &::before {
  370. position: absolute;
  371. left: 0;
  372. display: inline-block;
  373. content: '*';
  374. font-size: 22rpx;
  375. color: red;
  376. }
  377. }
  378. }
  379. .value {
  380. width: 75%;
  381. height: 100%;
  382. font-size: 22.5rpx;
  383. color: #000000;
  384. border-bottom: 1rpx solid #82848A;
  385. }
  386. .placeholder {
  387. font-size: 22.5rpx;
  388. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  389. font-weight: 400;
  390. color: #A1A7B3;
  391. }
  392. }
  393. }
  394. .bottomBtnGroup {
  395. position: absolute;
  396. bottom: 0;
  397. left: 0;
  398. width: 100%;
  399. display: flex;
  400. flex-direction: row;
  401. .cancel {
  402. flex: 1;
  403. height: 75rpx;
  404. text-align: center;
  405. line-height: 75rpx;
  406. font-size: 22.5rpx;
  407. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  408. font-weight: 400;
  409. color: #3377FF;
  410. border-radius: 0;
  411. border: none;
  412. &::after {
  413. border-radius: 0;
  414. }
  415. // border-top: 0.62rpx solid #DADEE6;
  416. }
  417. .comfirm {
  418. flex: 1;
  419. height: 75rpx;
  420. text-align: center;
  421. line-height: 75rpx;
  422. font-size: 22.5rpx;
  423. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  424. font-weight: 400;
  425. color: #FFFFFF;
  426. border-radius: 0;
  427. background-color: #3377FF;
  428. }
  429. }
  430. }
  431. .pageTitle {
  432. display: flex;
  433. width: 100%;
  434. flex-direction: row;
  435. justify-content: space-between;
  436. box-sizing: border-box;
  437. padding: 0 25rpx;
  438. padding-top: 25rpx;
  439. padding-bottom: 15rpx;
  440. .pageTitleLeft {
  441. font-size: 22.5rpx;
  442. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  443. font-weight: 400;
  444. color: #666F80;
  445. }
  446. .pageTitleRight {
  447. font-size: 20rpx;
  448. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  449. font-weight: 400;
  450. color: #3377FF;
  451. }
  452. }
  453. .listWrap {
  454. padding-left: 25rpx;
  455. margin-bottom: 15rpx;
  456. background-color: #FFFFFF;
  457. .list {
  458. position: relative;
  459. display: flex;
  460. height: 87.5rpx;
  461. flex-direction: row;
  462. justify-content: flex-start;
  463. align-items: center;
  464. border-bottom: 1px solid #DADEE6;
  465. .checked {
  466. position: absolute;
  467. top: 32.5rpx;
  468. right: 25rpx;
  469. font-size: 22.5rpx;
  470. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  471. font-weight: 400;
  472. color: #7A8599;
  473. }
  474. .editBtn {
  475. position: absolute;
  476. top: 32.5rpx;
  477. right: 90rpx;
  478. font-size: 22.5rpx;
  479. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  480. font-weight: 400;
  481. color: #3377FF;
  482. }
  483. .delBtn {
  484. position: absolute;
  485. top: 32.5rpx;
  486. right: 25rpx;
  487. font-size: 22.5rpx;
  488. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  489. font-weight: 400;
  490. color: #FF3355;
  491. }
  492. .infoWrap {
  493. .infoTag {
  494. font-size: 22.5rpx;
  495. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  496. font-weight: 400;
  497. color: #292C33;
  498. &::after {
  499. display: inline-block;
  500. content: '/';
  501. }
  502. &:last-child {
  503. &::after {
  504. display: inline-block;
  505. content: '';
  506. }
  507. }
  508. }
  509. }
  510. .status {
  511. width: 75rpx;
  512. height: 31.25rpx;
  513. border-radius: 5rpx;
  514. font-size: 17.5rpx;
  515. font-family: SourceHanSansCN-Medium, SourceHanSansCN;
  516. font-weight: 500;
  517. text-align: center;
  518. line-height: 31.25rpx;
  519. margin-left: 15rpx;
  520. &.done {
  521. color: #29CC96;
  522. background-color: rgba(41, 204, 150, 0.1);
  523. }
  524. &.checking {
  525. color: #FFAA00;
  526. background: rgba(255, 204, 102, 0.1);
  527. }
  528. }
  529. &:last-child {
  530. border: none;
  531. }
  532. }
  533. }
  534. .bottom {
  535. display: flex;
  536. justify-content: center;
  537. align-items: center;
  538. height: 75rpx;
  539. font-size: 22.5rpx;
  540. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  541. font-weight: 400;
  542. color: #3377FF;
  543. background: #FFFFFF;
  544. }
  545. }
  546. </style>