selectVisitPerson.vue 16 KB

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