index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <view :style="{ minHeight: sys.windowHeight + 'px' }"
  3. :class="[$tm.vx.state().tmVuetify.black ? 'black' : ' ']">
  4. <tm-menubars title="衣物录入" :shadow="0" :showback="true"></tm-menubars>
  5. <div class="zhuti">
  6. <tm-sheet class="kuang" style="padding-bottom: 70px !important;">
  7. <image v-if="active==1" class="jindu" src="/static/img/49.png" mode="widthFix"></image>
  8. <image v-if="active==2" class="jindu" src="/static/img/50.png" mode="widthFix"></image>
  9. <image v-if="active==3" class="jindu" src="/static/img/51.png" mode="widthFix"></image>
  10. <view class="wenzi flex-between flex-center" style="margin-top: 10px;">
  11. <view>
  12. <text class="text-white text-size-m">衣物拍照</text>
  13. </view>
  14. <view>
  15. <text class="text-white text-size-m">确认衣物属性</text>
  16. </view>
  17. <view>
  18. <text class="text-white text-size-m">入库成功</text>
  19. </view>
  20. </view>
  21. <view v-if="active==1">
  22. <view class="mt-20 ml-15">
  23. <text class="text-white text-size-m">*衣物拍照实例图</text>
  24. </view>
  25. <image block class="zhanshi" mode="widthFix" src="/static/img/48.png"></image>
  26. <tm-button :round="24" class="mb-40" @click="paizhao()" block>拍照录入</tm-button>
  27. </view>
  28. <view v-if="active==2">
  29. <image block class="nicheng" mode="widthFix" :src="koutu"></image>
  30. <view class="you black mt-30">
  31. <tm-input :required="true" title="商品名称" v-model="reqData.goods_name" align="right"></tm-input>
  32. <tm-pickers class="tan" :default-value.sync="category_danarr" rang-key="category_name" :list="category_arr">
  33. <tm-input :required="true" title="分类" placeholder="请选择分类" disabled :value="obTstr1(category_danarr,'category_name')" right-icon="icon-angle-right"></tm-input>
  34. </tm-pickers>
  35. <tm-pickers class="tan" :default-value.sync="role_danarr" rang-key="username" :list="role_arr">
  36. <tm-input title="所属成员" :required="true" placeholder="请选择所属成员" disabled :value="obTstr3(role_danarr)" right-icon="icon-angle-right"></tm-input>
  37. </tm-pickers>
  38. <tm-input title="年份" v-model="reqData.year" align="right"></tm-input>
  39. <tm-input title="颜色" v-model="reqData.color" align="right"></tm-input>
  40. <tm-pickers class="tan" :default-value.sync="size_danarr" rang-key="title" :list="size_arr">
  41. <tm-input title="尺码" placeholder="请选择尺码" disabled :value="obTstr2(size_danarr)" right-icon="icon-angle-right"></tm-input>
  42. </tm-pickers>
  43. <tm-input title="适用人群" v-model="reqData.type" align="right"></tm-input>
  44. <tm-input title="品牌" v-model="reqData.brand" align="right"></tm-input>
  45. <tm-input title="材料" v-model="reqData.science" align="right"></tm-input>
  46. </view>
  47. <tm-button :round="24" class="sao mb-40 mt-40" @click="chuangjianFun()" block>提交</tm-button>
  48. </view>
  49. <view v-if="active==3">
  50. <tm-translate ref="a_1" :auto="true" animation-name="zoomIn">
  51. <image block class="nicheng" mode="widthFix" src="/static/img/52.png"></image>
  52. </tm-translate>
  53. <view class="text-align-center mt-20">
  54. <text class="text-size-m text-white">衣物添加成功!</text>
  55. </view>
  56. <view class="text-align-center mb-40">
  57. <text class="text-size-m">您可以在我的衣柜中添加或删除衣物</text>
  58. </view>
  59. <view class="px-24">
  60. <tm-button @click="jixu()" :round="24" block class="mt-50 logincla">继续添加衣物</tm-button>
  61. <tm-button @click="quindex()" theme="primary" :round="24" block class="mt-30 quindex">进入衣柜</tm-button>
  62. </view>
  63. </view>
  64. </tm-sheet>
  65. </div>
  66. <!-- 弹出层消息 -->
  67. <tm-message ref="toast"></tm-message>
  68. </view>
  69. </template>
  70. <script>
  71. import{myRequest} from '@/api/request.js'
  72. import { pathToBase64, base64ToPath } from '@/js_sdk/mmmm-image-tools/index.js'
  73. export default {
  74. data() {
  75. return {
  76. koutu:'/static/img/53.png',
  77. active:1,
  78. category_arr:[],
  79. category_danarr:[],
  80. size_arr:[
  81. {title:"S",id:1},
  82. {title:"M",id:2},
  83. {title:"L",id:3},
  84. {title:"XL",id:4},
  85. {title:"XXL",id:5},
  86. {title:"其他",id:6},
  87. ],
  88. size_danarr:[],
  89. role_arr:[],
  90. role_danarr:[],
  91. reqData:{
  92. goods_name:'',
  93. category_id:'',
  94. year:'',
  95. color:'',
  96. image:'',
  97. type:'',
  98. thumb:'',
  99. size:'',
  100. brand:'',
  101. science:'',
  102. role_id:''
  103. },
  104. };
  105. },
  106. onLoad() {
  107. },
  108. created() {
  109. this.sys = uni.getSystemInfoSync();
  110. this.getFl();
  111. this.getCY();
  112. },
  113. methods: {
  114. getFl(){
  115. var that=this;
  116. myRequest({
  117. url: "/api/Category/list",
  118. method:'post',
  119. data:{}
  120. }).then(res => {
  121. console.log(res.data)
  122. if (res.data.code == 200) {
  123. this.category_arr=res.data.data;
  124. }else{
  125. that.category_arr=[];
  126. }
  127. })
  128. },
  129. getCY(){
  130. var that=this;
  131. myRequest({
  132. url: "/api/MemberInfo/getFamilyMember",
  133. method:'post',
  134. data:{family_id:uni.getStorageSync("family_id")}
  135. }).then(res => {
  136. if (res.data.code == 200) {
  137. that.role_arr=res.data.data;
  138. }else{
  139. that.role_arr=[];
  140. }
  141. })
  142. },
  143. obTstr1(o){
  144. if(Array.isArray(o)){
  145. if(o.length.length===0) return "";
  146. return o[0]?.category_name??""
  147. }
  148. return ''
  149. },
  150. obTstr2(o){
  151. if(Array.isArray(o)){
  152. if(o.length.length===0) return "";
  153. return o[0]?.title??""
  154. }
  155. return ''
  156. },
  157. obTstr3(o){
  158. if(Array.isArray(o)){
  159. if(o.length.length===0) return "";
  160. return o[0]?.username??""
  161. }
  162. return ''
  163. },
  164. jixu(){
  165. this.active=1;
  166. },
  167. quindex(){
  168. uni.navigateTo({
  169. url: "/pages/index/index?index=1",
  170. })
  171. },
  172. paizhao(){
  173. var that=this;
  174. uni.chooseImage({ //uni官方api,用于选取本地图片
  175. count: 1, //默认9
  176. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  177. sourceType: ['album','camera'], //从相册选择
  178. success: function (res) {
  179. that.imgpath = res.tempFilePaths[0] //先获得本地文件的路径列表,存储到数组
  180. console.log(that.imgpath) //注意该api会将路径转换为blob格式
  181. that.getBase64Image(that.imgpath);
  182. }
  183. })
  184. },
  185. getBase64Image(path){
  186. var that=this;
  187. console.log(" 开始转换")
  188. pathToBase64(path)
  189. .then(base64 => {
  190. that.shibie(base64)
  191. })
  192. .catch(error => {
  193. console.error(error)
  194. })
  195. },
  196. shibie(src){
  197. var that=this;
  198. // 抠图
  199. uni.request({
  200. url: 'https://objseg.market.alicloudapi.com/commonseg/rgba',
  201. method : "post",
  202. header: {
  203. 'Authorization':'APPCODE a4a922a41afa43a0bbca6c831a13bf43',
  204. "Content-Type":"application/json;charset=UTF-8"
  205. },
  206. data:{
  207. photo:src
  208. },
  209. success : function(data) {
  210. that.koutu=data.data.data.result;
  211. that.active=2;
  212. },
  213. error : function(e) {
  214. that.$refs.toast.show({model:'error',label:"网络异常,请重试"})
  215. }
  216. });
  217. },
  218. chuangjianFun(){
  219. var that=this;
  220. if(that.reqData.goods_name==""){
  221. that.$refs.toast.show({model:'warn',label:'请输入商品名称'})
  222. return
  223. }
  224. if(that.category_danarr.length==0){
  225. that.$refs.toast.show({model:'warn',label:'请选择分类'})
  226. return
  227. }else{
  228. that.reqData.category_id=that.category_danarr[0].id
  229. }
  230. if(that.role_danarr.length==0){
  231. that.$refs.toast.show({model:'warn',label:'请选择成员'})
  232. return
  233. }else{
  234. that.reqData.role_id=that.role_danarr[0].id
  235. }
  236. if(that.size_danarr.length!=0){
  237. that.reqData.size=that.size_danarr[0].id
  238. }
  239. that.reqData.image=that.koutu;
  240. that.reqData.thumb=that.koutu;
  241. myRequest({
  242. url: "/api/Goods/addGodds",
  243. method:'post',
  244. data:that.reqData
  245. }).then(res => {
  246. console.log(res.data)
  247. if (res.data.code == 200) {
  248. that.active=3;
  249. }else{
  250. that.$refs.toast.show({model:'error',label:res.data.msg})
  251. }
  252. })
  253. }
  254. },
  255. }
  256. </script>
  257. <style lang="scss">
  258. .zhanshi{
  259. width: 100%;
  260. margin: 0 auto;
  261. margin-top: 10px;
  262. margin-bottom: 40px;
  263. }
  264. /deep/ .tm-menubars .body{
  265. background-color: #1b1b1b !important;
  266. }
  267. /deep/ .kuang{margin:0 !important;padding: 14px !important;margin-bottom: 40px !important;}
  268. // /deep/ .kuang uni-button{background-color: #303440 !important;}
  269. .jindu{width: 90%;margin: 0 auto;display: block;}
  270. .wenzi{width: 94%;margin: 0 auto;}
  271. .nicheng{width: 60%;display: block;margin:0 auto;margin-top: 50px;}
  272. /deep/ .shuru .grey-darken-5{
  273. background-color: #0d0d0d!important;
  274. padding: 0px !important;
  275. }
  276. .shuru{border:1px solid #303030;border-radius: 10px;}
  277. /deep/ .shuru .text-primary.bk{color:#303030 !important;}
  278. /deep/ .shuru .border-grey-darken-4-b-1{border-bottom:none !important;}
  279. .zuo image{width:60px;display: block;}
  280. .you{border:1px solid #303030;border-radius: 10px;padding:10px;}
  281. /deep/ .you .grey-darken-5{
  282. background-color: #0d0d0d!important;
  283. padding: 0px !important;
  284. }
  285. /deep/ .you .text-red{color: white;}
  286. /deep/ .tan .active{background-color: #AAAAAA !important;}
  287. /deep/ .tan .tm-poups .grey-darken-5{background-color: gray !important;}
  288. /deep/ .tan uni-input{text-align: right;}
  289. /deep/ .you .border-grey-darken-4-b-1 {
  290. border-bottom: solid 1px #313131 !important;
  291. }
  292. /deep/ .tm--badges{position: absolute;top: 0px;right:6px}
  293. .logincla{margin-top: 100px;}
  294. /deep/ .logincla .primary{background-color: #303440 !important;}
  295. /deep/ .quindex uni-button{background-color: #0A84FF !important;}
  296. </style>