index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. <template>
  2. <view class="page-content complaints">
  3. <view class="page-header complaints-header">
  4. <u-tabs
  5. class="complaints-tabs"
  6. name="cust_tabs_name"
  7. :list="tabsList"
  8. :current="currentTabs"
  9. height="80"
  10. item-width="256"
  11. gutter="50"
  12. bar-width="120"
  13. font-size="32"
  14. @change="handletabsChange"
  15. ></u-tabs>
  16. </view>
  17. <view class="page-main">
  18. <template v-if="currentTabs == 0">
  19. <view class="initiate-complaints">
  20. <u-form
  21. :model="complaintsForm"
  22. label-position="top"
  23. :label-style="custLabelStyle"
  24. ref="complaintsFormRef"
  25. >
  26. <u-form-item
  27. label="真实姓名:"
  28. prop="plaUser"
  29. :required="true"
  30. maxlength="20"
  31. class="initiate-formitem"
  32. >
  33. <u-input
  34. v-model="complaintsForm.plaUser"
  35. placeholder="请输入真实姓名"
  36. :placeholder-style="custPlaceholderStyle"
  37. />
  38. </u-form-item>
  39. <u-form-item label="手机号码:" prop="plaPhone" :required="true" class="initiate-formitem">
  40. <u-input
  41. v-model="complaintsForm.plaPhone"
  42. placeholder="请输入手机号码"
  43. :placeholder-style="custPlaceholderStyle"
  44. />
  45. </u-form-item>
  46. <u-form-item
  47. label="投诉标题:"
  48. prop="plaName"
  49. :required="true"
  50. maxlength="50"
  51. class="initiate-formitem"
  52. >
  53. <u-input
  54. v-model="complaintsForm.plaName"
  55. placeholder="请输入投诉标题"
  56. :placeholder-style="custPlaceholderStyle"
  57. />
  58. </u-form-item>
  59. <u-form-item
  60. label="投诉内容:"
  61. prop="plaContent"
  62. :required="true"
  63. class="mt40 initiate-formitem"
  64. >
  65. <u-input
  66. v-model="complaintsForm.plaContent"
  67. type="textarea"
  68. maxlength="200"
  69. height="298"
  70. placeholder="请输入不少于10个字的描述"
  71. :placeholder-style="custPlaceholderStyle"
  72. @input="handleSumPlacontentNum"
  73. />
  74. <text class="formitem-sumplacontentnum">{{ sumPlacontentNum }}/200</text>
  75. </u-form-item>
  76. </u-form>
  77. <view class="complaintsform-footer">
  78. <u-button
  79. type="primary"
  80. @click="handleComplaintsformSubmit"
  81. class="complaint-submitbtn"
  82. >提交</u-button>
  83. </view>
  84. </view>
  85. </template>
  86. <template v-else-if="currentTabs == 1">
  87. <view class="history-complaints">
  88. <scroll-view scroll-y="true" class="scroll-Y" @scrolltolower="handleScrolltolower">
  89. <view class="history-complaints-listbody">
  90. <!-- 列表无数据 -->
  91. <template v-if="hisComplaintsObj.list_empty">
  92. <view class="history-complaints-nodata">
  93. <text class="complaints-nodata">暂无数据</text>
  94. </view>
  95. </template>
  96. <!-- 列表有数据 -->
  97. <template v-else>
  98. <u-row gutter="16" class="listbody-row">
  99. <u-col
  100. span="12"
  101. class="listbody-col"
  102. v-for="complaintsItem in hisComplaintsObj.complaintsList"
  103. :key="complaintsItem.plaId"
  104. @click="handleComplaintsDetails(complaintsItem)"
  105. >
  106. <view class="listbody-item">
  107. <view class="item-title">
  108. <text class="item-title-left">质量安全投诉</text>
  109. <text class="item-title-right">{{ complaintsItem.plaInTime }}</text>
  110. </view>
  111. <view class="item-body">
  112. <text class="item-body-text">
  113. 真实姓名:{{ complaintsItem.plaUser }}
  114. <br />
  115. 手机号码:{{ complaintsItem.plaPhone ? complaintsItem.plaPhone.toString().replace(/^(.{3})(.*)(.{4})$/, '$1-$2-$3') : '' }}
  116. </text>
  117. <template v-if="complaintsItem.plaIsRe == 1">
  118. <text class="item-body-feedback">已反馈</text>
  119. </template>
  120. <template v-else>
  121. <text class="item-body-nofeedback">未反馈</text>
  122. </template>
  123. </view>
  124. </view>
  125. </u-col>
  126. </u-row>
  127. </template>
  128. <!-- 加载更多组件 -->
  129. <uni-load-more
  130. :status="hisComplaintsObj.loadStatus"
  131. v-if="!hisComplaintsObj.list_empty"
  132. ></uni-load-more>
  133. </view>
  134. </scroll-view>
  135. </view>
  136. </template>
  137. <template v-else></template>
  138. </view>
  139. </view>
  140. </template>
  141. <script>
  142. import {
  143. complaintsAddData,
  144. complaintsListData
  145. } from '@/agrcloud-api/complaints';
  146. import uniLoadMore from "@/agrcloud-components/uni-load-more/uni-load-more.vue"
  147. export default {
  148. name: 'complaints',
  149. components: {
  150. uniLoadMore
  151. },
  152. data() {
  153. return {
  154. optionType: '',
  155. currentTabs: 0,
  156. tabsList: [{
  157. cust_tabs_name: '发起投诉'
  158. },
  159. {
  160. cust_tabs_name: '历史投诉'
  161. }
  162. ],
  163. complaintsForm: {
  164. plaUser: '',
  165. plaPhone: '',
  166. plaName: '',
  167. plaContent: ''
  168. },
  169. complaintsRules: {
  170. plaUser: [{
  171. required: true,
  172. message: '请输入真实姓名',
  173. trigger: ['change', 'blur']
  174. }],
  175. plaPhone: [{
  176. required: true,
  177. message: '请输入手机号码',
  178. trigger: ['change', 'blur']
  179. },
  180. {
  181. validator: (rule, value, callback) => {
  182. return this.$u.test.mobile(value);
  183. },
  184. message: '手机号码不正确',
  185. trigger: ['change', 'blur']
  186. }
  187. ],
  188. plaName: [{
  189. required: true,
  190. message: '请输入投诉标题',
  191. trigger: ['change', 'blur']
  192. }],
  193. plaContent: [{
  194. required: true,
  195. message: '请输入投诉内容',
  196. trigger: ['change', 'blur']
  197. },
  198. {
  199. min: 10,
  200. message: '投诉内容不少于10个字',
  201. trigger: ['change', 'blur']
  202. }
  203. ]
  204. },
  205. sumPlacontentNum: 0,
  206. custLabelStyle: {
  207. 'font-size': '30rpx',
  208. 'font-family': 'PingFangSC-Regular, PingFang SC',
  209. 'font-weight': '400',
  210. },
  211. custPlaceholderStyle: 'font-size: 34rpx;font-family: PingFangSC-Regular, PingFang SC;font-weight: 400;',
  212. hisComplaintsObj: {
  213. loadStatus: 'more',
  214. list_empty: false,
  215. pageTotal: 0,
  216. pageCount: 0,
  217. pagination: {
  218. pageNum: 1,
  219. pageSize: 10
  220. },
  221. complaintsList: []
  222. }
  223. };
  224. },
  225. onLoad: function (option) { },
  226. methods: {
  227. /** 切换页签 */
  228. handletabsChange(index) {
  229. if (index == 1) {
  230. if (!this.complaintsForm.plaUser) {
  231. this.currentTabs = 0;
  232. this.$msgbox('请输入真实姓名!', 'none');
  233. return;
  234. }
  235. if (!this.complaintsForm.plaPhone) {
  236. this.currentTabs = 0;
  237. this.$msgbox('请输入手机号码!', 'none');
  238. return;
  239. }
  240. this.hisComplaintsObj.pagination.pageNum = 1;
  241. this.getComplaintsListData();
  242. }
  243. this.currentTabs = index;
  244. },
  245. /** 获取历史投诉列表 */
  246. getComplaintsListData() {
  247. this.hisComplaintsObj = {
  248. ...this.hisComplaintsObj,
  249. list_empty: false,
  250. loadStatus: 'loading'
  251. };
  252. // 请求获取列表数据
  253. complaintsListData({
  254. ...this.hisComplaintsObj.pagination,
  255. plaUser: this.complaintsForm.plaUser,
  256. plaPhone: this.complaintsForm.plaPhone
  257. }).then(res => {
  258. // 数据总条数
  259. this.hisComplaintsObj.pageTotal = res.total || 0;
  260. // 如果列表为第一页,返回列表数据清空
  261. if (this.hisComplaintsObj.pagination.pageNum == 1) {
  262. this.hisComplaintsObj.complaintsList = [];
  263. };
  264. // 处理返回结果
  265. if ((res.rows || []).length <= 0) { // 返回结果没有数据
  266. if ((this.hisComplaintsObj.complaintsList || []).length <= 0) {
  267. this.hisComplaintsObj.loadStatus = 'noMores';
  268. this.hisComplaintsObj.list_empty = true;
  269. } else {
  270. this.hisComplaintsObj.loadStatus = 'noMores';
  271. }
  272. } else { //返回结果有数据
  273. //返回历史投诉列表存在
  274. this.hisComplaintsObj.list_empty = false;
  275. // 获取列表数据分页数量
  276. this.hisComplaintsObj.pageCount = Math.ceil((res.total || 0) / this.hisComplaintsObj.pagination.pageSize);
  277. if ((res.total || 0) % this.hisComplaintsObj.pagination.pageSize == 0) {
  278. this.hisComplaintsObj.pageCount = Math.ceil((res.total || 0) / this.hisComplaintsObj.pagination.pageSize);
  279. if (this.hisComplaintsObj.pageCount == 1) {
  280. this.hisComplaintsObj.pageCount--;
  281. }
  282. } else {
  283. this.hisComplaintsObj.pageCount--;
  284. };
  285. // 处理页面状态
  286. if (this.hisComplaintsObj.pageCount === 0) {
  287. this.hisComplaintsObj.loadStatus = 'noMores'
  288. } else {
  289. this.hisComplaintsObj.loadStatus = 'more'
  290. }
  291. // 组装返回数据
  292. this.hisComplaintsObj.complaintsList.push.apply(this.hisComplaintsObj.complaintsList, res.rows || []);
  293. uni.stopPullDownRefresh();
  294. }
  295. }).catch(err => {
  296. this.hisComplaintsObj.loadStatus = 'noMores';
  297. });
  298. },
  299. handleComplaintsformSubmit() {
  300. this.$refs.complaintsFormRef && this.$refs.complaintsFormRef.validate(valid => {
  301. if (valid) {
  302. complaintsAddData(this.complaintsForm).then(
  303. res => {
  304. this.$msgbox('操作成功!', 'success');
  305. this.complaintsForm = {
  306. ...this.complaintsForm,
  307. plaName: '',
  308. plaContent: ''
  309. };
  310. uni.navigateTo({
  311. url: '/pages/results/index'
  312. });
  313. }
  314. );
  315. }
  316. });
  317. },
  318. handleScrolltolower() {
  319. this.hisComplaintsObj.loadStatus = 'loading'
  320. if (this.hisComplaintsObj.pagination.pageNum - 1 >= this.hisComplaintsObj.pageCount) {
  321. this.hisComplaintsObj.loadStatus = 'noMores';
  322. return;
  323. } else {
  324. this.hisComplaintsObj.pagination.pageNum++;
  325. this.getComplaintsListData();
  326. }
  327. },
  328. handleSumPlacontentNum() {
  329. this.sumPlacontentNum = this.complaintsForm.plaContent.length;
  330. if (this.sumPlacontentNum == 200) {
  331. this.$msgbox('最多只能输入240个字!', 'none');
  332. }
  333. },
  334. handleComplaintsDetails(param) {
  335. this.$store.dispatch("SetComplaintsDetails", param).then(() => {
  336. uni.navigateTo({
  337. url: '/pages/complaints/details/index'
  338. });
  339. }).catch(() => {
  340. this.$msgbox('访问数据异常!', 'none');
  341. });
  342. }
  343. },
  344. onReady() {
  345. this.$refs.complaintsFormRef && this.$refs.complaintsFormRef.setRules(this.complaintsRules);
  346. }
  347. }
  348. </script>
  349. <style lang="scss" scoped>
  350. .complaints {
  351. padding: 0;
  352. &-header {
  353. width: 100%;
  354. border-top: 2rpx solid #eeeeee;
  355. border-bottom: 2rpx solid #eeeeee;
  356. }
  357. .complaints-tabs {
  358. height: 87rpx;
  359. display: flex;
  360. flex-direction: column;
  361. align-items: center;
  362. justify-content: center;
  363. }
  364. .initiate-complaints {
  365. .initiate-formitem {
  366. padding-left: 24rpx;
  367. background: #ffffff;
  368. .formitem-sumplacontentnum {
  369. position: absolute;
  370. bottom: 0;
  371. right: 0;
  372. }
  373. }
  374. }
  375. .complaintsform-footer {
  376. padding: 40rpx 32rpx;
  377. .complaint-submitbtn {
  378. height: 88rpx;
  379. }
  380. }
  381. .hiscomplaint-item {
  382. background: #ffffff;
  383. }
  384. .history-complaints {
  385. .scroll-Y {
  386. height: calc(
  387. 100vh - 88rpx - 100rpx - env(safe-area-inset-bottom) -
  388. var(--status-bar-height)
  389. );
  390. }
  391. .history-complaints-listbody {
  392. .history-complaints-nodata {
  393. text-align: center;
  394. margin-top: 20rpx;
  395. .complaints-nodata {
  396. font-size: 30rpx;
  397. color: #777777;
  398. }
  399. }
  400. .listbody-row {
  401. .listbody-col {
  402. padding: 24rpx 0 0 0 !important;
  403. .listbody-item {
  404. background: #ffffff;
  405. height: 196rpx;
  406. width: 100%;
  407. .item-title {
  408. padding-top: 24rpx;
  409. .item-title-left {
  410. float: left;
  411. height: 48rpx;
  412. font-size: 34rpx;
  413. font-family: PingFangSC-Medium, PingFang SC;
  414. font-weight: 500;
  415. color: #333333;
  416. line-height: 48rpx;
  417. padding-left: 24rpx;
  418. }
  419. .item-title-right {
  420. float: right;
  421. height: 48rpx;
  422. font-size: 30rpx;
  423. font-family: PingFangSC-Regular, PingFang SC;
  424. font-weight: 400;
  425. color: #999999;
  426. line-height: 48rpx;
  427. padding-right: 24rpx;
  428. }
  429. }
  430. .item-body {
  431. clear: both;
  432. padding: 16rpx 0 0 24rpx;
  433. .item-body-text {
  434. height: 84rpx;
  435. font-size: 30rpx;
  436. font-family: PingFangSC-Regular, PingFang SC;
  437. font-weight: 400;
  438. color: #666666;
  439. line-height: 42rpx;
  440. }
  441. .item-body-nofeedback {
  442. float: right;
  443. padding-right: 24rpx;
  444. height: 42rpx;
  445. font-size: 30rpx;
  446. font-family: PingFangSC-Medium, PingFang SC;
  447. font-weight: 500;
  448. color: #fd4779;
  449. line-height: 42rpx;
  450. }
  451. .item-body-feedback {
  452. float: right;
  453. padding-right: 24rpx;
  454. height: 42rpx;
  455. font-size: 30rpx;
  456. font-family: PingFangSC-Medium, PingFang SC;
  457. font-weight: 500;
  458. color: #48a79e;
  459. line-height: 42rpx;
  460. }
  461. }
  462. }
  463. }
  464. }
  465. }
  466. }
  467. }
  468. </style>