index.vue 14 KB

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