print.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <view class="container" v-if="modelDatas.length">
  3. <!-- 预览按钮区域 -->
  4. <view class="title">
  5. <img class="img" src="../../static/images/my/eye.png" @click="handlePreview" />
  6. <view @click="handlePreview">预览效果</view>
  7. </view>
  8. <!-- 分段器区域 -->
  9. <view class="subsection">
  10. <u-subsection
  11. v-if="modelDatas.length"
  12. bgColor="#fff"
  13. activeColor="#0061FF"
  14. inactiveColor="#808080"
  15. :list="modelDatas"
  16. :current="currentIndex"
  17. @change="changeIndex"
  18. ></u-subsection>
  19. </view>
  20. <view class="gap"></view>
  21. <!-- 小票编辑区域 -->
  22. <view class="edit">
  23. <view class="edit_title">小票编辑</view>
  24. <view class="edit_subTitle">
  25. <view class="sub_box"></view>
  26. 基本信息
  27. </view>
  28. <view class="edit_desc">注:{{ descList[currentIndex] }}为小票必须展示的信息</view>
  29. <view class="check_box">
  30. <view class="check_box_item" v-for="item in dataObj.details" :key="item.id">
  31. <u-checkbox
  32. size="50"
  33. v-model="item.isCheck == 0 ? true : false"
  34. :disabled="
  35. item.printName == '平台名称' ||
  36. item.printName == '店铺名' ||
  37. item.printName == '订单号' ||
  38. item.printName == '商品名称' ||
  39. item.printName == '单价' ||
  40. item.printName == '数量' ||
  41. item.printName == '备注' ||
  42. item.printName == '打包费' ||
  43. item.printName == '商品费' ||
  44. item.printName == '优惠券' ||
  45. item.printName == '跑腿费' ||
  46. item.printName == '优惠活动' ||
  47. item.printName == '合计' ||
  48. item.printName == '姓名' ||
  49. item.printName == '电话号' ||
  50. item.printName == '地址' ||
  51. item.printName == '订餐时间'
  52. "
  53. :checked="item.isCheck == 0"
  54. @change="changeCheck(item)"
  55. >
  56. {{ item.printName }}
  57. </u-checkbox>
  58. </view>
  59. </view>
  60. </view>
  61. <!-- 自定义样式区域 -->
  62. <view class="diy">
  63. <view class="diy_title">自定义样式</view>
  64. <view class="diy_box" v-for="item in dataObj.types" :key="item.id">
  65. <view class="box_title">{{ item.printName }}</view>
  66. <view class="box_row">
  67. <view style="margin-bottom: 10rpx">打印字号:</view>
  68. <u-radio-group v-model="item.wordSize">
  69. <u-radio :customStyle="{ marginBottom: '8px' }" v-for="(item, index) in radiolist1" :key="index" :name="item.label">
  70. {{ item.name }}
  71. </u-radio>
  72. </u-radio-group>
  73. </view>
  74. <view class="box_row">
  75. <view style="margin-bottom: 10rpx">字体:</view>
  76. <u-radio-group v-model="item.isBlod">
  77. <u-radio :customStyle="{ marginBottom: '8px' }" v-for="(item, index) in radiolist2" :key="index" :name="item.label">
  78. {{ item.name }}
  79. </u-radio>
  80. </u-radio-group>
  81. </view>
  82. </view>
  83. </view>
  84. <!-- 保存按钮区域 -->
  85. <view class="btn" v-if="modelDatas.length">
  86. <view class="btn_box" @click="handleSave">保存</view>
  87. </view>
  88. </view>
  89. </template>
  90. <script>
  91. export default {
  92. data() {
  93. return {
  94. // 店铺id
  95. shopId: '',
  96. // 打印数据id
  97. printId: '',
  98. // 当前激活分段器索引
  99. currentIndex: 0,
  100. // 打印字号数组
  101. radiolist1: [
  102. {
  103. name: '正常',
  104. label: 1
  105. },
  106. {
  107. name: '放大',
  108. label: 2
  109. }
  110. ],
  111. // 打印字体数组
  112. radiolist2: [
  113. {
  114. name: '正常',
  115. label: 0
  116. },
  117. {
  118. name: '加粗',
  119. label: 1
  120. }
  121. ],
  122. // 模版数据
  123. modelDatas: [],
  124. // 每一个分段器的数据
  125. dataObj: {},
  126. descList: ['平台名称、店铺名、订单号', '商品名称、单价、数量、备注', '打包费、商品费、优惠券、跑腿费、优惠活动和合计', '姓名、电话号、地址 、订餐时间']
  127. }
  128. },
  129. onLoad() {
  130. this.shopId = uni.getStorageSync('shopId')
  131. // 根据店铺ID获取小票模板数据
  132. this.getModelDatas()
  133. },
  134. methods: {
  135. // 根据店铺ID获取小票模板数据
  136. async getModelDatas() {
  137. const res = await this.$Request.getT('/admin/printInfo/getPrintModelData', {
  138. shopId: this.shopId
  139. })
  140. // console.log(res)
  141. if (res.code == 0) {
  142. this.printId = res.data.id
  143. this.modelDatas = res.data.modelDatas
  144. this.changeIndex(this.currentIndex)
  145. }
  146. },
  147. // 保存按钮回调
  148. async handleSave() {
  149. const res = await this.$Request.postJson(this.printId ? '/admin/printInfo/updatePrintModelData' : '/admin/printInfo/insertPrintModelData', {
  150. id: this.printId,
  151. modelDatas: this.modelDatas,
  152. shopId: this.shopId
  153. })
  154. // console.log(res)
  155. if (res.code == 0) {
  156. uni.showToast({
  157. title: '保存成功',
  158. mask: true,
  159. icon: 'success'
  160. })
  161. setTimeout(() => {
  162. this.getModelDatas()
  163. }, 1500)
  164. }
  165. },
  166. // 切换分段器时的回调
  167. changeIndex(i) {
  168. this.currentIndex = i
  169. this.dataObj = this.modelDatas[this.currentIndex]
  170. uni.pageScrollTo({
  171. selector: '.gap',
  172. offsetTop: -500
  173. })
  174. },
  175. // 切换check时的回调
  176. changeCheck(item) {
  177. // console.log(item)
  178. item.isCheck = item.isCheck == 0 ? 1 : 0
  179. },
  180. handlePreview() {
  181. let data = encodeURIComponent(JSON.stringify(this.modelDatas))
  182. uni.navigateTo({
  183. url: `/my/print/preview?data=${data}`
  184. })
  185. }
  186. }
  187. }
  188. </script>
  189. <style lang="scss" scoped>
  190. .container {
  191. min-height: 100vh;
  192. overflow-y: auto;
  193. .title {
  194. position: fixed;
  195. top: 0;
  196. left: 0;
  197. right: 0;
  198. display: flex;
  199. justify-content: flex-end;
  200. align-items: center;
  201. padding: 0 20rpx;
  202. height: 80rpx;
  203. font-size: 28rpx;
  204. color: #0061ff;
  205. background-color: #fff;
  206. border-bottom: 2rpx solid #f1f1f1;
  207. .img {
  208. margin-right: 6rpx;
  209. width: 58rpx;
  210. height: 58rpx;
  211. }
  212. }
  213. .subsection {
  214. position: fixed;
  215. top: 80rpx;
  216. left: 0;
  217. right: 0;
  218. }
  219. .gap {
  220. margin-top: 150rpx;
  221. height: 20rpx;
  222. background-color: #f1f1f1;
  223. }
  224. .edit {
  225. margin: 0 0 20rpx 0;
  226. background-color: #fff;
  227. .edit_title {
  228. display: flex;
  229. align-items: center;
  230. padding: 0 20rpx;
  231. height: 92rpx;
  232. font-size: 32rpx;
  233. font-weight: bold;
  234. border-bottom: 2rpx solid #f1f1f1;
  235. }
  236. .edit_subTitle {
  237. display: flex;
  238. align-items: center;
  239. padding: 0 20rpx;
  240. margin-top: 32rpx;
  241. font-size: 28rpx;
  242. .sub_box {
  243. margin-right: 12rpx;
  244. width: 20rpx;
  245. height: 20rpx;
  246. background-color: #0061ff;
  247. }
  248. }
  249. .edit_desc {
  250. padding: 0 20rpx 0 50rpx;
  251. margin: 15rpx 0;
  252. font-size: 24rpx;
  253. color: #999999;
  254. line-height: 36rpx;
  255. }
  256. .check_box {
  257. padding: 0 20rpx;
  258. margin-top: 15px;
  259. display: flex;
  260. flex-wrap: wrap;
  261. .check_box_item {
  262. margin-bottom: 35rpx;
  263. width: 350rpx;
  264. }
  265. }
  266. }
  267. .diy {
  268. background-color: #fff;
  269. .diy_title {
  270. display: flex;
  271. align-items: center;
  272. padding: 0 20rpx;
  273. height: 92rpx;
  274. font-size: 32rpx;
  275. font-weight: bold;
  276. border-bottom: 2rpx solid #f1f1f1;
  277. }
  278. .diy_box {
  279. padding: 0 20rpx 20rpx;
  280. font-size: 28rpx;
  281. .box_title {
  282. height: 80rpx;
  283. line-height: 80rpx;
  284. font-weight: bold;
  285. }
  286. .box_row {
  287. margin-bottom: 20rpx;
  288. }
  289. }
  290. }
  291. .btn {
  292. display: flex;
  293. justify-content: center;
  294. padding: 0 20rpx 40rpx;
  295. background-color: #fff;
  296. .btn_box {
  297. display: flex;
  298. justify-content: center;
  299. align-items: center;
  300. width: 200rpx;
  301. height: 80rpx;
  302. color: #fff;
  303. border-radius: 10rpx;
  304. background-color: #0061ff;
  305. }
  306. }
  307. }
  308. </style>