honor.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <template>
  2. <view class="content">
  3. <view>
  4. <uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="text" activeColor="#1c9bdc"></uni-segmented-control>
  5. <view class="content">
  6. <view v-show="current == 0">
  7. <view class="active-title-box">
  8. <!--<uni-datetime-picker
  9. class="time-select-box"
  10. type="date"
  11. :value="single"
  12. @change="change"
  13. :clear-icon="false"
  14. /> -->
  15. <picker mode="date" fields="year" @change="bindDateChange" class="picker-class">
  16. <view class="uni-input display-between items-center">{{dateYear}}年<image src="/static/calendar_icon.svg" mode="aspectFit" style="top: 18rpx;"></image></view>
  17. </picker>
  18. <picker :range="arrayMonth" :value="dateMonth" @change="bindDateMonthChange" class="picker-class" style="margin-left: 2%;">
  19. <view class="uni-input display-between items-center" style="color: #707070;">{{dateMonth}}月<image src="/static/calendar_icon.svg" mode="aspectFit" style="top: 18rpx;"></image></view>
  20. </picker>
  21. <picker @change="bindPickerChange" :value="index" :range="array">
  22. <view class="uni-input">{{array[index]}}</view>
  23. <image src="/static/arrow_down.svg" mode="aspectFit"></image>
  24. </picker>
  25. <button @click="goRecord()">+获奖记录</button>
  26. </view>
  27. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
  28. <view class="honor-box" v-for="(item,index) in honorList" :key="index" style="position: relative;">
  29. <view class="honor-name">{{item.name}}</view>
  30. <image :src="item.pic_url" mode="aspectFill" @click="showLarge(item.pic_url_resize)"></image>
  31. <view style="display: flex;">
  32. <view class="honor-award" style="width:120rpx;">获奖人:</view>
  33. <view class="honor-award">{{item.for_branch}} {{item.for_names}}</view>
  34. </view>
  35. <view class="honor-info-box">
  36. <text>{{item.year}}年{{item.month}}月</text>
  37. <text>|</text>
  38. <text>{{item.level_str}}</text>
  39. <text>|</text>
  40. <text>{{item.from_str}}</text>
  41. <text>|</text>
  42. <text>{{item.for_str}}</text>
  43. </view>
  44. <view class="edit-icon-box">
  45. <image src="/static/edit-icon.png" mode="aspectFit" v-show="item.edit_auth" @click="goRecord(item.id)"></image>
  46. <image src="/static/del-icon.png" mode="aspectFit" v-show="item.del_auth" @click="delRecord(item.id)"></image>
  47. </view>
  48. </view>
  49. </mescroll-body>
  50. <!-- <view v-if="!honorList.length" class="no-data-box">
  51. <image src="/static/nodata.svg" mode="aspectFit" style="width: 300rpx;height: 300rpx;"></image>
  52. </view> -->
  53. </view>
  54. <view v-if="current == 1">
  55. <view class="active-title-box">
  56. <picker mode="date" fields="year" @change="bindDateChangeSelf" class="picker-class">
  57. <view class="uni-input display-between items-center">{{dateYearSelf}}年<image src="/static/calendar_icon.svg" mode="aspectFit" style="top: 18rpx;"></image></view>
  58. </picker>
  59. <picker :range="arrayMonth" :value="dateMonthSelf" @change="bindDateMonthChangeSelf" class="picker-class" style="margin-left: 2%;">
  60. <view class="uni-input display-between items-center" style="color: #707070;">{{dateMonthSelf}}月<image src="/static/calendar_icon.svg" mode="aspectFit" style="top: 18rpx;"></image></view>
  61. </picker>
  62. <!-- <picker @change="bindPickerChangeSelf" :value="indexSelf" :range="arraySelf">
  63. <view class="uni-input">{{arraySelf[index]}}</view>
  64. <image src="/static/arrow_down.svg" mode="aspectFit"></image>
  65. </picker> -->
  66. <button @click="goRecord()" style="margin-left: 20%;">+获奖记录</button>
  67. </view>
  68. <view class="honor-box" v-for="(item,index) in myHonorList" :key="index" style="position: relative;">
  69. <view class="honor-name">{{item.name}}</view>
  70. <image :src="item.pic_url" mode="aspectFit" @click="showLarge(item.pic_url_resize)"></image>
  71. <view style="display: flex;">
  72. <view class="honor-award" style="width:120rpx;">获奖人:</view>
  73. <view class="honor-award">{{item.for_branch}} {{item.for_names}}</view>
  74. </view>
  75. <view class="honor-info-box">
  76. <text>{{item.year}}年{{item.month}}月</text>
  77. <text>|</text>
  78. <text>{{item.level_str}}</text>
  79. <text>|</text>
  80. <text>{{item.from_str}}</text>
  81. <text>|</text>
  82. <text>{{item.for_str}}</text>
  83. </view>
  84. <view class="edit-icon-box">
  85. <image src="/static/edit-icon.png" mode="aspectFit" v-show="item.edit_auth" @click="goRecord(item.id)"></image>
  86. <image src="/static/del-icon.png" mode="aspectFit" v-show="item.del_auth" @click="delRecord(item.id)"></image>
  87. </view>
  88. </view>
  89. <!-- <view v-if="!honorList.length" class="no-data-box">
  90. <image src="/static/nodata.svg" mode="aspectFit" style="width: 300rpx;height: 300rpx;"></image>
  91. </view> -->
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. </template>
  97. <script>
  98. import md5 from "@/common/md5.js";
  99. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  100. export default {
  101. mixins: [MescrollMixin], // 使用mixin
  102. data() {
  103. return {
  104. id: "",
  105. details: "",
  106. items:['支部/组织荣誉','我的荣誉'],
  107. current:0,
  108. shareUrl:getApp().globalData.shareUrl,
  109. array:['全部','中央','省级','市级','区级','单位'],
  110. index:0,
  111. indexSelf:0,
  112. dateYear:new Date().getFullYear(),
  113. dateMonth:new Date().getMonth() + 1,
  114. dateYearSelf:new Date().getFullYear(),
  115. dateMonthSelf:new Date().getMonth() + 1,
  116. arraySelf:['全部','中央','省级','市级','区级','单位'],
  117. arrayMonth:["1", "2","3", "4","5", "6","7", "8","9", "10","11", "12"],
  118. imageList: [],
  119. time: "",
  120. globalUrl:getApp().globalData.shareUrl,
  121. honorList:[],
  122. myHonorList:[],
  123. page:1,
  124. pageSize:10,
  125. };
  126. },
  127. onLoad() {
  128. // this.getHonorList(this.dateYear,this.dateMonth,this.index)
  129. },
  130. onShow(){
  131. //this.getHonorList(this.dateYear,this.dateMonth,this.index)
  132. },
  133. methods: {
  134. pageRefreshHonor(object) {
  135. if (object) {
  136. this.getHonorList(this.dateYear,this.dateMonth,this.index)
  137. } else {
  138. return
  139. }
  140. },
  141. onClickItem(e){
  142. this.current = e.currentIndex
  143. this.current ?
  144. this.getMyHonor(this.dateYearSelf,this.dateMonthSelf) :
  145. false
  146. },
  147. bindDateChange(e){
  148. this.dateYear = e.target.value;
  149. this.getHonorList(this.dateYear,this.dateMonth,this.index)
  150. },
  151. bindDateMonthChange(e){
  152. this.dateMonth = this.arrayMonth[e.target.value];
  153. this.getHonorList(this.dateYear,this.dateMonth,this.index)
  154. },
  155. bindPickerChange(e){
  156. this.index = e.detail.value
  157. this.getHonorList(this.dateYear,this.dateMonth,e.detail.value)
  158. },
  159. bindDateChangeSelf(e){
  160. this.dateYearSelf = e.target.value;
  161. this.getMyHonor(this.dateYearSelf,this.dateMonthSelf,this.indexSelf)
  162. },
  163. bindDateMonthChangeSelf(e){
  164. this.dateMonthSelf = this.arrayMonth[e.target.value];
  165. this.getMyHonor(this.dateYearSelf,this.dateMonthSelf,this.indexSelf)
  166. },
  167. // bindPickerChangeSelf(e){
  168. // this.indexSelf = e.detail.value
  169. // this.getMyHonor(this.dateYearSelf,this.dateMonthSelf,e.detail.value)
  170. // },
  171. upCallback(page) {
  172. let pageNum = page.num; // 页码, 默认从1开始
  173. let pageSize = page.size; // 页长, 默认每页10条
  174. let md5Sign = md5(
  175. "method=" +"glory" + "&timestamp=" + getApp().globalData.globalTimestamp +
  176. "&secret=" + getApp().globalData.secret
  177. );
  178. let url = getApp().globalData.shareUrl +"api/api.php" +
  179. "?method=glory&action=list&timestamp=" +
  180. getApp().globalData.globalTimestamp +
  181. "&sign=" +
  182. md5Sign;
  183. uni.request({
  184. url: url,
  185. method: "POST",
  186. header: {
  187. "content-type": "application/x-www-form-urlencoded",
  188. },
  189. data: {
  190. openid: getApp().globalData.open_id,
  191. year:this.dateYear,
  192. month:this.dateMonth,
  193. level:this.index,
  194. page:pageNum,
  195. page_size:pageSize
  196. },
  197. success: (res) => {
  198. if (res.data.code === 200) {
  199. // 接口返回的当前页数据列表 (数组)
  200. let curPageData = res.data.data.list;
  201. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  202. let curPageLen = curPageData.length;
  203. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  204. let totalPage = res.data.data.page_count;
  205. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  206. let totalSize = res.data.data.count;
  207. // // 接口返回的是否有下一页 (true/false)
  208. // let hasNext = data.xxx;
  209. if(page.num == 1) this.honorList = []; //如果是第一页需手动制空列表
  210. let list = res.data.data.list;
  211. list.forEach((item)=>{
  212. item.pic_url = this.shareUrl + item.pic_url;
  213. item.pic_url_resize = this.shareUrl + item.pic_url_resize;
  214. })
  215. this.honorList=this.honorList.concat(res.data.data.list); //追加新数据
  216. this.mescroll.endByPage(curPageLen || 0, totalPage);
  217. }
  218. },
  219. fail: () => {
  220. console.log("连接失败");
  221. this.mescroll.endErr();
  222. },
  223. });
  224. },
  225. goRecord(id){
  226. if(id){
  227. uni.navigateTo({
  228. url:'./record?id=' + id
  229. })
  230. }else {
  231. uni.navigateTo({
  232. url:'./record'
  233. })
  234. }
  235. },
  236. delRecordRequest(delId){
  237. let md5Sign = md5(
  238. "method=" +"glory" + "&timestamp=" + getApp().globalData.globalTimestamp +
  239. "&secret=" + getApp().globalData.secret
  240. );
  241. let url = getApp().globalData.shareUrl +"api/api.php" +
  242. "?method=glory&action=del&timestamp=" +
  243. getApp().globalData.globalTimestamp +
  244. "&sign=" +
  245. md5Sign;
  246. uni.request({
  247. url: url,
  248. method: "POST",
  249. header: {
  250. "content-type": "application/x-www-form-urlencoded",
  251. },
  252. data: {
  253. openid: getApp().globalData.open_id,
  254. id:delId
  255. },
  256. success: (res) => {
  257. if (res.data.code === 200) {
  258. uni.showToast({
  259. title: "删除成功",
  260. icon: "none",
  261. duration: 2500,
  262. success:()=>{
  263. this.getHonorList(this.dateYear,this.dateMonth,this.index)
  264. }
  265. });
  266. }
  267. },
  268. fail: () => {
  269. console.log("连接失败");
  270. },
  271. });
  272. },
  273. delRecord(id){
  274. let that = this;
  275. uni.showModal({
  276. title: "确定删除此荣誉吗?",
  277. success(res) {
  278. if (res.confirm) {
  279. that.delRecordRequest(id);
  280. } else if (res.cancel) {
  281. console.log("用户点击取消");
  282. }
  283. },
  284. });
  285. },
  286. showLarge(src) {
  287. uni.previewImage({
  288. urls: [src],
  289. longPressActions: {
  290. itemList: ["发送给朋友", "保存图片"],
  291. success: function (data) {},
  292. fail: function (err) {
  293. console.log(err.errMsg);
  294. },
  295. },
  296. });
  297. },
  298. getHonorList(y,m,level) {
  299. let md5Sign = md5(
  300. "method=" +"glory" + "&timestamp=" + getApp().globalData.globalTimestamp +
  301. "&secret=" + getApp().globalData.secret
  302. );
  303. let url = getApp().globalData.shareUrl +"api/api.php" +
  304. "?method=glory&action=list&timestamp=" +
  305. getApp().globalData.globalTimestamp +
  306. "&sign=" +
  307. md5Sign;
  308. uni.request({
  309. url: url,
  310. method: "POST",
  311. header: {
  312. "content-type": "application/x-www-form-urlencoded",
  313. },
  314. data: {
  315. openid: getApp().globalData.open_id,
  316. year:y,
  317. month:m,
  318. level:level,
  319. page:this.page,
  320. page_size:this.pageSize
  321. },
  322. success: (res) => {
  323. if (res.data.code === 200) {
  324. let list = res.data.data.list;
  325. list.forEach((item)=>{
  326. item.pic_url = this.shareUrl + item.pic_url;
  327. item.pic_url_resize = this.shareUrl + item.pic_url_resize;
  328. })
  329. this.honorList = list;
  330. }
  331. },
  332. fail: () => {
  333. console.log("连接失败");
  334. },
  335. });
  336. },
  337. getMyHonor(y,m) {
  338. let md5Sign = md5(
  339. "method=" +"glory" + "&timestamp=" + getApp().globalData.globalTimestamp +
  340. "&secret=" + getApp().globalData.secret
  341. );
  342. let url = getApp().globalData.shareUrl +"api/api.php" +
  343. "?method=glory&action=my_list&timestamp=" +
  344. getApp().globalData.globalTimestamp +
  345. "&sign=" +
  346. md5Sign;
  347. uni.request({
  348. url: url,
  349. method: "POST",
  350. header: {
  351. "content-type": "application/x-www-form-urlencoded",
  352. },
  353. data: {
  354. openid: getApp().globalData.open_id,
  355. year:y,
  356. month:m,
  357. // level:level,
  358. // page:1,
  359. // page_size:10
  360. },
  361. success: (res) => {
  362. if (res.data.code === 200) {
  363. let list = res.data.data.list;
  364. list.forEach((item)=>{
  365. item.pic_url = this.shareUrl + item.pic_url;
  366. item.pic_url_resize = this.shareUrl + item.pic_url_resize;
  367. })
  368. this.myHonorList = list;
  369. }
  370. },
  371. fail: () => {
  372. console.log("连接失败");
  373. },
  374. });
  375. },
  376. },
  377. };
  378. </script>
  379. <style lang="scss" scoped>
  380. .content {
  381. .active-title-box {
  382. display: flex;
  383. align-items: center;
  384. margin-top: 10rpx;
  385. font-size: 26rpx;
  386. height: 100rpx;
  387. border-bottom: 1px solid #d7d7d7;
  388. margin-top: 10rpx;
  389. .time-select-box {
  390. width: 32%;
  391. margin-left: 5%;
  392. }
  393. picker {
  394. width: 20%;
  395. border: 1px solid #d7d7d7;
  396. height: 60rpx;
  397. line-height: 60rpx;
  398. border-radius: 10rpx;
  399. margin-left: 20rpx;
  400. padding: 0 10rpx;
  401. position: relative;
  402. image {
  403. width: 20rpx;
  404. height: 20rpx;
  405. position: absolute;
  406. top: 11px;
  407. right: 5px;
  408. }
  409. }
  410. button {
  411. width: 25%;
  412. font-size: 25rpx;
  413. background: #4988fd;
  414. color: #fff;
  415. margin-left: 20rpx;
  416. margin-right: 20rpx;
  417. }
  418. }
  419. .honor-box {
  420. display: flex;
  421. flex-direction: column;
  422. padding: 20rpx 40rpx 20rpx 40rpx;
  423. border-bottom: 1px solid #d7d7d7;
  424. image {
  425. width: 360rpx;
  426. height: 160rpx;
  427. margin: 20rpx auto;
  428. }
  429. .honor-award {
  430. width: 80%;
  431. color: #ccc;
  432. font-size: 28rpx;
  433. margin: 20rpx 0 10rpx 0;
  434. }
  435. .honor-info-box {
  436. display: flex;
  437. align-items: center;
  438. font-size: 26rpx;
  439. color: #ccc;
  440. text {
  441. margin-right: 20rpx;
  442. }
  443. }
  444. .edit-icon-box {
  445. position: absolute;
  446. right: 10px;
  447. top: 10px;
  448. image {
  449. width: 35rpx;
  450. height: 35rpx;
  451. margin-right: 10rpx;
  452. }
  453. }
  454. }
  455. .no-data-box {
  456. position: fixed;
  457. top: 100px;
  458. left: 30%;
  459. }
  460. }
  461. </style>