honor.vue 14 KB

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