index.vue 15 KB

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